diff options
author | Alon Zakai <alonzakai@gmail.com> | 2015-12-10 23:18:19 -0500 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2015-12-10 23:18:19 -0500 |
commit | 3c0faf1bce309974c82e96620113bf29dbf4a99a (patch) | |
tree | 52ab533da28bcba66bc50dbcee3c3003209d0c15 /src | |
parent | 41757a06fbc13466e7f71cfe65c878685d76c457 (diff) | |
download | binaryen-3c0faf1bce309974c82e96620113bf29dbf4a99a.tar.gz binaryen-3c0faf1bce309974c82e96620113bf29dbf4a99a.tar.bz2 binaryen-3c0faf1bce309974c82e96620113bf29dbf4a99a.zip |
almost enough to parse basics.s
Diffstat (limited to 'src')
-rw-r--r-- | src/s2wasm.h | 45 |
1 files changed, 41 insertions, 4 deletions
diff --git a/src/s2wasm.h b/src/s2wasm.h index d4bfdc66d..d8a0e1e8e 100644 --- a/src/s2wasm.h +++ b/src/s2wasm.h @@ -116,6 +116,18 @@ private: return cashew::IString(str.c_str(), false); } + Name getQuoted() { // TODO: support 0 in the middle, etc., use a raw buffer, etc. + assert(*s == '"'); + s++; + std::string str; + while (*s && *s != '\"') { + str += *s; + s++; + } + skipWhitespace(); + return cashew::IString(str.c_str(), false); + } + WasmType getType() { if (match("i32")) return i32; if (match("i64")) return i64; @@ -138,7 +150,7 @@ private: if (*s != '.') break; s++; if (match("text")) parseText(); - else if (match("data")) parseData(); + else if (match("type")) parseType(); else abort_on(s); } } @@ -151,7 +163,7 @@ private: s++; if (match("file")) parseFile(); else if (match("globl")) parseGlobl(); - else abort_on(s); + else break; } } @@ -274,11 +286,27 @@ private: } else abort_on("i32.c"); break; } + case 'e': { + if (match("eq")) makeBinary(BinaryOp::Eq, i32); + break; + } + case 'g': { + if (match("gt_s")) makeBinary(BinaryOp::GtS, i32); + else if (match("gt_u")) makeBinary(BinaryOp::GtU, i32); + else abort_on("i32.g"); + break; + } case 'n': { if (match("ne")) makeBinary(BinaryOp::Ne, i32); else abort_on("i32.n"); break; } + case 'r': { + if (match("rem_s")) makeBinary(BinaryOp::RemS, i32); + else if (match("rem_u")) makeBinary(BinaryOp::RemU, i32); + else abort_on("i32.n"); + break; + } case 's': { if (match("shr_s")) makeBinary(BinaryOp::ShrS, i32); else if (match("shr_u")) makeBinary(BinaryOp::ShrU, i32); @@ -356,8 +384,17 @@ private: } } - void parseData() { - abort(); + void parseType() { + Name name = getStrToComma(); + mustMatch("@object"); + mustMatch(name.str); + mustMatch(":"); + mustMatch(".asciz"); + Name buffer = getQuoted(); + mustMatch(".size"); + mustMatch(name.str); + mustMatch(","); + Name size = getStr(); } }; |