Skip to content

Commit

Permalink
C API plus test
Browse files Browse the repository at this point in the history
  • Loading branch information
kripken committed May 3, 2016
1 parent e888c84 commit 0e18817
Show file tree
Hide file tree
Showing 6 changed files with 689 additions and 15 deletions.
5 changes: 5 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,11 @@ SET(support_SOURCES
)
ADD_LIBRARY(support STATIC ${support_SOURCES})

SET(binaryen_c_SOURCES
src/binaryen-c.cpp
)
ADD_LIBRARY(binaryen-c STATIC ${binaryen_c_SOURCES})

SET(binaryen-shell_SOURCES
src/binaryen-shell.cpp
src/pass.cpp
Expand Down
42 changes: 27 additions & 15 deletions check.py
Original file line number Diff line number Diff line change
Expand Up @@ -569,21 +569,33 @@ def fix(x):

print '\n[ checking example testcases... ]\n'

cmd = [os.environ.get('CXX') or 'g++', '-std=c++11',
os.path.join('test', 'example', 'find_div0s.cpp'),
os.path.join('src', 'pass.cpp'),
os.path.join('src', 'wasm.cpp'),
os.path.join('src', 'passes', 'Print.cpp'),
'-Isrc', '-g', '-lasmjs', '-lsupport', '-Llib/.', '-pthread']
if os.environ.get('COMPILER_FLAGS'):
for f in os.environ.get('COMPILER_FLAGS').split(' '):
cmd.append(f)
print ' '.join(cmd)
subprocess.check_call(cmd)
actual = subprocess.Popen(['./a.out'], stdout=subprocess.PIPE).communicate()[0]
expected = open(os.path.join('test', 'example', 'find_div0s.txt')).read()
if actual != expected:
fail(actual, expected)
for t in sorted(os.listdir(os.path.join('test', 'example'))):
cmd = [os.path.join('src', 'pass.cpp'),
os.path.join('src', 'wasm.cpp'),
os.path.join('src', 'passes', 'Print.cpp'),
'-Isrc', '-g', '-lasmjs', '-lsupport', '-Llib/.', '-pthread']
if t.endswith('.cpp'):
cmd = [os.path.join('test', 'example', t)] + cmd
elif 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',
'-Isrc', '-g', '-lasmjs', '-lsupport', '-Llib/.', '-pthread']
print ' '.join(extra)
subprocess.check_call(extra)
cmd = ['example.o', '-lbinaryen-c'] + cmd
else:
continue
if os.environ.get('COMPILER_FLAGS'):
for f in os.environ.get('COMPILER_FLAGS').split(' '):
cmd.append(f)
cmd = [os.environ.get('CXX') or 'g++', '-std=c++11'] + cmd
print ' '.join(cmd)
subprocess.check_call(cmd)
actual = subprocess.Popen(['./a.out'], stdout=subprocess.PIPE).communicate()[0]
expected = open(os.path.join('test', 'example', '.'.join(t.split('.')[:-1]) + '.txt')).read()
if actual != expected:
fail(actual, expected)

if has_emcc:

Expand Down
Loading

0 comments on commit 0e18817

Please sign in to comment.