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('-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( '--stdout', action='store_true', help='do one roundtrip and write wast output to stdout') 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('--no-check', action='store_true') parser.add_argument('--debug-names', action='store_true') parser.add_argument('--generate-names', action='store_true') parser.add_argument('--fold-exprs', action='store_true') parser.add_argument('--enable-exceptions', action='store_true') parser.add_argument('--enable-threads', action='store_true') parser.add_argument('--enable-simd', action='store_true') parser.add_argument('--inline-exports', action='store_true') parser.add_argument('--inline-imports', action='store_true') parser.add_argument('file', help='test file.') options = parser.parse_args(args) wat2wasm = utils.Executable(find_exe.GetWat2WasmExecutable(options.bindir), error_cmdline=options.error_cmdline) wat2wasm.AppendOptionalArgs({ '--debug-names': options.debug_names, '--enable-exceptions': options.enable_exceptions, '--enable-threads': options.enable_threads, '--enable-simd': options.enable_simd, '--no-check': options.no_check, }) wasm2wat = utils.Executable(find_exe.GetWasm2WatExecutable(options.bindir), error_cmdline=options.error_cmdline) wasm2wat.AppendOptionalArgs({ '--fold-exprs': options.fold_exprs, '--enable-exceptions': options.enable_exceptions, '--enable-threads': options.enable_threads, '--enable-simd': options.enable_simd, '--inline-exports': options.inline_exports, '--inline-imports': options.inline_imports, '--no-debug-names': not options.debug_names, '--generate-names': options.generate_names, '--no-check': options.no_check, }) wat2wasm.verbose = options.print_cmd wasm2wat.verbose = options.print_cmd filename = options.file if not os.path.exists(filename): sys.stderr.write('File not found: %s\n' % filename) return ERROR with utils.TempDirectory(options.out_dir, 'roundtrip-') as out_dir: if options.stdout: result, msg = OneRoundtripToStdout(wat2wasm, wasm2wat, out_dir, filename, options.verbose) else: result, msg = TwoRoundtrips(wat2wasm, wasm2wat, out_dir, filename, options.verbose) if result == ERROR: sys.stderr.write(msg) return result
def main(args): parser = argparse.ArgumentParser(description=__doc__) parser.add_argument('-o', '--output', metavar='PATH', help='output file.') parser.add_argument('-P', '--prefix', metavar='PATH', help='prefix file.', default=os.path.join(SCRIPT_DIR, 'gen-spec-prefix.js')) parser.add_argument('--bindir', metavar='PATH', default=find_exe.GetDefaultPath(), help='directory to search for all executables.') parser.add_argument('--temp-dir', metavar='PATH', help='set the directory that temporary wasm/wat' ' files are written.') 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='spec json file.') options = parser.parse_args(args) wat2wasm = Executable(find_exe.GetWat2WasmExecutable(options.bindir), error_cmdline=options.error_cmdline) wasm2wat = Executable(find_exe.GetWasm2WatExecutable(options.bindir), error_cmdline=options.error_cmdline) wat2wasm.verbose = options.print_cmd wasm2wat.verbose = options.print_cmd with open(options.file) as json_file: json_dir = os.path.dirname(options.file) spec_json = json.load(json_file) all_commands = spec_json['commands'] # modules is a list of pairs: [(module_command, [assert_command, ...]), ...] modules = CollectInvalidModuleCommands(all_commands) with utils.TempDirectory(options.temp_dir, 'gen-spec-js-') as temp_dir: extender = ModuleExtender(wat2wasm, wasm2wat, temp_dir) for module_command, assert_commands in modules: if assert_commands: wasm_path = os.path.join(json_dir, module_command['filename']) new_module_filename = extender.Extend(wasm_path, assert_commands) module_command['filename'] = new_module_filename output = io.StringIO() if options.prefix: with open(options.prefix) as prefix_file: output.write(prefix_file.read()) output.write('\n') JSWriter(json_dir, spec_json, output).Write() if options.output: out_file = open(options.output, 'w') else: out_file = sys.stdout try: out_file.write(output.getvalue()) finally: out_file.close() 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('--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!')