diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/wasm-s-parser.h | 21 | ||||
-rw-r--r-- | src/wasm-shell.cpp | 8 |
2 files changed, 14 insertions, 15 deletions
diff --git a/src/wasm-s-parser.h b/src/wasm-s-parser.h index a181278ab..2456c5cca 100644 --- a/src/wasm-s-parser.h +++ b/src/wasm-s-parser.h @@ -105,12 +105,12 @@ class SExpressionParser { public: // Assumes control of and modifies the input. - SExpressionParser(char* input) : beginning(input), input(input) {} - - Element* parseEverything() { - return parseInnerList(); + SExpressionParser(char* input) : beginning(input), input(input) { + root = parseInnerList(); } + Element* root; + private: // parses the internal part of a list, inside the parens. Element* parseInnerList() { @@ -181,18 +181,13 @@ class SExpressionWasmBuilder { Module& wasm; MixedArena allocator; - SExpressionParser parser; public: // Assumes control of and modifies the input. - SExpressionWasmBuilder(Module& wasm, char* input) : wasm(wasm), parser(input) { - Element* root = parser.parseEverything(); - if (debug) std::cout << *root << '\n'; - assert(root); - Element* module = (*root)[0]; - assert((*module)[0]->str() == MODULE); - for (unsigned i = 1; i < module->size(); i++) { - parseModuleElement(*(*module)[i]); + SExpressionWasmBuilder(Module& wasm, Element& module) : wasm(wasm) { + assert(module[0]->str() == MODULE); + for (unsigned i = 1; i < module.size(); i++) { + parseModuleElement(*module[i]); } } diff --git a/src/wasm-shell.cpp b/src/wasm-shell.cpp index c60cec81b..b3b249771 100644 --- a/src/wasm-shell.cpp +++ b/src/wasm-shell.cpp @@ -28,9 +28,13 @@ int main(int argc, char **argv) { fclose(f); input[num] = 0; - if (debug) std::cerr << "parsing...\n"; + if (debug) std::cerr << "parsing text to s-expressions...\n"; + SExpressionParser parser(input); + if (debug) std::cout << *parser.root << '\n'; + + if (debug) std::cerr << "parsing s-expressions to wasm...\n"; Module wasm; - SExpressionWasmBuilder builder(wasm, input); + SExpressionWasmBuilder builder(wasm, *(*parser.root)[0]); if (debug) std::cerr << "printing...\n"; std::cout << wasm; |