[meta] Rename OperandKind::default_member to format_field_name;

This commit is contained in:
Benjamin Bouvier
2019-10-29 15:41:13 +01:00
parent 4f5b0689f3
commit 0eb2dfc4a3
5 changed files with 24 additions and 24 deletions

View File

@@ -95,8 +95,8 @@ impl EncodingBuilder {
&inst.inst.format, &inst.inst.format,
immediate_operand immediate_operand
.kind .kind
.default_member() .rust_field_name()
.expect("Immediates must always have a default member name set."), .expect("Immediates must always have a field name."),
immediate_value.to_string(), immediate_value.to_string(),
); );
inst_predicate = if let Some(type_predicate) = inst_predicate { inst_predicate = if let Some(type_predicate) = inst_predicate {

View File

@@ -127,7 +127,7 @@ impl InstructionFormatBuilder {
pub fn imm(mut self, operand_kind: &OperandKind) -> Self { pub fn imm(mut self, operand_kind: &OperandKind) -> Self {
let field = FormatField { let field = FormatField {
kind: operand_kind.clone(), kind: operand_kind.clone(),
member: operand_kind.default_member().unwrap(), member: operand_kind.rust_field_name().unwrap(),
}; };
self.imm_fields.push(field); self.imm_fields.push(field);
self self

View File

@@ -112,7 +112,7 @@ pub(crate) enum OperandKindFields {
pub(crate) struct OperandKind { pub(crate) struct OperandKind {
pub name: &'static str, pub name: &'static str,
doc: Option<&'static str>, doc: Option<&'static str>,
default_member: Option<&'static str>, rust_field_name: Option<&'static str>,
/// The camel-cased name of an operand kind is also the Rust type used to represent it. /// The camel-cased name of an operand kind is also the Rust type used to represent it.
pub rust_type: String, pub rust_type: String,
pub fields: OperandKindFields, pub fields: OperandKindFields,
@@ -122,7 +122,7 @@ impl OperandKind {
fn new( fn new(
name: &'static str, name: &'static str,
doc: Option<&'static str>, doc: Option<&'static str>,
default_member: Option<&'static str>, rust_field_name: Option<&'static str>,
rust_type: Option<&'static str>, rust_type: Option<&'static str>,
fields: OperandKindFields, fields: OperandKindFields,
) -> Self { ) -> Self {
@@ -142,15 +142,15 @@ impl OperandKind {
Self { Self {
name, name,
doc, doc,
default_member, rust_field_name,
rust_type, rust_type,
fields, fields,
} }
} }
/// Name of this OperandKind in the format's member field. /// Name of this OperandKind in the format's member field.
pub fn default_member(&self) -> Option<&'static str> { pub fn rust_field_name(&self) -> Option<&'static str> {
if let Some(member) = &self.default_member { if let Some(member) = &self.rust_field_name {
return Some(member); return Some(member);
} }
match &self.fields { match &self.fields {
@@ -188,7 +188,7 @@ impl Into<OperandKind> for &OperandKind {
pub(crate) struct OperandKindBuilder { pub(crate) struct OperandKindBuilder {
name: &'static str, name: &'static str,
doc: Option<&'static str>, doc: Option<&'static str>,
default_member: Option<&'static str>, rust_field_name: Option<&'static str>,
rust_type: Option<&'static str>, rust_type: Option<&'static str>,
fields: OperandKindFields, fields: OperandKindFields,
} }
@@ -198,7 +198,7 @@ impl OperandKindBuilder {
Self { Self {
name, name,
doc: None, doc: None,
default_member: None, rust_field_name: None,
rust_type: None, rust_type: None,
fields, fields,
} }
@@ -207,7 +207,7 @@ impl OperandKindBuilder {
Self { Self {
name, name,
doc: None, doc: None,
default_member: None, rust_field_name: None,
rust_type: None, rust_type: None,
fields: OperandKindFields::ImmValue, fields: OperandKindFields::ImmValue,
} }
@@ -216,7 +216,7 @@ impl OperandKindBuilder {
Self { Self {
name, name,
doc: None, doc: None,
default_member: None, rust_field_name: None,
rust_type: None, rust_type: None,
fields: OperandKindFields::ImmEnum(values), fields: OperandKindFields::ImmEnum(values),
} }
@@ -226,9 +226,9 @@ impl OperandKindBuilder {
self.doc = Some(doc); self.doc = Some(doc);
self self
} }
pub fn default_member(mut self, default_member: &'static str) -> Self { pub fn rust_field_name(mut self, rust_field_name: &'static str) -> Self {
assert!(self.default_member.is_none()); assert!(self.rust_field_name.is_none());
self.default_member = Some(default_member); self.rust_field_name = Some(rust_field_name);
self self
} }
pub fn rust_type(mut self, rust_type: &'static str) -> Self { pub fn rust_type(mut self, rust_type: &'static str) -> Self {
@@ -240,7 +240,7 @@ impl OperandKindBuilder {
OperandKind::new( OperandKind::new(
self.name, self.name,
self.doc, self.doc,
self.default_member, self.rust_field_name,
self.rust_type, self.rust_type,
self.fields, self.fields,
) )

View File

@@ -36,7 +36,7 @@ impl EntityRefs {
pub fn new() -> Self { pub fn new() -> Self {
Self { Self {
ebb: create("ebb", "An extended basic block in the same function.") ebb: create("ebb", "An extended basic block in the same function.")
.default_member("destination") .rust_field_name("destination")
.build(), .build(),
stack_slot: create("stack_slot", "A stack slot").build(), stack_slot: create("stack_slot", "A stack slot").build(),
@@ -48,7 +48,7 @@ impl EntityRefs {
func_ref: create("func_ref", "An external function.").build(), func_ref: create("func_ref", "An external function.").build(),
jump_table: create("jump_table", "A jump table.") jump_table: create("jump_table", "A jump table.")
.default_member("table") .rust_field_name("table")
.build(), .build(),
heap: create("heap", "A heap.").build(), heap: create("heap", "A heap.").build(),

View File

@@ -95,13 +95,13 @@ impl Immediates {
pool_constant: Builder::new_imm("poolConstant") pool_constant: Builder::new_imm("poolConstant")
.doc("A constant stored in the constant pool.") .doc("A constant stored in the constant pool.")
.default_member("constant_handle") .rust_field_name("constant_handle")
.rust_type("ir::Constant") .rust_type("ir::Constant")
.build(), .build(),
offset32: Builder::new_imm("offset32") offset32: Builder::new_imm("offset32")
.doc("A 32-bit immediate signed offset.") .doc("A 32-bit immediate signed offset.")
.default_member("offset") .rust_field_name("offset")
.build(), .build(),
ieee32: Builder::new_imm("ieee32") ieee32: Builder::new_imm("ieee32")
@@ -133,7 +133,7 @@ impl Immediates {
intcc_values.insert("nof", "NotOverflow"); intcc_values.insert("nof", "NotOverflow");
Builder::new_enum("intcc", intcc_values) Builder::new_enum("intcc", intcc_values)
.doc("An integer comparison condition code.") .doc("An integer comparison condition code.")
.default_member("cond") .rust_field_name("cond")
.rust_type("ir::condcodes::IntCC") .rust_type("ir::condcodes::IntCC")
.build() .build()
}, },
@@ -156,14 +156,14 @@ impl Immediates {
floatcc_values.insert("uge", "UnorderedOrGreaterThanOrEqual"); floatcc_values.insert("uge", "UnorderedOrGreaterThanOrEqual");
Builder::new_enum("floatcc", floatcc_values) Builder::new_enum("floatcc", floatcc_values)
.doc("A floating point comparison condition code") .doc("A floating point comparison condition code")
.default_member("cond") .rust_field_name("cond")
.rust_type("ir::condcodes::FloatCC") .rust_type("ir::condcodes::FloatCC")
.build() .build()
}, },
memflags: Builder::new_imm("memflags") memflags: Builder::new_imm("memflags")
.doc("Memory operation flags") .doc("Memory operation flags")
.default_member("flags") .rust_field_name("flags")
.rust_type("ir::MemFlags") .rust_type("ir::MemFlags")
.build(), .build(),
@@ -180,7 +180,7 @@ impl Immediates {
trapcode_values.insert("int_divz", "IntegerDivisionByZero"); trapcode_values.insert("int_divz", "IntegerDivisionByZero");
Builder::new_enum("trapcode", trapcode_values) Builder::new_enum("trapcode", trapcode_values)
.doc("A trap reason code.") .doc("A trap reason code.")
.default_member("code") .rust_field_name("code")
.rust_type("ir::TrapCode") .rust_type("ir::TrapCode")
.build() .build()
}, },