Ejemplo n.º 1
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
Ejemplo n.º 2
0
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
Ejemplo n.º 3
0
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
Ejemplo n.º 4
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',
                      help='print the commands that are run.',
                      action='store_true')
  parser.add_argument('--headers', action='store_true')
  parser.add_argument('--no-check', action='store_true')
  parser.add_argument('--dump-verbose', action='store_true')
  parser.add_argument('--dump-debug', 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('--gen-wasm', action='store_true',
                      help='parse with gen-wasm')
  parser.add_argument('--spec', action='store_true')
  parser.add_argument('-r', '--relocatable', action='store_true')
  parser.add_argument('--no-canonicalize-leb128s', action='store_true')
  parser.add_argument('--debug-names', action='store_true')
  parser.add_argument('file', help='test file.')
  options = parser.parse_args(args)

  if options.gen_wasm and options.spec:
    parser.error('Can\'t use both --gen-wasm and --spec')

  gen_wasm = utils.Executable(sys.executable, GEN_WASM_PY,
                              error_cmdline=options.error_cmdline)

  wat_tool = None
  if options.spec:
    wat_tool = utils.Executable(
        find_exe.GetWast2JsonExecutable(options.bindir),
        error_cmdline=options.error_cmdline)
  else:
    wat_tool = utils.Executable(
        find_exe.GetWat2WasmExecutable(options.bindir),
        error_cmdline=options.error_cmdline)

  wat_tool.AppendOptionalArgs({
      '--debug-names': options.debug_names,
      '--enable-exceptions': options.enable_exceptions,
      '--enable-saturating-float-to-int':
          options.enable_saturating_float_to_int,
      '--enable-threads': options.enable_threads,
      '--enable-simd': options.enable_simd,
      '--no-check': options.no_check,
      '--no-canonicalize-leb128s': options.no_canonicalize_leb128s,
      '-v': options.verbose,
      '-r': options.relocatable,
  })

  wasm_objdump = utils.Executable(
      find_exe.GetWasmdumpExecutable(options.bindir),
      error_cmdline=options.error_cmdline)
  wasm_objdump.AppendOptionalArgs({
      '-h': options.headers,
      '-x': options.dump_verbose,
      '--debug': options.dump_debug,
  })

  gen_wasm.verbose = options.print_cmd
  wat_tool.verbose = options.print_cmd
  wasm_objdump.verbose = options.print_cmd

  filename = options.file

  with utils.TempDirectory(options.out_dir, 'objdump-') as out_dir:
    basename = os.path.basename(filename)
    basename_noext = os.path.splitext(basename)[0]
    if options.gen_wasm:
      out_file = os.path.join(out_dir, basename_noext + '.wasm')
      gen_wasm.RunWithArgs('-o', out_file, filename)
    else:
      if options.spec:
        out_file = os.path.join(out_dir, basename_noext + '.json')
      else:
        out_file = os.path.join(out_dir, basename_noext + '.wasm')
      wat_tool.RunWithArgs('-o', out_file, filename)

    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]

    wasm_objdump.RunWithArgs('-r', '-d', *wasm_files)
Ejemplo n.º 5
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('--enable-simd', 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,
      '--enable-simd': options.enable_simd,
  })

  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,
      '--enable-simd': options.enable_simd,
  })

  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
Ejemplo n.º 6
0
def main(args):
  parser = argparse.ArgumentParser()
  parser.add_argument('-v', '--verbose', help='print more diagnotic messages.',
                      action='store_true')
  parser.add_argument('-r', '--relocatable', action='store_true',
                      help='final output is relocatable')
  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',
                      help='print the commands that are run.',
                      action='store_true')
  parser.add_argument('--incremental', help='incremenatly link one object at' +
                      ' a time to produce the final linked binary.',
                      action='store_true')
  parser.add_argument('--debug-names', action='store_true')
  parser.add_argument('--dump-verbose', action='store_true')
  parser.add_argument('--spec', action='store_true')
  parser.add_argument('file', help='test file.')
  options = parser.parse_args(args)

  wast2json = utils.Executable(
      find_exe.GetWast2JsonExecutable(options.bindir),
      error_cmdline=options.error_cmdline)
  wast2json.AppendOptionalArgs({
      '--debug-names': options.debug_names,
      '-v': options.dump_verbose,
  })

  wasm_link = utils.Executable(
      find_exe.GetWasmlinkExecutable(options.bindir),
      error_cmdline=options.error_cmdline)
  wasm_link.AppendOptionalArgs({
      '-v': options.verbose,
      '-r': options.relocatable,
  })

  wasm_objdump = utils.Executable(
      find_exe.GetWasmdumpExecutable(options.bindir),
      error_cmdline=options.error_cmdline)

  spectest_interp = utils.Executable(
      find_exe.GetSpectestInterpExecutable(options.bindir),
      error_cmdline=options.error_cmdline)

  wast2json.verbose = options.print_cmd
  wasm_link.verbose = options.print_cmd
  wasm_objdump.verbose = options.print_cmd
  spectest_interp.verbose = options.print_cmd

  filename = options.file

  with utils.TempDirectory(options.out_dir, 'wasm-link-') as out_dir:
    basename = os.path.basename(filename)
    basename_noext = os.path.splitext(basename)[0]
    out_file = os.path.join(out_dir, basename_noext + '.json')
    wast2json.RunWithArgs('--debug-names', '--no-check', '-r', '-o',
                          out_file, filename)

    wasm_files = utils.GetModuleFilenamesFromSpecJSON(out_file)
    wasm_files = [utils.ChangeDir(f, out_dir) for f in wasm_files]

    output = os.path.join(out_dir, 'linked.wasm')
    if options.incremental:
      partially_linked = output + '.partial'
      for i, f in enumerate(wasm_files):
        if i == 0:
          wasm_link.RunWithArgs('-o', output, f)
        else:
          if os.path.exists(partially_linked):
            os.remove(partially_linked)
          os.rename(output, partially_linked)
          wasm_link.RunWithArgs('-r', '-o', output, partially_linked, f)
        #wasm_objdump.RunWithArgs('-d', '-h', output)
      wasm_objdump.RunWithArgs('-d', '-x', '-r', '-h', output)
    else:
      wasm_link.RunWithArgs('-o', output, *wasm_files)
      wasm_objdump.RunWithArgs('-d', '-x', '-r', '-h', output)

    if options.spec:
      with open(out_file) as json_file:
        spec = json.load(json_file, object_pairs_hook=OrderedDict)
        spec['commands'] = [c for c in spec['commands']
                            if c['type'] != 'module']
        module = OrderedDict([('type', 'module'),
                              ('line', 0),
                              ('filename', os.path.basename(output)),])
        spec['commands'].insert(0, module)

      with open(out_file, 'wb') as json_file:
        json.dump(spec, json_file, indent=4)

      spectest_interp.RunWithArgs(out_file)
Ejemplo n.º 7
0
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='wat file.')
    options = parser.parse_args(args)

    with utils.TempDirectory(options.out_dir, 'run-gen-spec-js-') as out_dir:
        wast2json = utils.Executable(find_exe.GetWast2JsonExecutable(
            options.bindir),
                                     error_cmdline=options.error_cmdline)
        wast2json.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')
        wast2json.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)