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