[meta] Remove the OperandKindBuilder;
And replace it by constructors in OperandKind. There's a single optional parameter function `set_doc` that remains, and didn't justify the whole OperandKindBuilder concept to exist.
This commit is contained in:
@@ -49,6 +49,7 @@ pub(crate) struct InstructionFormat {
|
||||
pub(crate) struct FormatStructure {
|
||||
pub num_value_operands: usize,
|
||||
pub has_value_list: bool,
|
||||
/// Tuples of (Rust field name / Rust type) for each immediate field.
|
||||
pub imm_field_names: Vec<(&'static str, &'static str)>,
|
||||
}
|
||||
|
||||
|
||||
@@ -1296,7 +1296,7 @@ impl Into<InstSpec> for BoundInstruction {
|
||||
mod test {
|
||||
use super::*;
|
||||
use crate::cdsl::formats::InstructionFormatBuilder;
|
||||
use crate::cdsl::operands::{OperandKindBuilder, OperandKindFields};
|
||||
use crate::cdsl::operands::{OperandKind, OperandKindFields};
|
||||
use crate::cdsl::typevar::TypeSetBuilder;
|
||||
use crate::shared::types::Int::{I32, I64};
|
||||
|
||||
@@ -1304,7 +1304,7 @@ mod test {
|
||||
// Pretend the index string is &'static.
|
||||
let name = Box::leak(index.to_string().into_boxed_str());
|
||||
// Format's name / rust_type don't matter here.
|
||||
let kind = OperandKindBuilder::new(name, name, field).build();
|
||||
let kind = OperandKind::new(name, name, field);
|
||||
let operand = Operand::new(name, kind);
|
||||
operand
|
||||
}
|
||||
|
||||
@@ -100,7 +100,7 @@ impl Operand {
|
||||
}
|
||||
}
|
||||
|
||||
type EnumValues = HashMap<&'static str, &'static str>;
|
||||
pub type EnumValues = HashMap<&'static str, &'static str>;
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub(crate) enum OperandKindFields {
|
||||
@@ -126,6 +126,23 @@ pub(crate) struct OperandKind {
|
||||
}
|
||||
|
||||
impl OperandKind {
|
||||
pub fn new(
|
||||
rust_field_name: &'static str,
|
||||
rust_type: &'static str,
|
||||
fields: OperandKindFields,
|
||||
) -> Self {
|
||||
Self {
|
||||
rust_field_name,
|
||||
rust_type,
|
||||
fields,
|
||||
doc: None,
|
||||
}
|
||||
}
|
||||
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);
|
||||
@@ -142,12 +159,11 @@ impl OperandKind {
|
||||
|
||||
impl Into<OperandKind> for &TypeVar {
|
||||
fn into(self) -> OperandKind {
|
||||
OperandKindBuilder::new(
|
||||
OperandKind::new(
|
||||
"value",
|
||||
"ir::Value",
|
||||
OperandKindFields::TypeVar(self.into()),
|
||||
)
|
||||
.build()
|
||||
}
|
||||
}
|
||||
impl Into<OperandKind> for &OperandKind {
|
||||
@@ -155,58 +171,3 @@ impl Into<OperandKind> for &OperandKind {
|
||||
self.clone()
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) struct OperandKindBuilder {
|
||||
rust_field_name: &'static str,
|
||||
rust_type: &'static str,
|
||||
fields: OperandKindFields,
|
||||
doc: Option<&'static str>,
|
||||
}
|
||||
|
||||
impl OperandKindBuilder {
|
||||
pub fn new(
|
||||
rust_field_name: &'static str,
|
||||
rust_type: &'static str,
|
||||
fields: OperandKindFields,
|
||||
) -> Self {
|
||||
Self {
|
||||
rust_field_name,
|
||||
rust_type,
|
||||
fields,
|
||||
doc: None,
|
||||
}
|
||||
}
|
||||
pub fn new_imm(rust_field_name: &'static str, rust_type: &'static str) -> Self {
|
||||
Self {
|
||||
rust_field_name,
|
||||
rust_type,
|
||||
fields: OperandKindFields::ImmValue,
|
||||
doc: None,
|
||||
}
|
||||
}
|
||||
pub fn new_enum(
|
||||
rust_field_name: &'static str,
|
||||
rust_type: &'static str,
|
||||
values: EnumValues,
|
||||
) -> Self {
|
||||
Self {
|
||||
rust_field_name,
|
||||
rust_type,
|
||||
fields: OperandKindFields::ImmEnum(values),
|
||||
doc: None,
|
||||
}
|
||||
}
|
||||
pub fn with_doc(mut self, doc: &'static str) -> Self {
|
||||
assert!(self.doc.is_none());
|
||||
self.doc = Some(doc);
|
||||
self
|
||||
}
|
||||
pub fn build(self) -> OperandKind {
|
||||
OperandKind {
|
||||
rust_type: self.rust_type,
|
||||
fields: self.fields,
|
||||
rust_field_name: self.rust_field_name,
|
||||
doc: self.doc,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user