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