summaryrefslogtreecommitdiff
path: root/src/s2wasm.h
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2015-12-11 18:43:47 -0500
committerAlon Zakai <alonzakai@gmail.com>2015-12-11 18:43:47 -0500
commit32240a18abfdfcf70796bb72b0851163f0314e19 (patch)
treecfd0b98b9f0c1497b2ce1270311ab0555f48032d /src/s2wasm.h
parent83c7d3f4c38157f2750f0f6cb7dc89693eab15eb (diff)
downloadbinaryen-32240a18abfdfcf70796bb72b0851163f0314e19.tar.gz
binaryen-32240a18abfdfcf70796bb72b0851163f0314e19.tar.bz2
binaryen-32240a18abfdfcf70796bb72b0851163f0314e19.zip
parse data in s2wasm
Diffstat (limited to 'src/s2wasm.h')
-rw-r--r--src/s2wasm.h22
1 files changed, 19 insertions, 3 deletions
diff --git a/src/s2wasm.h b/src/s2wasm.h
index 9766471f7..e1e913836 100644
--- a/src/s2wasm.h
+++ b/src/s2wasm.h
@@ -25,6 +25,10 @@ public:
}
private:
+ // state
+
+ size_t nextStatic = 0; // location of next static allocation, i.e., the data segment
+
// utilities
void skipWhitespace() {
@@ -84,7 +88,7 @@ private:
}
Name getStr() {
- std::string str;
+ std::string str; // TODO: optimize this and the other get* methods
while (*s && !isspace(*s)) {
str += *s;
s++;
@@ -141,6 +145,7 @@ private:
str += *s;
s++;
}
+ s++;
skipWhitespace();
return cashew::IString(str.c_str(), false);
}
@@ -175,7 +180,10 @@ private:
s++;
if (match("file")) parseFile();
else if (match("globl")) parseGlobl();
- else break;
+ else {
+ s--;
+ break;
+ }
}
}
@@ -432,7 +440,9 @@ private:
void parseType() {
Name name = getStrToComma();
+ skipComma();
mustMatch("@object");
+ mustMatch(".data");
mustMatch(name.str);
mustMatch(":");
mustMatch(".asciz");
@@ -440,7 +450,13 @@ private:
mustMatch(".size");
mustMatch(name.str);
mustMatch(",");
- Name size = getStr();
+ size_t size = atoi(getStr().str); // TODO: optimize
+ assert(strlen(buffer.str) == size);
+ const int ALIGN = 16;
+ if (nextStatic == 0) nextStatic = ALIGN;
+ wasm.memory.segments.emplace_back(nextStatic, buffer.str, size);
+ nextStatic += size;
+ nextStatic = (nextStatic + ALIGN - 1) & -ALIGN;
}
};