[meta] Introduce the Immediates structure instead of using dynamic lookup;
This commit is contained in:
@@ -14,11 +14,13 @@ use crate::cdsl::operands::OperandKind;
|
||||
use crate::cdsl::settings::SettingGroup;
|
||||
use crate::cdsl::xform::TransformGroups;
|
||||
|
||||
use crate::shared::immediates::Immediates;
|
||||
|
||||
pub struct Definitions {
|
||||
pub settings: SettingGroup,
|
||||
pub all_instructions: AllInstructions,
|
||||
pub instructions: InstructionGroup,
|
||||
pub operand_kinds: OperandKinds,
|
||||
pub imm: Immediates,
|
||||
pub format_registry: FormatRegistry,
|
||||
pub transform_groups: TransformGroups,
|
||||
}
|
||||
@@ -26,28 +28,12 @@ pub struct Definitions {
|
||||
pub struct OperandKinds(Vec<OperandKind>);
|
||||
|
||||
impl OperandKinds {
|
||||
pub fn new() -> Self {
|
||||
Self(Vec::new())
|
||||
}
|
||||
|
||||
pub fn by_name(&self, name: &'static str) -> &OperandKind {
|
||||
self.0
|
||||
.iter()
|
||||
.find(|op| op.name == name)
|
||||
.expect(&format!("unknown Operand name: {}", name))
|
||||
}
|
||||
|
||||
pub fn push(&mut self, operand_kind: OperandKind) {
|
||||
assert!(
|
||||
self.0
|
||||
.iter()
|
||||
.find(|existing| existing.name == operand_kind.name)
|
||||
.is_none(),
|
||||
"trying to insert operand kind '{}' for the second time",
|
||||
operand_kind.name
|
||||
);
|
||||
self.0.push(operand_kind);
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Vec<OperandKind>> for OperandKinds {
|
||||
@@ -59,7 +45,7 @@ impl From<Vec<OperandKind>> for OperandKinds {
|
||||
pub fn define() -> Definitions {
|
||||
let mut all_instructions = AllInstructions::new();
|
||||
|
||||
let immediates = OperandKinds(immediates::define());
|
||||
let immediates = Immediates::new();
|
||||
let entities = OperandKinds(entities::define());
|
||||
let format_registry = formats::define(&immediates, &entities);
|
||||
let instructions = instructions::define(
|
||||
@@ -74,7 +60,7 @@ pub fn define() -> Definitions {
|
||||
settings: settings::define(),
|
||||
all_instructions,
|
||||
instructions,
|
||||
operand_kinds: immediates,
|
||||
imm: immediates,
|
||||
format_registry,
|
||||
transform_groups,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user