diff options
author | Alon Zakai <alonzakai@gmail.com> | 2016-06-21 16:03:10 -0700 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2016-06-21 16:03:47 -0700 |
commit | cd788a1a62025fed3832672cb539dda4c4ce1329 (patch) | |
tree | 18e33d8ce46b4dfd9bb1e9b1645ad82bb77a70ea | |
parent | 509319ac42a18b5a120ae9e45daac624affc07e1 (diff) | |
download | binaryen-cd788a1a62025fed3832672cb539dda4c4ce1329.tar.gz binaryen-cd788a1a62025fed3832672cb539dda4c4ce1329.tar.bz2 binaryen-cd788a1a62025fed3832672cb539dda4c4ce1329.zip |
test only c api examples; c++ api is internal and unstable, it is tested by our own codebase
-rwxr-xr-x | check.py | 7 | ||||
-rw-r--r-- | test/example/find_div0s.cpp | 57 | ||||
-rw-r--r-- | test/example/find_div0s.txt | 10 |
3 files changed, 1 insertions, 73 deletions
@@ -665,12 +665,7 @@ print '\n[ checking example testcases... ]\n' for t in sorted(os.listdir(os.path.join('test', 'example'))): output_file = os.path.join('bin', 'example') cmd = ['-Isrc', '-g', '-lasmjs', '-lsupport', '-Llib/.', '-pthread', '-o', output_file] - if t.endswith('.cpp'): - cmd = [os.path.join('test', 'example', t), - os.path.join('src', 'passes', 'pass.cpp'), - os.path.join('src', 'wasm.cpp'), - os.path.join('src', 'passes', 'Print.cpp')] + cmd - elif t.endswith('.c'): + if t.endswith('.c'): # build the C file separately extra = [os.environ.get('CC') or 'gcc', os.path.join('test', 'example', t), '-c', '-o', 'example.o', diff --git a/test/example/find_div0s.cpp b/test/example/find_div0s.cpp deleted file mode 100644 index 15534d387..000000000 --- a/test/example/find_div0s.cpp +++ /dev/null @@ -1,57 +0,0 @@ - -// -// Tiny example, using Binaryen to walk a WebAssembly module in search -// for direct integer divisions by zero. To do so, we inherit from -// PostWalker, and implement visitBinary, which is called on every -// Binary node in the module's functions. -// - -#include <ostream> -#include <wasm.h> -#include <wasm-printing.h> -#include <wasm-s-parser.h> - -using namespace wasm; - -int main() { - // 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; - - // 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]); - - // Print it out - WasmPrinter::printModule(&module, std::cout); - - // Search it for divisions by zero: Walk the module, looking for - // that operation. - struct DivZeroSeeker : public PostWalker<DivZeroSeeker, Visitor<DivZeroSeeker>> { - void visitBinary(Binary* curr) { - // In every Binary, look for integer divisions - if (curr->op == BinaryOp::DivSInt32 || curr->op == BinaryOp::DivUInt32) { - // Check if the right operand is a constant, and if it is 0 - auto right = curr->right->dynCast<Const>(); - if (right && right->value.getInteger() == 0) { - std::cout << "We found that " << curr->left << " is divided by zero\n"; - } - } - } - }; - DivZeroSeeker seeker; - seeker.walkModule(&module); -} - diff --git a/test/example/find_div0s.txt b/test/example/find_div0s.txt deleted file mode 100644 index 756de10c5..000000000 --- a/test/example/find_div0s.txt +++ /dev/null @@ -1,10 +0,0 @@ -(module - (memory 0) - (func $has_div_zero - (i32.div_s - (i32.const 5) - (i32.const 0) - ) - ) -) -We found that (i32.const 5) is divided by zero |