diff options
author | Alon Zakai <alonzakai@gmail.com> | 2015-12-12 11:51:23 -0500 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2015-12-12 11:51:23 -0500 |
commit | 97670cdc62b48cea0237496996cabdfbe0ac5bad (patch) | |
tree | 82d3863ba3eeeb27952c980fff6a1d799fabce03 /src | |
parent | 1ad63eecab0cf8ad49b553827d623e43b074f883 (diff) | |
download | binaryen-97670cdc62b48cea0237496996cabdfbe0ac5bad.tar.gz binaryen-97670cdc62b48cea0237496996cabdfbe0ac5bad.tar.bz2 binaryen-97670cdc62b48cea0237496996cabdfbe0ac5bad.zip |
more data parsing
Diffstat (limited to 'src')
-rw-r--r-- | src/s2wasm.h | 36 |
1 files changed, 27 insertions, 9 deletions
diff --git a/src/s2wasm.h b/src/s2wasm.h index 0ef56774b..9a3e9b098 100644 --- a/src/s2wasm.h +++ b/src/s2wasm.h @@ -29,7 +29,7 @@ public: private: // state - size_t nextStatic = 0; // location of next static allocation, i.e., the data segment + size_t nextStatic = 1; // location of next static allocation, i.e., the data segment std::map<Name, int32_t> staticAddresses; // name => address typedef std::pair<Const*, Name> Addressing; std::vector<Addressing> addressings; // we fix these up @@ -656,22 +656,40 @@ private: skipComma(); mustMatch("@object"); mustMatch(".data"); + size_t align = 16; // XXX default? + if (match(".globl")) { + mustMatch(name.str); + if (match(".align")) { + align = getInt(); + } else abort_on(".global in type"); + } + skipWhitespace(); mustMatch(name.str); mustMatch(":"); - mustMatch(".asciz"); - Name buffer = getQuoted(); + const char* data; + char type; + if (match(".asciz")) { + Name buffer = getQuoted(); + data = buffer.str; + type = 0; + } else if (match(".zero")) { + int32_t size = getInt(); + data = (const char*)calloc(size, 1); + type = 1; + } else abort_on("data"); + skipWhitespace(); mustMatch(".size"); mustMatch(name.str); mustMatch(","); size_t size = atoi(getStr().str); // TODO: optimize - 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 + if (type == 0) { + assert(strlen(data) == size); + } + while (nextStatic % align) nextStatic++; + // assign the address, add to memory staticAddresses[name] = nextStatic; - wasm.memory.segments.emplace_back(nextStatic, buffer.str, size); + wasm.memory.segments.emplace_back(nextStatic, data, size); nextStatic += size; - nextStatic = (nextStatic + ALIGN - 1) & -ALIGN; } void skipImports() { |