[meta] Introduce the EntityRefs structure instead of using dynamic lookup;
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
//! Shared definitions for the Cranelift intermediate language.
|
||||
|
||||
pub mod entities;
|
||||
mod entities;
|
||||
pub mod formats;
|
||||
pub mod immediates;
|
||||
pub mod instructions;
|
||||
@@ -10,10 +10,10 @@ pub mod types;
|
||||
|
||||
use crate::cdsl::formats::FormatRegistry;
|
||||
use crate::cdsl::instructions::{AllInstructions, InstructionGroup};
|
||||
use crate::cdsl::operands::OperandKind;
|
||||
use crate::cdsl::settings::SettingGroup;
|
||||
use crate::cdsl::xform::TransformGroups;
|
||||
|
||||
use crate::shared::entities::EntityRefs;
|
||||
use crate::shared::immediates::Immediates;
|
||||
|
||||
pub struct Definitions {
|
||||
@@ -25,28 +25,11 @@ pub struct Definitions {
|
||||
pub transform_groups: TransformGroups,
|
||||
}
|
||||
|
||||
pub struct OperandKinds(Vec<OperandKind>);
|
||||
|
||||
impl OperandKinds {
|
||||
pub fn by_name(&self, name: &'static str) -> &OperandKind {
|
||||
self.0
|
||||
.iter()
|
||||
.find(|op| op.name == name)
|
||||
.expect(&format!("unknown Operand name: {}", name))
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Vec<OperandKind>> for OperandKinds {
|
||||
fn from(kinds: Vec<OperandKind>) -> Self {
|
||||
OperandKinds(kinds)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn define() -> Definitions {
|
||||
let mut all_instructions = AllInstructions::new();
|
||||
|
||||
let immediates = Immediates::new();
|
||||
let entities = OperandKinds(entities::define());
|
||||
let entities = EntityRefs::new();;
|
||||
let format_registry = formats::define(&immediates, &entities);
|
||||
let instructions = instructions::define(
|
||||
&mut all_instructions,
|
||||
|
||||
Reference in New Issue
Block a user