Skip to content

Commit bfb36dc

Browse files
committed
Export utils::BytecodeUtil.
Signed-off-by: Piotr Sikora <[email protected]>
1 parent 912c250 commit bfb36dc

File tree

6 files changed

+22
-19
lines changed

6 files changed

+22
-19
lines changed

src/common/bytecode_util.h renamed to include/proxy-wasm/bytecode_util.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
#include "include/proxy-wasm/wasm_vm.h"
2121

2222
namespace proxy_wasm {
23-
namespace common {
23+
namespace utils {
2424

2525
// Utilitiy functions which directly operate on Wasm bytecodes.
2626
class BytecodeUtil {
@@ -73,5 +73,5 @@ class BytecodeUtil {
7373
static bool parseVarint(const char *&begin, const char *end, uint32_t &ret);
7474
};
7575

76-
} // namespace common
76+
} // namespace utils
7777
} // namespace proxy_wasm

src/common/bytecode_util.cc renamed to src/utils/bytecode_util.cc

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,12 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
#include "src/common/bytecode_util.h"
15+
#include "include/proxy-wasm/bytecode_util.h"
16+
1617
#include <cstring>
1718

1819
namespace proxy_wasm {
19-
namespace common {
20+
namespace utils {
2021

2122
bool BytecodeUtil::checkWasmHeader(std::string_view bytecode) {
2223
// Wasm file header is 8 bytes (magic number + version).
@@ -240,5 +241,5 @@ bool BytecodeUtil::parseVarint(const char *&pos, const char *end, uint32_t &ret)
240241
return ret != static_cast<uint32_t>(-1);
241242
}
242243

243-
} // namespace common
244+
} // namespace utils
244245
} // namespace proxy_wasm

src/wamr/wamr.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,10 @@
2929
#include <utility>
3030
#include <vector>
3131

32+
#include "include/proxy-wasm/bytecode_util.h"
33+
3234
#include "src/wamr/types.h"
3335
#include "wasm_c_api.h"
34-
#include "src/common/bytecode_util.h"
3536

3637
namespace proxy_wasm {
3738
namespace wamr {

src/wasm.cc

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,11 @@
2626
#include <string>
2727
#include <unordered_map>
2828

29-
#include "src/common/bytecode_util.h"
29+
#include "include/proxy-wasm/bytecode_util.h"
30+
#include "include/proxy-wasm/vm_id_handle.h"
31+
3032
#include "src/third_party/base64.h"
3133
#include "src/third_party/picosha2.h"
32-
#include "include/proxy-wasm/vm_id_handle.h"
3334

3435
namespace proxy_wasm {
3536

@@ -250,7 +251,7 @@ bool WasmBase::load(const std::string &code, bool allow_precompiled) {
250251
}
251252

252253
// Get ABI version from the module.
253-
if (!common::BytecodeUtil::getAbiVersion(code, abi_version_)) {
254+
if (!utils::BytecodeUtil::getAbiVersion(code, abi_version_)) {
254255
fail(FailState::UnableToInitializeCode, "Failed to parse corrupted Wasm module");
255256
return false;
256257
}
@@ -260,7 +261,7 @@ bool WasmBase::load(const std::string &code, bool allow_precompiled) {
260261
}
261262

262263
// Get function names from the module.
263-
if (!common::BytecodeUtil::getFunctionNameIndex(code, function_names_)) {
264+
if (!utils::BytecodeUtil::getFunctionNameIndex(code, function_names_)) {
264265
fail(FailState::UnableToInitializeCode, "Failed to parse corrupted Wasm module");
265266
return false;
266267
}
@@ -270,7 +271,7 @@ bool WasmBase::load(const std::string &code, bool allow_precompiled) {
270271
std::string_view precompiled = {};
271272
const auto section_name = wasm_vm_->getPrecompiledSectionName();
272273
if (!section_name.empty()) {
273-
if (!common::BytecodeUtil::getCustomSection(code, section_name, precompiled)) {
274+
if (!utils::BytecodeUtil::getCustomSection(code, section_name, precompiled)) {
274275
fail(FailState::UnableToInitializeCode, "Failed to parse corrupted Wasm module");
275276
return false;
276277
}
@@ -293,7 +294,7 @@ bool WasmBase::load(const std::string &code, bool allow_precompiled) {
293294

294295
// Use original bytecode (possibly stripped).
295296
std::string stripped;
296-
if (!common::BytecodeUtil::getStrippedSource(code, stripped)) {
297+
if (!utils::BytecodeUtil::getStrippedSource(code, stripped)) {
297298
fail(FailState::UnableToInitializeCode, "Failed to parse corrupted Wasm module");
298299
return false;
299300
}
File renamed without changes.

test/common/bytecode_util_test.cc renamed to test/utils/bytecode_util_test.cc

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
#include "src/common/bytecode_util.h"
15+
#include "include/proxy-wasm/bytecode_util.h"
1616

1717
#include <fstream>
1818
#include <iostream>
@@ -23,9 +23,9 @@
2323
#include "gtest/gtest.h"
2424

2525
namespace proxy_wasm {
26-
namespace common {
26+
namespace utils {
2727

28-
TEST(TestWasmCommonUtil, getCustomSection) {
28+
TEST(TestBytecodeUtil, getCustomSection) {
2929
std::string custom_section = {
3030
0x00, 0x61, 0x73, 0x6d, // Wasm magic
3131
0x01, 0x00, 0x00, 0x00, // Wasm version
@@ -54,7 +54,7 @@ TEST(TestWasmCommonUtil, getCustomSection) {
5454
EXPECT_FALSE(BytecodeUtil::getCustomSection(corrupted, "hey", section));
5555
}
5656

57-
TEST(TestWasmCommonUtil, getFunctionNameIndex) {
57+
TEST(TestBytecodeUtil, getFunctionNameIndex) {
5858
const auto source = readTestWasmFile("abi_export.wasm");
5959
std::unordered_map<uint32_t, std::string> actual;
6060
// OK.
@@ -73,7 +73,7 @@ TEST(TestWasmCommonUtil, getFunctionNameIndex) {
7373
EXPECT_TRUE(actual.empty());
7474
}
7575

76-
TEST(TestWasmCommonUtil, getStrippedSource) {
76+
TEST(TestBytecodeUtil, getStrippedSource) {
7777
// Unmodified case.
7878
auto source = readTestWasmFile("abi_export.wasm");
7979
std::string actual;
@@ -110,12 +110,12 @@ TEST(TestWasmCommonUtil, getStrippedSource) {
110110
EXPECT_EQ(actual.size(), source.size() - custom_section.size());
111111
}
112112

113-
TEST(TestWasmCommonUtil, getAbiVersion) {
113+
TEST(TestBytecodeUtil, getAbiVersion) {
114114
const auto source = readTestWasmFile("abi_export.wasm");
115115
proxy_wasm::AbiVersion actual;
116116
EXPECT_TRUE(BytecodeUtil::getAbiVersion(source, actual));
117117
EXPECT_EQ(actual, proxy_wasm::AbiVersion::ProxyWasm_0_2_0);
118118
}
119119

120-
} // namespace common
120+
} // namespace utils
121121
} // namespace proxy_wasm

0 commit comments

Comments
 (0)