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