@@ -77,6 +77,230 @@ TEST(InterpreterTest, MulI32) {
77
77
EXPECT_EQ (results, expected);
78
78
}
79
79
80
+ TEST (InterpreterTest, EqI32) {
81
+ Module wasm;
82
+ IRBuilder builder (wasm);
83
+
84
+ ASSERT_FALSE (builder.makeConst (Literal (uint32_t (1 ))).getErr ());
85
+ ASSERT_FALSE (builder.makeConst (Literal (uint32_t (2 ))).getErr ());
86
+ ASSERT_FALSE (builder.makeBinary (EqInt32).getErr ());
87
+
88
+ auto expr = builder.build ();
89
+ ASSERT_FALSE (expr.getErr ());
90
+
91
+ auto results = Interpreter{}.run (*expr);
92
+ std::vector<Literal> expected{Literal (uint32_t (0 ))};
93
+
94
+ EXPECT_EQ (results, expected);
95
+ }
96
+
97
+ TEST (InterpreterTest, LtUI32) {
98
+ Module wasm;
99
+ IRBuilder builder (wasm);
100
+
101
+ ASSERT_FALSE (builder.makeConst (Literal (uint32_t (1 ))).getErr ());
102
+ ASSERT_FALSE (builder.makeConst (Literal (uint32_t (2 ))).getErr ());
103
+ ASSERT_FALSE (builder.makeBinary (LtUInt32).getErr ());
104
+
105
+ auto expr = builder.build ();
106
+ ASSERT_FALSE (expr.getErr ());
107
+
108
+ auto results = Interpreter{}.run (*expr);
109
+ std::vector<Literal> expected{Literal (uint32_t (1 ))};
110
+
111
+ EXPECT_EQ (results, expected);
112
+ }
113
+
114
+ TEST (InterpreterTest, GtUI32) {
115
+ Module wasm;
116
+ IRBuilder builder (wasm);
117
+
118
+ ASSERT_FALSE (builder.makeConst (Literal (uint32_t (1 ))).getErr ());
119
+ ASSERT_FALSE (builder.makeConst (Literal (uint32_t (2 ))).getErr ());
120
+ ASSERT_FALSE (builder.makeBinary (GtUInt32).getErr ());
121
+
122
+ auto expr = builder.build ();
123
+ ASSERT_FALSE (expr.getErr ());
124
+
125
+ auto results = Interpreter{}.run (*expr);
126
+ std::vector<Literal> expected{Literal (uint32_t (0 ))};
127
+
128
+ EXPECT_EQ (results, expected);
129
+ }
130
+
131
+ // sInt32
132
+ TEST (InterpreterTest, LtSI32) {
133
+ Module wasm;
134
+ IRBuilder builder (wasm);
135
+
136
+ ASSERT_FALSE (builder.makeConst (Literal (int32_t (-1 ))).getErr ());
137
+ ASSERT_FALSE (builder.makeConst (Literal (int32_t (-2 ))).getErr ());
138
+ ASSERT_FALSE (builder.makeBinary (LtSInt32).getErr ());
139
+
140
+ auto expr = builder.build ();
141
+ ASSERT_FALSE (expr.getErr ());
142
+
143
+ auto results = Interpreter{}.run (*expr);
144
+ std::vector<Literal> expected{Literal (int32_t (0 ))};
145
+
146
+ EXPECT_EQ (results, expected);
147
+ }
148
+
149
+ TEST (InterpreterTest, GtSI32) {
150
+ Module wasm;
151
+ IRBuilder builder (wasm);
152
+
153
+ ASSERT_FALSE (builder.makeConst (Literal (int32_t (-3 ))).getErr ());
154
+ ASSERT_FALSE (builder.makeConst (Literal (int32_t (-4 ))).getErr ());
155
+ ASSERT_FALSE (builder.makeBinary (GtSInt32).getErr ());
156
+
157
+ auto expr = builder.build ();
158
+ ASSERT_FALSE (expr.getErr ());
159
+
160
+ auto results = Interpreter{}.run (*expr);
161
+ std::vector<Literal> expected{Literal (int32_t (1 ))};
162
+
163
+ EXPECT_EQ (results, expected);
164
+ }
165
+
166
+ // uInt64
167
+ TEST (InterpreterTest, AddI64) {
168
+ Module wasm;
169
+ IRBuilder builder (wasm);
170
+
171
+ ASSERT_FALSE (builder.makeConst (Literal (uint64_t (1 ))).getErr ());
172
+ ASSERT_FALSE (builder.makeConst (Literal (uint64_t (2 ))).getErr ());
173
+ ASSERT_FALSE (builder.makeBinary (AddInt64).getErr ());
174
+
175
+ auto expr = builder.build ();
176
+ ASSERT_FALSE (expr.getErr ());
177
+
178
+ auto results = Interpreter{}.run (*expr);
179
+ std::vector<Literal> expected{Literal (uint64_t (3 ))};
180
+
181
+ EXPECT_EQ (results, expected);
182
+ }
183
+
184
+ TEST (InterpreterTest, SubI64) {
185
+ Module wasm;
186
+ IRBuilder builder (wasm);
187
+
188
+ ASSERT_FALSE (builder.makeConst (Literal (uint64_t (1 ))).getErr ());
189
+ ASSERT_FALSE (builder.makeConst (Literal (uint64_t (2 ))).getErr ());
190
+ ASSERT_FALSE (builder.makeBinary (SubInt64).getErr ());
191
+
192
+ auto expr = builder.build ();
193
+ ASSERT_FALSE (expr.getErr ());
194
+
195
+ auto results = Interpreter{}.run (*expr);
196
+ std::vector<Literal> expected{Literal (uint64_t (-1 ))};
197
+
198
+ EXPECT_EQ (results, expected);
199
+ }
200
+
201
+ TEST (InterpreterTest, MulI64) {
202
+ Module wasm;
203
+ IRBuilder builder (wasm);
204
+
205
+ ASSERT_FALSE (builder.makeConst (Literal (uint64_t (1 ))).getErr ());
206
+ ASSERT_FALSE (builder.makeConst (Literal (uint64_t (2 ))).getErr ());
207
+ ASSERT_FALSE (builder.makeBinary (MulInt64).getErr ());
208
+
209
+ auto expr = builder.build ();
210
+ ASSERT_FALSE (expr.getErr ());
211
+
212
+ auto results = Interpreter{}.run (*expr);
213
+ std::vector<Literal> expected{Literal (uint64_t (2 ))};
214
+
215
+ EXPECT_EQ (results, expected);
216
+ }
217
+
218
+ TEST (InterpreterTest, EqI64) {
219
+ Module wasm;
220
+ IRBuilder builder (wasm);
221
+
222
+ ASSERT_FALSE (builder.makeConst (Literal (uint64_t (1 ))).getErr ());
223
+ ASSERT_FALSE (builder.makeConst (Literal (uint64_t (2 ))).getErr ());
224
+ ASSERT_FALSE (builder.makeBinary (EqInt64).getErr ());
225
+
226
+ auto expr = builder.build ();
227
+ ASSERT_FALSE (expr.getErr ());
228
+
229
+ auto results = Interpreter{}.run (*expr);
230
+ std::vector<Literal> expected{Literal (uint32_t (0 ))};
231
+
232
+ EXPECT_EQ (results, expected);
233
+ }
234
+
235
+ TEST (InterpreterTest, LtUI64) {
236
+ Module wasm;
237
+ IRBuilder builder (wasm);
238
+
239
+ ASSERT_FALSE (builder.makeConst (Literal (uint64_t (1 ))).getErr ());
240
+ ASSERT_FALSE (builder.makeConst (Literal (uint64_t (2 ))).getErr ());
241
+ ASSERT_FALSE (builder.makeBinary (LtSInt64).getErr ());
242
+
243
+ auto expr = builder.build ();
244
+ ASSERT_FALSE (expr.getErr ());
245
+
246
+ auto results = Interpreter{}.run (*expr);
247
+ std::vector<Literal> expected{Literal (uint32_t (1 ))};
248
+
249
+ EXPECT_EQ (results, expected);
250
+ }
251
+
252
+ TEST (InterpreterTest, GtUI64) {
253
+ Module wasm;
254
+ IRBuilder builder (wasm);
255
+
256
+ ASSERT_FALSE (builder.makeConst (Literal (uint64_t (1 ))).getErr ());
257
+ ASSERT_FALSE (builder.makeConst (Literal (uint64_t (2 ))).getErr ());
258
+ ASSERT_FALSE (builder.makeBinary (GtSInt64).getErr ());
259
+
260
+ auto expr = builder.build ();
261
+ ASSERT_FALSE (expr.getErr ());
262
+
263
+ auto results = Interpreter{}.run (*expr);
264
+ std::vector<Literal> expected{Literal (uint32_t (0 ))};
265
+
266
+ EXPECT_EQ (results, expected);
267
+ }
268
+
269
+ // sInt64
270
+ TEST (InterpreterTest, LtSI64) {
271
+ Module wasm;
272
+ IRBuilder builder (wasm);
273
+
274
+ ASSERT_FALSE (builder.makeConst (Literal (int64_t (-1 ))).getErr ());
275
+ ASSERT_FALSE (builder.makeConst (Literal (int64_t (-2 ))).getErr ());
276
+ ASSERT_FALSE (builder.makeBinary (LtSInt64).getErr ());
277
+
278
+ auto expr = builder.build ();
279
+ ASSERT_FALSE (expr.getErr ());
280
+
281
+ auto results = Interpreter{}.run (*expr);
282
+ std::vector<Literal> expected{Literal (int32_t (0 ))};
283
+
284
+ EXPECT_EQ (results, expected);
285
+ }
286
+
287
+ TEST (InterpreterTest, GtSI64) {
288
+ Module wasm;
289
+ IRBuilder builder (wasm);
290
+
291
+ ASSERT_FALSE (builder.makeConst (Literal (int64_t (-3 ))).getErr ());
292
+ ASSERT_FALSE (builder.makeConst (Literal (int64_t (-4 ))).getErr ());
293
+ ASSERT_FALSE (builder.makeBinary (GtSInt64).getErr ());
294
+
295
+ auto expr = builder.build ();
296
+ ASSERT_FALSE (expr.getErr ());
297
+
298
+ auto results = Interpreter{}.run (*expr);
299
+ std::vector<Literal> expected{Literal (int32_t (1 ))};
300
+
301
+ EXPECT_EQ (results, expected);
302
+ }
303
+
80
304
// Float32
81
305
TEST (InterpreterTest, AddF32) {
82
306
Module wasm;
@@ -146,6 +370,23 @@ TEST(InterpreterTest, DivF32) {
146
370
EXPECT_EQ (results, expected);
147
371
}
148
372
373
+ TEST (InterpreterTest, EqF32) {
374
+ Module wasm;
375
+ IRBuilder builder (wasm);
376
+
377
+ ASSERT_FALSE (builder.makeConst (Literal (float (1.0 ))).getErr ());
378
+ ASSERT_FALSE (builder.makeConst (Literal (float (2.0 ))).getErr ());
379
+ ASSERT_FALSE (builder.makeBinary (EqFloat32).getErr ());
380
+
381
+ auto expr = builder.build ();
382
+ ASSERT_FALSE (expr.getErr ());
383
+
384
+ auto results = Interpreter{}.run (*expr);
385
+ std::vector<Literal> expected{Literal (uint32_t (0 ))};
386
+
387
+ EXPECT_EQ (results, expected);
388
+ }
389
+
149
390
TEST (InterpreterTest, SqrtF32) {
150
391
Module wasm;
151
392
IRBuilder builder (wasm);
@@ -295,6 +536,23 @@ TEST(InterpreterTest, DivF64) {
295
536
EXPECT_EQ (results, expected);
296
537
}
297
538
539
+ TEST (InterpreterTest, EqF64) {
540
+ Module wasm;
541
+ IRBuilder builder (wasm);
542
+
543
+ ASSERT_FALSE (builder.makeConst (Literal (double (1.0 ))).getErr ());
544
+ ASSERT_FALSE (builder.makeConst (Literal (double (2.0 ))).getErr ());
545
+ ASSERT_FALSE (builder.makeBinary (EqFloat64).getErr ());
546
+
547
+ auto expr = builder.build ();
548
+ ASSERT_FALSE (expr.getErr ());
549
+
550
+ auto results = Interpreter{}.run (*expr);
551
+ std::vector<Literal> expected{Literal (uint32_t (0 ))};
552
+
553
+ EXPECT_EQ (results, expected);
554
+ }
555
+
298
556
TEST (InterpreterTest, SqrtF64) {
299
557
Module wasm;
300
558
IRBuilder builder (wasm);
0 commit comments