diff options
-rw-r--r-- | CMakeLists.txt | 2 | ||||
-rw-r--r-- | README.md | 2 | ||||
-rw-r--r-- | src/tools/wasm2asm.cpp (renamed from src/wasm2asm-main.cpp) | 34 |
3 files changed, 24 insertions, 14 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index b41f15b9f..fbd0bedb9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -244,7 +244,7 @@ SET_PROPERTY(TARGET asm2wasm PROPERTY CXX_STANDARD_REQUIRED ON) INSTALL(TARGETS asm2wasm DESTINATION ${CMAKE_INSTALL_BINDIR}) SET(wasm2asm_SOURCES - src/wasm2asm-main.cpp + src/tools/wasm2asm.cpp ) ADD_EXECUTABLE(wasm2asm ${wasm2asm_SOURCES}) @@ -35,7 +35,7 @@ Binaryen's internal IR is designed to be There are a few differences between Binaryen IR and the WebAssembly language: * Tree structure - * Binaryen IR [is an tree](https://github.com/WebAssembly/binaryen/issues/663), i.e., it has hierarchical structure, for convenience of optimization. This differs from the WebAssembly binary format which is a stack machine. + * Binaryen IR [is a tree](https://github.com/WebAssembly/binaryen/issues/663), i.e., it has hierarchical structure, for convenience of optimization. This differs from the WebAssembly binary format which is a stack machine. * Consequently Binaryen's text format allows only s-expressions. WebAssembly's official text format is primarily a linear instruction list (with s-expression extensions). Binaryen can't read the linear style, but it can read a wasm text file if it contains only s-expressions. * Types and unreachable code * WebAssembly limits block/if/loop types to none and the concrete value types (i32, i64, f32, f64). Binaryen IR has an unreachable type, and it allows block/if/loop to take it, allowing [local transforms that don't need to know the global context](https://github.com/WebAssembly/binaryen/issues/903). diff --git a/src/wasm2asm-main.cpp b/src/tools/wasm2asm.cpp index 10e059d8d..5c331f4c3 100644 --- a/src/wasm2asm-main.cpp +++ b/src/tools/wasm2asm.cpp @@ -57,21 +57,31 @@ int main(int argc, const char *argv[]) { auto input( read_file<std::vector<char>>(options.extra["infile"], Flags::Text, options.debug ? Flags::Debug : Flags::Release)); - if (options.debug) std::cerr << "s-parsing..." << std::endl; - SExpressionParser parser(input.data()); - Element &root = *parser.root; - - if (options.debug) std::cerr << "w-parsing..." << std::endl; + Element* root; Module wasm; - SExpressionWasmBuilder builder(wasm, *root[0]); + Ref asmjs; + + try { + if (options.debug) std::cerr << "s-parsing..." << std::endl; + SExpressionParser parser(input.data()); + root = parser.root; + + if (options.debug) std::cerr << "w-parsing..." << std::endl; + SExpressionWasmBuilder builder(wasm, *(*root)[0]); - if (options.debug) std::cerr << "asming..." << std::endl; - Wasm2AsmBuilder wasm2asm(builderFlags); - Ref asmjs = wasm2asm.processWasm(&wasm); + if (options.debug) std::cerr << "asming..." << std::endl; + Wasm2AsmBuilder wasm2asm(builderFlags); + asmjs = wasm2asm.processWasm(&wasm); - if (options.extra["asserts"] == "1") { - if (options.debug) std::cerr << "asserting..." << std::endl; - flattenAppend(asmjs, wasm2asm.processAsserts(root, builder)); + if (options.extra["asserts"] == "1") { + if (options.debug) std::cerr << "asserting..." << std::endl; + flattenAppend(asmjs, wasm2asm.processAsserts(*root, builder)); + } + } catch (ParseException& p) { + p.dump(std::cerr); + Fatal() << "error in parsing input"; + } catch (std::bad_alloc& b) { + Fatal() << "error in building module, std::bad_alloc (possibly invalid request for silly amounts of memory)"; } if (options.debug) { |