diff options
author | Alon Zakai <alonzakai@gmail.com> | 2015-11-12 10:18:20 -0800 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2015-11-12 10:18:20 -0800 |
commit | afce1de1495cc5782ec55b016d4e864b316d9920 (patch) | |
tree | 0966b564132f79d741cde8d1ae75f462df44ea4f | |
parent | d226b1f67d2f42867e83e59fb362cf032b893c21 (diff) | |
download | binaryen-afce1de1495cc5782ec55b016d4e864b316d9920.tar.gz binaryen-afce1de1495cc5782ec55b016d4e864b316d9920.tar.bz2 binaryen-afce1de1495cc5782ec55b016d4e864b316d9920.zip |
simplify find_div0s
-rw-r--r-- | test/example/find_div0s.cpp | 33 | ||||
-rw-r--r-- | test/example/find_div0s.txt | 4 |
2 files changed, 21 insertions, 16 deletions
diff --git a/test/example/find_div0s.cpp b/test/example/find_div0s.cpp index be273390f..60eed5f62 100644 --- a/test/example/find_div0s.cpp +++ b/test/example/find_div0s.cpp @@ -8,25 +8,30 @@ #include <ostream> #include <wasm.h> +#include <wasm-s-parser.h> using namespace wasm; int main() { - // A module with a function with a division by zero in the body. + // A simple WebAssembly module in S-Expression format. + char input[] = + "(module" + " (func $has_div_zero" + " (i32.div_s" + " (i32.const 5)" + " (i32.const 0)" + " )" + " )" + ")"; + + // Parse the S-Expression text, and prepare to build a WebAssembly module. + SExpressionParser parser(input); + Element& root = *parser.root; Module module; - Function func; - func.name = "func"; - Binary div; - div.op = BinaryOp::DivS; - Const left; - left.value = 5; - Const right; - right.value = 0; - div.left = &left; - div.right = &right; - div.finalize(); - func.body = ÷ - module.addFunction(&func); + + // The parsed code has just one element, the module. Build the module + // from that (and abort on any errors, but there won't be one here). + SExpressionWasmBuilder builder(module, *root[0], [&]() { abort(); }); // Print it out std::cout << module; diff --git a/test/example/find_div0s.txt b/test/example/find_div0s.txt index 44397fbde..554790493 100644 --- a/test/example/find_div0s.txt +++ b/test/example/find_div0s.txt @@ -1,7 +1,7 @@ (module (memory 0 4294967295) - (func $func - (none.div_s + (func $has_div_zero + (i32.div_s (i32.const 5) (i32.const 0) ) |