Enforce all OperandKind have documentation
This commit is contained in:
@@ -130,19 +130,15 @@ impl OperandKind {
|
||||
rust_field_name: &'static str,
|
||||
rust_type: &'static str,
|
||||
fields: OperandKindFields,
|
||||
doc: &'static str,
|
||||
) -> Self {
|
||||
Self {
|
||||
rust_field_name,
|
||||
rust_type,
|
||||
fields,
|
||||
doc: None,
|
||||
doc: Some(doc),
|
||||
}
|
||||
}
|
||||
pub fn with_doc(mut self, doc: &'static str) -> Self {
|
||||
assert!(self.doc.is_none());
|
||||
self.doc = Some(doc);
|
||||
self
|
||||
}
|
||||
fn doc(&self) -> Option<&str> {
|
||||
if let Some(doc) = &self.doc {
|
||||
return Some(doc);
|
||||
@@ -152,18 +148,19 @@ impl OperandKind {
|
||||
OperandKindFields::ImmEnum(_)
|
||||
| OperandKindFields::ImmValue
|
||||
| OperandKindFields::EntityRef
|
||||
| OperandKindFields::VariableArgs => None,
|
||||
| OperandKindFields::VariableArgs => unreachable!(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Into<OperandKind> for &TypeVar {
|
||||
fn into(self) -> OperandKind {
|
||||
OperandKind::new(
|
||||
"value",
|
||||
"ir::Value",
|
||||
OperandKindFields::TypeVar(self.into()),
|
||||
)
|
||||
OperandKind {
|
||||
rust_field_name: "value",
|
||||
rust_type: "ir::Value",
|
||||
fields: OperandKindFields::TypeVar(self.into()),
|
||||
doc: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
impl Into<OperandKind> for &OperandKind {
|
||||
|
||||
@@ -2,7 +2,12 @@ use crate::cdsl::operands::{OperandKind, OperandKindFields};
|
||||
|
||||
/// Small helper to initialize an OperandBuilder with the right kind, for a given name and doc.
|
||||
fn new(format_field_name: &'static str, rust_type: &'static str, doc: &'static str) -> OperandKind {
|
||||
OperandKind::new(format_field_name, rust_type, OperandKindFields::EntityRef).with_doc(doc)
|
||||
OperandKind::new(
|
||||
format_field_name,
|
||||
rust_type,
|
||||
OperandKindFields::EntityRef,
|
||||
doc,
|
||||
)
|
||||
}
|
||||
|
||||
pub(crate) struct EntityRefs {
|
||||
@@ -59,7 +64,10 @@ impl EntityRefs {
|
||||
|
||||
table: new("table", "ir::Table", "A table."),
|
||||
|
||||
varargs: OperandKind::new("", "&[Value]", OperandKindFields::VariableArgs).with_doc(
|
||||
varargs: OperandKind::new(
|
||||
"",
|
||||
"&[Value]",
|
||||
OperandKindFields::VariableArgs,
|
||||
r#"
|
||||
A variable size list of `value` operands.
|
||||
|
||||
|
||||
@@ -73,40 +73,76 @@ pub(crate) struct Immediates {
|
||||
pub atomic_rmw_op: OperandKind,
|
||||
}
|
||||
|
||||
fn new_imm(format_field_name: &'static str, rust_type: &'static str) -> OperandKind {
|
||||
OperandKind::new(format_field_name, rust_type, OperandKindFields::ImmValue)
|
||||
fn new_imm(
|
||||
format_field_name: &'static str,
|
||||
rust_type: &'static str,
|
||||
doc: &'static str,
|
||||
) -> OperandKind {
|
||||
OperandKind::new(
|
||||
format_field_name,
|
||||
rust_type,
|
||||
OperandKindFields::ImmValue,
|
||||
doc,
|
||||
)
|
||||
}
|
||||
fn new_enum(
|
||||
format_field_name: &'static str,
|
||||
rust_type: &'static str,
|
||||
values: EnumValues,
|
||||
doc: &'static str,
|
||||
) -> OperandKind {
|
||||
OperandKind::new(
|
||||
format_field_name,
|
||||
rust_type,
|
||||
OperandKindFields::ImmEnum(values),
|
||||
doc,
|
||||
)
|
||||
}
|
||||
|
||||
impl Immediates {
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
imm64: new_imm("imm", "ir::immediates::Imm64").with_doc("A 64-bit immediate integer."),
|
||||
uimm8: new_imm("imm", "ir::immediates::Uimm8")
|
||||
.with_doc("An 8-bit immediate unsigned integer."),
|
||||
uimm32: new_imm("imm", "ir::immediates::Uimm32")
|
||||
.with_doc("A 32-bit immediate unsigned integer."),
|
||||
uimm128: new_imm("imm", "ir::Immediate")
|
||||
.with_doc("A 128-bit immediate unsigned integer."),
|
||||
pool_constant: new_imm("constant_handle", "ir::Constant")
|
||||
.with_doc("A constant stored in the constant pool."),
|
||||
offset32: new_imm("offset", "ir::immediates::Offset32")
|
||||
.with_doc("A 32-bit immediate signed offset."),
|
||||
ieee32: new_imm("imm", "ir::immediates::Ieee32")
|
||||
.with_doc("A 32-bit immediate floating point number."),
|
||||
ieee64: new_imm("imm", "ir::immediates::Ieee64")
|
||||
.with_doc("A 64-bit immediate floating point number."),
|
||||
boolean: new_imm("imm", "bool").with_doc("An immediate boolean."),
|
||||
imm64: new_imm(
|
||||
"imm",
|
||||
"ir::immediates::Imm64",
|
||||
"A 64-bit immediate integer.",
|
||||
),
|
||||
uimm8: new_imm(
|
||||
"imm",
|
||||
"ir::immediates::Uimm8",
|
||||
"An 8-bit immediate unsigned integer.",
|
||||
),
|
||||
uimm32: new_imm(
|
||||
"imm",
|
||||
"ir::immediates::Uimm32",
|
||||
"A 32-bit immediate unsigned integer.",
|
||||
),
|
||||
uimm128: new_imm(
|
||||
"imm",
|
||||
"ir::Immediate",
|
||||
"A 128-bit immediate unsigned integer.",
|
||||
),
|
||||
pool_constant: new_imm(
|
||||
"constant_handle",
|
||||
"ir::Constant",
|
||||
"A constant stored in the constant pool.",
|
||||
),
|
||||
offset32: new_imm(
|
||||
"offset",
|
||||
"ir::immediates::Offset32",
|
||||
"A 32-bit immediate signed offset.",
|
||||
),
|
||||
ieee32: new_imm(
|
||||
"imm",
|
||||
"ir::immediates::Ieee32",
|
||||
"A 32-bit immediate floating point number.",
|
||||
),
|
||||
ieee64: new_imm(
|
||||
"imm",
|
||||
"ir::immediates::Ieee64",
|
||||
"A 64-bit immediate floating point number.",
|
||||
),
|
||||
boolean: new_imm("imm", "bool", "An immediate boolean."),
|
||||
intcc: {
|
||||
let mut intcc_values = HashMap::new();
|
||||
intcc_values.insert("eq", "Equal");
|
||||
@@ -121,8 +157,12 @@ impl Immediates {
|
||||
intcc_values.insert("ult", "UnsignedLessThan");
|
||||
intcc_values.insert("of", "Overflow");
|
||||
intcc_values.insert("nof", "NotOverflow");
|
||||
new_enum("cond", "ir::condcodes::IntCC", intcc_values)
|
||||
.with_doc("An integer comparison condition code.")
|
||||
new_enum(
|
||||
"cond",
|
||||
"ir::condcodes::IntCC",
|
||||
intcc_values,
|
||||
"An integer comparison condition code.",
|
||||
)
|
||||
},
|
||||
|
||||
floatcc: {
|
||||
@@ -141,18 +181,27 @@ impl Immediates {
|
||||
floatcc_values.insert("ule", "UnorderedOrLessThanOrEqual");
|
||||
floatcc_values.insert("ugt", "UnorderedOrGreaterThan");
|
||||
floatcc_values.insert("uge", "UnorderedOrGreaterThanOrEqual");
|
||||
new_enum("cond", "ir::condcodes::FloatCC", floatcc_values)
|
||||
.with_doc("A floating point comparison condition code")
|
||||
new_enum(
|
||||
"cond",
|
||||
"ir::condcodes::FloatCC",
|
||||
floatcc_values,
|
||||
"A floating point comparison condition code",
|
||||
)
|
||||
},
|
||||
|
||||
memflags: new_imm("flags", "ir::MemFlags").with_doc("Memory operation flags"),
|
||||
memflags: new_imm("flags", "ir::MemFlags", "Memory operation flags"),
|
||||
trapcode: {
|
||||
let mut trapcode_values = HashMap::new();
|
||||
trapcode_values.insert("stk_ovf", "StackOverflow");
|
||||
trapcode_values.insert("heap_oob", "HeapOutOfBounds");
|
||||
trapcode_values.insert("int_ovf", "IntegerOverflow");
|
||||
trapcode_values.insert("int_divz", "IntegerDivisionByZero");
|
||||
new_enum("code", "ir::TrapCode", trapcode_values).with_doc("A trap reason code.")
|
||||
new_enum(
|
||||
"code",
|
||||
"ir::TrapCode",
|
||||
trapcode_values,
|
||||
"A trap reason code.",
|
||||
)
|
||||
},
|
||||
atomic_rmw_op: {
|
||||
let mut atomic_rmw_op_values = HashMap::new();
|
||||
@@ -167,8 +216,12 @@ impl Immediates {
|
||||
atomic_rmw_op_values.insert("umax", "Umax");
|
||||
atomic_rmw_op_values.insert("smin", "Smin");
|
||||
atomic_rmw_op_values.insert("smax", "Smax");
|
||||
new_enum("op", "ir::AtomicRmwOp", atomic_rmw_op_values)
|
||||
.with_doc("Atomic Read-Modify-Write Ops")
|
||||
new_enum(
|
||||
"op",
|
||||
"ir::AtomicRmwOp",
|
||||
atomic_rmw_op_values,
|
||||
"Atomic Read-Modify-Write Ops",
|
||||
)
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user