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 dynamic_stack slot declared in the function preamble.
22     pub(crate) dynamic_stack_slot: OperandKind,
23 
24     /// A reference to a global value.
25     pub(crate) global_value: OperandKind,
26 
27     /// A reference to a function signature declared in the function preamble.
28     /// This is used to provide the call signature in a call_indirect instruction.
29     pub(crate) sig_ref: OperandKind,
30 
31     /// A reference to an external function declared in the function preamble.
32     /// This is used to provide the callee and signature in a call instruction.
33     pub(crate) func_ref: OperandKind,
34 
35     /// A reference to a jump table declared in the function preamble.
36     pub(crate) jump_table: OperandKind,
37 
38     /// A reference to a heap declared in the function preamble.
39     pub(crate) heap: OperandKind,
40 
41     /// A reference to a table declared in the function preamble.
42     pub(crate) table: OperandKind,
43 
44     /// A variable-sized list of value operands. Use for Block and function call arguments.
45     pub(crate) varargs: OperandKind,
46 }
47 
48 impl EntityRefs {
49     pub fn new() -> Self {
50         Self {
51             block: new(
52                 "destination",
53                 "ir::Block",
54                 "a basic block in the same function.",
55             ),
56             stack_slot: new("stack_slot", "ir::StackSlot", "A stack slot"),
57 
58             dynamic_stack_slot: new(
59                 "dynamic_stack_slot",
60                 "ir::DynamicStackSlot",
61                 "A dynamic stack slot",
62             ),
63 
64             global_value: new("global_value", "ir::GlobalValue", "A global value."),
65 
66             sig_ref: new("sig_ref", "ir::SigRef", "A function signature."),
67 
68             func_ref: new("func_ref", "ir::FuncRef", "An external function."),
69 
70             jump_table: new("table", "ir::JumpTable", "A jump table."),
71 
72             heap: new("heap", "ir::Heap", "A heap."),
73 
74             table: new("table", "ir::Table", "A table."),
75 
76             varargs: OperandKind::new(
77                 "",
78                 "&[Value]",
79                 OperandKindFields::VariableArgs,
80                 r#"
81                         A variable size list of `value` operands.
82 
83                         Use this to represent arguments passed to a function call, arguments
84                         passed to a basic block, or a variable number of results
85                         returned from an instruction.
86                     "#,
87             ),
88         }
89     }
90 }
91