summaryrefslogtreecommitdiff
path: root/src/s2wasm.h
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2015-12-23 09:44:45 -0800
committerAlon Zakai <alonzakai@gmail.com>2015-12-23 09:44:45 -0800
commita009c9c935c732c357f73358630bd1c55e4a87a9 (patch)
treef21d0a2864daaa246ea59165656b16d083dc86c4 /src/s2wasm.h
parenta79329fbe135bab9a319fd3afc911620b12f0124 (diff)
downloadbinaryen-a009c9c935c732c357f73358630bd1c55e4a87a9.tar.gz
binaryen-a009c9c935c732c357f73358630bd1c55e4a87a9.tar.bz2
binaryen-a009c9c935c732c357f73358630bd1c55e4a87a9.zip
s2wasm const parsing fixes
Diffstat (limited to 'src/s2wasm.h')
-rw-r--r--src/s2wasm.h24
1 files changed, 16 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;
}