cranelift_codegen_meta/shared/
entities.rs

1use crate::cdsl::operands::{OperandKind, OperandKindFields};
2
3/// Small helper to initialize an OperandBuilder with the right kind, for a given name and doc.
4fn new(format_field_name: &'static str, rust_type: &'static str, doc: &'static str) -> OperandKind {
5    OperandKind::new(format_field_name, rust_type, OperandKindFields::EntityRef).with_doc(doc)
6}
7
8pub(crate) struct EntityRefs {
9    /// A reference to an extended basic block in the same function.
10    /// This is primarliy used in control flow instructions.
11    pub(crate) ebb: OperandKind,
12
13    /// A reference to a stack slot declared in the function preamble.
14    pub(crate) stack_slot: OperandKind,
15
16    /// A reference to a global value.
17    pub(crate) global_value: OperandKind,
18
19    /// A reference to a function signature declared in the function preamble.
20    /// This is used to provide the call signature in a call_indirect instruction.
21    pub(crate) sig_ref: OperandKind,
22
23    /// A reference to an external function declared in the function preamble.
24    /// This is used to provide the callee and signature in a call instruction.
25    pub(crate) func_ref: OperandKind,
26
27    /// A reference to a jump table declared in the function preamble.
28    pub(crate) jump_table: OperandKind,
29
30    /// A reference to a heap declared in the function preamble.
31    pub(crate) heap: OperandKind,
32
33    /// A reference to a table declared in the function preamble.
34    pub(crate) table: OperandKind,
35
36    /// A variable-sized list of value operands. Use for Ebb and function call arguments.
37    pub(crate) varargs: OperandKind,
38}
39
40impl EntityRefs {
41    pub fn new() -> Self {
42        Self {
43            ebb: new(
44                "destination",
45                "ir::Ebb",
46                "An extended basic block in the same function.",
47            ),
48            stack_slot: new("stack_slot", "ir::StackSlot", "A stack slot"),
49
50            global_value: new("global_value", "ir::GlobalValue", "A global value."),
51
52            sig_ref: new("sig_ref", "ir::SigRef", "A function signature."),
53
54            func_ref: new("func_ref", "ir::FuncRef", "An external function."),
55
56            jump_table: new("table", "ir::JumpTable", "A jump table."),
57
58            heap: new("heap", "ir::Heap", "A heap."),
59
60            table: new("table", "ir::Table", "A table."),
61
62            varargs: OperandKind::new("", "&[Value]", OperandKindFields::VariableArgs).with_doc(
63                r#"
64                        A variable size list of `value` operands.
65
66                        Use this to represent arguments passed to a function call, arguments
67                        passed to an extended basic block, or a variable number of results
68                        returned from an instruction.
69                    "#,
70            ),
71        }
72    }
73}