|
1 | 1 | ```k |
2 | | -requires "mir-syntax.md" |
3 | 2 | requires "mir-configuration.md" |
4 | | -requires "mir-operand.md" |
5 | | -``` |
6 | | - |
7 | | -Syntax of rvalues |
8 | | ------------------ |
9 | | - |
10 | | -Rvalues are expression that appear on a right-hand-side of an assignment statement. |
11 | | - |
12 | | -```k |
13 | | -module MIR-RVALUE-SYNTAX |
14 | | - imports BOOL |
15 | | - imports UNSIGNED-INT-SYNTAX |
16 | | - imports MIR-TYPE-SYNTAX |
17 | | - imports MIR-OPERAND-SYNTAX |
18 | | -``` |
19 | | - |
20 | | -### [`RValue`](https://doc.rust-lang.org/beta/nightly-rustc/rustc_middle/mir/enum.Rvalue.html) |
21 | | - |
22 | | -The various kinds of rvalues that can appear in MIR. |
23 | | - |
24 | | -```k |
25 | | - syntax RValue ::= Use |
26 | | - | Repeat |
27 | | - | Ref |
28 | | -// | ThreadLocalRef |
29 | | - | AddressOf |
30 | | - | Len |
31 | | - | Cast |
32 | | - | NullaryOp |
33 | | - | UnaryOp |
34 | | - | BinaryOp |
35 | | - | Discriminant |
36 | | - | Aggregate |
37 | | - | ShallowInitBox |
38 | | - | CopyForDeref |
39 | | -
|
40 | | - syntax Use ::= Operand |
41 | | -
|
42 | | - syntax Repeat ::= "[" Operand ";" Constant "]" |
43 | | - | "[" Operand ";" RustExpression "]" [avoid] |
44 | | - syntax Ref // TODO: define |
45 | | -
|
46 | | - // this seems to be responsible for function pointer assignmetn, e.g. `_1 = fn_name` |
47 | | -// syntax ThreadLocalRef ::= PathExpression |
48 | | -
|
49 | | - syntax AddressOf ::= "&" PtrModifiers Place |
50 | | -
|
51 | | - syntax Len ::= "Len" "(" Place ")" |
52 | | -
|
53 | | - // TODO: this needs additional productions |
54 | | - syntax Cast ::= Operand "as" Type [prefer] |
55 | | - | Operand "as" Type "(" PointerCastArg ")" [prefer] |
56 | | - | PathExpression "as" Type |
57 | | - | PathExpression "as" Type "(" PointerCastArg ")" |
58 | | -
|
59 | | - syntax PointerCastArg ::= "Pointer" "(" PointerCast ")" |
60 | | - syntax PointerCast ::= "ReifyFnPointer" |
61 | | - | "UnsafeFnPointer" |
62 | | - | "ClosureFnPointer" "(" Unsafety ")" |
63 | | - | "MutToConstPointer" |
64 | | - | "ArrayToPointer" |
65 | | - | "Unsize" |
66 | | -
|
67 | | - syntax Unsafety ::= "Unsafe" | "Normal" |
68 | | -
|
69 | | - syntax NullaryOp ::= NullaryOpName "(" Type ")" |
70 | | - syntax NullaryOpName ::= "SizeOf" [token] |
71 | | - | "AlignOf" [token] |
72 | | -
|
73 | | - syntax UnaryOp ::= UnaryOpName "(" Operand ")" |
74 | | - syntax UnaryOpName ::= "Not" [token] |
75 | | - | "Neg" [token] |
76 | | -
|
77 | | - syntax BinaryOp ::= BinaryOpName "(" Operand "," Operand ")" |
78 | | - syntax BinaryOpName ::= "Add" [token] |
79 | | - | "Sub" [token] |
80 | | - | "Mul" [token] |
81 | | - | "Div" [token] |
82 | | - | "Rem" [token] |
83 | | - | "BitXor" [token] |
84 | | - | "BitAnd" [token] |
85 | | - | "BitOr" [token] |
86 | | - | "Shl" [token] |
87 | | - | "Shr" [token] |
88 | | - | "Eq" [token] |
89 | | - | "Lt" [token] |
90 | | - | "Le" [token] |
91 | | - | "Ne" [token] |
92 | | - | "Ge" [token] |
93 | | - | "Gt" [token] |
94 | | - | "Offset" [token] |
95 | | - |
96 | | - syntax Discriminant ::= "discriminant" "(" Place ")" |
97 | | -
|
98 | | - syntax CopyForDeref ::= "deref_copy" NonTerminalPlace |
99 | | -
|
100 | | - syntax Aggregate ::= Array |
101 | | - | Tuple |
102 | | - | Adt |
103 | | - | Closure |
104 | | - | Generator |
105 | | -
|
106 | | - syntax Array ::= "[" "]" |
107 | | - | "[" Operand "]" |
108 | | - | "[" Operand "," OperandList "]" |
109 | | -
|
110 | | - syntax Tuple ::= "(" ")" |
111 | | - | "(" Operand "," OperandList ")" |
112 | | -
|
113 | | - syntax Adt ::= StructConstructor |
114 | | - | EnumConstructor |
115 | | -
|
116 | | - syntax StructConstructor ::= Type "{" AdtFieldList "}" |
117 | | - // | TypePath "(" OperandList ")" // compiletest-rs/ui/traits/copy-requires-self-wf.mir LINE 17 |
118 | | -
|
119 | | - // `AssertKind` `Eq`, `Ne` conflict with BinaryOp names https://github.com/rust-lang/rust/blob/f562931178ff103f23b9e9a10dc0deb38e0d064f/library/core/src/panicking.rs#L259-L263 |
120 | | - syntax EnumConstructor ::= Identifier |
121 | | - | Identifier "(" OperandList ")" |
122 | | - | PathExpression "::" Identifier [avoid] |
123 | | - | PathExpression "::" "Eq" |
124 | | - | PathExpression "::" "Ne" |
125 | | - // | PathExpression "::" "Match" // Match isn't conflicting at the moment but might later |
126 | | - | PathExpression "::" Identifier "(" OperandList ")" |
127 | | -
|
128 | | - syntax AdtField ::= AdtFieldName ":" Operand |
129 | | - syntax AdtFieldList ::= List{AdtField, ","} |
130 | | -
|
131 | | - syntax Closure ::= "[" "closure" "@" FilePosition "]" |
132 | | -
|
133 | | - syntax Generator ::= "[" "generator" "@" FilePosition "(" "#" Int ")" "]" |
134 | | - | "[" "generator" "@" FilePosition "(" "#" Int ")" "]" "{" AdtFieldList "}" |
135 | | -
|
136 | | - syntax ShallowInitBox ::= "ShallowInitBox" "(" Operand "," Type ")" |
137 | | -
|
138 | | - syntax OperandList ::= List{Operand, ","} |
139 | | -
|
140 | | - syntax PtrModifiers ::= "" | "mut" | "raw" "mut" | "raw" "const" |
141 | | -
|
142 | | - syntax RValue ::= #unwrap(Operand) |
143 | | -``` |
144 | | - |
145 | | -```k |
146 | | -endmodule |
147 | 3 | ``` |
148 | 4 |
|
149 | 5 | Evaluation of rvalues |
@@ -242,7 +98,7 @@ Evaluate a syntactic `RValue` into a semantics `RValueResult`. Inspired by [eval |
242 | 98 | //------------------------------------------------------------- |
243 | 99 | rule evalConstantValue(VALUE:UnsignedLiteral) => UnsignedLiteral2Int(VALUE) |
244 | 100 | rule evalConstantValue(VALUE:SignedLiteral) => SignedLiteral2Int(VALUE) |
245 | | - rule evalConstantValue(VALUE:StringLiteral) => StringLitertal2String(VALUE) |
| 101 | + rule evalConstantValue(VALUE:StringLiteral) => StringLiteral2String(VALUE) |
246 | 102 | rule evalConstantValue(( )) => Unit |
247 | 103 | rule evalConstantValue(VALUE:Bool) => VALUE |
248 | 104 | rule evalConstantValue(VALUE:ConstEnumConstructor) => evalPrimitiveBound(VALUE) |
|
0 commit comments