[meta] Port Formats and Operands to the Rust crate;
This commit is contained in:
@@ -1,4 +1,55 @@
|
||||
//! Shared definitions for the Cranelift intermediate language.
|
||||
|
||||
pub mod entities;
|
||||
pub mod formats;
|
||||
pub mod immediates;
|
||||
pub mod settings;
|
||||
pub mod types;
|
||||
|
||||
use crate::cdsl::formats::FormatRegistry;
|
||||
use crate::cdsl::operands::OperandKind;
|
||||
use crate::cdsl::settings::SettingGroup;
|
||||
|
||||
pub struct Definitions {
|
||||
pub settings: SettingGroup,
|
||||
pub operand_kinds: OperandKinds,
|
||||
pub format_registry: FormatRegistry,
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn define() -> Definitions {
|
||||
let immediates = OperandKinds(immediates::define());
|
||||
let entities = OperandKinds(entities::define());
|
||||
let format_registry = formats::define(&immediates, &entities);
|
||||
Definitions {
|
||||
settings: settings::define(),
|
||||
operand_kinds: immediates,
|
||||
format_registry,
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user