Skip to content

Commit

Permalink
update shell-interface
Browse files Browse the repository at this point in the history
  • Loading branch information
axic committed Nov 6, 2019
1 parent c3e8e5d commit f59e239
Showing 1 changed file with 3 additions and 20 deletions.
23 changes: 3 additions & 20 deletions src/shell-interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,28 +97,9 @@ struct ShellExternalInterface : ModuleInstance::ExternalInterface {
virtual ~ShellExternalInterface() = default;

void init(Module& wasm, ModuleInstance& instance) override {
(void)instance;
memory.resize(wasm.memory.initial * wasm::Memory::kPageSize);
// apply memory segments
for (auto& segment : wasm.memory.segments) {
Address offset = static_cast<uint32_t>(ConstantExpressionRunner<TrivialGlobalManager>(instance.globals).visit(segment.offset).value.geti32());
if (offset + segment.data.size() > wasm.memory.initial * wasm::Memory::kPageSize) {
trap("invalid offset when initializing memory");
}
for (size_t i = 0; i != segment.data.size(); ++i) {
memory.set(offset + i, segment.data[i]);
}
}

table.resize(wasm.table.initial);
for (auto& segment : wasm.table.segments) {
Address offset = static_cast<uint32_t>(ConstantExpressionRunner<TrivialGlobalManager>(instance.globals).visit(segment.offset).value.geti32());
if (offset + segment.data.size() > wasm.table.initial) {
trap("invalid offset when initializing table");
}
for (size_t i = 0; i != segment.data.size(); ++i) {
table[offset + i] = segment.data[i];
}
}
}

void importGlobals(std::map<Name, Literal>& globals, Module& wasm) override {
Expand Down Expand Up @@ -174,6 +155,8 @@ struct ShellExternalInterface : ModuleInstance::ExternalInterface {
memory.set<std::array<uint8_t, 16>>(addr, value);
}

void tableStore(Address addr, Name entry) override { table[addr] = entry; }

void growMemory(Address /*oldSize*/, Address newSize) override {
memory.resize(newSize);
}
Expand Down

0 comments on commit f59e239

Please sign in to comment.