Skip to content

Commit 53d9e59

Browse files
authored
Merge pull request #409 from wasmx/execute_helpers
Move execute(Module, ...) to execute_helpers.hpp (testutils)
2 parents 96daa07 + 7526cf2 commit 53d9e59

9 files changed

Lines changed: 25 additions & 10 deletions

File tree

lib/fizzy/execute.cpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1464,12 +1464,6 @@ execution_result execute(
14641464
return {trap, {stack.rbegin(), stack.rend()}};
14651465
}
14661466

1467-
execution_result execute(const Module& module, FuncIdx func_idx, std::vector<uint64_t> args)
1468-
{
1469-
auto instance = instantiate(module);
1470-
return execute(*instance, func_idx, std::move(args));
1471-
}
1472-
14731467
std::vector<ExternalFunction> resolve_imported_functions(
14741468
const Module& module, std::vector<ImportedFunction> imported_functions)
14751469
{

lib/fizzy/execute.hpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,6 @@ std::unique_ptr<Instance> instantiate(Module module,
9797
execution_result execute(
9898
Instance& instance, FuncIdx func_idx, std::vector<uint64_t> args, int depth = 0);
9999

100-
// TODO: remove this helper
101-
execution_result execute(const Module& module, FuncIdx func_idx, std::vector<uint64_t> args);
102100

103101
// Function that should be used by instantiate as imports, identified by module and function name.
104102
struct ImportedFunction

test/unittests/end_to_end_test.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,9 @@ TEST(end_to_end, milestone1)
3131
const auto wasm = from_hex(
3232
"0061736d0100000001070160027f7f017f030201000a13011101017f200020016a20026a220220006a0b");
3333
const auto module = parse(wasm);
34+
auto instance = instantiate(module);
3435

35-
EXPECT_THAT(execute(module, 0, {20, 22}), Result(20 + 22 + 20));
36+
EXPECT_THAT(execute(*instance, 0, {20, 22}), Result(20 + 22 + 20));
3637
}
3738

3839
TEST(end_to_end, milestone2)
@@ -128,7 +129,8 @@ TEST(end_to_end, nested_loops_in_c)
128129
const auto func_idx = find_exported_function(module, "test");
129130
ASSERT_TRUE(func_idx);
130131

131-
EXPECT_THAT(execute(module, *func_idx, {10, 2, 5}), Result(4));
132+
auto instance = instantiate(module);
133+
EXPECT_THAT(execute(*instance, *func_idx, {10, 2, 5}), Result(4));
132134
}
133135

134136
TEST(end_to_end, memset)

test/unittests/execute_call_test.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include "parser.hpp"
88
#include <gtest/gtest.h>
99
#include <test/utils/asserts.hpp>
10+
#include <test/utils/execute_helpers.hpp>
1011
#include <test/utils/hex.hpp>
1112

1213
using namespace fizzy;

test/unittests/execute_control_test.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include "parser.hpp"
77
#include <gtest/gtest.h>
88
#include <test/utils/asserts.hpp>
9+
#include <test/utils/execute_helpers.hpp>
910
#include <test/utils/hex.hpp>
1011

1112
using namespace fizzy;

test/unittests/execute_numeric_test.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include "parser.hpp"
77
#include <gtest/gtest.h>
88
#include <test/utils/asserts.hpp>
9+
#include <test/utils/execute_helpers.hpp>
910
#include <test/utils/hex.hpp>
1011

1112
using namespace fizzy;

test/unittests/execute_test.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include "parser.hpp"
88
#include <gtest/gtest.h>
99
#include <test/utils/asserts.hpp>
10+
#include <test/utils/execute_helpers.hpp>
1011
#include <test/utils/hex.hpp>
1112

1213
using namespace fizzy;

test/utils/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ target_sources(
1313
adler32.hpp
1414
asserts.cpp
1515
asserts.hpp
16+
execute_helpers.hpp
1617
fizzy_engine.cpp
1718
hex.cpp
1819
hex.hpp

test/utils/execute_helpers.hpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Fizzy: A fast WebAssembly interpreter
2+
// Copyright 2020 The Fizzy Authors.
3+
// SPDX-License-Identifier: Apache-2.0
4+
5+
#pragma once
6+
7+
#include "execute.hpp"
8+
9+
namespace fizzy::test
10+
{
11+
inline execution_result execute(const Module& module, FuncIdx func_idx, std::vector<uint64_t> args)
12+
{
13+
auto instance = instantiate(module);
14+
return execute(*instance, func_idx, std::move(args));
15+
}
16+
} // namespace fizzy::test

0 commit comments

Comments
 (0)