def main(args): parser = argparse.ArgumentParser() parser.add_argument('-o', '--out-dir', metavar='PATH', help='output directory for files.') parser.add_argument('--bindir', metavar='PATH', default=find_exe.GetDefaultPath(), help='directory to search for all executables.') parser.add_argument( '--js-engine', metavar='PATH', help='the path to the JavaScript engine with which to run' ' the generated JavaScript. If not specified, JavaScript' ' output will be written to stdout.') parser.add_argument('--js-engine-flags', metavar='FLAGS', help='additional flags for JavaScript engine.', action='append', default=[]) parser.add_argument('--prefix-js', help='Prefix JavaScript file to pass to gen-spec-js') parser.add_argument('-v', '--verbose', help='print more diagnotic messages.', action='store_true') parser.add_argument('--no-error-cmdline', help='don\'t display the subprocess\'s commandline when' + ' an error occurs', dest='error_cmdline', action='store_false') parser.add_argument('-p', '--print-cmd', help='print the commands that are run.', action='store_true') parser.add_argument('file', help='wast file.') options = parser.parse_args(args) with utils.TempDirectory(options.out_dir, 'run-gen-spec-js-') as out_dir: wast2wasm = utils.Executable( find_exe.GetWast2WasmExecutable(options.bindir), '--spec', error_cmdline=options.error_cmdline) wast2wasm.AppendOptionalArgs({'-v': options.verbose}) gen_spec_js = utils.Executable(sys.executable, GEN_SPEC_JS_PY, '--temp-dir', out_dir, error_cmdline=options.error_cmdline) gen_spec_js.AppendOptionalArgs({ '--bindir': options.bindir, '--prefix': options.prefix_js, }) gen_spec_js.verbose = options.print_cmd json_file = utils.ChangeDir( utils.ChangeExt(options.file, '.json'), out_dir) js_file = utils.ChangeExt(json_file, '.js') wast2wasm.RunWithArgs(options.file, '-o', json_file) if options.js_engine: gen_spec_js.RunWithArgs(json_file, '-o', js_file) js = utils.Executable(options.js_engine, *options.js_engine_flags) js.RunWithArgs(js_file) else: # Write JavaScript output to stdout gen_spec_js.RunWithArgs(json_file)
def Compile(cc, c_filename, out_dir, *args): if IS_WINDOWS: ext = '.obj' else: ext = '.o' o_filename = utils.ChangeDir(utils.ChangeExt(c_filename, ext), out_dir) args = list(args) if IS_WINDOWS: args += ['/nologo', '/MDd', '/c', c_filename, '/Fo' + o_filename] else: # See "Compiling the wasm2c output" section of wasm2c/README.md # When compiling with -O2, GCC and clang require '-fno-optimize-sibling-calls' # and '-frounding-math' to maintain conformance with the spec tests # (GCC also requires '-fsignaling-nans') args += [ '-c', c_filename, '-o', o_filename, '-O2', '-Wall', '-Werror', '-Wno-unused', '-Wno-ignored-optimization-argument', '-Wno-tautological-constant-out-of-range-compare', '-Wno-infinite-recursion', '-fno-optimize-sibling-calls', '-frounding-math', '-fsignaling-nans', '-std=c99', '-D_DEFAULT_SOURCE' ] # Use RunWithArgsForStdout and discard stdout because cl.exe # unconditionally prints the name of input files on stdout # and we don't want that to be part of our stdout. cc.RunWithArgsForStdout(*args) return o_filename
def main(args): parser = argparse.ArgumentParser() parser.add_argument('-v', '--verbose', help='print more diagnotic messages.', action='store_true') parser.add_argument('-o', '--out-dir', metavar='PATH', help='output directory for files.') parser.add_argument('--bindir', metavar='PATH', default=find_exe.GetDefaultPath(), help='directory to search for all executables.') parser.add_argument( '--no-error-cmdline', help='don\'t display the subprocess\'s commandline when' + ' an error occurs', dest='error_cmdline', action='store_false') parser.add_argument('-p', '--print-cmd', action='store_true', help='print the commands that are run.') parser.add_argument('--no-debug-names', action='store_true') parser.add_argument('--objdump', action='store_true', help="objdump the resulting binary") parser.add_argument('file', help='test file.') options = parser.parse_args(args) gen_wasm = utils.Executable(sys.executable, GEN_WASM_PY, error_cmdline=options.error_cmdline, basename=os.path.basename(GEN_WASM_PY)) objdump = utils.Executable(find_exe.GetWasmdumpExecutable(options.bindir), error_cmdline=options.error_cmdline) wasm2wat = utils.Executable(find_exe.GetWasm2WatExecutable(options.bindir), error_cmdline=options.error_cmdline) wasm2wat.AppendOptionalArgs({ '--no-debug-names': options.no_debug_names, }) wasm2wat.AppendOptionalArgs({ '--verbose': options.verbose, }) gen_wasm.verbose = options.print_cmd wasm2wat.verbose = options.print_cmd objdump.verbose = options.print_cmd with utils.TempDirectory(options.out_dir, 'run-gen-wasm-') as out_dir: out_file = utils.ChangeDir(utils.ChangeExt(options.file, '.wasm'), out_dir) gen_wasm.RunWithArgs(options.file, '-o', out_file) if options.objdump: objdump.RunWithArgs(out_file, '-x') else: wasm2wat.RunWithArgs(out_file)
def main(args): parser = argparse.ArgumentParser() parser.add_argument('-o', '--out-dir', metavar='PATH', help='output directory for files.') parser.add_argument('-v', '--verbose', help='print more diagnotic messages.', action='store_true') parser.add_argument('--bindir', metavar='PATH', default=find_exe.GetDefaultPath(), help='directory to search for all executables.') parser.add_argument( '--no-error-cmdline', help='don\'t display the subprocess\'s commandline when' + ' an error occurs', dest='error_cmdline', action='store_false') parser.add_argument('-p', '--print-cmd', help='print the commands that are run.', action='store_true') parser.add_argument('--run-all-exports', action='store_true') parser.add_argument('--spec', action='store_true') parser.add_argument('-t', '--trace', action='store_true') parser.add_argument('file', help='test file.') options = parser.parse_args(args) wast2wasm = utils.Executable(find_exe.GetWast2WasmExecutable( options.bindir), error_cmdline=options.error_cmdline) wast2wasm.AppendOptionalArgs({ '-v': options.verbose, '--spec': options.spec, }) wasm_interp = utils.Executable(find_exe.GetWasmInterpExecutable( options.bindir), error_cmdline=options.error_cmdline) wasm_interp.AppendOptionalArgs({ '-v': options.verbose, '--run-all-exports': options.run_all_exports, '--spec': options.spec, '--trace': options.trace, }) wast2wasm.verbose = options.print_cmd wasm_interp.verbose = options.print_cmd with utils.TempDirectory(options.out_dir, 'run-interp-') as out_dir: new_ext = '.json' if options.spec else '.wasm' out_file = utils.ChangeDir(utils.ChangeExt(options.file, new_ext), out_dir) wast2wasm.RunWithArgs(options.file, '-o', out_file) wasm_interp.RunWithArgs(out_file) return 0
def _MaybeWriteDummyModule(self): if len(self.GetModuleFilenames()) == 0: # This test doesn't have any valid modules, so just use a dummy instead. filename = utils.ChangeExt(self.source_filename, '-dummy.wasm') with open(os.path.join(self.out_dir, filename), 'wb') as wasm_file: wasm_file.write(b'\x00\x61\x73\x6d\x01\x00\x00\x00') dummy_command = {'type': 'module', 'line': 0, 'filename': filename} self.commands.insert(0, dummy_command)
def main(args): parser = argparse.ArgumentParser() parser.add_argument('-o', '--out-dir', metavar='PATH', help='output directory for files.') parser.add_argument('--wasm-interp-executable', metavar='PATH', help='override wasm-interp executable.') parser.add_argument('-v', '--verbose', help='print more diagnotic messages.', action='store_true') parser.add_argument( '--no-error-cmdline', help='don\'t display the subprocess\'s commandline when' + ' an error occurs', dest='error_cmdline', action='store_false') parser.add_argument('--run-all-exports', action='store_true') parser.add_argument('--spec', action='store_true') parser.add_argument('--use-libc-allocator', action='store_true') parser.add_argument('--print-cmd', help='print the commands that are run.', action='store_true') parser.add_argument('file', help='test file.') options = parser.parse_args(args) gen_wasm = utils.Executable(sys.executable, GEN_WASM_PY, error_cmdline=options.error_cmdline) wasm_interp = utils.Executable(find_exe.GetWasmInterpExecutable( options.wasm_interp_executable), error_cmdline=options.error_cmdline) wasm_interp.AppendOptionalArgs({ '--run-all-exports': options.run_all_exports, '--spec': options.spec, '--trace': options.verbose, '--use-libc-allocator': options.use_libc_allocator }) gen_wasm.verbose = options.print_cmd wasm_interp.verbose = options.print_cmd with utils.TempDirectory(options.out_dir, 'run-gen-wasm-interp-') as out_dir: out_file = utils.ChangeDir(utils.ChangeExt(options.file, '.wasm'), out_dir) gen_wasm.RunWithArgs(options.file, '-o', out_file) wasm_interp.RunWithArgs(out_file) return 0
def main(args): parser = argparse.ArgumentParser() parser.add_argument('-v', '--verbose', help='print more diagnotic messages.', action='store_true') parser.add_argument('-o', '--out-dir', metavar='PATH', help='output directory for files.') parser.add_argument('--wasm2wast', metavar='PATH', help='set the wasm2wast executable to use.') parser.add_argument( '--no-error-cmdline', help='don\'t display the subprocess\'s commandline when' + ' an error occurs', dest='error_cmdline', action='store_false') parser.add_argument('-p', '--print-cmd', action='store_true', help='print the commands that are run.') parser.add_argument('--use-libc-allocator', action='store_true') parser.add_argument('--debug-names', action='store_true') parser.add_argument('--generate-names', action='store_true') parser.add_argument('file', help='test file.') options = parser.parse_args(args) gen_wasm = utils.Executable(sys.executable, GEN_WASM_PY, error_cmdline=options.error_cmdline) wasm2wast = utils.Executable(find_exe.GetWasm2WastExecutable( options.wasm2wast), error_cmdline=options.error_cmdline) wasm2wast.AppendOptionalArgs({ '--debug-names': options.debug_names, '--generate-names': options.generate_names, '--use-libc-allocator': options.use_libc_allocator }) gen_wasm.verbose = options.print_cmd wasm2wast.verbose = options.print_cmd wasm2wast.AppendOptionalArgs({ '--verbose': options.verbose, }) with utils.TempDirectory(options.out_dir, 'run-gen-wasm-') as out_dir: out_file = utils.ChangeDir(utils.ChangeExt(options.file, '.wasm'), out_dir) gen_wasm.RunWithArgs(options.file, '-o', out_file) wasm2wast.RunWithArgs(out_file)
def main(args): parser = argparse.ArgumentParser() parser.add_argument('-o', '--out-dir', metavar='PATH', help='output directory for files.') parser.add_argument('--wast2wasm-executable', metavar='PATH', help='override wast2wasm executable.') parser.add_argument('--wasmopcodecnt-executable', metavar='PATH', help='override wasmopcodecnt executable.') parser.add_argument('-v', '--verbose', help='print more diagnotic messages.', action='store_true') parser.add_argument( '--no-error-cmdline', help='don\'t display the subprocess\'s commandline when' + ' an error occurs', dest='error_cmdline', action='store_false') parser.add_argument('--print-cmd', help='print the commands that are run.', action='store_true') parser.add_argument('--use-libc-allocator', action='store_true') parser.add_argument('file', help='test file.') options = parser.parse_args(args) wast2wasm = utils.Executable(find_exe.GetWast2WasmExecutable( options.wast2wasm_executable), error_cmdline=options.error_cmdline) wast2wasm.AppendOptionalArgs({ '-v': options.verbose, '--use-libc-allocator': options.use_libc_allocator }) wasmopcodecnt = utils.Executable(find_exe.GetWasmOpcodeCntExecutable( options.wasmopcodecnt_executable), error_cmdline=options.error_cmdline) wasmopcodecnt.AppendOptionalArgs( {'--use-libc-allocator': options.use_libc_allocator}) wast2wasm.verbose = options.print_cmd wasmopcodecnt.verbose = options.print_cmd with utils.TempDirectory(options.out_dir, 'run-opcodecnt-') as out_dir: out_file = utils.ChangeDir(utils.ChangeExt(options.file, '.wasm'), out_dir) wast2wasm.RunWithArgs(options.file, '-o', out_file) wasmopcodecnt.RunWithArgs(out_file) return 0
def main(args): parser = argparse.ArgumentParser() parser.add_argument('-o', '--out-dir', metavar='PATH', help='output directory for files.') parser.add_argument('-e', '--executable', metavar='PATH', help='override sexpr-wasm executable.') parser.add_argument('--js-executable', metavar='PATH', help='override js executable.') parser.add_argument('-v', '--verbose', help='print more diagnotic messages.', action='store_true') parser.add_argument( '--no-error-cmdline', help='don\'t display the subprocess\'s commandline when' + ' an error occurs', dest='error_cmdline', action='store_false') parser.add_argument('--use-libc-allocator', action='store_true') parser.add_argument('--spec', help='run spec tests.', action='store_true') parser.add_argument('file', help='test file.') options = parser.parse_args(args) sexpr_wasm = utils.Executable(find_exe.GetSexprWasmExecutable( options.executable), error_cmdline=options.error_cmdline) sexpr_wasm.AppendOptionalArgs({ '-v': options.verbose, '--spec': options.spec, '--use-libc-allocator': options.use_libc_allocator }) js = GetJSExecutable(options) with utils.TempDirectory(options.out_dir, 'run-js-') as out_dir: new_ext = '.json' if options.spec else '.wasm' out_file = utils.ChangeDir(utils.ChangeExt(options.file, new_ext), out_dir) sexpr_wasm.RunWithArgs(options.file, '-o', out_file) js_file = SPEC_JS if options.spec else WASM_JS RunJS(js, js_file, out_file) return 0
def Compile(cc, c_filename, out_dir, *args): if IS_WINDOWS: ext = '.obj' else: ext = '.o' o_filename = utils.ChangeDir(utils.ChangeExt(c_filename, ext), out_dir) args = list(args) if IS_WINDOWS: args += ['/nologo', '/MDd', '/c', c_filename, '/Fo' + o_filename] else: args += ['-c', c_filename, '-o', o_filename, '-Wall', '-Werror', '-Wno-unused', '-Wno-tautological-constant-out-of-range-compare', '-Wno-infinite-recursion', '-std=c99', '-D_DEFAULT_SOURCE'] # Use RunWithArgsForStdout and discard stdout because cl.exe # unconditionally prints the name of input files on stdout # and we don't want that to be part of our stdout. cc.RunWithArgsForStdout(*args) return o_filename
def main(args): parser = argparse.ArgumentParser() parser.add_argument('-o', '--out-dir', metavar='PATH', help='output directory for files.') parser.add_argument('--bindir', metavar='PATH', default=find_exe.GetDefaultPath(), help='directory to search for all executables.') parser.add_argument('-v', '--verbose', help='print more diagnotic messages.', action='store_true') parser.add_argument('--no-error-cmdline', help='don\'t display the subprocess\'s commandline when' + ' an error occurs', dest='error_cmdline', action='store_false') parser.add_argument('--print-cmd', help='print the commands that are run.', action='store_true') parser.add_argument('-c', '--cutoff', type=int, default=0) parser.add_argument('file', help='test file.') options = parser.parse_args(args) wast2wasm = utils.Executable( find_exe.GetWast2WasmExecutable(options.bindir), error_cmdline=options.error_cmdline) wast2wasm.AppendOptionalArgs({ '-v': options.verbose, }) wasm_opcodecnt = utils.Executable( find_exe.GetWasmOpcodeCntExecutable(options.bindir), error_cmdline=options.error_cmdline) wast2wasm.verbose = options.print_cmd wasm_opcodecnt.verbose = options.print_cmd with utils.TempDirectory(options.out_dir, 'run-opcodecnt-') as out_dir: out_file = utils.ChangeDir(utils.ChangeExt(options.file, '.wasm'), out_dir) wast2wasm.RunWithArgs(options.file, '-o', out_file) wasm_opcodecnt.RunWithArgs(out_file, '-c', str(options.cutoff)) return 0
def main(args): parser = argparse.ArgumentParser() parser.add_argument('-o', '--out-dir', metavar='PATH', help='output directory for files.') parser.add_argument('-P', '--prefix', metavar='PATH', help='prefix file.', default=os.path.join(SCRIPT_DIR, 'spec-wasm2c-prefix.c')) parser.add_argument('--bindir', metavar='PATH', default=find_exe.GetDefaultPath(), help='directory to search for all executables.') parser.add_argument('--wasmrt-dir', metavar='PATH', help='directory with wasm-rt files', default=WASM2C_DIR) parser.add_argument('--cc', metavar='PATH', help='the path to the C compiler', default='cc') parser.add_argument('--cflags', metavar='FLAGS', help='additional flags for C compiler.', action='append', default=[]) parser.add_argument('--compile', help='compile the C code (default)', dest='compile', action='store_true') parser.add_argument('--no-compile', help='don\'t compile the C code', dest='compile', action='store_false') parser.set_defaults(compile=True) parser.add_argument('--no-run', help='don\'t run the compiled executable', dest='run', action='store_false') parser.add_argument('-v', '--verbose', help='print more diagnotic messages.', action='store_true') parser.add_argument('--no-error-cmdline', help='don\'t display the subprocess\'s commandline when ' 'an error occurs', dest='error_cmdline', action='store_false') parser.add_argument('-p', '--print-cmd', help='print the commands that are run.', action='store_true') parser.add_argument('file', help='wast file.') options = parser.parse_args(args) with utils.TempDirectory(options.out_dir, 'run-spec-wasm2c-') as out_dir: # Parse JSON file and generate main .c file with calls to test functions. wast2json = utils.Executable( find_exe.GetWast2JsonExecutable(options.bindir), error_cmdline=options.error_cmdline) wast2json.AppendOptionalArgs({'-v': options.verbose}) json_file_path = utils.ChangeDir( utils.ChangeExt(options.file, '.json'), out_dir) wast2json.RunWithArgs(options.file, '-o', json_file_path) wasm2c = utils.Executable( find_exe.GetWasm2CExecutable(options.bindir), error_cmdline=options.error_cmdline) cc = utils.Executable(options.cc, *options.cflags) with open(json_file_path) as json_file: spec_json = json.load(json_file) prefix = '' if options.prefix: with open(options.prefix) as prefix_file: prefix = prefix_file.read() + '\n' output = io.StringIO() cwriter = CWriter(spec_json, prefix, output, out_dir) cwriter.Write() main_filename = utils.ChangeExt(json_file_path, '-main.c') with open(main_filename, 'w') as out_main_file: out_main_file.write(output.getvalue()) o_filenames = [] includes = '-I%s' % options.wasmrt_dir # Compile wasm-rt-impl. wasm_rt_impl_c = os.path.join(options.wasmrt_dir, 'wasm-rt-impl.c') o_filenames.append(Compile(cc, wasm_rt_impl_c, out_dir, includes)) for i, wasm_filename in enumerate(cwriter.GetModuleFilenames()): c_filename = utils.ChangeExt(wasm_filename, '.c') wasm2c.RunWithArgs(wasm_filename, '-o', c_filename, cwd=out_dir) if options.compile: defines = '-DWASM_RT_MODULE_PREFIX=%s' % cwriter.GetModulePrefix(i) o_filenames.append(Compile(cc, c_filename, out_dir, includes, defines)) if options.compile: main_c = os.path.basename(main_filename) o_filenames.append(Compile(cc, main_c, out_dir, includes, defines)) main_exe = os.path.basename(utils.ChangeExt(json_file_path, '')) Link(cc, o_filenames, main_exe, out_dir, '-lm') if options.compile and options.run: utils.Executable(os.path.join(out_dir, main_exe), forward_stdout=True).RunWithArgs() return 0
def main(args): parser = argparse.ArgumentParser() parser.add_argument('-o', '--out-dir', metavar='PATH', help='output directory for files.') parser.add_argument('-v', '--verbose', help='print more diagnotic messages.', action='store_true') parser.add_argument('--bindir', metavar='PATH', default=find_exe.GetDefaultPath(), help='directory to search for all executables.') parser.add_argument( '--no-error-cmdline', help='don\'t display the subprocess\'s commandline when' + ' an error occurs', dest='error_cmdline', action='store_false') parser.add_argument('-p', '--print-cmd', help='print the commands that are run.', action='store_true') parser.add_argument('--run-all-exports', action='store_true') parser.add_argument('--host-print', action='store_true') parser.add_argument('--spec', action='store_true') parser.add_argument('-t', '--trace', action='store_true') parser.add_argument('file', help='test file.') parser.add_argument('--enable-saturating-float-to-int', action='store_true') parser.add_argument('--enable-threads', action='store_true') parser.add_argument('--disable-jit', action='store_true') parser.add_argument('--trap-on-failed-comp', action='store_true') options = parser.parse_args(args) wast_tool = None interp_tool = None if options.spec: wast_tool = utils.Executable(find_exe.GetWast2JsonExecutable( options.bindir), error_cmdline=options.error_cmdline) interp_tool = utils.Executable(find_exe.GetSpectestInterpExecutable( options.bindir), error_cmdline=options.error_cmdline) else: wast_tool = utils.Executable(find_exe.GetWat2WasmExecutable( options.bindir), error_cmdline=options.error_cmdline) interp_tool = utils.Executable(find_exe.GetWasmInterpExecutable( options.bindir), error_cmdline=options.error_cmdline) interp_tool.AppendOptionalArgs({ '--host-print': options.host_print, '--run-all-exports': options.run_all_exports, }) wast_tool.AppendOptionalArgs({ '-v': options.verbose, '--enable-saturating-float-to-int': options.enable_saturating_float_to_int, '--enable-threads': options.enable_threads, }) interp_tool.AppendOptionalArgs({ '-v': options.verbose, '--run-all-exports': options.run_all_exports, '--trap-on-failed-comp': options.trap_on_failed_comp, '--trace': options.trace, '--enable-saturating-float-to-int': options.enable_saturating_float_to_int, '--enable-threads': options.enable_threads, '--disable-jit': options.disable_jit, '--no-stack-trace': not options.spec }) wast_tool.verbose = options.print_cmd interp_tool.verbose = options.print_cmd with utils.TempDirectory(options.out_dir, 'run-interp-') as out_dir: new_ext = '.json' if options.spec else '.wasm' out_file = utils.ChangeDir(utils.ChangeExt(options.file, new_ext), out_dir) wast_tool.RunWithArgs(options.file, '-o', out_file) interp_tool.RunWithArgs(out_file) return 0
def main(args): parser = argparse.ArgumentParser() parser.add_argument('-o', '--out-dir', metavar='PATH', help='output directory for files.') parser.add_argument('-v', '--verbose', help='print more diagnotic messages.', action='store_true') parser.add_argument('--bindir', metavar='PATH', default=find_exe.GetDefaultPath(), help='directory to search for all executables.') parser.add_argument( '--no-error-cmdline', help='don\'t display the subprocess\'s commandline when' + ' an error occurs', dest='error_cmdline', action='store_false') parser.add_argument('-p', '--print-cmd', help='print the commands that are run.', action='store_true') parser.add_argument('--run-all-exports', action='store_true') parser.add_argument('--host-print', action='store_true') parser.add_argument('-t', '--trace', action='store_true') parser.add_argument('file', help='test file.') parser.add_argument('--enable-saturating-float-to-int', action='store_true') parser.add_argument('--enable-threads', action='store_true') parser.add_argument('--trap-on-failed-comp', action='store_true') options = parser.parse_args(args) wast_tool = None interp_tool = None interp_jit_tool = None wast_tool = utils.Executable(find_exe.GetWat2WasmExecutable( options.bindir), error_cmdline=options.error_cmdline) interp_tool = utils.Executable(find_exe.GetWasmInterpExecutable( options.bindir), error_cmdline=options.error_cmdline) interp_tool.AppendOptionalArgs({ '--host-print': options.host_print, '--run-all-exports': options.run_all_exports, }) interp_jit_tool = utils.Executable(find_exe.GetWasmInterpExecutable( options.bindir), error_cmdline=options.error_cmdline) interp_jit_tool.AppendOptionalArgs({ '--host-print': options.host_print, '--run-all-exports': options.run_all_exports, }) wast_tool.AppendOptionalArgs({ '-v': options.verbose, '--enable-saturating-float-to-int': options.enable_saturating_float_to_int, '--enable-threads': options.enable_threads, }) interp_tool.AppendOptionalArgs({ '-v': options.verbose, '--run-all-exports': options.run_all_exports, '--trace': options.trace, '--enable-saturating-float-to-int': options.enable_saturating_float_to_int, '--enable-threads': options.enable_threads, '--disable-jit': True, }) interp_jit_tool.AppendOptionalArgs({ '-v': options.verbose, '--run-all-exports': options.run_all_exports, '--trace': options.trace, '--enable-saturating-float-to-int': options.enable_saturating_float_to_int, '--enable-threads': options.enable_threads, '--trap-on-failed-comp': options.trap_on_failed_comp, }) wast_tool.verbose = options.print_cmd interp_tool.verbose = options.print_cmd interp_jit_tool.verbose = options.print_cmd with utils.TempDirectory(options.out_dir, 'run-jit-perform-') as out_dir: if not options.file.endswith('.wasm'): new_ext = '.wasm' out_file = utils.ChangeDir(utils.ChangeExt(options.file, new_ext), out_dir) wast_tool.RunWithArgs(options.file, '-o', out_file) else: out_file = options.file start = time.time() interp_out = interp_tool.RunWithArgsForStdout(out_file) interp_time = time.time() - start start = time.time() jit_out = interp_jit_tool.RunWithArgsForStdout(out_file) jit_time = time.time() - start print("Interpreter: {}\nJIT: {}".format(interp_time, jit_time)) expected_lines = [line for line in interp_out.splitlines() if line] actual_lines = [line for line in jit_out.splitlines() if line] diff_lines = list( difflib.unified_diff(expected_lines, actual_lines, fromfile='expected', tofile='actual', lineterm='')) msg = "" if len(diff_lines) > 0: msg += 'STDOUT MISMATCH:\n' + '\n'.join(diff_lines) + '\n' if msg: raise Error(msg) return 0
def Compile(cc, c_filename, out_dir, *args): out_dir = os.path.abspath(out_dir) o_filename = utils.ChangeDir(utils.ChangeExt(c_filename, '.o'), out_dir) cc.RunWithArgs('-c', '-o', o_filename, c_filename, *args, cwd=out_dir) return o_filename
def main(args): default_compiler = 'cc' if IS_WINDOWS: default_compiler = 'cl.exe' parser = argparse.ArgumentParser() parser.add_argument('-o', '--out-dir', metavar='PATH', help='output directory for files.') parser.add_argument('-P', '--prefix', metavar='PATH', help='prefix file.', default=os.path.join(SCRIPT_DIR, 'spec-wasm2c-prefix.c')) parser.add_argument('--bindir', metavar='PATH', default=find_exe.GetDefaultPath(), help='directory to search for all executables.') parser.add_argument('--wasmrt-dir', metavar='PATH', help='directory with wasm-rt files', default=WASM2C_DIR) parser.add_argument('--cc', metavar='PATH', help='the path to the C compiler', default=default_compiler) parser.add_argument('--cflags', metavar='FLAGS', help='additional flags for C compiler.', action='append', default=[]) parser.add_argument('--compile', help='compile the C code (default)', dest='compile', action='store_true') parser.add_argument('--no-compile', help='don\'t compile the C code', dest='compile', action='store_false') parser.set_defaults(compile=True) parser.add_argument('--no-run', help='don\'t run the compiled executable', dest='run', action='store_false') parser.add_argument('-v', '--verbose', help='print more diagnotic messages.', action='store_true') parser.add_argument('--no-error-cmdline', help='don\'t display the subprocess\'s commandline when ' 'an error occurs', dest='error_cmdline', action='store_false') parser.add_argument('-p', '--print-cmd', help='print the commands that are run.', action='store_true') parser.add_argument('file', help='wast file.') parser.add_argument('--enable-multi-memory', action='store_true') parser.add_argument('--disable-bulk-memory', action='store_true') parser.add_argument('--disable-reference-types', action='store_true') options = parser.parse_args(args) with utils.TempDirectory(options.out_dir, 'run-spec-wasm2c-') as out_dir: # Parse JSON file and generate main .c file with calls to test functions. wast2json = utils.Executable( find_exe.GetWast2JsonExecutable(options.bindir), error_cmdline=options.error_cmdline) wast2json.verbose = options.print_cmd wast2json.AppendOptionalArgs({ '-v': options.verbose, '--enable-multi-memory': options.enable_multi_memory, '--disable-bulk-memory': options.disable_bulk_memory, '--disable-reference-types': options.disable_reference_types}) json_file_path = utils.ChangeDir( utils.ChangeExt(options.file, '.json'), out_dir) wast2json.RunWithArgs(options.file, '-o', json_file_path) wasm2c = utils.Executable( find_exe.GetWasm2CExecutable(options.bindir), error_cmdline=options.error_cmdline) wasm2c.verbose = options.print_cmd wasm2c.AppendOptionalArgs({ '--enable-multi-memory': options.enable_multi_memory}) options.cflags += shlex.split(os.environ.get('WASM2C_CFLAGS', '')) cc = utils.Executable(options.cc, *options.cflags, forward_stderr=True, forward_stdout=False) cc.verbose = options.print_cmd with open(json_file_path, encoding='utf-8') as json_file: spec_json = json.load(json_file) prefix = '' if options.prefix: with open(options.prefix) as prefix_file: prefix = prefix_file.read() + '\n' output = io.StringIO() cwriter = CWriter(spec_json, prefix, output, out_dir) cwriter.Write() main_filename = utils.ChangeExt(json_file_path, '-main.c') with open(main_filename, 'w') as out_main_file: out_main_file.write(output.getvalue()) o_filenames = [] includes = '-I%s' % options.wasmrt_dir for i, wasm_filename in enumerate(cwriter.GetModuleFilenames()): wasm_filename = os.path.join(out_dir, wasm_filename) c_filename = utils.ChangeExt(wasm_filename, '.c') args = ['-n', cwriter.GetModulePrefixUnmangled(i)] wasm2c.RunWithArgs(wasm_filename, '-o', c_filename, *args) if options.compile: o_filenames.append(Compile(cc, c_filename, out_dir, includes)) if options.compile: # Compile wasm-rt-impl. wasm_rt_impl_c = os.path.join(options.wasmrt_dir, 'wasm-rt-impl.c') o_filenames.append(Compile(cc, wasm_rt_impl_c, out_dir, includes)) # Compile and link -main test run entry point o_filenames.append(Compile(cc, main_filename, out_dir, includes)) if IS_WINDOWS: exe_ext = '.exe' libs = [] else: exe_ext = '' libs = ['-lm'] main_exe = utils.ChangeExt(json_file_path, exe_ext) Link(cc, o_filenames, main_exe, *libs) # Run the resulting binary if options.run: utils.Executable(main_exe, forward_stdout=True).RunWithArgs() return 0
def main(args): parser = argparse.ArgumentParser() parser.add_argument('-o', '--out-dir', metavar='PATH', help='output directory for files.') parser.add_argument('--wast2wasm', metavar='PATH', help='override wast2wasm executable.') parser.add_argument('--wasmdump', metavar='PATH', help='override wast2wasm executable.') parser.add_argument('--wasm-interp', metavar='PATH', help='override wasm-interp executable.') parser.add_argument('-v', '--verbose', help='print more diagnotic messages.', action='store_true') parser.add_argument( '--no-error-cmdline', help='don\'t display the subprocess\'s commandline when' + ' an error occurs', dest='error_cmdline', action='store_false') parser.add_argument('-p', '--print-cmd', help='print the commands that are run.', action='store_true') parser.add_argument('--run-all-exports', action='store_true') parser.add_argument('--spec', action='store_true') parser.add_argument('--use-libc-allocator', action='store_true') parser.add_argument('file', help='test file.') options = parser.parse_args(args) wast2wasm = utils.Executable(find_exe.GetWast2WasmExecutable( options.wast2wasm), error_cmdline=options.error_cmdline) wast2wasm.AppendOptionalArgs({ '-v': options.verbose, '--spec': options.spec, '--use-libc-allocator': options.use_libc_allocator }) wasmdump = utils.Executable(find_exe.GetWasmdumpExecutable( options.wasmdump), error_cmdline=options.error_cmdline) wasm_interp = utils.Executable(find_exe.GetWasmInterpExecutable( options.wasm_interp), error_cmdline=options.error_cmdline) wasm_interp.AppendOptionalArgs({ '--run-all-exports': options.run_all_exports, '--spec': options.spec, '--trace': options.verbose, '--use-libc-allocator': options.use_libc_allocator }) wast2wasm.verbose = options.print_cmd wasm_interp.verbose = options.print_cmd with utils.TempDirectory(options.out_dir, 'run-interp-') as out_dir: new_ext = '.json' if options.spec else '.wasm' out_file = utils.ChangeDir(utils.ChangeExt(options.file, new_ext), out_dir) wast2wasm.RunWithArgs(options.file, '-o', out_file) if options.spec: wasm_files = utils.GetModuleFilenamesFromSpecJSON(out_file) wasm_files = [utils.ChangeDir(f, out_dir) for f in wasm_files] else: wasm_files = [out_file] for wasm_file in wasm_files: wasmdump.RunWithArgs(wasm_file) wasm_interp.RunWithArgs(out_file) return 0
def Compile(cc, c_filename, out_dir, *args): o_filename = utils.ChangeDir(utils.ChangeExt(c_filename, '.o'), out_dir) cc.RunWithArgs('-c', c_filename, '-o', o_filename, *args) return o_filename
def main(args): parser = argparse.ArgumentParser() parser.add_argument('-v', '--verbose', help='print more diagnotic messages.', action='store_true') parser.add_argument('-o', '--out-dir', metavar='PATH', help='output directory for files.') parser.add_argument('--bindir', metavar='PATH', default=find_exe.GetDefaultPath(), help='directory to search for all executables.') parser.add_argument( '--no-error-cmdline', help='don\'t display the subprocess\'s commandline when' + ' an error occurs', dest='error_cmdline', action='store_false') parser.add_argument('-p', '--print-cmd', action='store_true', help='print the commands that are run.') parser.add_argument('--no-debug-names', action='store_true') parser.add_argument('--objdump', action='store_true', help="objdump the resulting binary") parser.add_argument('file', help='test file.') options = parser.parse_args(args) gen_wasm = utils.Executable(sys.executable, GEN_WASM_PY, error_cmdline=options.error_cmdline, basename=os.path.basename(GEN_WASM_PY)) objdump = utils.Executable(find_exe.GetWasmdumpExecutable(options.bindir), error_cmdline=options.error_cmdline) wasm2wat = utils.Executable(find_exe.GetWasm2WatExecutable(options.bindir), error_cmdline=options.error_cmdline) wasm2wat.AppendOptionalArgs({ '--no-debug-names': options.no_debug_names, '--verbose': options.verbose, }) wasmvalidate = utils.Executable(find_exe.GetWasmValidateExecutable( options.bindir), error_cmdline=options.error_cmdline) wasmvalidate.AppendOptionalArgs({ '--no-debug-names': options.no_debug_names, }) gen_wasm.verbose = options.print_cmd wasm2wat.verbose = options.print_cmd wasmvalidate.verbose = options.print_cmd objdump.verbose = options.print_cmd with utils.TempDirectory(options.out_dir, 'run-gen-wasm-') as out_dir: out_file = utils.ChangeDir(utils.ChangeExt(options.file, '.wasm'), out_dir) gen_wasm.RunWithArgs(options.file, '-o', out_file) if options.objdump: objdump.RunWithArgs(out_file, '-x') else: # Test running wasm-validate on all files. wasm2wat should produce the # same errors, so let's make sure that's true. validate_ok = False wasm2wat_ok = False try: try: wasmvalidate.RunWithArgs(out_file) validate_ok = True except Error as e: sys.stderr.write(str(e) + '\n') try: wasm2wat.RunWithArgs(out_file) wasm2wat_ok = True except Error as e: raise finally: if validate_ok != wasm2wat_ok: sys.stderr.write( 'wasm-validate and wasm2wat have different results!')
def main(args): parser = argparse.ArgumentParser() parser.add_argument('-o', '--out-dir', metavar='PATH', help='output directory for files.') parser.add_argument('-P', '--prefix', metavar='PATH', help='prefix file.', default=os.path.join(INCLUDES_DIR, 'spec-wasm2c-prefix.c')) parser.add_argument('--external-bin-dir', metavar='PATH', default=EXTERNAL_BINDIR, dest='external_bin_dir', help='directory to search for all executables.') parser.add_argument('--compiler-bin-dir', help='directory containing cmm_of_wasm', default=ROOT_DIR, dest='compiler_dir') parser.add_argument('--wasmrt-dir', metavar='PATH', help='directory with wasm-rt files', default=WASMRT_DIR, dest='wasmrt_dir') parser.add_argument('--cc', metavar='PATH', help='the path to the C compiler', default='cc') parser.add_argument('--cflags', metavar='FLAGS', help='additional flags for C compiler.', action='append', default=[]) parser.add_argument('--compile', help='compile the C code (default)', dest='compile', action='store_true') parser.add_argument('--no-compile', help='don\'t compile the C code', dest='compile', action='store_false') parser.set_defaults(compile=True) parser.add_argument('--no-run', help='don\'t run the compiled executable', dest='run', action='store_false') parser.add_argument('-v', '--verbose', help='print more diagnostic messages.', action='store_true') parser.add_argument( '--no-error-cmdline', help='don\'t display the subprocess\'s commandline when' + ' an error occurs', dest='error_cmdline', action='store_false') parser.add_argument('-p', '--print-cmd', help='print the commands that are run.', action='store_true') parser.add_argument('-m', '--mangle', help='mangle names', action='store_true') parser.add_argument('-t', '--keep-temp', help='keep temporary files', action='store_true') parser.add_argument('file', help='wast file.') options = parser.parse_args(args) with utils.TempDirectory(options.out_dir, 'cmm_of_wasm-test-') as out_dir: # Parse JSON file and generate main .c file with calls to test functions. #print("out_dir: ", out_dir) wast2json = utils.Executable(wast2json_executable( options.external_bin_dir), error_cmdline=options.error_cmdline) wast2json.AppendOptionalArgs({'-v': options.verbose}) json_file_path = utils.ChangeDir( utils.ChangeExt(options.file, '.json'), out_dir) wast2json.RunWithArgs(options.file, '-o', json_file_path) cmm_of_wasm = utils.Executable(cmm_of_wasm_executable( options.compiler_dir), error_cmdline=options.error_cmdline) cc = utils.Executable(options.cc, *options.cflags) with open(json_file_path) as json_file: spec_json = json.load(json_file) prefix = '' if options.prefix: with open(options.prefix) as prefix_file: prefix = prefix_file.read() + '\n' output = StringIO() cwriter = CWriter(spec_json, prefix, output, out_dir, options.mangle) cwriter.Write() main_filename = utils.ChangeExt(json_file_path, '-main.c') with open(main_filename, 'w') as out_main_file: out_main_file.write(output.getvalue()) o_filenames = [] includes = '-I%s' % options.wasmrt_dir # Compile wasm-rt-impl. wasm_rt_impl_c = os.path.join(options.wasmrt_dir, 'wasm-rt-impl.c') o_filenames.append(Compile(cc, wasm_rt_impl_c, out_dir, includes)) for i, wasm_filename in enumerate(cwriter.GetModuleFilenames()): chopped_filename = os.path.splitext( os.path.basename(wasm_filename))[0] prefix = cwriter.GetModulePrefix(i) if options.keep_temp: cmm_of_wasm.RunWithArgs('-o', chopped_filename, '-p', prefix, wasm_filename, '-tv', cwd=out_dir) else: cmm_of_wasm.RunWithArgs('-o', chopped_filename, '-p', prefix, wasm_filename, cwd=out_dir) o_filenames.append(chopped_filename + '.o') if options.compile: main_c = os.path.basename(main_filename) o_filenames.append(Compile(cc, main_c, out_dir, includes)) main_exe = os.path.basename(utils.ChangeExt(json_file_path, '')) Link(cc, o_filenames, main_exe, out_dir, '-lm') if options.compile and options.run: print("Running", os.path.join(out_dir, main_exe)) utils.Executable(os.path.join(out_dir, main_exe), forward_stdout=True).RunWithArgs() return 0