Beispiel #1
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('--wast2wasm',
                        metavar='PATH',
                        help='set the wast2wasm executable to use.')
    parser.add_argument('--wasmdump',
                        metavar='PATH',
                        help='set the wasmdump 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',
                        help='print the commands that are run.',
                        action='store_true')
    parser.add_argument('--no-check', action='store_true')
    parser.add_argument('--spec', action='store_true')
    parser.add_argument('--no-canonicalize-leb128s', action='store_true')
    parser.add_argument('--use-libc-allocator', action='store_true')
    parser.add_argument('--debug-names', 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({
        '--debug-names':
        options.debug_names,
        '--no-check':
        options.no_check,
        '--no-canonicalize-leb128s':
        options.no_canonicalize_leb128s,
        '--spec':
        options.spec,
        '-v':
        options.verbose,
        '--use-libc-allocator':
        options.use_libc_allocator
    })

    wasmdump = utils.Executable(find_exe.GetWasmdumpExecutable(
        options.wasmdump),
                                error_cmdline=options.error_cmdline)

    wast2wasm.verbose = options.print_cmd
    wasmdump.verbose = options.print_cmd

    filename = options.file

    with utils.TempDirectory(options.out_dir, 'wasmdump-') as out_dir:
        basename = os.path.basename(filename)
        basename_noext = os.path.splitext(basename)[0]
        if options.spec:
            out_file = os.path.join(out_dir, basename_noext + '.json')
        else:
            out_file = os.path.join(out_dir, basename_noext + '.wasm')
        wast2wasm.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]

        for wasm_file in wasm_files:
            wasmdump.RunWithArgs('-d', wasm_file)
Beispiel #2
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)
Beispiel #3
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('-c', '--compile-only', action='store_true')
  parser.add_argument('--dump-verbose', action='store_true')
  parser.add_argument('--dump-debug', 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('--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)

  wast2wasm = utils.Executable(
      find_exe.GetWast2WasmExecutable(options.bindir),
      error_cmdline=options.error_cmdline)
  wast2wasm.AppendOptionalArgs({
      '--debug-names': options.debug_names,
      '--no-check': options.no_check,
      '--no-canonicalize-leb128s': options.no_canonicalize_leb128s,
      '--spec': options.spec,
      '-v': options.verbose,
      '-c': options.compile_only,
  })

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

  gen_wasm.verbose = options.print_cmd
  wast2wasm.verbose = options.print_cmd
  wasmdump.verbose = options.print_cmd

  filename = options.file

  with utils.TempDirectory(options.out_dir, 'wasmdump-') 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')
      wast2wasm.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]

    for wasm_file in wasm_files:
      wasmdump.RunWithArgs('-d', wasm_file)
Beispiel #4
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