summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xcheck.py20
-rw-r--r--src/binaryen-shell.cpp9
-rw-r--r--test/if_else.txt52
3 files changed, 78 insertions, 3 deletions
diff --git a/check.py b/check.py
index c5d9f7d28..b992610b4 100755
--- a/check.py
+++ b/check.py
@@ -18,6 +18,14 @@ def fail(actual, expected):
''.join([a.rstrip()+'\n' for a in difflib.unified_diff(expected.split('\n'), actual.split('\n'), fromfile='expected', tofile='actual')])
))
+def fail_if_not_identical(actual, expected):
+ if expected != actual:
+ fail(actual, expected)
+
+def fail_if_not_contained(actual, expected):
+ if expected not in actual:
+ fail(actual, expected)
+
if not interpreter:
print '[ no wasm interpreter provided, you should pass one as --interpreter=path/to/interpreter ]'
@@ -64,6 +72,18 @@ for asm in tests:
raise Exception('wasm interpreter error: ' + err) # failed to pretty-print
raise Exception('wasm interpreter error')
+print '\n[ checking binaryen-shell... ]\n'
+
+actual, err = subprocess.Popen([os.path.join('bin', 'binaryen-shell'), '--help'], stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate()
+fail_if_not_contained(actual, 'binaryen shell')
+fail_if_not_contained(actual, 'options:')
+fail_if_not_contained(actual, 'passes:')
+fail_if_not_contained(actual, ' -lower-if-else')
+
+print ' '.join([os.path.join('bin', 'binaryen-shell'), '-print-before', '-print-after', '-lower-if-else', os.path.join('test', 'if_else.wast')])
+actual, err = subprocess.Popen([os.path.join('bin', 'binaryen-shell'), '-print-before', '-print-after', '-lower-if-else', os.path.join('test', 'if_else.wast')], stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate()
+fail_if_not_identical(actual, open(os.path.join('test', 'if_else.txt')).read())
+
print '\n[ checking binaryen-shell testcases... ]\n'
for t in tests:
diff --git a/src/binaryen-shell.cpp b/src/binaryen-shell.cpp
index 4ff93cf2b..97f7f1346 100644
--- a/src/binaryen-shell.cpp
+++ b/src/binaryen-shell.cpp
@@ -165,16 +165,19 @@ int main(int argc, char **argv) {
} else if (arg == "-print-after") {
print_after = true;
} else if (arg == "--help") {
+ std::cout << "\n";
std::cout << "binaryen shell\n";
std::cout << "--------------\n\n";
std::cout << "options:\n";
std::cout << " -print-before : print modules before processing them\n";
+ std::cout << " -print-after : print modules after processing them\n";
std::cout << "\n";
std::cout << "passes:\n";
auto allPasses = PassRegistry::get()->getRegisteredNames();
for (auto& name : allPasses) {
std::cout << " -" << name << "\n";
}
+ std::cout << "\n";
exit(0);
} else {
// otherwise, assumed to be a pass
@@ -202,7 +205,7 @@ int main(int argc, char **argv) {
}
if (debug) std::cerr << "loading '" << infile << "'...\n";
- FILE *f = fopen(argv[1], "r");
+ FILE *f = fopen(infile, "r");
if (!f) {
printf("error: could not open input file: %s\n", infile);
exit(1);
@@ -237,7 +240,7 @@ int main(int argc, char **argv) {
auto instance = new ModuleInstance(wasm, interface);
if (print_before) {
- if (debug) std::cerr << "printing...\n";
+ std::cout << "printing before:\n";
std::cout << wasm;
}
@@ -253,7 +256,7 @@ int main(int argc, char **argv) {
}
if (print_after) {
- if (debug) std::cerr << "printing...\n";
+ std::cout << "printing after:\n";
std::cout << wasm;
}
diff --git a/test/if_else.txt b/test/if_else.txt
new file mode 100644
index 000000000..2245f7230
--- /dev/null
+++ b/test/if_else.txt
@@ -0,0 +1,52 @@
+printing before:
+(module
+ (memory 16777216 16777216)
+ (func $ifs
+ (block
+ (if
+ (i32.const 0)
+ (i32.const 1)
+ )
+ (if_else
+ (i32.const 0)
+ (i32.const 1)
+ (i32.const 2)
+ )
+ (if_else
+ (i32.const 4)
+ (i32.const 5)
+ (i32.const 6)
+ )
+ )
+ )
+)
+printing after:
+(module
+ (memory 16777216 16777216)
+ (func $ifs
+ (block
+ (if
+ (i32.const 0)
+ (i32.const 1)
+ )
+ (block $L0
+ (if
+ (i32.const 0)
+ (br $L0
+ (i32.const 1)
+ )
+ )
+ (i32.const 2)
+ )
+ (block $L1
+ (if
+ (i32.const 4)
+ (br $L1
+ (i32.const 5)
+ )
+ )
+ (i32.const 6)
+ )
+ )
+ )
+)