@@ -77,12 +77,33 @@ The various kinds of rvalues that can appear in MIR.
77
77
78
78
syntax Unsafety ::= "Unsafe" | "Normal"
79
79
80
- syntax NullaryOp ::= Identifier "(" Type ")"
81
-
82
- syntax UnaryOp ::= Identifier "(" Operand ")"
80
+ syntax NullaryOp ::= NullaryOpName "(" Type ")"
81
+ syntax NullaryOpName ::= "SizeOf" [token]
82
+ | "AlignOf" [token]
83
83
84
- syntax BinaryOp ::= Identifier "(" Operand "," Operand ")"
84
+ syntax UnaryOp ::= UnaryOpName "(" Operand ")"
85
+ syntax UnaryOpName ::= "Not" [token]
86
+ | "Neg" [token]
85
87
88
+ syntax BinaryOp ::= BinaryOpName "(" Operand "," Operand ")"
89
+ syntax BinaryOpName ::= "Add" [token]
90
+ | "Sub" [token]
91
+ | "Mul" [token]
92
+ | "Div" [token]
93
+ | "Rem" [token]
94
+ | "BitXor" [token]
95
+ | "BitAnd" [token]
96
+ | "BitOr" [token]
97
+ | "Shl" [token]
98
+ | "Shr" [token]
99
+ | "Eq" [token]
100
+ | "Lt" [token]
101
+ | "Le" [token]
102
+ | "Ne" [token]
103
+ | "Ge" [token]
104
+ | "Gt" [token]
105
+ | "Offset" [token]
106
+
86
107
syntax Discriminant ::= "discriminant" "(" Place ")"
87
108
88
109
syntax CopyForDeref ::= "deref_copy" NonTerminalPlace
@@ -176,93 +197,12 @@ TODO: these sorts may need refactoring to closer match the `rustc` implementatio
176
197
endmodule
177
198
```
178
199
179
- ### Build-in operations
180
-
181
- ``` k
182
- module MIR-BUILTINS-SYNTAX
183
- imports BOOL
184
- imports STRING
185
-
186
- syntax MirBuiltInToken ::= NullaryOpName
187
- | UnaryOpName
188
- | BinaryOpName
189
- | CheckedBinaryOpName
190
-
191
- syntax MirBuiltInToken ::= String2MirBuiltInToken(MirBuiltInToken) [function, hook(STRING.token2string)]
192
-
193
- syntax NullaryOpName ::= "SizeOf" [token]
194
- | "AlignOf" [token]
195
-
196
- syntax UnaryOpName ::= String2UnaryOpName(String) [function, hook(STRING.string2token)]
197
-
198
- syntax UnaryOpName ::= "Not" [token]
199
- | "Neg" [token]
200
-
201
- syntax BinaryOpName ::= String2BinaryOpName(String) [function, hook(STRING.string2token)]
202
-
203
- syntax BinaryOpName ::= "Add" [token]
204
- | "Sub" [token]
205
- | "Mul" [token]
206
- | "Div" [token]
207
- | "Rem" [token]
208
- | "BitXor" [token]
209
- | "BitAnd" [token]
210
- | "BitOr" [token]
211
- | "Shl" [token]
212
- | "Shr" [token]
213
- | "Eq" [token]
214
- | "Lt" [token]
215
- | "Le" [token]
216
- | "Ne" [token]
217
- | "Ge" [token]
218
- | "Gt" [token]
219
- | "Offset" [token]
220
-
221
- syntax Bool ::= isUnOp(String) [function, total]
222
- //----------------------------------------------
223
- rule isUnOp(OP_NAME) => true
224
- requires OP_NAME ==String "Not"
225
- orBool OP_NAME ==String "Neg"
226
- rule isUnOp(_) => false [owise]
227
-
228
- syntax Bool ::= isBinOp(String) [function, total]
229
- //-----------------------------------------------
230
- rule isBinOp(OP_NAME) => true
231
- requires OP_NAME ==String "Add"
232
- orBool OP_NAME ==String "Sub"
233
- orBool OP_NAME ==String "Mul"
234
- orBool OP_NAME ==String "Div"
235
- orBool OP_NAME ==String "Rem"
236
- orBool OP_NAME ==String "BitXor"
237
- orBool OP_NAME ==String "BitAnd"
238
- orBool OP_NAME ==String "BitOr"
239
- orBool OP_NAME ==String "Shl"
240
- orBool OP_NAME ==String "Shr"
241
- orBool OP_NAME ==String "Eq"
242
- orBool OP_NAME ==String "Lt"
243
- orBool OP_NAME ==String "Le"
244
- orBool OP_NAME ==String "Ne"
245
- orBool OP_NAME ==String "Ge"
246
- orBool OP_NAME ==String "Gt"
247
- orBool OP_NAME ==String "Offset"
248
- rule isBinOp(_) => false [owise]
249
-
250
- syntax CheckedBinaryOpName ::= "CheckedAdd"
251
- | "CheckedSub"
252
- | "CheckedMul"
253
- | "CheckedShl"
254
- | "CheckedShr"
255
-
256
- endmodule
257
- ```
258
-
259
200
Evaluation of rvalues
260
201
---------------------
261
202
262
203
``` k
263
204
module MIR-RVALUE
264
205
imports MIR-RVALUE-SYNTAX
265
- imports MIR-BUILTINS-SYNTAX
266
206
imports MIR-TYPES
267
207
imports MIR-CONFIGURATION
268
208
```
@@ -293,8 +233,8 @@ Evaluate a syntactic `RValue` into a semantics `RValueResult`. Inspired by [eval
293
233
``` k
294
234
syntax MIRValue ::= evalUnaryOp(FunctionLikeKey, UnaryOp) [function]
295
235
//------------------------------------------------------------------
296
- rule evalUnaryOp(FN_KEY, NAME:IdentifierToken (X:Operand)) =>
297
- evalUnaryOpImpl(FN_KEY, String2UnaryOpName(IdentifierToken2String( NAME)) , X)
236
+ rule evalUnaryOp(FN_KEY, NAME:UnaryOpName (X:Operand)) =>
237
+ evalUnaryOpImpl(FN_KEY, NAME, X)
298
238
299
239
syntax MIRValue ::= evalUnaryOpImpl(FunctionLikeKey, UnaryOpName, Operand) [function]
300
240
//-----------------------------------------------------------------------------------
@@ -307,8 +247,8 @@ Evaluate a syntactic `RValue` into a semantics `RValueResult`. Inspired by [eval
307
247
``` k
308
248
syntax MIRValue ::= evalBinaryOp(FunctionLikeKey, BinaryOp) [function]
309
249
//--------------------------------------------------------------------
310
- rule evalBinaryOp(FN_KEY, NAME:IdentifierToken (X:Operand, Y:Operand)) =>
311
- evalBinaryOpImpl(FN_KEY, String2BinaryOpName(IdentifierToken2String( NAME)) , X, Y)
250
+ rule evalBinaryOp(FN_KEY, NAME:BinaryOpName (X:Operand, Y:Operand)) =>
251
+ evalBinaryOpImpl(FN_KEY, NAME, X, Y)
312
252
313
253
syntax MIRValue ::= evalBinaryOpImpl(FunctionLikeKey, BinaryOpName, Operand, Operand) [function]
314
254
//-----------------------------------------------------------------------
@@ -328,7 +268,7 @@ Evaluate a syntactic `RValue` into a semantics `RValueResult`. Inspired by [eval
328
268
rule evalBinaryOpImpl(FN_KEY, Ne, X, Y) => {evalOperand(FN_KEY, X)}:>Int =/=Int {evalOperand(FN_KEY, Y)}:>Int
329
269
rule evalBinaryOpImpl(FN_KEY, Ge, X, Y) => {evalOperand(FN_KEY, X)}:>Int >=Int {evalOperand(FN_KEY, Y)}:>Int
330
270
rule evalBinaryOpImpl(FN_KEY, Gt, X, Y) => {evalOperand(FN_KEY, X)}:>Int >Int {evalOperand(FN_KEY, Y)}:>Int
331
- // rule evalBinaryOpImpl("Offset", X, Y) => "not implemented"
271
+ // rule evalBinaryOpImpl(FN_KEY, _, X, Y) => "not supported" [owise]
332
272
```
333
273
334
274
### Constant evaluation.
0 commit comments