def generate_wast_files(lld_bin): print '\n[ linking wasm files from object files... ]\n' lld_path = os.path.join(shared.options.binaryen_test, 'lld') for obj_file, ext in files_with_extensions(lld_path, ['.o']): print '..', obj_file wasm_file = obj_file.replace(ext, '.wasm') wast_file = obj_file.replace(ext, '.wast') obj_path = os.path.join(lld_path, obj_file) wasm_path = os.path.join(lld_path, wasm_file) wast_path = os.path.join(lld_path, wast_file) run_command([ lld_bin, '-flavor', 'wasm', '-z', '-stack-size=1048576', obj_path, '-o', wasm_path, '--entry=main', '--allow-undefined', '--export', '__wasm_call_ctors', ]) try: run_command(shared.WASM_DIS + [wasm_path, '-o', wast_path]) finally: # Don't need the .wasm file, don't leave it around shared.delete_from_orbit(wasm_path)
def generate_wat_files(llvm_bin, emscripten_root): print('\n[ building wat files from C sources... ]\n') lld_path = os.path.join(shared.options.binaryen_test, 'lld') for src_file, ext in files_with_extensions(lld_path, ['.c', '.cpp', '.s']): print('..', src_file) obj_file = src_file.replace(ext, '.o') src_path = os.path.join(lld_path, src_file) obj_path = os.path.join(lld_path, obj_file) wasm_file = src_file.replace(ext, '.wasm') wat_file = src_file.replace(ext, '.wat') obj_path = os.path.join(lld_path, obj_file) wasm_path = os.path.join(lld_path, wasm_file) wat_path = os.path.join(lld_path, wat_file) is_shared = 'shared' in src_file compile_cmd = [ os.path.join(llvm_bin, 'clang'), src_path, '-o', obj_path, '--target=wasm32-emscripten', '-mllvm', '-enable-emscripten-sjlj', '-c', '-nostdinc', '-Xclang', '-nobuiltininc', '-Xclang', '-nostdsysteminc', '-Xclang', '-I%s/system/include' % emscripten_root, '-O1', ] link_cmd = [ os.path.join(llvm_bin, 'wasm-ld'), '-flavor', 'wasm', '-z', '-stack-size=1048576', obj_path, '-o', wasm_path, '--allow-undefined', '--export', '__wasm_call_ctors', '--export', '__data_end', '--global-base=568', ] # We had a regression where this test only worked if debug names # were included. if 'longjmp' in src_file: link_cmd.append('--strip-debug') if is_shared: compile_cmd.append('-fPIC') compile_cmd.append('-fvisibility=default') link_cmd.append('-shared') link_cmd.append('--experimental-pic') else: link_cmd.append('--entry=main') try: support.run_command(compile_cmd) support.run_command(link_cmd) support.run_command(shared.WASM_DIS + [wasm_path, '-o', wat_path]) finally: # Don't need the .o or .wasm files, don't leave them around shared.delete_from_orbit(obj_path) shared.delete_from_orbit(wasm_path)
def test_asm2wasm_binary(): print '\n[ checking asm2wasm binary reading/writing... ]\n' asmjs = os.path.join(options.binaryen_test, 'hello_world.asm.js') delete_from_orbit('a.wasm') delete_from_orbit('b.wast') run_command(ASM2WASM + [asmjs, '-o', 'a.wasm']) assert open('a.wasm', 'rb').read()[0] == '\0', 'we emit binary by default' run_command(ASM2WASM + [asmjs, '-o', 'b.wast', '-S']) assert open('b.wast', 'rb').read()[0] != '\0', 'we emit text with -S'
def generate_wast_files(clang_bin, lld_bin, emscripten_root): print '\n[ building wast files from C sources... ]\n' lld_path = os.path.join(shared.options.binaryen_test, 'lld') for src_file, ext in files_with_extensions(lld_path, ['.c', '.cpp']): print '..', src_file try: obj_file = src_file.replace(ext, '.o') src_path = os.path.join(lld_path, src_file) obj_path = os.path.join(lld_path, obj_file) run_command([ clang_bin, src_path, '-o', obj_path, '--target=wasm32-unknown-unknown-wasm', '-c', '-nostdinc', '-Xclang', '-nobuiltininc', '-Xclang', '-nostdsysteminc', '-Xclang', '-I%s/system/include' % emscripten_root, '-O1', ]) wasm_file = src_file.replace(ext, '.wasm') wast_file = src_file.replace(ext, '.wast') obj_path = os.path.join(lld_path, obj_file) wasm_path = os.path.join(lld_path, wasm_file) wast_path = os.path.join(lld_path, wast_file) run_command([ lld_bin, '-flavor', 'wasm', '-z', '-stack-size=1048576', obj_path, '-o', wasm_path, '--entry=main', '--allow-undefined', '--export', '__wasm_call_ctors', '--global-base=568', ]) run_command(shared.WASM_DIS + [wasm_path, '-o', wast_path]) finally: # Don't need the .o or .wasm files, don't leave them around shared.delete_from_orbit(obj_path) shared.delete_from_orbit(wasm_path)
def generate_wast_files(llvm_bin, emscripten_root): print '\n[ building wast files from C sources... ]\n' lld_path = os.path.join(shared.options.binaryen_test, 'lld') for src_file, ext in files_with_extensions(lld_path, ['.c', '.cpp']): print '..', src_file obj_file = src_file.replace(ext, '.o') src_path = os.path.join(lld_path, src_file) obj_path = os.path.join(lld_path, obj_file) wasm_file = src_file.replace(ext, '.wasm') wast_file = src_file.replace(ext, '.wast') obj_path = os.path.join(lld_path, obj_file) wasm_path = os.path.join(lld_path, wasm_file) wast_path = os.path.join(lld_path, wast_file) is_shared = 'shared' in src_file compile_cmd = [ os.path.join(llvm_bin, 'clang'), src_path, '-o', obj_path, '--target=wasm32-unknown-unknown-wasm', '-c', '-nostdinc', '-Xclang', '-nobuiltininc', '-Xclang', '-nostdsysteminc', '-Xclang', '-I%s/system/include' % emscripten_root, '-O1', ] link_cmd = [ os.path.join(llvm_bin, 'wasm-ld'), '-flavor', 'wasm', '-z', '-stack-size=1048576', obj_path, '-o', wasm_path, '--allow-undefined', '--export', '__wasm_call_ctors', '--global-base=568', ] if is_shared: compile_cmd.append('-fPIC') compile_cmd.append('-fvisibility=default') link_cmd.append('-shared') else: link_cmd.append('--entry=main') try: run_command(compile_cmd) run_command(link_cmd) run_command(shared.WASM_DIS + [wasm_path, '-o', wast_path]) finally: # Don't need the .o or .wasm files, don't leave them around shared.delete_from_orbit(obj_path) shared.delete_from_orbit(wasm_path)
def generate_wast_files(llvm_bin, emscripten_root): print('\n[ building wast files from C sources... ]\n') lld_path = os.path.join(shared.options.binaryen_test, 'lld') for src_file, ext in files_with_extensions(lld_path, ['.c', '.cpp']): print('..', src_file) obj_file = src_file.replace(ext, '.o') src_path = os.path.join(lld_path, src_file) obj_path = os.path.join(lld_path, obj_file) wasm_file = src_file.replace(ext, '.wasm') wast_file = src_file.replace(ext, '.wast') obj_path = os.path.join(lld_path, obj_file) wasm_path = os.path.join(lld_path, wasm_file) wast_path = os.path.join(lld_path, wast_file) is_shared = 'shared' in src_file compile_cmd = [ os.path.join(llvm_bin, 'clang'), src_path, '-o', obj_path, '--target=wasm32-unknown-unknown-wasm', '-c', '-nostdinc', '-Xclang', '-nobuiltininc', '-Xclang', '-nostdsysteminc', '-Xclang', '-I%s/system/include' % emscripten_root, '-O1', ] link_cmd = [ os.path.join(llvm_bin, 'wasm-ld'), '-flavor', 'wasm', '-z', '-stack-size=1048576', obj_path, '-o', wasm_path, '--allow-undefined', '--export', '__wasm_call_ctors', '--global-base=568', ] if is_shared: compile_cmd.append('-fPIC') compile_cmd.append('-fvisibility=default') link_cmd.append('-shared') else: link_cmd.append('--entry=main') try: run_command(compile_cmd) run_command(link_cmd) run_command(shared.WASM_DIS + [wasm_path, '-o', wast_path]) finally: # Don't need the .o or .wasm files, don't leave them around shared.delete_from_orbit(obj_path) shared.delete_from_orbit(wasm_path)