/
select.rs
496 lines (454 loc) 路 20.5 KB
/
select.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
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
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
// Rust test file autogenerated with cargo build (build/spectests.rs).
// Please do NOT modify it by hand, as it will be reseted on next build.
// Test based on spectests/select.wast
#![allow(
warnings,
dead_code
)]
use wabt::wat2wasm;
use crate::webassembly::{instantiate, compile, ImportObject, ResultObject, Instance, Export};
use super::_common::{
spectest_importobject,
NaNCheck,
};
// Line 1
fn create_module_1() -> ResultObject {
let module_str = "(module
(type (;0;) (func (param i32 i32 i32) (result i32)))
(type (;1;) (func (param i64 i64 i32) (result i64)))
(type (;2;) (func (param f32 f32 i32) (result f32)))
(type (;3;) (func (param f64 f64 i32) (result f64)))
(type (;4;) (func (param i32) (result i32)))
(type (;5;) (func))
(func (;0;) (type 0) (param i32 i32 i32) (result i32)
get_local 0
get_local 1
get_local 2
select)
(func (;1;) (type 1) (param i64 i64 i32) (result i64)
get_local 0
get_local 1
get_local 2
select)
(func (;2;) (type 2) (param f32 f32 i32) (result f32)
get_local 0
get_local 1
get_local 2
select)
(func (;3;) (type 3) (param f64 f64 i32) (result f64)
get_local 0
get_local 1
get_local 2
select)
(func (;4;) (type 4) (param i32) (result i32)
unreachable
i32.const 0
get_local 0
select)
(func (;5;) (type 4) (param i32) (result i32)
i32.const 0
unreachable
get_local 0
select)
(func (;6;) (type 5)
unreachable
select
unreachable
i32.const 0
select
unreachable
i32.const 0
i32.const 0
select
unreachable
f32.const 0x0p+0 (;=0;)
i32.const 0
select
unreachable)
(export \"select_i32\" (func 0))
(export \"select_i64\" (func 1))
(export \"select_f32\" (func 2))
(export \"select_f64\" (func 3))
(export \"select_trap_l\" (func 4))
(export \"select_trap_r\" (func 5))
(export \"select_unreached\" (func 6)))
";
let wasm_binary = wat2wasm(module_str.as_bytes()).expect("WAST not valid or malformed");
instantiate(wasm_binary, spectest_importobject()).expect("WASM can't be instantiated")
}
fn start_module_1(result_object: &ResultObject) {
result_object.instance.start();
}
// Line 31
fn c1_l31_action_invoke(result_object: &ResultObject) {
println!("Executing function {}", "c1_l31_action_invoke");
let func_index = match result_object.module.info.exports.get("select_i32") {
Some(&Export::Function(index)) => index,
_ => panic!("Function not found"),
};
let invoke_fn: fn(i32, i32, i32, &Instance) -> i32 = get_instance_function!(result_object.instance, func_index);
let result = invoke_fn(1 as i32, 2 as i32, 1 as i32, &result_object.instance);
assert_eq!(result, 1 as i32);
}
// Line 32
fn c2_l32_action_invoke(result_object: &ResultObject) {
println!("Executing function {}", "c2_l32_action_invoke");
let func_index = match result_object.module.info.exports.get("select_i64") {
Some(&Export::Function(index)) => index,
_ => panic!("Function not found"),
};
let invoke_fn: fn(i64, i64, i32, &Instance) -> i64 = get_instance_function!(result_object.instance, func_index);
let result = invoke_fn(2 as i64, 1 as i64, 1 as i32, &result_object.instance);
assert_eq!(result, 2 as i64);
}
// Line 33
fn c3_l33_action_invoke(result_object: &ResultObject) {
println!("Executing function {}", "c3_l33_action_invoke");
let func_index = match result_object.module.info.exports.get("select_f32") {
Some(&Export::Function(index)) => index,
_ => panic!("Function not found"),
};
let invoke_fn: fn(f32, f32, i32, &Instance) -> f32 = get_instance_function!(result_object.instance, func_index);
let result = invoke_fn(1.0 as f32, 2.0 as f32, 1 as i32, &result_object.instance);
assert_eq!(result, 1.0 as f32);
}
// Line 34
fn c4_l34_action_invoke(result_object: &ResultObject) {
println!("Executing function {}", "c4_l34_action_invoke");
let func_index = match result_object.module.info.exports.get("select_f64") {
Some(&Export::Function(index)) => index,
_ => panic!("Function not found"),
};
let invoke_fn: fn(f64, f64, i32, &Instance) -> f64 = get_instance_function!(result_object.instance, func_index);
let result = invoke_fn(1.0 as f64, 2.0 as f64, 1 as i32, &result_object.instance);
assert_eq!(result, 1.0 as f64);
}
// Line 36
fn c5_l36_action_invoke(result_object: &ResultObject) {
println!("Executing function {}", "c5_l36_action_invoke");
let func_index = match result_object.module.info.exports.get("select_i32") {
Some(&Export::Function(index)) => index,
_ => panic!("Function not found"),
};
let invoke_fn: fn(i32, i32, i32, &Instance) -> i32 = get_instance_function!(result_object.instance, func_index);
let result = invoke_fn(1 as i32, 2 as i32, 0 as i32, &result_object.instance);
assert_eq!(result, 2 as i32);
}
// Line 37
fn c6_l37_action_invoke(result_object: &ResultObject) {
println!("Executing function {}", "c6_l37_action_invoke");
let func_index = match result_object.module.info.exports.get("select_i32") {
Some(&Export::Function(index)) => index,
_ => panic!("Function not found"),
};
let invoke_fn: fn(i32, i32, i32, &Instance) -> i32 = get_instance_function!(result_object.instance, func_index);
let result = invoke_fn(2 as i32, 1 as i32, 0 as i32, &result_object.instance);
assert_eq!(result, 1 as i32);
}
// Line 38
fn c7_l38_action_invoke(result_object: &ResultObject) {
println!("Executing function {}", "c7_l38_action_invoke");
let func_index = match result_object.module.info.exports.get("select_i64") {
Some(&Export::Function(index)) => index,
_ => panic!("Function not found"),
};
let invoke_fn: fn(i64, i64, i32, &Instance) -> i64 = get_instance_function!(result_object.instance, func_index);
let result = invoke_fn(2 as i64, 1 as i64, -1 as i32, &result_object.instance);
assert_eq!(result, 2 as i64);
}
// Line 39
fn c8_l39_action_invoke(result_object: &ResultObject) {
println!("Executing function {}", "c8_l39_action_invoke");
let func_index = match result_object.module.info.exports.get("select_i64") {
Some(&Export::Function(index)) => index,
_ => panic!("Function not found"),
};
let invoke_fn: fn(i64, i64, i32, &Instance) -> i64 = get_instance_function!(result_object.instance, func_index);
let result = invoke_fn(2 as i64, 1 as i64, -252645136 as i32, &result_object.instance);
assert_eq!(result, 2 as i64);
}
// Line 41
fn c9_l41_action_invoke(result_object: &ResultObject) {
println!("Executing function {}", "c9_l41_action_invoke");
let func_index = match result_object.module.info.exports.get("select_f32") {
Some(&Export::Function(index)) => index,
_ => panic!("Function not found"),
};
let invoke_fn: fn(f32, f32, i32, &Instance) -> f32 = get_instance_function!(result_object.instance, func_index);
let result = invoke_fn(f32::from_bits(2143289344), 1.0 as f32, 1 as i32, &result_object.instance);
assert!(result.is_nan());
assert_eq!(result.is_sign_positive(), (f32::from_bits(2143289344)).is_sign_positive());
}
// Line 42
fn c10_l42_action_invoke(result_object: &ResultObject) {
println!("Executing function {}", "c10_l42_action_invoke");
let func_index = match result_object.module.info.exports.get("select_f32") {
Some(&Export::Function(index)) => index,
_ => panic!("Function not found"),
};
let invoke_fn: fn(f32, f32, i32, &Instance) -> f32 = get_instance_function!(result_object.instance, func_index);
let result = invoke_fn(f32::from_bits(2139226884), 1.0 as f32, 1 as i32, &result_object.instance);
assert!(result.is_nan());
assert_eq!(result.is_sign_positive(), (f32::from_bits(2139226884)).is_sign_positive());
}
// Line 43
fn c11_l43_action_invoke(result_object: &ResultObject) {
println!("Executing function {}", "c11_l43_action_invoke");
let func_index = match result_object.module.info.exports.get("select_f32") {
Some(&Export::Function(index)) => index,
_ => panic!("Function not found"),
};
let invoke_fn: fn(f32, f32, i32, &Instance) -> f32 = get_instance_function!(result_object.instance, func_index);
let result = invoke_fn(f32::from_bits(2143289344), 1.0 as f32, 0 as i32, &result_object.instance);
assert_eq!(result, 1.0 as f32);
}
// Line 44
fn c12_l44_action_invoke(result_object: &ResultObject) {
println!("Executing function {}", "c12_l44_action_invoke");
let func_index = match result_object.module.info.exports.get("select_f32") {
Some(&Export::Function(index)) => index,
_ => panic!("Function not found"),
};
let invoke_fn: fn(f32, f32, i32, &Instance) -> f32 = get_instance_function!(result_object.instance, func_index);
let result = invoke_fn(f32::from_bits(2139226884), 1.0 as f32, 0 as i32, &result_object.instance);
assert_eq!(result, 1.0 as f32);
}
// Line 45
fn c13_l45_action_invoke(result_object: &ResultObject) {
println!("Executing function {}", "c13_l45_action_invoke");
let func_index = match result_object.module.info.exports.get("select_f32") {
Some(&Export::Function(index)) => index,
_ => panic!("Function not found"),
};
let invoke_fn: fn(f32, f32, i32, &Instance) -> f32 = get_instance_function!(result_object.instance, func_index);
let result = invoke_fn(2.0 as f32, f32::from_bits(2143289344), 1 as i32, &result_object.instance);
assert_eq!(result, 2.0 as f32);
}
// Line 46
fn c14_l46_action_invoke(result_object: &ResultObject) {
println!("Executing function {}", "c14_l46_action_invoke");
let func_index = match result_object.module.info.exports.get("select_f32") {
Some(&Export::Function(index)) => index,
_ => panic!("Function not found"),
};
let invoke_fn: fn(f32, f32, i32, &Instance) -> f32 = get_instance_function!(result_object.instance, func_index);
let result = invoke_fn(2.0 as f32, f32::from_bits(2139226884), 1 as i32, &result_object.instance);
assert_eq!(result, 2.0 as f32);
}
// Line 47
fn c15_l47_action_invoke(result_object: &ResultObject) {
println!("Executing function {}", "c15_l47_action_invoke");
let func_index = match result_object.module.info.exports.get("select_f32") {
Some(&Export::Function(index)) => index,
_ => panic!("Function not found"),
};
let invoke_fn: fn(f32, f32, i32, &Instance) -> f32 = get_instance_function!(result_object.instance, func_index);
let result = invoke_fn(2.0 as f32, f32::from_bits(2143289344), 0 as i32, &result_object.instance);
assert!(result.is_nan());
assert_eq!(result.is_sign_positive(), (f32::from_bits(2143289344)).is_sign_positive());
}
// Line 48
fn c16_l48_action_invoke(result_object: &ResultObject) {
println!("Executing function {}", "c16_l48_action_invoke");
let func_index = match result_object.module.info.exports.get("select_f32") {
Some(&Export::Function(index)) => index,
_ => panic!("Function not found"),
};
let invoke_fn: fn(f32, f32, i32, &Instance) -> f32 = get_instance_function!(result_object.instance, func_index);
let result = invoke_fn(2.0 as f32, f32::from_bits(2139226884), 0 as i32, &result_object.instance);
assert!(result.is_nan());
assert_eq!(result.is_sign_positive(), (f32::from_bits(2139226884)).is_sign_positive());
}
// Line 50
fn c17_l50_action_invoke(result_object: &ResultObject) {
println!("Executing function {}", "c17_l50_action_invoke");
let func_index = match result_object.module.info.exports.get("select_f64") {
Some(&Export::Function(index)) => index,
_ => panic!("Function not found"),
};
let invoke_fn: fn(f64, f64, i32, &Instance) -> f64 = get_instance_function!(result_object.instance, func_index);
let result = invoke_fn(f64::from_bits(9221120237041090560), 1.0 as f64, 1 as i32, &result_object.instance);
assert!(result.is_nan());
assert_eq!(result.is_sign_positive(), (f64::from_bits(9221120237041090560)).is_sign_positive());
}
// Line 51
fn c18_l51_action_invoke(result_object: &ResultObject) {
println!("Executing function {}", "c18_l51_action_invoke");
let func_index = match result_object.module.info.exports.get("select_f64") {
Some(&Export::Function(index)) => index,
_ => panic!("Function not found"),
};
let invoke_fn: fn(f64, f64, i32, &Instance) -> f64 = get_instance_function!(result_object.instance, func_index);
let result = invoke_fn(f64::from_bits(9218868437227537156), 1.0 as f64, 1 as i32, &result_object.instance);
assert!(result.is_nan());
assert_eq!(result.is_sign_positive(), (f64::from_bits(9218868437227537156)).is_sign_positive());
}
// Line 52
fn c19_l52_action_invoke(result_object: &ResultObject) {
println!("Executing function {}", "c19_l52_action_invoke");
let func_index = match result_object.module.info.exports.get("select_f64") {
Some(&Export::Function(index)) => index,
_ => panic!("Function not found"),
};
let invoke_fn: fn(f64, f64, i32, &Instance) -> f64 = get_instance_function!(result_object.instance, func_index);
let result = invoke_fn(f64::from_bits(9221120237041090560), 1.0 as f64, 0 as i32, &result_object.instance);
assert_eq!(result, 1.0 as f64);
}
// Line 53
fn c20_l53_action_invoke(result_object: &ResultObject) {
println!("Executing function {}", "c20_l53_action_invoke");
let func_index = match result_object.module.info.exports.get("select_f64") {
Some(&Export::Function(index)) => index,
_ => panic!("Function not found"),
};
let invoke_fn: fn(f64, f64, i32, &Instance) -> f64 = get_instance_function!(result_object.instance, func_index);
let result = invoke_fn(f64::from_bits(9218868437227537156), 1.0 as f64, 0 as i32, &result_object.instance);
assert_eq!(result, 1.0 as f64);
}
// Line 54
fn c21_l54_action_invoke(result_object: &ResultObject) {
println!("Executing function {}", "c21_l54_action_invoke");
let func_index = match result_object.module.info.exports.get("select_f64") {
Some(&Export::Function(index)) => index,
_ => panic!("Function not found"),
};
let invoke_fn: fn(f64, f64, i32, &Instance) -> f64 = get_instance_function!(result_object.instance, func_index);
let result = invoke_fn(2.0 as f64, f64::from_bits(9221120237041090560), 1 as i32, &result_object.instance);
assert_eq!(result, 2.0 as f64);
}
// Line 55
fn c22_l55_action_invoke(result_object: &ResultObject) {
println!("Executing function {}", "c22_l55_action_invoke");
let func_index = match result_object.module.info.exports.get("select_f64") {
Some(&Export::Function(index)) => index,
_ => panic!("Function not found"),
};
let invoke_fn: fn(f64, f64, i32, &Instance) -> f64 = get_instance_function!(result_object.instance, func_index);
let result = invoke_fn(2.0 as f64, f64::from_bits(9218868437227537156), 1 as i32, &result_object.instance);
assert_eq!(result, 2.0 as f64);
}
// Line 56
fn c23_l56_action_invoke(result_object: &ResultObject) {
println!("Executing function {}", "c23_l56_action_invoke");
let func_index = match result_object.module.info.exports.get("select_f64") {
Some(&Export::Function(index)) => index,
_ => panic!("Function not found"),
};
let invoke_fn: fn(f64, f64, i32, &Instance) -> f64 = get_instance_function!(result_object.instance, func_index);
let result = invoke_fn(2.0 as f64, f64::from_bits(9221120237041090560), 0 as i32, &result_object.instance);
assert!(result.is_nan());
assert_eq!(result.is_sign_positive(), (f64::from_bits(9221120237041090560)).is_sign_positive());
}
// Line 57
fn c24_l57_action_invoke(result_object: &ResultObject) {
println!("Executing function {}", "c24_l57_action_invoke");
let func_index = match result_object.module.info.exports.get("select_f64") {
Some(&Export::Function(index)) => index,
_ => panic!("Function not found"),
};
let invoke_fn: fn(f64, f64, i32, &Instance) -> f64 = get_instance_function!(result_object.instance, func_index);
let result = invoke_fn(2.0 as f64, f64::from_bits(9218868437227537156), 0 as i32, &result_object.instance);
assert!(result.is_nan());
assert_eq!(result.is_sign_positive(), (f64::from_bits(9218868437227537156)).is_sign_positive());
}
// Line 59
fn c25_l59_action_invoke(result_object: &ResultObject) {
println!("Executing function {}", "c25_l59_action_invoke");
let func_index = match result_object.module.info.exports.get("select_trap_l") {
Some(&Export::Function(index)) => index,
_ => panic!("Function not found"),
};
let invoke_fn: fn(i32, &Instance) = get_instance_function!(result_object.instance, func_index);
let result = invoke_fn(1 as i32, &result_object.instance);
}
#[test]
fn c25_l59_assert_trap() {
let result_object = create_module_1();
let result = call_protected!(c25_l59_action_invoke(&result_object));
assert!(result.is_err());
}
// Line 60
fn c26_l60_action_invoke(result_object: &ResultObject) {
println!("Executing function {}", "c26_l60_action_invoke");
let func_index = match result_object.module.info.exports.get("select_trap_l") {
Some(&Export::Function(index)) => index,
_ => panic!("Function not found"),
};
let invoke_fn: fn(i32, &Instance) = get_instance_function!(result_object.instance, func_index);
let result = invoke_fn(0 as i32, &result_object.instance);
}
#[test]
fn c26_l60_assert_trap() {
let result_object = create_module_1();
let result = call_protected!(c26_l60_action_invoke(&result_object));
assert!(result.is_err());
}
// Line 61
fn c27_l61_action_invoke(result_object: &ResultObject) {
println!("Executing function {}", "c27_l61_action_invoke");
let func_index = match result_object.module.info.exports.get("select_trap_r") {
Some(&Export::Function(index)) => index,
_ => panic!("Function not found"),
};
let invoke_fn: fn(i32, &Instance) = get_instance_function!(result_object.instance, func_index);
let result = invoke_fn(1 as i32, &result_object.instance);
}
#[test]
fn c27_l61_assert_trap() {
let result_object = create_module_1();
let result = call_protected!(c27_l61_action_invoke(&result_object));
assert!(result.is_err());
}
// Line 62
fn c28_l62_action_invoke(result_object: &ResultObject) {
println!("Executing function {}", "c28_l62_action_invoke");
let func_index = match result_object.module.info.exports.get("select_trap_r") {
Some(&Export::Function(index)) => index,
_ => panic!("Function not found"),
};
let invoke_fn: fn(i32, &Instance) = get_instance_function!(result_object.instance, func_index);
let result = invoke_fn(0 as i32, &result_object.instance);
}
#[test]
fn c28_l62_assert_trap() {
let result_object = create_module_1();
let result = call_protected!(c28_l62_action_invoke(&result_object));
assert!(result.is_err());
}
// Line 65
#[test]
fn c29_l65_assert_invalid() {
let wasm_binary = [0, 97, 115, 109, 1, 0, 0, 0, 1, 4, 1, 96, 0, 0, 3, 2, 1, 0, 10, 9, 1, 7, 0, 1, 1, 65, 1, 27, 11];
let compilation = compile(wasm_binary.to_vec());
assert!(compilation.is_err(), "WASM should not compile as is invalid");
}
#[test]
fn test_module_1() {
let result_object = create_module_1();
// We group the calls together
start_module_1(&result_object);
c1_l31_action_invoke(&result_object);
c2_l32_action_invoke(&result_object);
c3_l33_action_invoke(&result_object);
c4_l34_action_invoke(&result_object);
c5_l36_action_invoke(&result_object);
c6_l37_action_invoke(&result_object);
c7_l38_action_invoke(&result_object);
c8_l39_action_invoke(&result_object);
c9_l41_action_invoke(&result_object);
c10_l42_action_invoke(&result_object);
c11_l43_action_invoke(&result_object);
c12_l44_action_invoke(&result_object);
c13_l45_action_invoke(&result_object);
c14_l46_action_invoke(&result_object);
c15_l47_action_invoke(&result_object);
c16_l48_action_invoke(&result_object);
c17_l50_action_invoke(&result_object);
c18_l51_action_invoke(&result_object);
c19_l52_action_invoke(&result_object);
c20_l53_action_invoke(&result_object);
c21_l54_action_invoke(&result_object);
c22_l55_action_invoke(&result_object);
c23_l56_action_invoke(&result_object);
c24_l57_action_invoke(&result_object);
}