Added labels spectest

This commit is contained in:
Syrus Akbary 2018-10-24 00:25:11 +02:00
parent 1b728e8903
commit a0a8e7512b
4 changed files with 1132 additions and 1 deletions

321
spectests/labels.wast Normal file
View File

@ -0,0 +1,321 @@
(module
(func (export "block") (result i32)
(block $exit (result i32)
(br $exit (i32.const 1))
(i32.const 0)
)
)
(func (export "loop1") (result i32)
(local $i i32)
(set_local $i (i32.const 0))
(block $exit (result i32)
(loop $cont (result i32)
(set_local $i (i32.add (get_local $i) (i32.const 1)))
(if (i32.eq (get_local $i) (i32.const 5))
(then (br $exit (get_local $i)))
)
(br $cont)
)
)
)
(func (export "loop2") (result i32)
(local $i i32)
(set_local $i (i32.const 0))
(block $exit (result i32)
(loop $cont (result i32)
(set_local $i (i32.add (get_local $i) (i32.const 1)))
(if (i32.eq (get_local $i) (i32.const 5))
(then (br $cont))
)
(if (i32.eq (get_local $i) (i32.const 8))
(then (br $exit (get_local $i)))
)
(set_local $i (i32.add (get_local $i) (i32.const 1)))
(br $cont)
)
)
)
(func (export "loop3") (result i32)
(local $i i32)
(set_local $i (i32.const 0))
(block $exit (result i32)
(loop $cont (result i32)
(set_local $i (i32.add (get_local $i) (i32.const 1)))
(if (i32.eq (get_local $i) (i32.const 5))
(then (br $exit (get_local $i)))
)
(get_local $i)
)
)
)
(func (export "loop4") (param $max i32) (result i32)
(local $i i32)
(set_local $i (i32.const 1))
(block $exit (result i32)
(loop $cont (result i32)
(set_local $i (i32.add (get_local $i) (get_local $i)))
(if (i32.gt_u (get_local $i) (get_local $max))
(then (br $exit (get_local $i)))
)
(br $cont)
)
)
)
(func (export "loop5") (result i32)
(i32.add
(loop $l (result i32) (i32.const 1))
(i32.const 1)
)
)
(func (export "loop6") (result i32)
(loop (result i32)
(br_if 0 (i32.const 0))
(i32.const 3)
)
)
(func (export "if") (result i32)
(local $i i32)
(set_local $i (i32.const 0))
(block
(if $l
(i32.const 1)
(then (br $l) (set_local $i (i32.const 666)))
)
(set_local $i (i32.add (get_local $i) (i32.const 1)))
(if $l
(i32.const 1)
(then (br $l) (set_local $i (i32.const 666)))
(else (set_local $i (i32.const 888)))
)
(set_local $i (i32.add (get_local $i) (i32.const 1)))
(if $l
(i32.const 1)
(then (br $l) (set_local $i (i32.const 666)))
(else (set_local $i (i32.const 888)))
)
(set_local $i (i32.add (get_local $i) (i32.const 1)))
(if $l
(i32.const 0)
(then (set_local $i (i32.const 888)))
(else (br $l) (set_local $i (i32.const 666)))
)
(set_local $i (i32.add (get_local $i) (i32.const 1)))
(if $l
(i32.const 0)
(then (set_local $i (i32.const 888)))
(else (br $l) (set_local $i (i32.const 666)))
)
(set_local $i (i32.add (get_local $i) (i32.const 1)))
)
(get_local $i)
)
(func (export "if2") (result i32)
(local $i i32)
(set_local $i (i32.const 0))
(block
(if
(i32.const 1)
(then (br 0) (set_local $i (i32.const 666)))
)
(set_local $i (i32.add (get_local $i) (i32.const 1)))
(if
(i32.const 1)
(then (br 0) (set_local $i (i32.const 666)))
(else (set_local $i (i32.const 888)))
)
(set_local $i (i32.add (get_local $i) (i32.const 1)))
(if
(i32.const 1)
(then (br 0) (set_local $i (i32.const 666)))
(else (set_local $i (i32.const 888)))
)
(set_local $i (i32.add (get_local $i) (i32.const 1)))
(if
(i32.const 0)
(then (set_local $i (i32.const 888)))
(else (br 0) (set_local $i (i32.const 666)))
)
(set_local $i (i32.add (get_local $i) (i32.const 1)))
(if
(i32.const 0)
(then (set_local $i (i32.const 888)))
(else (br 0) (set_local $i (i32.const 666)))
)
(set_local $i (i32.add (get_local $i) (i32.const 1)))
)
(get_local $i)
)
(func (export "switch") (param i32) (result i32)
(block $ret (result i32)
(i32.mul (i32.const 10)
(block $exit (result i32)
(block $0
(block $default
(block $3
(block $2
(block $1
(br_table $0 $1 $2 $3 $default (get_local 0))
) ;; 1
) ;; 2
(br $exit (i32.const 2))
) ;; 3
(br $ret (i32.const 3))
) ;; default
) ;; 0
(i32.const 5)
)
)
)
)
(func (export "return") (param i32) (result i32)
(block $default
(block $1
(block $0
(br_table $0 $1 (get_local 0))
(br $default)
) ;; 0
(return (i32.const 0))
) ;; 1
) ;; default
(i32.const 2)
)
(func (export "br_if0") (result i32)
(local $i i32)
(set_local $i (i32.const 0))
(block $outer (result i32)
(block $inner
(br_if $inner (i32.const 0))
(set_local $i (i32.or (get_local $i) (i32.const 0x1)))
(br_if $inner (i32.const 1))
(set_local $i (i32.or (get_local $i) (i32.const 0x2)))
)
(drop (br_if $outer
(block (result i32)
(set_local $i (i32.or (get_local $i) (i32.const 0x4)))
(get_local $i)
)
(i32.const 0)
))
(set_local $i (i32.or (get_local $i) (i32.const 0x8)))
(drop (br_if $outer
(block (result i32)
(set_local $i (i32.or (get_local $i) (i32.const 0x10)))
(get_local $i)
)
(i32.const 1)
))
(set_local $i (i32.or (get_local $i) (i32.const 0x20))) (get_local $i)
)
)
(func (export "br_if1") (result i32)
(block $l0 (result i32)
(drop
(br_if $l0
(block $l1 (result i32) (br $l1 (i32.const 1)))
(i32.const 1)
)
)
(i32.const 1)
)
)
(func (export "br_if2") (result i32)
(block $l0 (result i32)
(if (i32.const 1)
(then (br $l0 (block $l1 (result i32) (br $l1 (i32.const 1)))))
)
(i32.const 1)
)
)
(func (export "br_if3") (result i32)
(local $i1 i32)
(drop
(i32.add
(block $l0 (result i32)
(drop (br_if $l0
(block (result i32) (set_local $i1 (i32.const 1)) (get_local $i1))
(block (result i32) (set_local $i1 (i32.const 2)) (get_local $i1))
))
(i32.const 0)
)
(i32.const 0)
)
)
(get_local $i1)
)
(func (export "br") (result i32)
(block $l0 (result i32)
(if (i32.const 1)
(then (br $l0 (block $l1 (result i32) (br $l1 (i32.const 1)))))
(else (block (drop (block $l1 (result i32) (br $l1 (i32.const 1))))))
)
(i32.const 1)
)
)
(func (export "shadowing") (result i32)
(block $l1 (result i32) (i32.xor (br $l1 (i32.const 1)) (i32.const 2)))
)
(func (export "redefinition") (result i32)
(block $l1 (result i32)
(i32.add
(block $l1 (result i32) (i32.const 2))
(block $l1 (result i32) (br $l1 (i32.const 3)))
)
)
)
)
(assert_return (invoke "block") (i32.const 1))
(assert_return (invoke "loop1") (i32.const 5))
(assert_return (invoke "loop2") (i32.const 8))
(assert_return (invoke "loop3") (i32.const 1))
(assert_return (invoke "loop4" (i32.const 8)) (i32.const 16))
(assert_return (invoke "loop5") (i32.const 2))
(assert_return (invoke "loop6") (i32.const 3))
(assert_return (invoke "if") (i32.const 5))
(assert_return (invoke "if2") (i32.const 5))
(assert_return (invoke "switch" (i32.const 0)) (i32.const 50))
(assert_return (invoke "switch" (i32.const 1)) (i32.const 20))
(assert_return (invoke "switch" (i32.const 2)) (i32.const 20))
(assert_return (invoke "switch" (i32.const 3)) (i32.const 3))
(assert_return (invoke "switch" (i32.const 4)) (i32.const 50))
(assert_return (invoke "switch" (i32.const 5)) (i32.const 50))
(assert_return (invoke "return" (i32.const 0)) (i32.const 0))
(assert_return (invoke "return" (i32.const 1)) (i32.const 2))
(assert_return (invoke "return" (i32.const 2)) (i32.const 2))
(assert_return (invoke "br_if0") (i32.const 0x1d))
(assert_return (invoke "br_if1") (i32.const 1))
(assert_return (invoke "br_if2") (i32.const 1))
(assert_return (invoke "br_if3") (i32.const 2))
(assert_return (invoke "br") (i32.const 1))
(assert_return (invoke "shadowing") (i32.const 1))
(assert_return (invoke "redefinition") (i32.const 5))
(assert_invalid
(module (func (block $l (f32.neg (br_if $l (i32.const 1))) (nop))))
"type mismatch"
)
(assert_invalid
(module (func (block $l (br_if $l (f32.const 0) (i32.const 1)))))
"type mismatch"
)
(assert_invalid
(module (func (block $l (br_if $l (f32.const 0) (i32.const 1)))))
"type mismatch"
)

