Skip to content

Commit 3ed8a53

Browse files
committed
able to consume precompiled content
- skip leading paddings in .aot section Signed-off-by: [email protected] <[email protected]>
1 parent 5734774 commit 3ed8a53

File tree

1 file changed

+20
-7
lines changed

1 file changed

+20
-7
lines changed

src/wamr/wamr.cc

+20-7
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ class Wamr : public WasmVm {
5959
Wamr() = default;
6060

6161
std::string_view getEngineName() override { return "wamr"; }
62-
std::string_view getPrecompiledSectionName() override { return ""; }
62+
std::string_view getPrecompiledSectionName() override { return "aot"; }
6363

6464
Cloneable cloneable() override { return Cloneable::CompiledBytecode; }
6565
std::unique_ptr<WasmVm> clone() override;
@@ -121,18 +121,31 @@ class Wamr : public WasmVm {
121121
std::unordered_map<std::string, WasmFuncPtr> module_functions_;
122122
};
123123

124-
bool Wamr::load(std::string_view bytecode, std::string_view /*precompiled*/,
124+
bool Wamr::load(std::string_view bytecode, std::string_view precompiled,
125125
const std::unordered_map<uint32_t, std::string> & /*function_names*/) {
126126
store_ = wasm_store_new(engine());
127127
if (store_ == nullptr) {
128128
return false;
129129
}
130130

131-
wasm_byte_vec_t binary = {.size = bytecode.size(),
132-
.data = (char *)bytecode.data(),
133-
.num_elems = bytecode.size(),
134-
.size_of_elem = sizeof(byte_t),
135-
.lock = nullptr};
131+
wasm_byte_vec_t binary = {0};
132+
if (precompiled.empty()) {
133+
binary.size = bytecode.size();
134+
binary.data = (char *)bytecode.data();
135+
binary.num_elems = bytecode.size();
136+
binary.size_of_elem = sizeof(byte_t);
137+
binary.lock = nullptr;
138+
} else {
139+
// skip leading paddings
140+
unsigned padding_count = precompiled[0];
141+
precompiled.remove_prefix(padding_count + 1);
142+
143+
binary.size = precompiled.size();
144+
binary.data = (char *)precompiled.data();
145+
binary.num_elems = precompiled.size();
146+
binary.size_of_elem = sizeof(byte_t);
147+
binary.lock = nullptr;
148+
}
136149

137150
module_ = wasm_module_new(store_.get(), &binary);
138151
if (module_ == nullptr) {

0 commit comments

Comments
 (0)