Skip to content

Commit 29e66fc

Browse files
committed
refactor: move copying instantiate to test/utils/instantiate_helpers.hpp
1 parent faf28fc commit 29e66fc

File tree

10 files changed

+30
-19
lines changed

10 files changed

+30
-19
lines changed

lib/fizzy/instantiate.cpp

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -373,16 +373,6 @@ std::unique_ptr<Instance> instantiate(std::unique_ptr<Module> module,
373373
return instance;
374374
}
375375

376-
std::unique_ptr<Instance> instantiate(Module module,
377-
std::vector<ExternalFunction> imported_functions, std::vector<ExternalTable> imported_tables,
378-
std::vector<ExternalMemory> imported_memories, std::vector<ExternalGlobal> imported_globals,
379-
uint32_t memory_pages_limit)
380-
{
381-
return instantiate(std::make_unique<Module>(std::move(module)), std::move(imported_functions),
382-
std::move(imported_tables), std::move(imported_memories), std::move(imported_globals),
383-
memory_pages_limit);
384-
}
385-
386376
std::vector<ExternalFunction> resolve_imported_functions(
387377
const Module& module, std::vector<ImportedFunction> imported_functions)
388378
{

lib/fizzy/instantiate.hpp

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -94,14 +94,6 @@ std::unique_ptr<Instance> instantiate(std::unique_ptr<Module> module,
9494
std::vector<ExternalGlobal> imported_globals = {},
9595
uint32_t memory_pages_limit = DefaultMemoryPagesLimit);
9696

97-
// Instantiate a module.
98-
std::unique_ptr<Instance> instantiate(Module _module,
99-
std::vector<ExternalFunction> imported_functions = {},
100-
std::vector<ExternalTable> imported_tables = {},
101-
std::vector<ExternalMemory> imported_memories = {},
102-
std::vector<ExternalGlobal> imported_globals = {},
103-
uint32_t memory_pages_limit = DefaultMemoryPagesLimit);
104-
10597
// Function that should be used by instantiate as imports, identified by module and function name.
10698
struct ImportedFunction
10799
{

test/spectests/spectests.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,8 @@ class test_runner
8989
explicit test_runner(const test_settings& ts)
9090
: m_settings{ts}, m_registered_names{{spectest_name, spectest_name}}
9191
{
92-
m_instances[spectest_name] = fizzy::instantiate(*spectest_module);
92+
m_instances[spectest_name] =
93+
fizzy::instantiate(std::make_unique<fizzy::Module>(*spectest_module));
9394
}
9495

9596
test_results run_from_file(const fs::path& path)

test/unittests/api_test.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include <lib/fizzy/limits.hpp>
99
#include <test/utils/asserts.hpp>
1010
#include <test/utils/hex.hpp>
11+
#include <test/utils/instantiate_helpers.hpp>
1112

1213
using namespace fizzy;
1314
using namespace fizzy::test;

test/unittests/end_to_end_test.cpp

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

1112
using namespace fizzy;
1213
using namespace fizzy::test;

test/unittests/execute_floating_point_test.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include <test/utils/asserts.hpp>
1111
#include <test/utils/floating_point_utils.hpp>
1212
#include <test/utils/hex.hpp>
13+
#include <test/utils/instantiate_helpers.hpp>
1314
#include <array>
1415
#include <cfenv>
1516
#include <cmath>

test/unittests/instantiate_test.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include <gtest/gtest.h>
99
#include <test/utils/asserts.hpp>
1010
#include <test/utils/hex.hpp>
11+
#include <test/utils/instantiate_helpers.hpp>
1112

1213
using namespace fizzy;
1314
using namespace fizzy::test;

test/utils/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ target_sources(
1818
floating_point_utils.hpp
1919
hex.cpp
2020
hex.hpp
21+
instantiate_helpers.hpp
2122
leb128_encode.cpp
2223
leb128_encode.hpp
2324
wabt_engine.cpp

test/utils/execute_helpers.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#pragma once
66

77
#include "execute.hpp"
8+
#include <test/utils/instantiate_helpers.hpp>
89
#include <initializer_list>
910

1011
namespace fizzy::test

test/utils/instantiate_helpers.hpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
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 "instantiate.hpp"
8+
9+
namespace fizzy::test
10+
{
11+
inline std::unique_ptr<Instance> instantiate(Module module,
12+
std::vector<ExternalFunction> imported_functions = {},
13+
std::vector<ExternalTable> imported_tables = {},
14+
std::vector<ExternalMemory> imported_memories = {},
15+
std::vector<ExternalGlobal> imported_globals = {},
16+
uint32_t memory_pages_limit = DefaultMemoryPagesLimit)
17+
{
18+
return instantiate(std::make_unique<Module>(std::move(module)), std::move(imported_functions),
19+
std::move(imported_tables), std::move(imported_memories), std::move(imported_globals),
20+
memory_pages_limit);
21+
}
22+
} // namespace fizzy::test

0 commit comments

Comments
 (0)