diff options
author | Alon Zakai <alonzakai@gmail.com> | 2015-11-28 15:14:36 -0800 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2015-11-28 15:14:36 -0800 |
commit | b4a8d4f3e58426e3807f7f4f5d1e983ee2737c03 (patch) | |
tree | 179deafc013d7c72e3fda48330674447ac73325a /src/wasm-js.cpp | |
parent | f30c01daf0375dee57d0d88896cad1c3dbd59db8 (diff) | |
download | binaryen-b4a8d4f3e58426e3807f7f4f5d1e983ee2737c03.tar.gz binaryen-b4a8d4f3e58426e3807f7f4f5d1e983ee2737c03.tar.bz2 binaryen-b4a8d4f3e58426e3807f7f4f5d1e983ee2737c03.zip |
work on s-parsing in wasm.js
Diffstat (limited to 'src/wasm-js.cpp')
-rw-r--r-- | src/wasm-js.cpp | 22 |
1 files changed, 19 insertions, 3 deletions
diff --git a/src/wasm-js.cpp b/src/wasm-js.cpp index 93e5b9205..e822da66a 100644 --- a/src/wasm-js.cpp +++ b/src/wasm-js.cpp @@ -21,12 +21,14 @@ int debug = 0; // global singletons Asm2WasmBuilder* asm2wasm = nullptr; +SExpressionParser* sExpressionParser = nullptr; +SExpressionWasmBuilder* sExpressionWasmBuilder = nullptr; ModuleInstance* instance = nullptr; AllocatingModule* module = nullptr; bool wasmJSDebug = false; static void prepare2wasm() { - assert(instance == nullptr); // singleton + assert(asm2wasm == nullptr && sExpressionParser == nullptr && sExpressionWasmBuilder == nullptr && instance == nullptr); // singletons #if WASM_JS_DEBUG wasmJSDebug = 1; #else @@ -43,7 +45,7 @@ extern "C" void EMSCRIPTEN_KEEPALIVE load_asm2wasm(char *input) { input = pre.process(input); // proceed to parse and wasmify - if (wasmJSDebug) std::cerr << "parsing...\n"; + if (wasmJSDebug) std::cerr << "asm parsing...\n"; cashew::Parser<Ref, DotZeroValueBuilder> builder; Ref asmjs = builder.parseToplevel(input); @@ -65,7 +67,21 @@ extern "C" void EMSCRIPTEN_KEEPALIVE load_asm2wasm(char *input) { // loads wasm code in s-expression format extern "C" void EMSCRIPTEN_KEEPALIVE load_s_expr2wasm(char *input) { prepare2wasm(); - abort(); + + if (wasmJSDebug) std::cerr << "wasm-s-expression parsing...\n"; + + sExpressionParser = new SExpressionParser(input); + Element& root = *sExpressionParser->root; + if (wasmJSDebug) std::cout << root << '\n'; + + if (wasmJSDebug) std::cerr << "wasming...\n"; + + module = new AllocatingModule(); + // A .wast may have multiple modules, with some asserts after them, but we just read the first here. + sExpressionWasmBuilder = new SExpressionWasmBuilder(*module, *root[0], [&]() { + std::cerr << "error in parsing s-expressions to wasm\n"; + abort(); + }); } // instantiates the loaded wasm (which might be from asm2wasm, or |