32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
|
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
|
-
-
+
+
-
-
-
-
-
+
-
-
-
-
-
+
-
-
-
-
|
)
) );
} )
);
CreateLeftAssInfixOp( e, "^"_sid, "operator_xor"_sid, precedence::OrOp,
// Logical xor
ForType< bool >( []( auto&& lhs, auto&& rhs ) -> Value
{
ForType< bool, Xor >(),
return BuildComputedValue( GetValueType< bool >(),
Xor( lhs, rhs ) );
} ),
// ct_int xor
ForType< BigInt >( []( auto&& lhs, auto&& rhs ) -> Value
ForType< BigInt, Xor >(),
{
return BuildComputedValue( GetValueType< BigInt >(),
Xor( lhs, rhs ) );
} ),
// runtime integer xor, defined to work for any two integers of same
// bit size and signedness.
ForType< CustomPattern< RTInteger, RTInteger::Pattern > >(
[]( auto&& lhs, auto&& rhs ) -> Value
{
return BuildComputedValue( lhs.type(),
Xor( lhs, rhs ) );
} )
);
CreateLeftAssInfixOp( e, "|"_sid, "operator_or"_sid, precedence::OrOp,
// ct_int or
ForType< BigInt >( []( auto&& lhs, auto&& rhs ) -> Value
ForType< BigInt, Or >(),
{
return BuildComputedValue( GetValueType< BigInt >(),
Or( lhs, rhs ) );
} ),
// runtime integer or, defined to work for any two integers of same
// bit size and signedness.
ForType< CustomPattern< RTInteger, RTInteger::Pattern > >(
[]( auto&& lhs, auto&& rhs ) -> Value
{
return BuildComputedValue( lhs.type(),
|
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
|
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
|
-
+
-
-
-
-
-
+
|
// Pachage our cfg in a value with an inline CFG instruction.
return BuildComputedValue( GetValueType< bool >(), move( cfg ) );
} )
);
CreateLeftAssInfixOp( e, "&"_sid, "operator_and"_sid, precedence::AndOp,
// ct_int and
ForType< BigInt >( []( auto&& lhs, auto&& rhs ) -> Value
ForType< BigInt, And >(),
{
return BuildComputedValue( GetValueType< BigInt >(),
And( lhs, rhs ) );
} ),
// runtime integer and, defined to work for any two integers of same
// bit size and signedness.
ForType< CustomPattern< RTInteger, RTInteger::Pattern > >(
[]( auto&& lhs, auto&& rhs ) -> Value
{
return BuildComputedValue( lhs.type(),
And( lhs, rhs ) );
} ),
// bool or
// bool and
ForType< bool >( []( auto&& lhs, auto&& rhs ) -> Value
{
// Build a CFG that implements the control flow for
// shortcut evaluation.
auto cfg = make_shared< CFG >();
auto pLhsBB = cfg->entryBB();
auto pRhsBB = cfg->createBB();
|
180
181
182
183
184
185
186
187
188
|
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
|
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
|
// Return it
pEndBB->setTerminator( Ret( move( resultVal ) ) );
// Pachage our cfg in a value with an inline CFG instruction.
return BuildComputedValue( GetValueType< bool >(), move( cfg ) );
} )
);
}
}
CreateLeftAssInfixOp( e, "<<"_sid, "operator_shift_left"_sid, precedence::OrOp,
// ct_int left shift
ForType< BigInt, Shl >(),
// runtime integer left shift, defined to work for any two integers of same
// bit size and signedness.
ForType< CustomPattern< RTInteger, RTInteger::Pattern > >(
[]( auto&& lhs, auto&& rhs ) -> Value
{
return BuildComputedValue( lhs.type(),
Shl( lhs, rhs ) );
} )
);
CreateLeftAssInfixOp( e, ">>"_sid, "operator_shift_right"_sid, precedence::OrOp,
// ct_int right shift
ForType< BigInt, AShr >(),
// runtime signed integer right shift, defined to work for any two integers of same
// bit size.
ForType< CustomPattern< RTInteger, RTInteger::PatternSigned > >(
[]( auto&& lhs, auto&& rhs ) -> Value
{
return BuildComputedValue( lhs.type(),
AShr( lhs, rhs ) );
} ),
// runtime unsigned integer right shift, defined to work for any two integers of same
// bit size.
ForType< CustomPattern< RTInteger, RTInteger::PatternUnsigned > >(
[]( auto&& lhs, auto&& rhs ) -> Value
{
return BuildComputedValue( lhs.type(),
LShr( lhs, rhs ) );
} )
);
}
}
|