Skip to main content

cranelift_codegen_meta/shared/
formats.rs

1use crate::cdsl::formats::{InstructionFormat, InstructionFormatBuilder as Builder};
2use crate::shared::{entities::EntityRefs, immediates::Immediates};
3use std::rc::Rc;
4
5pub(crate) struct Formats {
6    pub(crate) atomic_cas: Rc<InstructionFormat>,
7    pub(crate) atomic_rmw: Rc<InstructionFormat>,
8    pub(crate) binary: Rc<InstructionFormat>,
9    pub(crate) binary_imm8: Rc<InstructionFormat>,
10    pub(crate) branch_table: Rc<InstructionFormat>,
11    pub(crate) brif: Rc<InstructionFormat>,
12    pub(crate) call: Rc<InstructionFormat>,
13    pub(crate) call_indirect: Rc<InstructionFormat>,
14    pub(crate) try_call: Rc<InstructionFormat>,
15    pub(crate) try_call_indirect: Rc<InstructionFormat>,
16    pub(crate) cond_trap: Rc<InstructionFormat>,
17    pub(crate) float_compare: Rc<InstructionFormat>,
18    pub(crate) func_addr: Rc<InstructionFormat>,
19    pub(crate) int_compare: Rc<InstructionFormat>,
20    pub(crate) int_add_trap: Rc<InstructionFormat>,
21    pub(crate) jump: Rc<InstructionFormat>,
22    pub(crate) load: Rc<InstructionFormat>,
23    pub(crate) load_no_offset: Rc<InstructionFormat>,
24    pub(crate) multiary: Rc<InstructionFormat>,
25    pub(crate) nullary: Rc<InstructionFormat>,
26    pub(crate) shuffle: Rc<InstructionFormat>,
27    pub(crate) stack_load: Rc<InstructionFormat>,
28    pub(crate) stack_store: Rc<InstructionFormat>,
29    pub(crate) dynamic_stack_load: Rc<InstructionFormat>,
30    pub(crate) dynamic_stack_store: Rc<InstructionFormat>,
31    pub(crate) store: Rc<InstructionFormat>,
32    pub(crate) store_no_offset: Rc<InstructionFormat>,
33    pub(crate) ternary: Rc<InstructionFormat>,
34    pub(crate) ternary_imm8: Rc<InstructionFormat>,
35    pub(crate) trap: Rc<InstructionFormat>,
36    pub(crate) unary: Rc<InstructionFormat>,
37    pub(crate) unary_const: Rc<InstructionFormat>,
38    pub(crate) unary_global_value: Rc<InstructionFormat>,
39    pub(crate) unary_ieee16: Rc<InstructionFormat>,
40    pub(crate) unary_ieee32: Rc<InstructionFormat>,
41    pub(crate) unary_ieee64: Rc<InstructionFormat>,
42    pub(crate) unary_imm: Rc<InstructionFormat>,
43    pub(crate) exception_handler_address: Rc<InstructionFormat>,
44}
45
46impl Formats {
47    pub fn new(imm: &Immediates, entities: &EntityRefs) -> Self {
48        Self {
49            unary: Builder::new("Unary").value().build(),
50
51            unary_imm: Builder::new("UnaryImm").imm(&imm.imm64).build(),
52
53            unary_ieee16: Builder::new("UnaryIeee16").imm(&imm.ieee16).build(),
54
55            unary_ieee32: Builder::new("UnaryIeee32").imm(&imm.ieee32).build(),
56
57            unary_ieee64: Builder::new("UnaryIeee64").imm(&imm.ieee64).build(),
58
59            unary_const: Builder::new("UnaryConst")
60                .imm(&entities.pool_constant)
61                .build(),
62
63            unary_global_value: Builder::new("UnaryGlobalValue")
64                .imm(&entities.global_value)
65                .build(),
66
67            binary: Builder::new("Binary").value().value().build(),
68
69            binary_imm8: Builder::new("BinaryImm8").value().imm(&imm.uimm8).build(),
70
71            // The select instructions are controlled by the second VALUE operand.
72            // The first VALUE operand is the controlling flag which has a derived type.
73            // The fma instruction has the same constraint on all inputs.
74            ternary: Builder::new("Ternary")
75                .value()
76                .value()
77                .value()
78                .typevar_operand(1)
79                .build(),
80
81            ternary_imm8: Builder::new("TernaryImm8")
82                .value()
83                .imm(&imm.uimm8)
84                .value()
85                .build(),
86
87            // Catch-all for instructions with many outputs and inputs and no immediate
88            // operands.
89            multiary: Builder::new("MultiAry").varargs().build(),
90
91            nullary: Builder::new("NullAry").build(),
92
93            shuffle: Builder::new("Shuffle")
94                .value()
95                .value()
96                .imm(&entities.uimm128)
97                .build(),
98
99            int_compare: Builder::new("IntCompare")
100                .imm(&imm.intcc)
101                .value()
102                .value()
103                .build(),
104
105            float_compare: Builder::new("FloatCompare")
106                .imm(&imm.floatcc)
107                .value()
108                .value()
109                .build(),
110
111            jump: Builder::new("Jump").block().build(),
112
113            brif: Builder::new("Brif").value().block().block().build(),
114
115            branch_table: Builder::new("BranchTable")
116                .value()
117                .imm(&entities.jump_table)
118                .build(),
119
120            call: Builder::new("Call")
121                .imm(&entities.func_ref)
122                .varargs()
123                .build(),
124
125            call_indirect: Builder::new("CallIndirect")
126                .imm(&entities.sig_ref)
127                .value()
128                .varargs()
129                .build(),
130
131            try_call: Builder::new("TryCall")
132                .imm(&entities.func_ref)
133                .varargs()
134                .imm(&&entities.exception_table)
135                .build(),
136
137            try_call_indirect: Builder::new("TryCallIndirect")
138                .value()
139                .varargs()
140                .imm(&&entities.exception_table)
141                .build(),
142
143            func_addr: Builder::new("FuncAddr").imm(&entities.func_ref).build(),
144
145            atomic_rmw: Builder::new("AtomicRmw")
146                .imm(&imm.memflags)
147                .imm(&imm.atomic_rmw_op)
148                .value()
149                .value()
150                .build(),
151
152            atomic_cas: Builder::new("AtomicCas")
153                .imm(&imm.memflags)
154                .value()
155                .value()
156                .value()
157                .typevar_operand(2)
158                .build(),
159
160            load: Builder::new("Load")
161                .imm(&imm.memflags)
162                .value()
163                .imm(&imm.offset32)
164                .build(),
165
166            load_no_offset: Builder::new("LoadNoOffset")
167                .imm(&imm.memflags)
168                .value()
169                .build(),
170
171            store: Builder::new("Store")
172                .imm(&imm.memflags)
173                .value()
174                .value()
175                .imm(&imm.offset32)
176                .build(),
177
178            store_no_offset: Builder::new("StoreNoOffset")
179                .imm(&imm.memflags)
180                .value()
181                .value()
182                .build(),
183
184            stack_load: Builder::new("StackLoad")
185                .imm(&entities.stack_slot)
186                .imm(&imm.offset32)
187                .build(),
188
189            stack_store: Builder::new("StackStore")
190                .value()
191                .imm(&entities.stack_slot)
192                .imm(&imm.offset32)
193                .build(),
194
195            dynamic_stack_load: Builder::new("DynamicStackLoad")
196                .imm(&entities.dynamic_stack_slot)
197                .build(),
198
199            dynamic_stack_store: Builder::new("DynamicStackStore")
200                .value()
201                .imm(&entities.dynamic_stack_slot)
202                .build(),
203
204            trap: Builder::new("Trap").imm(&imm.trapcode).build(),
205
206            cond_trap: Builder::new("CondTrap").value().imm(&imm.trapcode).build(),
207
208            int_add_trap: Builder::new("IntAddTrap")
209                .value()
210                .value()
211                .imm(&imm.trapcode)
212                .build(),
213
214            exception_handler_address: Builder::new("ExceptionHandlerAddress")
215                .raw_block()
216                .imm(&imm.imm64)
217                .build(),
218        }
219    }
220}