summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2015-11-03 17:49:48 -0800
committerAlon Zakai <alonzakai@gmail.com>2015-11-03 17:49:48 -0800
commitf9ccaa4157bacd3a4690497bc8b5fa2e49ef739c (patch)
treee0b177e08350ff40c017da1a59c59dcc7cc2dac5
parentd64776c06b70afac0a05c51f4538743cbb74a8c2 (diff)
downloadbinaryen-f9ccaa4157bacd3a4690497bc8b5fa2e49ef739c.tar.gz
binaryen-f9ccaa4157bacd3a4690497bc8b5fa2e49ef739c.tar.bz2
binaryen-f9ccaa4157bacd3a4690497bc8b5fa2e49ef739c.zip
shell fixes
-rw-r--r--src/wasm-sexpr-parser.h15
-rw-r--r--src/wasm-shell.cpp2
2 files changed, 9 insertions, 8 deletions
diff --git a/src/wasm-sexpr-parser.h b/src/wasm-sexpr-parser.h
index 5fb4d44ea..9729d6b1f 100644
--- a/src/wasm-sexpr-parser.h
+++ b/src/wasm-sexpr-parser.h
@@ -8,6 +8,8 @@
namespace wasm {
+int debug;
+
using namespace cashew;
// Globals
@@ -67,13 +69,14 @@ public:
//
class SExpressionParser {
+ char *beginning;
char* input;
MixedArena allocator;
public:
// Assumes control of and modifies the input.
- SExpressionParser(char* input) : input(input) {}
+ SExpressionParser(char* input) : beginning(input), input(input) {}
Element* parseEverything() {
return parseInnerList();
@@ -93,13 +96,13 @@ private:
while (1) {
Element* curr = parse();
if (!curr) return ret;
- curr->list().push_back(curr);
+ ret->list().push_back(curr);
}
}
Element* parse() {
skipWhitespace();
- if (!input) return nullptr;
+ if (input[0] == 0 || input[0] == ')') return nullptr;
if (input[0] == '(') {
// a list
input++;
@@ -118,7 +121,7 @@ private:
Element* parseString() {
char *start = input;
- while (input[0] && !isspace(input[0])) input++;
+ while (input[0] && !isspace(input[0]) && input[0] != ')') input++;
return allocator.alloc<Element>()->setString(IString(start, false)); // TODO: reuse the string here, carefully
}
};
@@ -135,9 +138,7 @@ class SExpressionWasmBuilder {
public:
// Assumes control of and modifies the input.
- SExpressionWasmBuilder(Module& wasm, char* input) : wasm(wasm), parser(input) {}
-
- void parse() {
+ SExpressionWasmBuilder(Module& wasm, char* input) : wasm(wasm), parser(input) {
Element* root = parser.parseEverything();
assert(root);
assert((*root)[0]->str() == MODULE);
diff --git a/src/wasm-shell.cpp b/src/wasm-shell.cpp
index 1f242860d..c910b5958 100644
--- a/src/wasm-shell.cpp
+++ b/src/wasm-shell.cpp
@@ -9,7 +9,7 @@ using namespace cashew;
using namespace wasm;
int main(int argc, char **argv) {
- int debug = getenv("WASM_SHELL_DEBUG") ? getenv("WASM_SHELL_DEBUG")[0] - '0' : 0;
+ debug = getenv("WASM_SHELL_DEBUG") ? getenv("WASM_SHELL_DEBUG")[0] - '0' : 0;
char *infile = argv[1];