summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2015-12-04 21:40:14 -0800
committerAlon Zakai <alonzakai@gmail.com>2015-12-04 21:40:14 -0800
commit23f28802796080813f0e806248a91a9ad5fc6275 (patch)
treed572509b0e4b48920a208c3a5f48f93e469d2215
parent56c1189004dbfa1713dfe418c322906403402d60 (diff)
downloadbinaryen-23f28802796080813f0e806248a91a9ad5fc6275.tar.gz
binaryen-23f28802796080813f0e806248a91a9ad5fc6275.tar.bz2
binaryen-23f28802796080813f0e806248a91a9ad5fc6275.zip
add first working wasm2asm testcase
-rwxr-xr-xcheck.py11
-rw-r--r--src/wasm2asm-main.cpp8
-rw-r--r--test/min.wasm2asm.js21
3 files changed, 32 insertions, 8 deletions
diff --git a/check.py b/check.py
index cab2d5445..a0517aff5 100755
--- a/check.py
+++ b/check.py
@@ -76,18 +76,19 @@ for asm in tests:
print '\n[ checking wasm2asm testcases... ]\n'
-for wasm in []:#tests:
+for wasm in ['min.wast']:
if wasm.endswith('.wast'):
print '..', wasm
- asm = asm.replace('.wast', '.wasm2asm.js')
+ asm = wasm.replace('.wast', '.wasm2asm.js')
actual, err = subprocess.Popen([os.path.join('bin', 'wasm2asm'), os.path.join('test', wasm)], stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate()
assert err == '', 'bad err:' + err
# verify output
- if not os.path.exists(os.path.join('test', asm)):
+ expected_file = os.path.join('test', asm)
+ if not os.path.exists(expected_file):
print actual
- raise Exception('output .wast file does not exist')
- expected = open(os.path.join('test', aasm)).read()
+ raise Exception('output ' + expected_file + ' does not exist')
+ expected = open(expected_file).read()
if actual != expected:
fail(actual, expected)
diff --git a/src/wasm2asm-main.cpp b/src/wasm2asm-main.cpp
index 4a134e576..85fa58179 100644
--- a/src/wasm2asm-main.cpp
+++ b/src/wasm2asm-main.cpp
@@ -44,9 +44,11 @@ int main(int argc, char **argv) {
Wasm2AsmBuilder wasm2asm;
Ref asmjs = wasm2asm.processWasm(&wasm);
- if (debug) std::cerr << "a-printing...\n";
- asmjs->stringify(std::cout);
- std::cout << '\n';
+ if (debug) {
+ std::cerr << "a-printing...\n";
+ asmjs->stringify(std::cout);
+ std::cout << '\n';
+ }
if (debug) std::cerr << "j-printing...\n";
JSPrinter jser(true, true, asmjs);
diff --git a/test/min.wasm2asm.js b/test/min.wasm2asm.js
new file mode 100644
index 000000000..226f62807
--- /dev/null
+++ b/test/min.wasm2asm.js
@@ -0,0 +1,21 @@
+function asmFunc() {
+ function floats(f) {
+ f = Math_fround(f);
+ var t = Math_fround(0);
+ return Math_fround(t + f);
+ }
+
+ function neg(k, p) {
+ k = k | 0;
+ p = p | 0;
+ var n = Math_fround(0), wasm2asm_f32$1 = Math_fround(0), wasm2asm_f32$0 = Math_fround(0);
+ {
+ HEAP32[k >> 2] = p;
+ wasm2asm_f32$1 = HEAPF32[k >> 2];
+ wasm2asm_f32$0 = Math_fround(-wasm2asm_f32$1);
+ n = wasm2asm_f32$0;
+ }
+ }
+
+}
+