View File

@ -15,7 +15,7 @@ static ENV_VAR: &str = "WASM_GENERATE_SPECTESTS";
static BANNER: &str = "// Rust test file autogenerated with cargo build (src/build_spectests.rs).
// Please do NOT modify it by hand, as it will be reseted on next build.\n";
const TESTS: [&str; 14] = [
const TESTS: [&str; 15] = [
"spectests/block.wast",
"spectests/br.wast",
"spectests/br_if.wast",
@ -27,6 +27,7 @@ const TESTS: [&str; 14] = [
"spectests/func_ptrs.wast",
"spectests/i32_.wast",
"spectests/i64_.wast",
"spectests/labels.wast",
"spectests/memory.wast",
"spectests/set_local.wast",
"spectests/types.wast",

808
src/spectests/labels.rs Normal file
View File

@ -0,0 +1,808 @@
// Rust test file autogenerated with cargo build (src/build_spectests.rs).
// Please do NOT modify it by hand, as it will be reseted on next build.
// Test based on spectests/labels.wast
#![allow(
warnings,
dead_code
)]
use crate::webassembly::{instantiate, compile, ImportObject, ResultObject, VmCtx, Export};
use super::_common::spectest_importobject;
use wabt::wat2wasm;
// Line 1
fn create_module_1() -> ResultObject {
let module_str = "(module
(type (;0;) (func (result i32)))
(type (;1;) (func (param i32) (result i32)))
(func (;0;) (type 0) (result i32)
block (result i32) ;; label = @1
i32.const 1
br 0 (;@1;)
i32.const 0
end)
(func (;1;) (type 0) (result i32)
(local i32)
i32.const 0
set_local 0
block (result i32) ;; label = @1
loop (result i32) ;; label = @2
get_local 0
i32.const 1
i32.add
set_local 0
get_local 0
i32.const 5
i32.eq
if ;; label = @3
get_local 0
br 2 (;@1;)
end
br 0 (;@2;)
end
end)
(func (;2;) (type 0) (result i32)
(local i32)
i32.const 0
set_local 0
block (result i32) ;; label = @1
loop (result i32) ;; label = @2
get_local 0
i32.const 1
i32.add
set_local 0
get_local 0
i32.const 5
i32.eq
if ;; label = @3
br 1 (;@2;)
end
get_local 0
i32.const 8
i32.eq
if ;; label = @3
get_local 0
br 2 (;@1;)
end
get_local 0
i32.const 1
i32.add
set_local 0
br 0 (;@2;)
end
end)
(func (;3;) (type 0) (result i32)
(local i32)
i32.const 0
set_local 0
block (result i32) ;; label = @1
loop (result i32) ;; label = @2
get_local 0
i32.const 1
i32.add
set_local 0
get_local 0
i32.const 5
i32.eq
if ;; label = @3
get_local 0
br 2 (;@1;)
end
get_local 0
end
end)
(func (;4;) (type 1) (param i32) (result i32)
(local i32)
i32.const 1
set_local 1
block (result i32) ;; label = @1
loop (result i32) ;; label = @2
get_local 1
get_local 1
i32.add
set_local 1
get_local 1
get_local 0
i32.gt_u
if ;; label = @3
get_local 1
br 2 (;@1;)
end
br 0 (;@2;)
end
end)
(func (;5;) (type 0) (result i32)
loop (result i32) ;; label = @1
i32.const 1
end
i32.const 1
i32.add)
(func (;6;) (type 0) (result i32)
loop (result i32) ;; label = @1
i32.const 0
br_if 0 (;@1;)
i32.const 3
end)
(func (;7;) (type 0) (result i32)
(local i32)
i32.const 0
set_local 0
block ;; label = @1
i32.const 1
if ;; label = @2
br 0 (;@2;)
i32.const 666
set_local 0
end
get_local 0
i32.const 1
i32.add
set_local 0
i32.const 1
if ;; label = @2
br 0 (;@2;)
i32.const 666
set_local 0
else
i32.const 888
set_local 0
end
get_local 0
i32.const 1
i32.add
set_local 0
i32.const 1
if ;; label = @2
br 0 (;@2;)
i32.const 666
set_local 0
else
i32.const 888
set_local 0
end
get_local 0
i32.const 1
i32.add
set_local 0
i32.const 0
if ;; label = @2
i32.const 888
set_local 0
else
br 0 (;@2;)
i32.const 666
set_local 0
end
get_local 0
i32.const 1
i32.add
set_local 0
i32.const 0
if ;; label = @2
i32.const 888
set_local 0
else
br 0 (;@2;)
i32.const 666
set_local 0
end
get_local 0
i32.const 1
i32.add
set_local 0
end
get_local 0)
(func (;8;) (type 0) (result i32)
(local i32)
i32.const 0
set_local 0
block ;; label = @1
i32.const 1
if ;; label = @2
br 0 (;@2;)
i32.const 666
set_local 0
end
get_local 0
i32.const 1
i32.add
set_local 0
i32.const 1
if ;; label = @2
br 0 (;@2;)
i32.const 666
set_local 0
else
i32.const 888
set_local 0
end
get_local 0
i32.const 1
i32.add
set_local 0
i32.const 1
if ;; label = @2
br 0 (;@2;)
i32.const 666
set_local 0
else
i32.const 888
set_local 0
end
get_local 0
i32.const 1
i32.add
set_local 0
i32.const 0
if ;; label = @2
i32.const 888
set_local 0
else
br 0 (;@2;)
i32.const 666
set_local 0
end
get_local 0
i32.const 1
i32.add
set_local 0
i32.const 0
if ;; label = @2
i32.const 888
set_local 0
else
br 0 (;@2;)
i32.const 666
set_local 0
end
get_local 0
i32.const 1
i32.add
set_local 0
end
get_local 0)
(func (;9;) (type 1) (param i32) (result i32)
block (result i32) ;; label = @1
i32.const 10
block (result i32) ;; label = @2
block ;; label = @3
block ;; label = @4
block ;; label = @5
block ;; label = @6
block ;; label = @7
get_local 0
br_table 4 (;@3;) 0 (;@7;) 1 (;@6;) 2 (;@5;) 3 (;@4;)
end
end
i32.const 2
br 3 (;@2;)
end
i32.const 3
br 3 (;@1;)
end
end
i32.const 5
end
i32.mul
end)
(func (;10;) (type 1) (param i32) (result i32)
block ;; label = @1
block ;; label = @2
block ;; label = @3
get_local 0
br_table 0 (;@3;) 1 (;@2;)
br 2 (;@1;)
end
i32.const 0
return
end
end
i32.const 2)
(func (;11;) (type 0) (result i32)
(local i32)
i32.const 0
set_local 0
block (result i32) ;; label = @1
block ;; label = @2
i32.const 0
br_if 0 (;@2;)
get_local 0
i32.const 1
i32.or
set_local 0
i32.const 1
br_if 0 (;@2;)
get_local 0
i32.const 2
i32.or
set_local 0
end
block (result i32) ;; label = @2
get_local 0
i32.const 4
i32.or
set_local 0
get_local 0
end
i32.const 0
br_if 0 (;@1;)
drop
get_local 0
i32.const 8
i32.or
set_local 0
block (result i32) ;; label = @2
get_local 0
i32.const 16
i32.or
set_local 0
get_local 0
end
i32.const 1
br_if 0 (;@1;)
drop
get_local 0
i32.const 32
i32.or
set_local 0
get_local 0
end)
(func (;12;) (type 0) (result i32)
block (result i32) ;; label = @1
block (result i32) ;; label = @2
i32.const 1
br 0 (;@2;)
end
i32.const 1
br_if 0 (;@1;)
drop
i32.const 1
end)
(func (;13;) (type 0) (result i32)
block (result i32) ;; label = @1
i32.const 1
if ;; label = @2
block (result i32) ;; label = @3
i32.const 1
br 0 (;@3;)
end
br 1 (;@1;)
end
i32.const 1
end)
(func (;14;) (type 0) (result i32)
(local i32)
block (result i32) ;; label = @1
block (result i32) ;; label = @2
i32.const 1
set_local 0
get_local 0
end
block (result i32) ;; label = @2
i32.const 2
set_local 0
get_local 0
end
br_if 0 (;@1;)
drop
i32.const 0
end
i32.const 0
i32.add
drop
get_local 0)
(func (;15;) (type 0) (result i32)
block (result i32) ;; label = @1
i32.const 1
if ;; label = @2
block (result i32) ;; label = @3
i32.const 1
br 0 (;@3;)
end
br 1 (;@1;)
else
block ;; label = @3
block (result i32) ;; label = @4
i32.const 1
br 0 (;@4;)
end
drop
end
end
i32.const 1
end)
(func (;16;) (type 0) (result i32)
block (result i32) ;; label = @1
i32.const 1
br 0 (;@1;)
i32.const 2
i32.xor
end)
(func (;17;) (type 0) (result i32)
block (result i32) ;; label = @1
block (result i32) ;; label = @2
i32.const 2
end
block (result i32) ;; label = @2
i32.const 3
br 0 (;@2;)
end
i32.add
end)
(export \"block\" (func 0))
(export \"loop1\" (func 1))
(export \"loop2\" (func 2))
(export \"loop3\" (func 3))
(export \"loop4\" (func 4))
(export \"loop5\" (func 5))
(export \"loop6\" (func 6))
(export \"if\" (func 7))
(export \"if2\" (func 8))
(export \"switch\" (func 9))
(export \"return\" (func 10))
(export \"br_if0\" (func 11))
(export \"br_if1\" (func 12))
(export \"br_if2\" (func 13))
(export \"br_if3\" (func 14))
(export \"br\" (func 15))
(export \"shadowing\" (func 16))
(export \"redefinition\" (func 17)))
";
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")
}
// Line 284
fn l284_assert_return_invoke(result_object: &ResultObject) {
let func_index = match result_object.module.info.exports.get("block") {
Some(&Export::Function(index)) => index,
_ => panic!("Function not found"),
};
let invoke_fn: fn(&VmCtx) -> i32 = get_instance_function!(result_object.instance, func_index);
let vm_context = result_object.instance.generate_context();
let result = invoke_fn(&vm_context);
assert_eq!(result, 1 as i32);
}
// Line 285
fn l285_assert_return_invoke(result_object: &ResultObject) {
let func_index = match result_object.module.info.exports.get("loop1") {
Some(&Export::Function(index)) => index,
_ => panic!("Function not found"),
};
let invoke_fn: fn(&VmCtx) -> i32 = get_instance_function!(result_object.instance, func_index);
let vm_context = result_object.instance.generate_context();
let result = invoke_fn(&vm_context);
assert_eq!(result, 5 as i32);
}
// Line 286
fn l286_assert_return_invoke(result_object: &ResultObject) {
let func_index = match result_object.module.info.exports.get("loop2") {
Some(&Export::Function(index)) => index,
_ => panic!("Function not found"),
};
let invoke_fn: fn(&VmCtx) -> i32 = get_instance_function!(result_object.instance, func_index);
let vm_context = result_object.instance.generate_context();
let result = invoke_fn(&vm_context);
assert_eq!(result, 8 as i32);
}
// Line 287
fn l287_assert_return_invoke(result_object: &ResultObject) {
let func_index = match result_object.module.info.exports.get("loop3") {
Some(&Export::Function(index)) => index,
_ => panic!("Function not found"),
};
let invoke_fn: fn(&VmCtx) -> i32 = get_instance_function!(result_object.instance, func_index);
let vm_context = result_object.instance.generate_context();
let result = invoke_fn(&vm_context);
assert_eq!(result, 1 as i32);
}
// Line 288
fn l288_assert_return_invoke(result_object: &ResultObject) {
let func_index = match result_object.module.info.exports.get("loop4") {
Some(&Export::Function(index)) => index,
_ => panic!("Function not found"),
};
let invoke_fn: fn(i32, &VmCtx) -> i32 = get_instance_function!(result_object.instance, func_index);
let vm_context = result_object.instance.generate_context();
let result = invoke_fn(8 as i32, &vm_context);
assert_eq!(result, 16 as i32);
}
// Line 289
fn l289_assert_return_invoke(result_object: &ResultObject) {
let func_index = match result_object.module.info.exports.get("loop5") {
Some(&Export::Function(index)) => index,
_ => panic!("Function not found"),
};
let invoke_fn: fn(&VmCtx) -> i32 = get_instance_function!(result_object.instance, func_index);
let vm_context = result_object.instance.generate_context();
let result = invoke_fn(&vm_context);
assert_eq!(result, 2 as i32);
}
// Line 290
fn l290_assert_return_invoke(result_object: &ResultObject) {
let func_index = match result_object.module.info.exports.get("loop6") {
Some(&Export::Function(index)) => index,
_ => panic!("Function not found"),
};
let invoke_fn: fn(&VmCtx) -> i32 = get_instance_function!(result_object.instance, func_index);
let vm_context = result_object.instance.generate_context();
let result = invoke_fn(&vm_context);
assert_eq!(result, 3 as i32);
}
// Line 291
fn l291_assert_return_invoke(result_object: &ResultObject) {
let func_index = match result_object.module.info.exports.get("if") {
Some(&Export::Function(index)) => index,
_ => panic!("Function not found"),
};
let invoke_fn: fn(&VmCtx) -> i32 = get_instance_function!(result_object.instance, func_index);
let vm_context = result_object.instance.generate_context();
let result = invoke_fn(&vm_context);
assert_eq!(result, 5 as i32);
}
// Line 292
fn l292_assert_return_invoke(result_object: &ResultObject) {
let func_index = match result_object.module.info.exports.get("if2") {
Some(&Export::Function(index)) => index,
_ => panic!("Function not found"),
};
let invoke_fn: fn(&VmCtx) -> i32 = get_instance_function!(result_object.instance, func_index);
let vm_context = result_object.instance.generate_context();
let result = invoke_fn(&vm_context);
assert_eq!(result, 5 as i32);
}
// Line 293
fn l293_assert_return_invoke(result_object: &ResultObject) {
let func_index = match result_object.module.info.exports.get("switch") {
Some(&Export::Function(index)) => index,
_ => panic!("Function not found"),
};
let invoke_fn: fn(i32, &VmCtx) -> i32 = get_instance_function!(result_object.instance, func_index);
let vm_context = result_object.instance.generate_context();
let result = invoke_fn(0 as i32, &vm_context);
assert_eq!(result, 50 as i32);
}
// Line 294
fn l294_assert_return_invoke(result_object: &ResultObject) {
let func_index = match result_object.module.info.exports.get("switch") {
Some(&Export::Function(index)) => index,
_ => panic!("Function not found"),
};
let invoke_fn: fn(i32, &VmCtx) -> i32 = get_instance_function!(result_object.instance, func_index);
let vm_context = result_object.instance.generate_context();
let result = invoke_fn(1 as i32, &vm_context);
assert_eq!(result, 20 as i32);
}
// Line 295
fn l295_assert_return_invoke(result_object: &ResultObject) {
let func_index = match result_object.module.info.exports.get("switch") {
Some(&Export::Function(index)) => index,
_ => panic!("Function not found"),
};
let invoke_fn: fn(i32, &VmCtx) -> i32 = get_instance_function!(result_object.instance, func_index);
let vm_context = result_object.instance.generate_context();
let result = invoke_fn(2 as i32, &vm_context);
assert_eq!(result, 20 as i32);
}
// Line 296
fn l296_assert_return_invoke(result_object: &ResultObject) {
let func_index = match result_object.module.info.exports.get("switch") {
Some(&Export::Function(index)) => index,
_ => panic!("Function not found"),
};
let invoke_fn: fn(i32, &VmCtx) -> i32 = get_instance_function!(result_object.instance, func_index);
let vm_context = result_object.instance.generate_context();
let result = invoke_fn(3 as i32, &vm_context);
assert_eq!(result, 3 as i32);
}
// Line 297
fn l297_assert_return_invoke(result_object: &ResultObject) {
let func_index = match result_object.module.info.exports.get("switch") {
Some(&Export::Function(index)) => index,
_ => panic!("Function not found"),
};
let invoke_fn: fn(i32, &VmCtx) -> i32 = get_instance_function!(result_object.instance, func_index);
let vm_context = result_object.instance.generate_context();
let result = invoke_fn(4 as i32, &vm_context);
assert_eq!(result, 50 as i32);
}
// Line 298
fn l298_assert_return_invoke(result_object: &ResultObject) {
let func_index = match result_object.module.info.exports.get("switch") {
Some(&Export::Function(index)) => index,
_ => panic!("Function not found"),
};
let invoke_fn: fn(i32, &VmCtx) -> i32 = get_instance_function!(result_object.instance, func_index);
let vm_context = result_object.instance.generate_context();
let result = invoke_fn(5 as i32, &vm_context);
assert_eq!(result, 50 as i32);
}
// Line 299
fn l299_assert_return_invoke(result_object: &ResultObject) {
let func_index = match result_object.module.info.exports.get("return") {
Some(&Export::Function(index)) => index,
_ => panic!("Function not found"),
};
let invoke_fn: fn(i32, &VmCtx) -> i32 = get_instance_function!(result_object.instance, func_index);
let vm_context = result_object.instance.generate_context();
let result = invoke_fn(0 as i32, &vm_context);
assert_eq!(result, 0 as i32);
}
// Line 300
fn l300_assert_return_invoke(result_object: &ResultObject) {
let func_index = match result_object.module.info.exports.get("return") {
Some(&Export::Function(index)) => index,
_ => panic!("Function not found"),
};
let invoke_fn: fn(i32, &VmCtx) -> i32 = get_instance_function!(result_object.instance, func_index);
let vm_context = result_object.instance.generate_context();
let result = invoke_fn(1 as i32, &vm_context);
assert_eq!(result, 2 as i32);
}
// Line 301
fn l301_assert_return_invoke(result_object: &ResultObject) {
let func_index = match result_object.module.info.exports.get("return") {
Some(&Export::Function(index)) => index,
_ => panic!("Function not found"),
};
let invoke_fn: fn(i32, &VmCtx) -> i32 = get_instance_function!(result_object.instance, func_index);
let vm_context = result_object.instance.generate_context();
let result = invoke_fn(2 as i32, &vm_context);
assert_eq!(result, 2 as i32);
}
// Line 302
fn l302_assert_return_invoke(result_object: &ResultObject) {
let func_index = match result_object.module.info.exports.get("br_if0") {
Some(&Export::Function(index)) => index,
_ => panic!("Function not found"),
};
let invoke_fn: fn(&VmCtx) -> i32 = get_instance_function!(result_object.instance, func_index);
let vm_context = result_object.instance.generate_context();
let result = invoke_fn(&vm_context);
assert_eq!(result, 29 as i32);
}
// Line 303
fn l303_assert_return_invoke(result_object: &ResultObject) {
let func_index = match result_object.module.info.exports.get("br_if1") {
Some(&Export::Function(index)) => index,
_ => panic!("Function not found"),
};
let invoke_fn: fn(&VmCtx) -> i32 = get_instance_function!(result_object.instance, func_index);
let vm_context = result_object.instance.generate_context();
let result = invoke_fn(&vm_context);
assert_eq!(result, 1 as i32);
}
// Line 304
fn l304_assert_return_invoke(result_object: &ResultObject) {
let func_index = match result_object.module.info.exports.get("br_if2") {
Some(&Export::Function(index)) => index,
_ => panic!("Function not found"),
};
let invoke_fn: fn(&VmCtx) -> i32 = get_instance_function!(result_object.instance, func_index);
let vm_context = result_object.instance.generate_context();
let result = invoke_fn(&vm_context);
assert_eq!(result, 1 as i32);
}
// Line 305
fn l305_assert_return_invoke(result_object: &ResultObject) {
let func_index = match result_object.module.info.exports.get("br_if3") {
Some(&Export::Function(index)) => index,
_ => panic!("Function not found"),
};
let invoke_fn: fn(&VmCtx) -> i32 = get_instance_function!(result_object.instance, func_index);
let vm_context = result_object.instance.generate_context();
let result = invoke_fn(&vm_context);
assert_eq!(result, 2 as i32);
}
// Line 306
fn l306_assert_return_invoke(result_object: &ResultObject) {
let func_index = match result_object.module.info.exports.get("br") {
Some(&Export::Function(index)) => index,
_ => panic!("Function not found"),
};
let invoke_fn: fn(&VmCtx) -> i32 = get_instance_function!(result_object.instance, func_index);
let vm_context = result_object.instance.generate_context();
let result = invoke_fn(&vm_context);
assert_eq!(result, 1 as i32);
}
// Line 307
fn l307_assert_return_invoke(result_object: &ResultObject) {
let func_index = match result_object.module.info.exports.get("shadowing") {
Some(&Export::Function(index)) => index,
_ => panic!("Function not found"),
};
let invoke_fn: fn(&VmCtx) -> i32 = get_instance_function!(result_object.instance, func_index);
let vm_context = result_object.instance.generate_context();
let result = invoke_fn(&vm_context);
assert_eq!(result, 1 as i32);
}
// Line 308
fn l308_assert_return_invoke(result_object: &ResultObject) {
let func_index = match result_object.module.info.exports.get("redefinition") {
Some(&Export::Function(index)) => index,
_ => panic!("Function not found"),
};
let invoke_fn: fn(&VmCtx) -> i32 = get_instance_function!(result_object.instance, func_index);
let vm_context = result_object.instance.generate_context();
let result = invoke_fn(&vm_context);
assert_eq!(result, 5 as i32);
}
// Line 311
#[test]
fn l311_assert_invalid() {
let wasm_binary = [0, 97, 115, 109, 1, 0, 0, 0, 1, 4, 1, 96, 0, 0, 3, 2, 1, 0, 10, 13, 1, 11, 0, 2, 64, 65, 1, 13, 0, 140, 1, 11, 11];
let compilation = compile(wasm_binary.to_vec());
assert!(compilation.is_err(), "WASM should not compile as is invalid");
}
// Line 315
#[test]
fn l315_assert_invalid() {
let wasm_binary = [0, 97, 115, 109, 1, 0, 0, 0, 1, 4, 1, 96, 0, 0, 3, 2, 1, 0, 10, 16, 1, 14, 0, 2, 64, 67, 0, 0, 0, 0, 65, 1, 13, 0, 11, 11];
let compilation = compile(wasm_binary.to_vec());
assert!(compilation.is_err(), "WASM should not compile as is invalid");
}
// Line 319
#[test]
fn l319_assert_invalid() {
let wasm_binary = [0, 97, 115, 109, 1, 0, 0, 0, 1, 4, 1, 96, 0, 0, 3, 2, 1, 0, 10, 16, 1, 14, 0, 2, 64, 67, 0, 0, 0, 0, 65, 1, 13, 0, 11, 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
l284_assert_return_invoke(&result_object);
l285_assert_return_invoke(&result_object);
l286_assert_return_invoke(&result_object);
l287_assert_return_invoke(&result_object);
l288_assert_return_invoke(&result_object);
l289_assert_return_invoke(&result_object);
l290_assert_return_invoke(&result_object);
l291_assert_return_invoke(&result_object);
l292_assert_return_invoke(&result_object);
l293_assert_return_invoke(&result_object);
l294_assert_return_invoke(&result_object);
l295_assert_return_invoke(&result_object);
l296_assert_return_invoke(&result_object);
l297_assert_return_invoke(&result_object);
l298_assert_return_invoke(&result_object);
l299_assert_return_invoke(&result_object);
l300_assert_return_invoke(&result_object);
l301_assert_return_invoke(&result_object);
l302_assert_return_invoke(&result_object);
l303_assert_return_invoke(&result_object);
l304_assert_return_invoke(&result_object);
l305_assert_return_invoke(&result_object);
l306_assert_return_invoke(&result_object);
l307_assert_return_invoke(&result_object);
l308_assert_return_invoke(&result_object);
}

View File

@ -14,6 +14,7 @@ mod const_;
mod func_ptrs;
mod i32_;
mod i64_;
mod labels;
mod memory;
mod set_local;
mod types;