diff --git a/test/unittests/api_test.cpp b/test/unittests/api_test.cpp index bed605a57..6cd698f78 100644 --- a/test/unittests/api_test.cpp +++ b/test/unittests/api_test.cpp @@ -344,7 +344,7 @@ TEST(api, find_exported_global) auto opt_global = find_exported_global(*instance, "g1"); ASSERT_TRUE(opt_global); - EXPECT_EQ(as_uint32(*opt_global->value), 0); + EXPECT_EQ(opt_global->value->i32, 0); EXPECT_EQ(opt_global->type.value_type, ValType::i32); EXPECT_TRUE(opt_global->type.is_mutable); diff --git a/test/unittests/execute_call_test.cpp b/test/unittests/execute_call_test.cpp index 88514d5c7..2a66941b2 100644 --- a/test/unittests/execute_call_test.cpp +++ b/test/unittests/execute_call_test.cpp @@ -390,7 +390,7 @@ TEST(execute_call, imported_function_call_with_arguments) const auto module = parse(wasm); - auto host_foo = [](Instance&, const Value* args, int) { return Value{as_uint32(args[0]) * 2}; }; + auto host_foo = [](Instance&, const Value* args, int) { return Value{args[0].i32 * 2}; }; const auto host_foo_type = module->typesec[0]; auto instance = instantiate(*module, {{host_foo, host_foo_type}}); @@ -433,12 +433,10 @@ TEST(execute_call, imported_functions_call_indirect) ASSERT_EQ(module->codesec.size(), 2); constexpr auto sqr = [](Instance&, const Value* args, int) { - const auto x = as_uint32(args[0]); - return Value{uint64_t{x} * uint64_t{x}}; + return Value{uint64_t{args[0].i32} * uint64_t{args[0].i32}}; }; constexpr auto isqrt = [](Instance&, const Value* args, int) { - const auto x = as_uint32(args[0]); - return Value{(11 + uint64_t{x} / 11) / 2}; + return Value{(11 + uint64_t{args[0].i32} / 11) / 2}; }; auto instance = instantiate(*module, {{sqr, module->typesec[0]}, {isqrt, module->typesec[0]}}); diff --git a/test/unittests/execute_test.cpp b/test/unittests/execute_test.cpp index e38ed17ee..8d54f7ceb 100644 --- a/test/unittests/execute_test.cpp +++ b/test/unittests/execute_test.cpp @@ -262,7 +262,7 @@ TEST(execute, global_set) auto instance = instantiate(parse(wasm)); EXPECT_THAT(execute(*instance, 0, {}), Result()); - EXPECT_EQ(as_uint32(instance->globals[0]), 42); + EXPECT_EQ(instance->globals[0].i32, 42); } TEST(execute, global_set_two_globals) @@ -283,8 +283,8 @@ TEST(execute, global_set_two_globals) auto instance = instantiate(parse(wasm)); EXPECT_THAT(execute(*instance, 0, {}), Result()); - EXPECT_EQ(as_uint32(instance->globals[0]), 44); - EXPECT_EQ(as_uint32(instance->globals[1]), 45); + EXPECT_EQ(instance->globals[0].i32, 44); + EXPECT_EQ(instance->globals[1].i32, 45); } TEST(execute, global_set_imported) @@ -303,7 +303,7 @@ TEST(execute, global_set_imported) auto instance = instantiate(parse(wasm), {}, {}, {}, {ExternalGlobal{&global_value, {ValType::i32, true}}}); EXPECT_THAT(execute(*instance, 0, {}), Result()); - EXPECT_EQ(as_uint32(global_value), 42); + EXPECT_EQ(global_value.i32, 42); } TEST(execute, global_set_float) @@ -811,7 +811,7 @@ TEST(execute, imported_function) ASSERT_EQ(module->typesec.size(), 1); constexpr auto host_foo = [](Instance&, const Value* args, int) { - return Value{as_uint32(args[0]) + as_uint32(args[1])}; + return Value{args[0].i32 + args[1].i32}; }; auto instance = instantiate(*module, {{host_foo, module->typesec[0]}}); @@ -831,10 +831,10 @@ TEST(execute, imported_two_functions) ASSERT_EQ(module->typesec.size(), 1); constexpr auto host_foo1 = [](Instance&, const Value* args, int) { - return Value{as_uint32(args[0]) + as_uint32(args[1])}; + return Value{args[0].i32 + args[1].i32}; }; constexpr auto host_foo2 = [](Instance&, const Value* args, int) { - return Value{as_uint32(args[0]) * as_uint32(args[1])}; + return Value{args[0].i32 * args[1].i32}; }; auto instance = @@ -858,10 +858,10 @@ TEST(execute, imported_functions_and_regular_one) "000a0901070041aa80a8010b"); constexpr auto host_foo1 = [](Instance&, const Value* args, int) { - return Value{as_uint32(args[0]) + as_uint32(args[1])}; + return Value{args[0].i32 + args[1].i32}; }; constexpr auto host_foo2 = [](Instance&, const Value* args, int) { - return Value{as_uint32(args[0]) * as_uint32(args[1])}; + return Value{args[0].i32 * args[1].i32}; }; const auto module = parse(wasm); @@ -888,7 +888,7 @@ TEST(execute, imported_two_functions_different_type) "0001030201010a0901070042aa80a8010b"); constexpr auto host_foo1 = [](Instance&, const Value* args, int) { - return Value{as_uint32(args[0]) + as_uint32(args[1])}; + return Value{args[0].i32 + args[1].i32}; }; constexpr auto host_foo2 = [](Instance&, const Value* args, int) { return Value{args[0].i64 * args[0].i64}; diff --git a/test/unittests/instantiate_test.cpp b/test/unittests/instantiate_test.cpp index c876ca5f0..08decd382 100644 --- a/test/unittests/instantiate_test.cpp +++ b/test/unittests/instantiate_test.cpp @@ -30,7 +30,7 @@ uint32_t call_table_func(Instance& instance, size_t idx) const auto& elem = (*instance.table)[idx]; const auto res = execute(*elem.instance, elem.func_idx, {}, 0); EXPECT_TRUE(res.has_value); - return as_uint32(res.value); + return res.value.i32; } } // namespace @@ -319,7 +319,7 @@ TEST(instantiate, imported_globals) ASSERT_EQ(instance->imported_globals.size(), 1); EXPECT_EQ(instance->imported_globals[0].type.value_type, ValType::i32); EXPECT_TRUE(instance->imported_globals[0].type.is_mutable); - EXPECT_EQ(as_uint32(*instance->imported_globals[0].value), 42); + EXPECT_EQ(instance->imported_globals[0].value->i32, 42); ASSERT_EQ(instance->globals.size(), 0); } @@ -342,8 +342,8 @@ TEST(instantiate, imported_globals_multiple) EXPECT_TRUE(instance->imported_globals[0].type.is_mutable); EXPECT_EQ(instance->imported_globals[1].type.value_type, ValType::i32); EXPECT_FALSE(instance->imported_globals[1].type.is_mutable); - EXPECT_EQ(as_uint32(*instance->imported_globals[0].value), 42); - EXPECT_EQ(as_uint32(*instance->imported_globals[1].value), 43); + EXPECT_EQ(instance->imported_globals[0].value->i32, 42); + EXPECT_EQ(instance->imported_globals[1].value->i32, 43); ASSERT_EQ(instance->globals.size(), 0); } @@ -864,7 +864,7 @@ TEST(instantiate, globals_single) auto instance = instantiate(*module); ASSERT_EQ(instance->globals.size(), 1); - EXPECT_EQ(as_uint32(instance->globals[0]), 42); + EXPECT_EQ(instance->globals[0].i32, 42); } TEST(instantiate, globals_multiple) @@ -878,8 +878,8 @@ TEST(instantiate, globals_multiple) auto instance = instantiate(*module); ASSERT_EQ(instance->globals.size(), 2); - EXPECT_EQ(as_uint32(instance->globals[0]), 42); - EXPECT_EQ(as_uint32(instance->globals[1]), 43); + EXPECT_EQ(instance->globals[0].i32, 42); + EXPECT_EQ(instance->globals[1].i32, 43); } TEST(instantiate, globals_with_imported) @@ -898,11 +898,11 @@ TEST(instantiate, globals_with_imported) auto instance = instantiate(parse(bin), {}, {}, {}, {g}); ASSERT_EQ(instance->imported_globals.size(), 1); - EXPECT_EQ(as_uint32(*instance->imported_globals[0].value), 41); + EXPECT_EQ(instance->imported_globals[0].value->i32, 41); EXPECT_EQ(instance->imported_globals[0].type.is_mutable, true); ASSERT_EQ(instance->globals.size(), 2); - EXPECT_EQ(as_uint32(instance->globals[0]), 42); - EXPECT_EQ(as_uint32(instance->globals[1]), 43); + EXPECT_EQ(instance->globals[0].i32, 42); + EXPECT_EQ(instance->globals[1].i32, 43); } TEST(instantiate, globals_initialized_from_imported) @@ -919,7 +919,7 @@ TEST(instantiate, globals_initialized_from_imported) auto instance = instantiate(parse(bin), {}, {}, {}, {g}); ASSERT_EQ(instance->globals.size(), 1); - EXPECT_EQ(as_uint32(instance->globals[0]), 42); + EXPECT_EQ(instance->globals[0].i32, 42); } TEST(instantiate, globals_float) diff --git a/test/unittests/parser_test.cpp b/test/unittests/parser_test.cpp index 6dad7e928..12beef428 100644 --- a/test/unittests/parser_test.cpp +++ b/test/unittests/parser_test.cpp @@ -592,7 +592,7 @@ TEST(parser, global_single_mutable_const_inited) EXPECT_TRUE(module->globalsec[0].type.is_mutable); EXPECT_EQ(module->globalsec[0].type.value_type, ValType::i32); EXPECT_EQ(module->globalsec[0].expression.kind, ConstantExpression::Kind::Constant); - EXPECT_EQ(as_uint32(module->globalsec[0].expression.value.constant), 0x10); + EXPECT_EQ(module->globalsec[0].expression.value.constant.i32, 0x10); } TEST(parser, global_multi_global_inited) @@ -625,11 +625,11 @@ TEST(parser, global_multi_const_inited) EXPECT_FALSE(module->globalsec[0].type.is_mutable); EXPECT_EQ(module->globalsec[0].type.value_type, ValType::i32); EXPECT_EQ(module->globalsec[0].expression.kind, ConstantExpression::Kind::Constant); - EXPECT_EQ(as_uint32(module->globalsec[0].expression.value.constant), 1); + EXPECT_EQ(module->globalsec[0].expression.value.constant.i32, 1); EXPECT_TRUE(module->globalsec[1].type.is_mutable); EXPECT_EQ(module->globalsec[1].type.value_type, ValType::i32); EXPECT_EQ(module->globalsec[1].expression.kind, ConstantExpression::Kind::Constant); - EXPECT_EQ(as_uint32(module->globalsec[1].expression.value.constant), uint32_t(-1)); + EXPECT_EQ(module->globalsec[1].expression.value.constant.i32, -1); } TEST(parser, global_float) @@ -909,12 +909,12 @@ TEST(parser, element_section) ASSERT_EQ(module->elementsec.size(), 3); EXPECT_EQ(module->elementsec[0].offset.kind, ConstantExpression::Kind::Constant); - EXPECT_EQ(as_uint32(module->elementsec[0].offset.value.constant), 1); + EXPECT_EQ(module->elementsec[0].offset.value.constant.i32, 1); ASSERT_EQ(module->elementsec[0].init.size(), 2); EXPECT_EQ(module->elementsec[0].init[0], 0); EXPECT_EQ(module->elementsec[0].init[1], 1); EXPECT_EQ(module->elementsec[1].offset.kind, ConstantExpression::Kind::Constant); - EXPECT_EQ(as_uint32(module->elementsec[1].offset.value.constant), 2); + EXPECT_EQ(module->elementsec[1].offset.value.constant.i32, 2); ASSERT_EQ(module->elementsec[1].init.size(), 2); EXPECT_EQ(module->elementsec[1].init[0], 2); EXPECT_EQ(module->elementsec[1].init[1], 3); @@ -1311,10 +1311,10 @@ TEST(parser, data_section) ASSERT_EQ(module->datasec.size(), 3); EXPECT_EQ(module->datasec[0].offset.kind, ConstantExpression::Kind::Constant); - EXPECT_EQ(as_uint32(module->datasec[0].offset.value.constant), 1); + EXPECT_EQ(module->datasec[0].offset.value.constant.i32, 1); EXPECT_EQ(module->datasec[0].init, "aaff"_bytes); EXPECT_EQ(module->datasec[1].offset.kind, ConstantExpression::Kind::Constant); - EXPECT_EQ(as_uint32(module->datasec[1].offset.value.constant), 2); + EXPECT_EQ(module->datasec[1].offset.value.constant.i32, 2); EXPECT_EQ(module->datasec[1].init, "5555"_bytes); EXPECT_EQ(module->datasec[2].offset.kind, ConstantExpression::Kind::GlobalGet); EXPECT_EQ(module->datasec[2].offset.value.global_index, 0); diff --git a/test/utils/asserts.hpp b/test/utils/asserts.hpp index 3fdaf12d1..4ac735316 100644 --- a/test/utils/asserts.hpp +++ b/test/utils/asserts.hpp @@ -153,10 +153,5 @@ std::ostream& operator<<(std::ostream& os, ExecutionResult); namespace fizzy::test { -inline uint32_t as_uint32(fizzy::Value value) -{ - return value.i32; -} - std::ostream& operator<<(std::ostream& os, const TypedExecutionResult&); } // namespace fizzy::test