From 15f1677713a2b9eb6180788ae3f26bc1ecffec5a Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Fri, 11 Dec 2015 18:46:13 -0500 Subject: fix up static allocation code in s2wasm --- src/s2wasm.h | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/s2wasm.h b/src/s2wasm.h index e1e913836..1731aa2e4 100644 --- a/src/s2wasm.h +++ b/src/s2wasm.h @@ -28,6 +28,9 @@ private: // state size_t nextStatic = 0; // location of next static allocation, i.e., the data segment + std::map staticAddresses; // name => address + typedef std::pair Addressing; + std::vector addressings; // we fix these up // utilities @@ -284,8 +287,6 @@ private: setOutput(curr, assign); }; // fixups - typedef std::pair Addressing; - std::vector addressings; std::vector loopBlocks; // we need to clear their names std::set seenLabels; // if we already used a label, we don't need it in a loop (there is a block above it, with that label) // main loop @@ -454,6 +455,8 @@ private: assert(strlen(buffer.str) == size); const int ALIGN = 16; if (nextStatic == 0) nextStatic = ALIGN; + // assign the address, add to memory, and increment for the next one + staticAddresses[name] = nextStatic; wasm.memory.segments.emplace_back(nextStatic, buffer.str, size); nextStatic += size; nextStatic = (nextStatic + ALIGN - 1) & -ALIGN; -- cgit v1.2.3