Skip to content

Commit ffd9a72

Browse files
tlivelykripken
authored andcommitted
Get wasm2asm building again (#1107)
* Get wasm2asm building again Updates CMakeLists.txt to have wasm2asm built by default, updates wasm2asm.h to account for recent interface changes, and restores JSPrinter functionality. * Implement splice for array values * Clean up wasm2asm testing * Print semicolons after statements in blocks * Cleanups and semicolons for condition arms * Prettify semicolon emission
1 parent de15161 commit ffd9a72

17 files changed

Lines changed: 1026 additions & 114 deletions

CMakeLists.txt

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ FOREACH(SUFFIX "_DEBUG" "_RELEASE" "_RELWITHDEBINFO" "_MINSIZEREL" "")
6060
ENDFOREACH()
6161

6262
IF(MSVC)
63-
IF(CMAKE_CXX_COMPILER_VERSION VERSION_LESS "19.0") # VS2013 and older explicitly need /arch:sse2 set, VS2015 no longer has that option, but always enabled.
63+
IF(CMAKE_CXX_COMPILER_VERSION VERSION_LESS "19.0") # VS2013 and older explicitly need /arch:sse2 set, VS2015 no longer has that option, but always enabled.
6464
ADD_COMPILE_FLAG("/arch:sse2")
6565
ENDIF()
6666
ADD_COMPILE_FLAG("/wd4146") # Ignore warning "warning C4146: unary minus operator applied to unsigned type, result still unsigned", this pattern is used somewhat commonly in the code.
@@ -189,7 +189,7 @@ SET(binaryen_SOURCES
189189
src/binaryen-c.cpp
190190
)
191191
IF(BUILD_STATIC_LIB)
192-
ADD_LIBRARY(binaryen STATIC ${binaryen_SOURCES})
192+
ADD_LIBRARY(binaryen STATIC ${binaryen_SOURCES})
193193
ELSE()
194194
ADD_LIBRARY(binaryen SHARED ${binaryen_SOURCES})
195195
ENDIF()
@@ -243,6 +243,16 @@ SET_PROPERTY(TARGET asm2wasm PROPERTY CXX_STANDARD 11)
243243
SET_PROPERTY(TARGET asm2wasm PROPERTY CXX_STANDARD_REQUIRED ON)
244244
INSTALL(TARGETS asm2wasm DESTINATION ${CMAKE_INSTALL_BINDIR})
245245

246+
SET(wasm2asm_SOURCES
247+
src/wasm2asm-main.cpp
248+
)
249+
ADD_EXECUTABLE(wasm2asm
250+
${wasm2asm_SOURCES})
251+
TARGET_LINK_LIBRARIES(wasm2asm passes wasm asmjs emscripten-optimizer ast cfg support)
252+
SET_PROPERTY(TARGET wasm2asm PROPERTY CXX_STANDARD 11)
253+
SET_PROPERTY(TARGET wasm2asm PROPERTY CXX_STANDARD_REQUIRED ON)
254+
INSTALL(TARGETS wasm2asm DESTINATION ${CMAKE_INSTALL_BINDIR})
255+
246256
SET(s2wasm_SOURCES
247257
src/tools/s2wasm.cpp
248258
src/wasm-emscripten.cpp
@@ -284,4 +294,3 @@ TARGET_LINK_LIBRARIES(wasm-ctor-eval emscripten-optimizer passes wasm asmjs ast
284294
SET_PROPERTY(TARGET wasm-ctor-eval PROPERTY CXX_STANDARD 11)
285295
SET_PROPERTY(TARGET wasm-ctor-eval PROPERTY CXX_STANDARD_REQUIRED ON)
286296
INSTALL(TARGETS wasm-ctor-eval DESTINATION bin)
287-

check.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
)
3232

3333
import scripts.test.s2wasm as s2wasm
34+
import scripts.test.wasm2asm as wasm2asm
3435

3536
if options.interpreter:
3637
print '[ using wasm interpreter at "%s" ]' % options.interpreter
@@ -423,6 +424,7 @@ def fix(x):
423424

424425
s2wasm.test_s2wasm()
425426
s2wasm.test_linker()
427+
# wasm2asm.test_wasm2asm()
426428

427429
print '\n[ running validation tests... ]\n'
428430
# Ensure the tests validate by default

scripts/test/shared.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ def is_exe(fpath):
155155
WASM_AS = [os.path.join(options.binaryen_bin, 'wasm-as')]
156156
WASM_DIS = [os.path.join(options.binaryen_bin, 'wasm-dis')]
157157
ASM2WASM = [os.path.join(options.binaryen_bin, 'asm2wasm')]
158+
WASM2ASM = [os.path.join(options.binaryen_bin, 'wasm2asm')]
158159
WASM_CTOR_EVAL = [os.path.join(options.binaryen_bin, 'wasm-ctor-eval')]
159160
WASM_SHELL = [os.path.join(options.binaryen_bin, 'wasm-shell')]
160161
WASM_MERGE = [os.path.join(options.binaryen_bin, 'wasm-merge')]

scripts/test/support.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,8 @@ def to_end(j):
147147
return ret
148148

149149

150-
def run_command(cmd, expected_status=0, stderr=None, expected_err=None):
150+
def run_command(cmd, expected_status=0, stderr=None,
151+
expected_err=None, err_contains=False):
151152
if expected_err is not None:
152153
assert stderr == subprocess.PIPE or stderr is None,\
153154
"Can't redirect stderr if using expected_err"
@@ -157,7 +158,9 @@ def run_command(cmd, expected_status=0, stderr=None, expected_err=None):
157158
out, err = proc.communicate()
158159
if proc.returncode != expected_status:
159160
raise Exception(('run_command failed', err))
160-
if expected_err is not None and err != expected_err:
161+
err_correct = expected_err is None or \
162+
(expected_err in err if err_contains else expected_err == err)
163+
if not err_correct:
161164
raise Exception(('run_command unexpected stderr',
162165
"expected '%s', actual '%s'" % (expected_err, err)))
163166
return out

scripts/test/wasm2asm.py

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
#!/usr/bin/env python2
2+
3+
import os
4+
5+
from support import run_command
6+
from shared import (WASM2ASM, MOZJS, NODEJS, fail_if_not_identical, tests)
7+
8+
9+
def test_wasm2asm():
10+
print '\n[ checking wasm2asm testcases... ]\n'
11+
12+
# tests with i64s, invokes, etc.
13+
blacklist = ['atomics.wast', 'address.wast']
14+
spec_tests = [os.path.join('spec', t) for t in
15+
sorted(os.listdir(os.path.join('test', 'spec')))]
16+
for wasm in tests + spec_tests:
17+
if not wasm.endswith('.wast') or os.path.basename(wasm) in blacklist:
18+
continue
19+
20+
asm = os.path.basename(wasm).replace('.wast', '.2asm.js')
21+
expected_file = os.path.join('test', asm)
22+
if not os.path.exists(expected_file):
23+
continue
24+
25+
print '..', wasm
26+
27+
cmd = WASM2ASM + [os.path.join('test', wasm)]
28+
out = run_command(cmd)
29+
30+
# verify output
31+
expected = open(expected_file).read()
32+
fail_if_not_identical(out, expected)
33+
34+
open('a.2asm.js', 'w').write(out)
35+
36+
if NODEJS:
37+
# verify asm.js is valid js
38+
out = run_command([NODEJS, 'a.2asm.js'])
39+
fail_if_not_identical(out, '')
40+
41+
if MOZJS:
42+
# verify asm.js validates
43+
# check only subset of err because mozjs emits timing info
44+
out = run_command([MOZJS, '-w', 'a.2asm.js'],
45+
expected_err='Successfully compiled asm.js code',
46+
err_contains=True)
47+
fail_if_not_identical(out, '')
48+
49+
50+
if __name__ == "__main__":
51+
test_wasm2asm()

src/asmjs/shared-constants.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ cashew::IString GLOBAL("global"),
5959
INSTRUMENT("instrument"),
6060
MATH_IMUL("Math_imul"),
6161
MATH_CLZ32("Math_clz32"),
62-
MATH_CTZ32("Math_ctz32"),
6362
MATH_POPCNT32("Math_popcnt32"),
6463
MATH_ABS("Math_abs"),
6564
MATH_CEIL("Math_ceil"),

src/asmjs/shared-constants.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@ extern cashew::IString GLOBAL,
6262
INSTRUMENT,
6363
MATH_IMUL,
6464
MATH_CLZ32,
65-
MATH_CTZ32,
6665
MATH_POPCNT32,
6766
MATH_ABS,
6867
MATH_CEIL,

0 commit comments

Comments
 (0)