def GetNM(emscripten_dir): python = Executable(sys.executable) stdout = python.RunWithArgsForStdout( '-c', 'import tools.shared; print(tools.shared.LLVM_ROOT)', cwd=emscripten_dir) return Executable(os.path.join(stdout.strip(), 'llvm-nm'))
def main(args): parser = argparse.ArgumentParser(description=__doc__) parser.add_argument('-o', '--output', metavar='PATH', help='output file.') parser.add_argument('file', help='spec json file.') 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('--enable-exceptions', action='store_true') parser.add_argument('--enable-saturating-float-to-int', action='store_true') parser.add_argument('--enable-threads', action='store_true') parser.add_argument('--enable-simd', action='store_true') parser.add_argument('--enable-sign-extension', action='store_true') parser.add_argument('--enable-multi-value', action='store_true') parser.add_argument('--enable-bulk-memory', action='store_true') parser.add_argument('--enable-tail-call', action='store_true') parser.add_argument('--enable-reference-types', action='store_true') options = parser.parse_args(args) wast2json = Executable(find_exe.GetWast2JsonExecutable(options.bindir), error_cmdline=options.error_cmdline) wast2json.verbose = options.print_cmd wast2json.AppendOptionalArgs({ '--enable-exceptions': options.enable_exceptions, '--enable-multi-value': options.enable_multi_value, '--enable-saturating-float-to-int': options.enable_saturating_float_to_int, '--enable-sign-extension': options.enable_sign_extension, '--enable-simd': options.enable_simd, '--enable-threads': options.enable_threads, '--enable-bulk-memory': options.enable_bulk_memory, '--enable-tail-call': options.enable_tail_call, '--enable-reference-types': options.enable_reference_types, }) json_filename = options.file with utils.TempDirectory(options.temp_dir, 'gen-spec-wast-') as temp_dir: file_base, file_ext = os.path.splitext(json_filename) if file_ext == '.wast': wast_filename = options.file json_filename = ChangeDir(file_base + '.json', temp_dir) wast2json.RunWithArgs(wast_filename, '-o', json_filename) with open(json_filename) as json_file: json_dir = os.path.dirname(json_filename) spec_json = json.load(json_file) output = io.StringIO() WastWriter(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(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('-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'] = os.path.relpath(new_module_filename, json_dir) output = StringIO() if options.prefix: with open(options.prefix) as prefix_file: output.write(prefix_file.read()) output.write('\n') JSWriter(json_dir, all_commands, 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