Skip to content

Commit

Permalink
able to consume precompiled content
Browse files Browse the repository at this point in the history
- skip leading paddings in .aot section
  • Loading branch information
lum1n0us committed Jan 15, 2024
1 parent 5734774 commit bc6cd28
Showing 1 changed file with 20 additions and 7 deletions.
27 changes: 20 additions & 7 deletions src/wamr/wamr.cc
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class Wamr : public WasmVm {
Wamr() = default;

std::string_view getEngineName() override { return "wamr"; }
std::string_view getPrecompiledSectionName() override { return ""; }
std::string_view getPrecompiledSectionName() override { return "aot"; }

Cloneable cloneable() override { return Cloneable::CompiledBytecode; }
std::unique_ptr<WasmVm> clone() override;
Expand Down Expand Up @@ -121,18 +121,31 @@ class Wamr : public WasmVm {
std::unordered_map<std::string, WasmFuncPtr> module_functions_;
};

bool Wamr::load(std::string_view bytecode, std::string_view /*precompiled*/,
bool Wamr::load(std::string_view bytecode, std::string_view precompiled,
const std::unordered_map<uint32_t, std::string> & /*function_names*/) {
store_ = wasm_store_new(engine());
if (store_ == nullptr) {
return false;
}

wasm_byte_vec_t binary = {.size = bytecode.size(),
.data = (char *)bytecode.data(),
.num_elems = bytecode.size(),
.size_of_elem = sizeof(byte_t),
.lock = nullptr};
wasm_byte_vec_t binary = {0};
if (precompiled.empty()) {
binary.size = bytecode.size();
binary.data = (char *)bytecode.data();
binary.num_elems = bytecode.size();
binary.size_of_elem = sizeof(byte_t);
binary.lock = nullptr;
} else {
// skip leading paddings
unsigned padding_count = precompiled[0];
precompiled.remove_prefix(padding_count + 1);

binary.size = precompiled.size();
binary.data = (char *)precompiled.data();
binary.num_elems = precompiled.size();
binary.size_of_elem = sizeof(byte_t);
binary.lock = nullptr;
}

module_ = wasm_module_new(store_.get(), &binary);
if (module_ == nullptr) {
Expand Down

0 comments on commit bc6cd28

Please sign in to comment.