From 2ceaaf0c976e4fdb9bb10bdf1d5fb8ef56406de5 Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Fri, 11 Dec 2015 18:52:12 -0500 Subject: fix up static addresses in s2wasm; basics test is complete --- src/s2wasm.h | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/s2wasm.h b/src/s2wasm.h index 1731aa2e4..57982f857 100644 --- a/src/s2wasm.h +++ b/src/s2wasm.h @@ -22,13 +22,14 @@ class S2WasmBuilder { public: S2WasmBuilder(AllocatingModule& wasm, char *s) : wasm(wasm), allocator(wasm.allocator), s(s) { process(); + fix(); } private: // state size_t nextStatic = 0; // location of next static allocation, i.e., the data segment - std::map staticAddresses; // name => address + std::map staticAddresses; // name => address typedef std::pair Addressing; std::vector addressings; // we fix these up @@ -461,6 +462,17 @@ private: nextStatic += size; nextStatic = (nextStatic + ALIGN - 1) & -ALIGN; } + + void fix() { + for (auto& pair : addressings) { + Const* curr = pair.first; + Name name = pair.second; + curr->value = Literal(staticAddresses[name]); + assert(curr->value.i32 > 0); + curr->type = i32; + } + } + }; } // namespace wasm -- cgit v1.2.3