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 reference to a table declared in the function preamble.
47     pub(crate) table: OperandKind,
48 
49     /// A variable-sized list of value operands. Use for Block and function call arguments.
50     pub(crate) varargs: OperandKind,
51 }
52 
53 impl EntityRefs {
54     pub fn new() -> Self {
55         Self {
56             block_call: new(
57                 "destination",
58                 "ir::BlockCall",
59                 "a basic block in the same function, with its arguments provided.",
60             ),
61 
62             block_then: new(
63                 "block_then",
64                 "ir::BlockCall",
65                 "a basic block in the same function, with its arguments provided.",
66             ),
67 
68             block_else: new(
69                 "block_else",
70                 "ir::BlockCall",
71                 "a basic block in the same function, with its arguments provided.",
72             ),
73 
74             stack_slot: new("stack_slot", "ir::StackSlot", "A stack slot"),
75 
76             dynamic_stack_slot: new(
77                 "dynamic_stack_slot",
78                 "ir::DynamicStackSlot",
79                 "A dynamic stack slot",
80             ),
81 
82             global_value: new("global_value", "ir::GlobalValue", "A global value."),
83 
84             sig_ref: new("sig_ref", "ir::SigRef", "A function signature."),
85 
86             func_ref: new("func_ref", "ir::FuncRef", "An external function."),
87 
88             jump_table: new("table", "ir::JumpTable", "A jump table."),
89 
90             table: new("table", "ir::Table", "A table."),
91 
92             varargs: OperandKind::new(
93                 "",
94                 "&[Value]",
95                 OperandKindFields::VariableArgs,
96                 r#"
97                         A variable size list of `value` operands.
98 
99                         Use this to represent arguments passed to a function call, arguments
100                         passed to a basic block, or a variable number of results
101                         returned from an instruction.
102                     "#,
103             ),
104         }
105     }
106 }
107