summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2015-12-15 14:54:39 -0800
committerAlon Zakai <alonzakai@gmail.com>2015-12-15 14:54:39 -0800
commitc9d8cd2b39a286687b917ff1b4f32c2ebb827ba7 (patch)
tree35a9987f579153553088e31a9c55b34ddfdaaf2f /src
parent7df1e482dcdc2305767ab483406a60490fe98555 (diff)
downloadbinaryen-c9d8cd2b39a286687b917ff1b4f32c2ebb827ba7.tar.gz
binaryen-c9d8cd2b39a286687b917ff1b4f32c2ebb827ba7.tar.bz2
binaryen-c9d8cd2b39a286687b917ff1b4f32c2ebb827ba7.zip
refactor type parsing in s2wasm
Diffstat (limited to 'src')
-rw-r--r--src/s2wasm.h27
1 files changed, 17 insertions, 10 deletions
diff --git a/src/s2wasm.h b/src/s2wasm.h
index 9a0ab69c5..9b63666a1 100644
--- a/src/s2wasm.h
+++ b/src/s2wasm.h
@@ -119,7 +119,7 @@ private:
Name getStrToSep() {
std::string str;
- while (*s && !isspace(*s) && *s != ',' && *s != ')') {
+ while (*s && !isspace(*s) && *s != ',' && *s != ')' && *s != ':') {
str += *s;
s++;
}
@@ -274,6 +274,7 @@ private:
s++;
if (match("file")) parseFile();
else if (match("globl")) parseGlobl();
+ else if (match("type")) parseType();
else {
s--;
break;
@@ -294,19 +295,20 @@ private:
}
void parseGlobl() {
+ Name name = getStr();
+ skipWhitespace();
+ }
+
+ void parseFunction() {
+ if (debug) dump("func");
+ Name name = getStrToSep();
+ mustMatch(":");
+
unsigned nextId = 0;
auto getNextId = [&nextId]() {
return cashew::IString(('$' + std::to_string(nextId++)).c_str(), false);
};
- if (debug) dump("func");
- Name name = getStr();
- skipWhitespace();
- mustMatch(".type");
- mustMatch(name.str);
- mustMatch(",@function");
- mustMatch(name.str);
- mustMatch(":");
auto func = allocator.alloc<Function>();
func->name = name;
std::map<Name, WasmType> localTypes;
@@ -798,7 +800,12 @@ private:
if (debug) dump("type");
Name name = getStrToSep();
skipComma();
- mustMatch("@object");
+ if (match("@function")) return parseFunction();
+ else if (match("@object")) return parseObject(name);
+ abort_on("parseType");
+ }
+
+ void parseObject(Name name) {
match(".data");
size_t align = 16; // XXX default?
if (match(".globl")) {