[meta] Introduce the EntityRefs structure instead of using dynamic lookup;
This commit is contained in:
@@ -1,54 +1,61 @@
|
|||||||
use crate::cdsl::operands::{OperandKind, OperandKindBuilder as Builder, OperandKindFields};
|
use crate::cdsl::operands::{OperandKind, OperandKindBuilder as Builder, OperandKindFields};
|
||||||
|
|
||||||
/// Small helper to initialize an OperandBuilder with the right kind, for a given name and doc.
|
pub struct EntityRefs {
|
||||||
fn create(name: &'static str, doc: &'static str) -> Builder {
|
/// A reference to an extended basic block in the same function.
|
||||||
Builder::new(name, OperandKindFields::EntityRef).doc(doc)
|
/// This is primarliy used in control flow instructions.
|
||||||
|
pub ebb: OperandKind,
|
||||||
|
|
||||||
|
/// A reference to a stack slot declared in the function preamble.
|
||||||
|
pub stack_slot: OperandKind,
|
||||||
|
|
||||||
|
/// A reference to a global value.
|
||||||
|
pub global_value: OperandKind,
|
||||||
|
|
||||||
|
/// A reference to a function signature declared in the function preamble.
|
||||||
|
/// This is used to provide the call signature in a call_indirect instruction.
|
||||||
|
pub sig_ref: OperandKind,
|
||||||
|
|
||||||
|
/// A reference to an external function declared in the function preamble.
|
||||||
|
/// This is used to provide the callee and signature in a call instruction.
|
||||||
|
pub func_ref: OperandKind,
|
||||||
|
|
||||||
|
/// A reference to a jump table declared in the function preamble.
|
||||||
|
pub jump_table: OperandKind,
|
||||||
|
|
||||||
|
/// A reference to a heap declared in the function preamble.
|
||||||
|
pub heap: OperandKind,
|
||||||
|
|
||||||
|
/// A reference to a table declared in the function preamble.
|
||||||
|
pub table: OperandKind,
|
||||||
|
|
||||||
|
/// A variable-sized list of value operands. Use for Ebb and function call arguments.
|
||||||
|
pub varargs: OperandKind,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn define() -> Vec<OperandKind> {
|
impl EntityRefs {
|
||||||
let mut kinds = Vec::new();
|
pub fn new() -> Self {
|
||||||
|
Self {
|
||||||
// A reference to an extended basic block in the same function.
|
ebb: create("ebb", "An extended basic block in the same function.")
|
||||||
// This is primarliy used in control flow instructions.
|
|
||||||
let ebb = create("ebb", "An extended basic block in the same function.")
|
|
||||||
.default_member("destination")
|
.default_member("destination")
|
||||||
.build();
|
.build(),
|
||||||
kinds.push(ebb);
|
|
||||||
|
|
||||||
// A reference to a stack slot declared in the function preamble.
|
stack_slot: create("stack_slot", "A stack slot").build(),
|
||||||
let stack_slot = create("stack_slot", "A stack slot").build();
|
|
||||||
kinds.push(stack_slot);
|
|
||||||
|
|
||||||
// A reference to a global value.
|
global_value: create("global_value", "A global value.").build(),
|
||||||
let global_value = create("global_value", "A global value.").build();
|
|
||||||
kinds.push(global_value);
|
|
||||||
|
|
||||||
// A reference to a function signature declared in the function preamble.
|
sig_ref: create("sig_ref", "A function signature.").build(),
|
||||||
// This is used to provide the call signature in a call_indirect instruction.
|
|
||||||
let sig_ref = create("sig_ref", "A function signature.").build();
|
|
||||||
kinds.push(sig_ref);
|
|
||||||
|
|
||||||
// A reference to an external function declared in the function preamble.
|
func_ref: create("func_ref", "An external function.").build(),
|
||||||
// This is used to provide the callee and signature in a call instruction.
|
|
||||||
let func_ref = create("func_ref", "An external function.").build();
|
|
||||||
kinds.push(func_ref);
|
|
||||||
|
|
||||||
// A reference to a jump table declared in the function preamble.
|
jump_table: create("jump_table", "A jump table.")
|
||||||
let jump_table = create("jump_table", "A jump table.")
|
|
||||||
.default_member("table")
|
.default_member("table")
|
||||||
.build();
|
.build(),
|
||||||
kinds.push(jump_table);
|
|
||||||
|
|
||||||
// A reference to a heap declared in the function preamble.
|
heap: create("heap", "A heap.").build(),
|
||||||
let heap = create("heap", "A heap.").build();
|
|
||||||
kinds.push(heap);
|
|
||||||
|
|
||||||
// A reference to a table declared in the function preamble.
|
table: create("table", "A table.").build(),
|
||||||
let table = create("table", "A table.").build();
|
|
||||||
kinds.push(table);
|
|
||||||
|
|
||||||
// A variable-sized list of value operands. Use for Ebb and function call arguments.
|
varargs: Builder::new("variable_args", OperandKindFields::VariableArgs)
|
||||||
let varargs = Builder::new("variable_args", OperandKindFields::VariableArgs)
|
|
||||||
.doc(
|
.doc(
|
||||||
r#"
|
r#"
|
||||||
A variable size list of `value` operands.
|
A variable size list of `value` operands.
|
||||||
@@ -58,8 +65,12 @@ pub fn define() -> Vec<OperandKind> {
|
|||||||
returned from an instruction.
|
returned from an instruction.
|
||||||
"#,
|
"#,
|
||||||
)
|
)
|
||||||
.build();
|
.build(),
|
||||||
kinds.push(varargs);
|
}
|
||||||
|
}
|
||||||
return kinds;
|
}
|
||||||
|
|
||||||
|
/// Small helper to initialize an OperandBuilder with the right kind, for a given name and doc.
|
||||||
|
fn create(name: &'static str, doc: &'static str) -> Builder {
|
||||||
|
Builder::new(name, OperandKindFields::EntityRef).doc(doc)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,18 +1,7 @@
|
|||||||
use crate::cdsl::formats::{FormatRegistry, InstructionFormatBuilder as Builder};
|
use crate::cdsl::formats::{FormatRegistry, InstructionFormatBuilder as Builder};
|
||||||
use crate::shared::immediates::Immediates;
|
use crate::shared::{entities::EntityRefs, immediates::Immediates};
|
||||||
use crate::shared::OperandKinds;
|
|
||||||
|
|
||||||
pub fn define(imm: &Immediates, entities: &OperandKinds) -> FormatRegistry {
|
|
||||||
// Shorthands for entities.
|
|
||||||
let global_value = entities.by_name("global_value");
|
|
||||||
let ebb = entities.by_name("ebb");
|
|
||||||
let jump_table = entities.by_name("jump_table");
|
|
||||||
let func_ref = entities.by_name("func_ref");
|
|
||||||
let sig_ref = entities.by_name("sig_ref");
|
|
||||||
let stack_slot = entities.by_name("stack_slot");
|
|
||||||
let heap = entities.by_name("heap");
|
|
||||||
let table = entities.by_name("table");
|
|
||||||
|
|
||||||
|
pub fn define(imm: &Immediates, entities: &EntityRefs) -> FormatRegistry {
|
||||||
let mut registry = FormatRegistry::new();
|
let mut registry = FormatRegistry::new();
|
||||||
|
|
||||||
registry.insert(Builder::new("Unary").value());
|
registry.insert(Builder::new("Unary").value());
|
||||||
@@ -21,7 +10,7 @@ pub fn define(imm: &Immediates, entities: &OperandKinds) -> FormatRegistry {
|
|||||||
registry.insert(Builder::new("UnaryIeee32").imm(&imm.ieee32));
|
registry.insert(Builder::new("UnaryIeee32").imm(&imm.ieee32));
|
||||||
registry.insert(Builder::new("UnaryIeee64").imm(&imm.ieee64));
|
registry.insert(Builder::new("UnaryIeee64").imm(&imm.ieee64));
|
||||||
registry.insert(Builder::new("UnaryBool").imm(&imm.boolean));
|
registry.insert(Builder::new("UnaryBool").imm(&imm.boolean));
|
||||||
registry.insert(Builder::new("UnaryGlobalValue").imm(global_value));
|
registry.insert(Builder::new("UnaryGlobalValue").imm(&entities.global_value));
|
||||||
|
|
||||||
registry.insert(Builder::new("Binary").value().value());
|
registry.insert(Builder::new("Binary").value().value());
|
||||||
registry.insert(Builder::new("BinaryImm").value().imm(&imm.imm64));
|
registry.insert(Builder::new("BinaryImm").value().imm(&imm.imm64));
|
||||||
@@ -80,20 +69,20 @@ pub fn define(imm: &Immediates, entities: &OperandKinds) -> FormatRegistry {
|
|||||||
.value(),
|
.value(),
|
||||||
);
|
);
|
||||||
|
|
||||||
registry.insert(Builder::new("Jump").imm(ebb).varargs());
|
registry.insert(Builder::new("Jump").imm(&entities.ebb).varargs());
|
||||||
registry.insert(Builder::new("Branch").value().imm(ebb).varargs());
|
registry.insert(Builder::new("Branch").value().imm(&entities.ebb).varargs());
|
||||||
registry.insert(
|
registry.insert(
|
||||||
Builder::new("BranchInt")
|
Builder::new("BranchInt")
|
||||||
.imm(&imm.intcc)
|
.imm(&imm.intcc)
|
||||||
.value()
|
.value()
|
||||||
.imm(ebb)
|
.imm(&entities.ebb)
|
||||||
.varargs(),
|
.varargs(),
|
||||||
);
|
);
|
||||||
registry.insert(
|
registry.insert(
|
||||||
Builder::new("BranchFloat")
|
Builder::new("BranchFloat")
|
||||||
.imm(&imm.floatcc)
|
.imm(&imm.floatcc)
|
||||||
.value()
|
.value()
|
||||||
.imm(ebb)
|
.imm(&entities.ebb)
|
||||||
.varargs(),
|
.varargs(),
|
||||||
);
|
);
|
||||||
registry.insert(
|
registry.insert(
|
||||||
@@ -101,23 +90,37 @@ pub fn define(imm: &Immediates, entities: &OperandKinds) -> FormatRegistry {
|
|||||||
.imm(&imm.intcc)
|
.imm(&imm.intcc)
|
||||||
.value()
|
.value()
|
||||||
.value()
|
.value()
|
||||||
.imm(ebb)
|
.imm(&entities.ebb)
|
||||||
.varargs(),
|
.varargs(),
|
||||||
);
|
);
|
||||||
registry.insert(Builder::new("BranchTable").value().imm(ebb).imm(jump_table));
|
registry.insert(
|
||||||
|
Builder::new("BranchTable")
|
||||||
|
.value()
|
||||||
|
.imm(&entities.ebb)
|
||||||
|
.imm(&entities.jump_table),
|
||||||
|
);
|
||||||
registry.insert(
|
registry.insert(
|
||||||
Builder::new("BranchTableEntry")
|
Builder::new("BranchTableEntry")
|
||||||
.value()
|
.value()
|
||||||
.value()
|
.value()
|
||||||
.imm(&imm.uimm8)
|
.imm(&imm.uimm8)
|
||||||
.imm(jump_table),
|
.imm(&entities.jump_table),
|
||||||
|
);
|
||||||
|
registry.insert(Builder::new("BranchTableBase").imm(&entities.jump_table));
|
||||||
|
registry.insert(
|
||||||
|
Builder::new("IndirectJump")
|
||||||
|
.value()
|
||||||
|
.imm(&entities.jump_table),
|
||||||
);
|
);
|
||||||
registry.insert(Builder::new("BranchTableBase").imm(jump_table));
|
|
||||||
registry.insert(Builder::new("IndirectJump").value().imm(jump_table));
|
|
||||||
|
|
||||||
registry.insert(Builder::new("Call").imm(func_ref).varargs());
|
registry.insert(Builder::new("Call").imm(&entities.func_ref).varargs());
|
||||||
registry.insert(Builder::new("CallIndirect").imm(sig_ref).value().varargs());
|
registry.insert(
|
||||||
registry.insert(Builder::new("FuncAddr").imm(func_ref));
|
Builder::new("CallIndirect")
|
||||||
|
.imm(&entities.sig_ref)
|
||||||
|
.value()
|
||||||
|
.varargs(),
|
||||||
|
);
|
||||||
|
registry.insert(Builder::new("FuncAddr").imm(&entities.func_ref));
|
||||||
|
|
||||||
registry.insert(
|
registry.insert(
|
||||||
Builder::new("Load")
|
Builder::new("Load")
|
||||||
@@ -145,21 +148,30 @@ pub fn define(imm: &Immediates, entities: &OperandKinds) -> FormatRegistry {
|
|||||||
.varargs()
|
.varargs()
|
||||||
.imm(&imm.offset32),
|
.imm(&imm.offset32),
|
||||||
);
|
);
|
||||||
registry.insert(Builder::new("StackLoad").imm(stack_slot).imm(&imm.offset32));
|
registry.insert(
|
||||||
|
Builder::new("StackLoad")
|
||||||
|
.imm(&entities.stack_slot)
|
||||||
|
.imm(&imm.offset32),
|
||||||
|
);
|
||||||
registry.insert(
|
registry.insert(
|
||||||
Builder::new("StackStore")
|
Builder::new("StackStore")
|
||||||
.value()
|
.value()
|
||||||
.imm(stack_slot)
|
.imm(&entities.stack_slot)
|
||||||
.imm(&imm.offset32),
|
.imm(&imm.offset32),
|
||||||
);
|
);
|
||||||
|
|
||||||
// Accessing a WebAssembly heap.
|
// Accessing a WebAssembly heap.
|
||||||
registry.insert(Builder::new("HeapAddr").imm(heap).value().imm(&imm.uimm32));
|
registry.insert(
|
||||||
|
Builder::new("HeapAddr")
|
||||||
|
.imm(&entities.heap)
|
||||||
|
.value()
|
||||||
|
.imm(&imm.uimm32),
|
||||||
|
);
|
||||||
|
|
||||||
// Accessing a WebAssembly table.
|
// Accessing a WebAssembly table.
|
||||||
registry.insert(
|
registry.insert(
|
||||||
Builder::new("TableAddr")
|
Builder::new("TableAddr")
|
||||||
.imm(table)
|
.imm(&entities.table)
|
||||||
.value()
|
.value()
|
||||||
.imm(&imm.offset32),
|
.imm(&imm.offset32),
|
||||||
);
|
);
|
||||||
@@ -180,12 +192,12 @@ pub fn define(imm: &Immediates, entities: &OperandKinds) -> FormatRegistry {
|
|||||||
Builder::new("RegSpill")
|
Builder::new("RegSpill")
|
||||||
.value()
|
.value()
|
||||||
.imm_with_name("src", &imm.regunit)
|
.imm_with_name("src", &imm.regunit)
|
||||||
.imm_with_name("dst", stack_slot),
|
.imm_with_name("dst", &entities.stack_slot),
|
||||||
);
|
);
|
||||||
registry.insert(
|
registry.insert(
|
||||||
Builder::new("RegFill")
|
Builder::new("RegFill")
|
||||||
.value()
|
.value()
|
||||||
.imm_with_name("src", stack_slot)
|
.imm_with_name("src", &entities.stack_slot)
|
||||||
.imm_with_name("dst", &imm.regunit),
|
.imm_with_name("dst", &imm.regunit),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@@ -8,14 +8,14 @@ use crate::cdsl::operands::{create_operand as operand, create_operand_doc as ope
|
|||||||
use crate::cdsl::type_inference::Constraint::WiderOrEq;
|
use crate::cdsl::type_inference::Constraint::WiderOrEq;
|
||||||
use crate::cdsl::types::{LaneType, ValueType};
|
use crate::cdsl::types::{LaneType, ValueType};
|
||||||
use crate::cdsl::typevar::{Interval, TypeSetBuilder, TypeVar};
|
use crate::cdsl::typevar::{Interval, TypeSetBuilder, TypeVar};
|
||||||
use crate::shared::immediates::Immediates;
|
use crate::shared::types;
|
||||||
use crate::shared::{types, OperandKinds};
|
use crate::shared::{entities::EntityRefs, immediates::Immediates};
|
||||||
|
|
||||||
pub fn define(
|
pub fn define(
|
||||||
all_instructions: &mut AllInstructions,
|
all_instructions: &mut AllInstructions,
|
||||||
format_registry: &FormatRegistry,
|
format_registry: &FormatRegistry,
|
||||||
imm: &Immediates,
|
imm: &Immediates,
|
||||||
entities: &OperandKinds,
|
entities: &EntityRefs,
|
||||||
) -> InstructionGroup {
|
) -> InstructionGroup {
|
||||||
let mut ig = InstructionGroupBuilder::new(
|
let mut ig = InstructionGroupBuilder::new(
|
||||||
"base",
|
"base",
|
||||||
@@ -25,16 +25,6 @@ pub fn define(
|
|||||||
);
|
);
|
||||||
|
|
||||||
// Operand kind shorthands.
|
// Operand kind shorthands.
|
||||||
let ebb = entities.by_name("ebb");
|
|
||||||
let jump_table = entities.by_name("jump_table");
|
|
||||||
let variable_args = entities.by_name("variable_args");
|
|
||||||
let func_ref = entities.by_name("func_ref");
|
|
||||||
let sig_ref = entities.by_name("sig_ref");
|
|
||||||
let stack_slot = entities.by_name("stack_slot");
|
|
||||||
let global_value = entities.by_name("global_value");
|
|
||||||
let heap = entities.by_name("heap");
|
|
||||||
let table = entities.by_name("table");
|
|
||||||
|
|
||||||
let iflags: &TypeVar = &ValueType::Special(types::Flag::IFlags.into()).into();
|
let iflags: &TypeVar = &ValueType::Special(types::Flag::IFlags.into()).into();
|
||||||
let fflags: &TypeVar = &ValueType::Special(types::Flag::FFlags.into()).into();
|
let fflags: &TypeVar = &ValueType::Special(types::Flag::FFlags.into()).into();
|
||||||
|
|
||||||
@@ -132,8 +122,8 @@ pub fn define(
|
|||||||
let Cond = &operand("Cond", &imm.intcc);
|
let Cond = &operand("Cond", &imm.intcc);
|
||||||
let x = &operand("x", iB);
|
let x = &operand("x", iB);
|
||||||
let y = &operand("y", iB);
|
let y = &operand("y", iB);
|
||||||
let EBB = &operand_doc("EBB", ebb, "Destination extended basic block");
|
let EBB = &operand_doc("EBB", &entities.ebb, "Destination extended basic block");
|
||||||
let args = &operand_doc("args", variable_args, "EBB arguments");
|
let args = &operand_doc("args", &entities.varargs, "EBB arguments");
|
||||||
|
|
||||||
ig.push(
|
ig.push(
|
||||||
Inst::new(
|
Inst::new(
|
||||||
@@ -257,7 +247,7 @@ pub fn define(
|
|||||||
// The index into the br_table can be any type; legalizer will convert it to the right type.
|
// The index into the br_table can be any type; legalizer will convert it to the right type.
|
||||||
let x = &operand_doc("x", iB, "index into jump table");
|
let x = &operand_doc("x", iB, "index into jump table");
|
||||||
let entry = &operand_doc("entry", iAddr, "entry of jump table");
|
let entry = &operand_doc("entry", iAddr, "entry of jump table");
|
||||||
let JT = &operand("JT", jump_table);
|
let JT = &operand("JT", &entities.jump_table);
|
||||||
|
|
||||||
ig.push(
|
ig.push(
|
||||||
Inst::new(
|
Inst::new(
|
||||||
@@ -433,7 +423,7 @@ pub fn define(
|
|||||||
.can_trap(true),
|
.can_trap(true),
|
||||||
);
|
);
|
||||||
|
|
||||||
let rvals = &operand_doc("rvals", variable_args, "return values");
|
let rvals = &operand_doc("rvals", &entities.varargs, "return values");
|
||||||
|
|
||||||
ig.push(
|
ig.push(
|
||||||
Inst::new(
|
Inst::new(
|
||||||
@@ -467,8 +457,12 @@ pub fn define(
|
|||||||
.is_terminator(true),
|
.is_terminator(true),
|
||||||
);
|
);
|
||||||
|
|
||||||
let FN = &operand_doc("FN", func_ref, "function to call, declared by `function`");
|
let FN = &operand_doc(
|
||||||
let args = &operand_doc("args", variable_args, "call arguments");
|
"FN",
|
||||||
|
&entities.func_ref,
|
||||||
|
"function to call, declared by `function`",
|
||||||
|
);
|
||||||
|
let args = &operand_doc("args", &entities.varargs, "call arguments");
|
||||||
|
|
||||||
ig.push(
|
ig.push(
|
||||||
Inst::new(
|
Inst::new(
|
||||||
@@ -485,7 +479,7 @@ pub fn define(
|
|||||||
.is_call(true),
|
.is_call(true),
|
||||||
);
|
);
|
||||||
|
|
||||||
let SIG = &operand_doc("SIG", sig_ref, "function signature");
|
let SIG = &operand_doc("SIG", &entities.sig_ref, "function signature");
|
||||||
let callee = &operand_doc("callee", iAddr, "address of function to call");
|
let callee = &operand_doc("callee", iAddr, "address of function to call");
|
||||||
|
|
||||||
ig.push(
|
ig.push(
|
||||||
@@ -525,13 +519,13 @@ pub fn define(
|
|||||||
.operands_out(vec![addr]),
|
.operands_out(vec![addr]),
|
||||||
);
|
);
|
||||||
|
|
||||||
let SS = &operand("SS", stack_slot);
|
let SS = &operand("SS", &entities.stack_slot);
|
||||||
let Offset = &operand_doc("Offset", &imm.offset32, "Byte offset from base address");
|
let Offset = &operand_doc("Offset", &imm.offset32, "Byte offset from base address");
|
||||||
let x = &operand_doc("x", Mem, "Value to be stored");
|
let x = &operand_doc("x", Mem, "Value to be stored");
|
||||||
let a = &operand_doc("a", Mem, "Value loaded");
|
let a = &operand_doc("a", Mem, "Value loaded");
|
||||||
let p = &operand("p", iAddr);
|
let p = &operand("p", iAddr);
|
||||||
let MemFlags = &operand("MemFlags", &imm.memflags);
|
let MemFlags = &operand("MemFlags", &imm.memflags);
|
||||||
let args = &operand_doc("args", variable_args, "Address arguments");
|
let args = &operand_doc("args", &entities.varargs, "Address arguments");
|
||||||
|
|
||||||
ig.push(
|
ig.push(
|
||||||
Inst::new(
|
Inst::new(
|
||||||
@@ -917,7 +911,7 @@ pub fn define(
|
|||||||
.operands_out(vec![addr]),
|
.operands_out(vec![addr]),
|
||||||
);
|
);
|
||||||
|
|
||||||
let GV = &operand("GV", global_value);
|
let GV = &operand("GV", &entities.global_value);
|
||||||
|
|
||||||
ig.push(
|
ig.push(
|
||||||
Inst::new(
|
Inst::new(
|
||||||
@@ -947,7 +941,7 @@ pub fn define(
|
|||||||
TypeSetBuilder::new().ints(32..64).build(),
|
TypeSetBuilder::new().ints(32..64).build(),
|
||||||
);
|
);
|
||||||
|
|
||||||
let H = &operand("H", heap);
|
let H = &operand("H", &entities.heap);
|
||||||
let p = &operand("p", HeapOffset);
|
let p = &operand("p", HeapOffset);
|
||||||
let Size = &operand_doc("Size", &imm.uimm32, "Size in bytes");
|
let Size = &operand_doc("Size", &imm.uimm32, "Size in bytes");
|
||||||
|
|
||||||
@@ -975,7 +969,7 @@ pub fn define(
|
|||||||
"An unsigned table offset",
|
"An unsigned table offset",
|
||||||
TypeSetBuilder::new().ints(32..64).build(),
|
TypeSetBuilder::new().ints(32..64).build(),
|
||||||
);
|
);
|
||||||
let T = &operand("T", table);
|
let T = &operand("T", &entities.table);
|
||||||
let p = &operand("p", TableOffset);
|
let p = &operand("p", TableOffset);
|
||||||
let Offset = &operand_doc("Offset", &imm.offset32, "Byte offset from element address");
|
let Offset = &operand_doc("Offset", &imm.offset32, "Byte offset from element address");
|
||||||
|
|
||||||
@@ -1382,7 +1376,7 @@ pub fn define(
|
|||||||
|
|
||||||
let N = &operand_doc(
|
let N = &operand_doc(
|
||||||
"args",
|
"args",
|
||||||
variable_args,
|
&entities.varargs,
|
||||||
"Variable number of args for Stackmap",
|
"Variable number of args for Stackmap",
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
//! Shared definitions for the Cranelift intermediate language.
|
//! Shared definitions for the Cranelift intermediate language.
|
||||||
|
|
||||||
pub mod entities;
|
mod entities;
|
||||||
pub mod formats;
|
pub mod formats;
|
||||||
pub mod immediates;
|
pub mod immediates;
|
||||||
pub mod instructions;
|
pub mod instructions;
|
||||||
@@ -10,10 +10,10 @@ pub mod types;
|
|||||||
|
|
||||||
use crate::cdsl::formats::FormatRegistry;
|
use crate::cdsl::formats::FormatRegistry;
|
||||||
use crate::cdsl::instructions::{AllInstructions, InstructionGroup};
|
use crate::cdsl::instructions::{AllInstructions, InstructionGroup};
|
||||||
use crate::cdsl::operands::OperandKind;
|
|
||||||
use crate::cdsl::settings::SettingGroup;
|
use crate::cdsl::settings::SettingGroup;
|
||||||
use crate::cdsl::xform::TransformGroups;
|
use crate::cdsl::xform::TransformGroups;
|
||||||
|
|
||||||
|
use crate::shared::entities::EntityRefs;
|
||||||
use crate::shared::immediates::Immediates;
|
use crate::shared::immediates::Immediates;
|
||||||
|
|
||||||
pub struct Definitions {
|
pub struct Definitions {
|
||||||
@@ -25,28 +25,11 @@ pub struct Definitions {
|
|||||||
pub transform_groups: TransformGroups,
|
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 {
|
pub fn define() -> Definitions {
|
||||||
let mut all_instructions = AllInstructions::new();
|
let mut all_instructions = AllInstructions::new();
|
||||||
|
|
||||||
let immediates = Immediates::new();
|
let immediates = Immediates::new();
|
||||||
let entities = OperandKinds(entities::define());
|
let entities = EntityRefs::new();;
|
||||||
let format_registry = formats::define(&immediates, &entities);
|
let format_registry = formats::define(&immediates, &entities);
|
||||||
let instructions = instructions::define(
|
let instructions = instructions::define(
|
||||||
&mut all_instructions,
|
&mut all_instructions,
|
||||||
|
|||||||
Reference in New Issue
Block a user