diff options
author | Alon Zakai <alonzakai@gmail.com> | 2015-12-23 09:44:45 -0800 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2015-12-23 09:44:45 -0800 |
commit | a009c9c935c732c357f73358630bd1c55e4a87a9 (patch) | |
tree | f21d0a2864daaa246ea59165656b16d083dc86c4 /src | |
parent | a79329fbe135bab9a319fd3afc911620b12f0124 (diff) | |
download | binaryen-a009c9c935c732c357f73358630bd1c55e4a87a9.tar.gz binaryen-a009c9c935c732c357f73358630bd1c55e4a87a9.tar.bz2 binaryen-a009c9c935c732c357f73358630bd1c55e4a87a9.zip |
s2wasm const parsing fixes
Diffstat (limited to 'src')
-rw-r--r-- | src/s2wasm.h | 24 | ||||
-rw-r--r-- | src/shared-constants.h | 2 |
2 files changed, 18 insertions, 8 deletions
diff --git a/src/s2wasm.h b/src/s2wasm.h index 02fc37cfe..45d943446 100644 --- a/src/s2wasm.h +++ b/src/s2wasm.h @@ -55,7 +55,12 @@ private: 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; + struct Addressing { + Const* value; + Name name; + int32_t offset; + Addressing(Const* value, Name name, int32_t offset) : value(value), name(name), offset(offset) {} + }; std::vector<Addressing> addressings; // we fix these up struct Relocation { @@ -588,12 +593,14 @@ private: if (match("const")) { Name assign = getAssign(); char start = *s; - cashew::IString str = getStr(); - if (start == '.' || (isalpha(start) && str != NAN_ && str != INFINITY_)) { + cashew::IString str = getStrToSep(); + if (start == '.' || (isalpha(start) && str != NAN__ && str != INFINITY__)) { // global address + int32_t offset = 0; + if (match("+")) offset = getInt(); auto curr = allocator.alloc<Const>(); curr->type = i32; - addressings.emplace_back(curr, str); + addressings.emplace_back(curr, str, offset); setOutput(curr, assign); } else { // constant @@ -950,10 +957,11 @@ private: } void fix() { - for (auto& pair : addressings) { - Const* curr = pair.first; - Name name = pair.second; - curr->value = Literal(staticAddresses[name]); + for (auto& triple : addressings) { + Const* curr = triple.value; + Name name = triple.name; + size_t offset = triple.offset; + curr->value = Literal(staticAddresses[name] + offset); assert(curr->value.i32 > 0); curr->type = i32; } diff --git a/src/shared-constants.h b/src/shared-constants.h index ea8980fa2..a928756da 100644 --- a/src/shared-constants.h +++ b/src/shared-constants.h @@ -24,6 +24,8 @@ namespace wasm { cashew::IString GLOBAL("global"), NAN_("NaN"), INFINITY_("Infinity"), + NAN__("nan"), + INFINITY__("infinity"), TOPMOST("topmost"), INT8ARRAY("Int8Array"), INT16ARRAY("Int16Array"), |