コード例 #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('--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)
コード例 #2
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('--wasm2wast',
                        metavar='PATH',
                        help='set the wasm2wast executable to use.')
    parser.add_argument(
        '--stdout',
        action='store_true',
        help='do one roundtrip and write wast output to stdout')
    parser.add_argument(
        '--no-error-cmdline',
        help='don\'t display the subprocess\'s commandline when' +
        ' an error occurs',
        dest='error_cmdline',
        action='store_false')
    parser.add_argument('-p',
                        '--print-cmd',
                        help='print the commands that are run.',
                        action='store_true')
    parser.add_argument('--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)

    wast2wasm = utils.Executable(find_exe.GetWast2WasmExecutable(
        options.wast2wasm),
                                 error_cmdline=options.error_cmdline)
    wast2wasm.AppendOptionalArgs({
        '--debug-names':
        options.debug_names,
        '--use-libc-allocator':
        options.use_libc_allocator
    })

    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
    })

    wast2wasm.verbose = options.print_cmd
    wasm2wast.verbose = options.print_cmd

    filename = options.file
    if not os.path.exists(filename):
        sys.stderr.write('File not found: %s\n' % filename)
        return ERROR

    with utils.TempDirectory(options.out_dir, 'roundtrip-') as out_dir:
        if options.stdout:
            result, msg = OneRoundtripToStdout(wast2wasm, wasm2wast, out_dir,
                                               filename, options.verbose)
        else:
            result, msg = TwoRoundtrips(wast2wasm, wasm2wast, out_dir,
                                        filename, options.verbose)
        if result == ERROR:
            sys.stderr.write(msg)
        return result
コード例 #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)

    wasm2wast = utils.Executable(find_exe.GetWasm2WastExecutable(
        options.bindir),
                                 error_cmdline=options.error_cmdline)
    wasm2wast.AppendOptionalArgs({
        '--no-debug-names': options.no_debug_names,
    })
    wasm2wast.AppendOptionalArgs({
        '--verbose': options.verbose,
    })

    gen_wasm.verbose = options.print_cmd
    wasm2wast.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:
            wasm2wast.RunWithArgs(out_file)
コード例 #4
0
ファイル: gen-spec-js.py プロジェクト: soapdog/wabt
def main(args):
    parser = argparse.ArgumentParser()
    parser.add_argument('-o', '--output', metavar='PATH', help='output file.')
    parser.add_argument('-P',
                        '--prefix',
                        metavar='PATH',
                        help='prefix file.',
                        default=os.path.join(SCRIPT_DIR, 'gen-spec-prefix.js'))
    parser.add_argument('--bindir',
                        metavar='PATH',
                        default=find_exe.GetDefaultPath(),
                        help='directory to search for all executables.')
    parser.add_argument('--temp-dir',
                        metavar='PATH',
                        help='set the directory that temporary wasm/wast'
                        ' files are written.')
    parser.add_argument(
        '--no-error-cmdline',
        help='don\'t display the subprocess\'s commandline when' +
        ' an error occurs',
        dest='error_cmdline',
        action='store_false')
    parser.add_argument('-p',
                        '--print-cmd',
                        help='print the commands that are run.',
                        action='store_true')
    parser.add_argument('file', help='spec json file.')
    options = parser.parse_args(args)

    wast2wasm = Executable(find_exe.GetWast2WasmExecutable(options.bindir),
                           error_cmdline=options.error_cmdline)
    wasm2wast = Executable(find_exe.GetWasm2WastExecutable(options.bindir),
                           error_cmdline=options.error_cmdline)

    wast2wasm.verbose = options.print_cmd
    wasm2wast.verbose = options.print_cmd

    with open(options.file) as json_file:
        json_dir = os.path.dirname(options.file)
        spec_json = json.load(json_file)
        all_commands = spec_json['commands']

    # modules is a list of pairs: [(module_command, [assert_command, ...]), ...]
    modules = CollectInvalidModuleCommands(all_commands)

    with utils.TempDirectory(options.temp_dir, 'gen-spec-js-') as temp_dir:
        extender = ModuleExtender(wast2wasm, wasm2wast, temp_dir)
        for module_command, assert_commands in modules:
            if assert_commands:
                wasm_path = os.path.join(json_dir, module_command['filename'])
                new_module_filename = extender.Extend(wasm_path,
                                                      assert_commands)
                module_command['filename'] = os.path.relpath(
                    new_module_filename, json_dir)

        output = StringIO()
        if options.prefix:
            with open(options.prefix) as prefix_file:
                output.write(prefix_file.read())
                output.write('\n')

        JSWriter(json_dir, all_commands, output).Write()

    if options.output:
        out_file = open(options.output, 'w')
    else:
        out_file = sys.stdout

    try:
        out_file.write(output.getvalue())
    finally:
        out_file.close()

    return 0