diff options
author | Alon Zakai <alonzakai@gmail.com> | 2015-12-12 11:30:38 -0500 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2015-12-12 11:30:38 -0500 |
commit | 1ad63eecab0cf8ad49b553827d623e43b074f883 (patch) | |
tree | 8c241c78ae40507dde5823aede21aa670b753ac7 /src | |
parent | 1bdc7ea94745412d73821e7ab3846f1693423756 (diff) | |
download | binaryen-1ad63eecab0cf8ad49b553827d623e43b074f883.tar.gz binaryen-1ad63eecab0cf8ad49b553827d623e43b074f883.tar.bz2 binaryen-1ad63eecab0cf8ad49b553827d623e43b074f883.zip |
most hosts, and better const parsing
Diffstat (limited to 'src')
-rw-r--r-- | src/s2wasm.h | 25 |
1 files changed, 22 insertions, 3 deletions
diff --git a/src/s2wasm.h b/src/s2wasm.h index 3f5efc803..0ef56774b 100644 --- a/src/s2wasm.h +++ b/src/s2wasm.h @@ -322,6 +322,19 @@ private: curr->type = type; setOutput(curr, assign); }; + auto makeHost = [&](HostOp op) { + Name assign = getAssign(); + auto curr = allocator.alloc<Host>(); + curr->op = MemorySize; + setOutput(curr, assign); + }; + auto makeHost1 = [&](HostOp op) { + Name assign = getAssign(); + auto curr = allocator.alloc<Host>(); + curr->op = MemorySize; + curr->operands.push_back(getInput()); + setOutput(curr, assign); + }; auto makeLoad = [&](WasmType type) { skipComma(); auto curr = allocator.alloc<Load>(); @@ -377,15 +390,17 @@ private: case 'c': { if (match("const")) { Name assign = getAssign(); - if (*s == '.') { + char start = *s; + cashew::IString str = getStr(); + if (start == '.' || (isalpha(*s) && str != NAN_ && str != INFINITY_)) { // global address auto curr = allocator.alloc<Const>(); curr->type = i32; - addressings.emplace_back(curr, getStr()); + addressings.emplace_back(curr, str); setOutput(curr, assign); } else { // constant - setOutput(parseConst(getStr(), type, allocator), assign); + setOutput(parseConst(str, type, allocator), assign); } } else if (match("convert_s/i32")) makeUnary(UnaryOp::ConvertSInt32, type); else if (match("convert_u/i32")) makeUnary(UnaryOp::ConvertUInt32, type); @@ -613,6 +628,10 @@ private: bstack.back()->list.push_back(curr); } else if (match("unreachable")) { bstack.back()->list.push_back(allocator.alloc<Unreachable>()); + } else if (match("memory_size")) { + makeHost(MemorySize); + } else if (match("grow_memory")) { + makeHost1(GrowMemory); } else if (match("func_end")) { s = strchr(s, '\n'); s++; |