예제 #1
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:
        # 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
예제 #2
0
def reprocess(target, source, umask=None):
    target = os.path.abspath(target)
    with utils.ChangeDir(source):
        if umask is not None:
            os.umask(umask)

        print('starting processing of all recipes')
        common.clean_output_dir(target)
        files = git.ls_tree('HEAD')

        # do a dry run to catch errors
        for f in files:
            file = ' '.join(f[3:])
            obj_id = f[2]

            if file.split('.')[-1] != 'rmd':
                continue

            r = common.process(obj_id, '/dev/null', settings.XSLT)

        # do a real run
        for f in files:
            file = f[3]
            obj_id = f[2]

            if file.split('.')[-1] != 'rmd':
                continue

            print('P {}'.format(file))
            common.process(obj_id, common.xml_filename(file, target),
                           settings.XSLT)

        print('finished processing of files')
예제 #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',
                        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)
예제 #4
0
파일: run-interp.py 프로젝트: smvv/wabt
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
예제 #5
0
파일: test_git.py 프로젝트: ltgrant/opt
    def test_ls_tree(self):
        with tempfile.TemporaryDirectory() as tmp:
            with utils.ChangeDir(tmp):
                self._setup_git()
                self._second_commit()

                tree = git.ls_tree('HEAD')
                self.assertEqual(tree, result['tree'])
예제 #6
0
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
예제 #7
0
파일: test_git.py 프로젝트: ltgrant/opt
 def test_blob_file_handle(self):
     with tempfile.TemporaryDirectory() as tmp:
         with utils.ChangeDir(tmp):
             self._setup_git()
             with git.blob_file_handle(
                     'ba0e162e1c47469e3fe4b393a8bf8c569f302116') as f:
                 self.assertType(f, io.BufferedReader)
                 content = f.readlines()
                 self.assertEqual(content, [b'bar'])
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)
예제 #9
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='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)
예제 #10
0
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
예제 #11
0
파일: test_git.py 프로젝트: ltgrant/opt
    def test_changed_files(self):
        with tempfile.TemporaryDirectory() as tmp:
            with utils.ChangeDir(tmp):
                self._setup_git()
                changes = git.changed_files(
                    '0000000000000000000000000000000000000000', 'HEAD')
                self.assertEqual(changes, result['first'])

                self._second_commit()
                changes = git.changed_files('HEAD^', 'HEAD')
                self.assertEqual(changes, result['second'])
예제 #12
0
    def test_clean_output_dir(self):
        with tempfile.TemporaryDirectory() as tmp:
            with utils.ChangeDir(tmp):
                open('should_delete.xml', 'w').close()
                open('should_not_xml', 'w').close()

            clean_output_dir(tmp)

            files = [
                f for f in os.listdir(tmp) if path.isfile(path.join(tmp, f))
            ]
            self.assertEqual(files, ['should_not_xml'])
예제 #13
0
    def _real_test_all(self, source, target, outdir):
        # for now we'll just be happy that the files are there
        with utils.ChangeDir(source):
            _write_file('ignore.foo', 'foobar')
            _write_file('add.rmd', add_text)
            _run_command(['git', 'add', '.'])
            _run_command(['git', 'commit', '-m', 'add step'])
            _run_command(['git', 'push', 'target', 'master'])

        with utils.ChangeDir(outdir):
            self.assertTrue(os.path.isfile('add.xml'), 'Xml has not been generated')
            self.assertTrue(os.path.isfile('index.html'), 'Index has not been generated')

            os.remove('add.xml')
            os.remove('index.html')

        with utils.ChangeDir(source):
            _write_file('add.rmd', change_text)
            _run_command(['git', 'commit', '-am', 'change step'])
            _run_command(['git', 'push', 'target', 'master'])

        with utils.ChangeDir(outdir):
            self.assertTrue(os.path.isfile('add.xml'), 'Xml has not been generated')
            self.assertTrue(os.path.isfile('index.html'), 'Index has not been generated')

            os.remove('index.html')

        with utils.ChangeDir(source):
            _run_command(['git', 'rm', 'add.rmd'])
            _run_command(['git', 'commit', '-m', 'delete step'])
            _run_command(['git', 'push', 'target', 'master'])

        with utils.ChangeDir(outdir):
            self.assertFalse(os.path.isfile('add.xml'), 'Xml has not been deleted')
            self.assertTrue(os.path.isfile('index.html'), 'Index has not been generated')
예제 #14
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
예제 #15
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
예제 #16
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('-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
예제 #17
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
예제 #18
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
예제 #19
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
예제 #20
0
 def _setup_source_git(self, source, target):
     with utils.ChangeDir(source):
         _run_command(['git', 'init'])
         _run_command(['git', 'remote', 'add', 'target', target])
         _run_command(['git', 'config', 'push.default', 'simple'])
예제 #21
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
예제 #22
0
 def _setup_target_git(self, target, outdir):
     hook_path = os.path.abspath('./update-hook.py')
     with utils.ChangeDir(target):
         _run_command(['git', 'init', '--bare'])
         os.symlink(hook_path, 'hooks/update')
         _write_file('hooks/settings.py', settings.format(outdir))
예제 #23
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)
예제 #24
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
예제 #25
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
예제 #26
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(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
예제 #27
0
파일: run-wasmdump.py 프로젝트: smvv/wabt
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)
예제 #28
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!')
예제 #29
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)
예제 #30
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