From 85ee7389f625b777b496c77b2364c5c7f317f18e Mon Sep 17 00:00:00 2001 From: Andrei Maiboroda Date: Wed, 27 May 2020 13:47:41 +0200 Subject: [PATCH] test: immediates for br inside if blocks --- test/unittests/parser_expr_test.cpp | 48 +++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/test/unittests/parser_expr_test.cpp b/test/unittests/parser_expr_test.cpp index b49fce72b..a71b77b27 100644 --- a/test/unittests/parser_expr_test.cpp +++ b/test/unittests/parser_expr_test.cpp @@ -261,6 +261,54 @@ TEST(parser_expr, block_return) "00"_bytes); // arity } +TEST(parser_expr, if_br) +{ + /* wat2wasm + (func + (i32.const 0) + (if (then (br 0))) + ) + */ + const auto wasm = from_hex("0061736d01000000010401600000030201000a0b010900410004400c000b0b"); + const auto module = parse(wasm); + + EXPECT_EQ(module.codesec[0].instructions, + (std::vector{Instr::i32_const, Instr::if_, Instr::br, Instr::end, Instr::end})); + EXPECT_EQ(module.codesec[0].immediates, + "00000000" // i32.const + "04000000" // else code offset + "19000000" // else imm offset + "04000000" // code_offset + "19000000" // imm_offset + "00000000" // stack_height + "00"_bytes); // arity + + /* wat2wasm + (func + (i32.const 0) + (i32.const 0) + (if (then (br 0))) + drop + ) + */ + const auto wasm_parent_stack = + from_hex("0061736d01000000010401600000030201000a0e010c004100410004400c000b1a0b"); + const auto module_parent_stack = parse(wasm_parent_stack); + + EXPECT_EQ(module_parent_stack.codesec[0].instructions, + (std::vector{Instr::i32_const, Instr::i32_const, Instr::if_, Instr::br, Instr::end, + Instr::drop, Instr::end})); + EXPECT_EQ(module_parent_stack.codesec[0].immediates, + "00000000" // i32.const + "00000000" // i32.const + "05000000" // else code offset + "1d000000" // else imm offset + "05000000" // code_offset + "1d000000" // imm_offset + "01000000" // stack_height + "00"_bytes); // arity +} + TEST(parser_expr, instr_br_table) { /*