Chromium Code Reviews| Index: runtime/tools/bin_to_assembly.py |
| diff --git a/runtime/tools/bin_to_assembly.py b/runtime/tools/bin_to_assembly.py |
| new file mode 100755 |
| index 0000000000000000000000000000000000000000..fd41f4dfe238893f329281b70eed5091c65d438e |
| --- /dev/null |
| +++ b/runtime/tools/bin_to_assembly.py |
| @@ -0,0 +1,78 @@ |
| +#!/usr/bin/env python |
| +# |
| +# Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file |
| +# for details. All rights reserved. Use of this source code is governed by a |
| +# BSD-style license that can be found in the LICENSE file. |
| + |
|
zra
2017/05/24 16:20:30
Please add a comment explaining what this script d
rmacnak
2017/05/24 19:26:45
Done.
|
| +import os |
| +import sys |
| +from optparse import OptionParser |
| + |
| +def Main(): |
| + parser = OptionParser() |
| + parser.add_option("--output", |
| + action="store", type="string", |
| + help="output assembly file name") |
| + parser.add_option("--input", |
| + action="store", type="string", |
| + help="input binary blob file") |
| + parser.add_option("--symbol_name", |
| + action="store", type="string") |
| + parser.add_option("--executable", |
| + action="store_true") |
| + parser.set_defaults(executable=False) |
|
zra
2017/05/24 16:20:27
maybe instead add 'default=True' to the add_option
rmacnak
2017/05/24 19:26:45
Done.
|
| + parser.add_option("--target_os", |
| + action="store", type="string") |
| + |
| + (options, args) = parser.parse_args() |
| + if not options.output: |
| + sys.stderr.write('--output not specified\n') |
|
zra
2017/05/24 16:20:29
parser.print_help()
rmacnak
2017/05/24 19:26:45
Done.
|
| + return -1 |
| + if not options.input: |
|
zra
2017/05/24 16:20:27
or not os.path.isfile(options.input)
|
| + sys.stderr.write('--input not specified\n') |
|
zra
2017/05/24 16:20:29
parser.print_help()
|
| + return -1 |
| + if not options.symbol_name: |
| + sys.stderr.write('--symbol_name not specified\n') |
|
zra
2017/05/24 16:20:27
ditto
|
| + return -1 |
| + if not options.target_os: |
|
zra
2017/05/24 16:20:27
or options.target_os not in [...]:
|
| + sys.stderr.write('--target_os not specified\n') |
|
zra
2017/05/24 16:20:28
parser.print_help()
|
| + return -1 |
| + |
| + output_file = open(options.output, 'w') |
|
zra
2017/05/24 16:20:26
with open(options.output) as output_file:
rmacnak
2017/05/24 19:26:45
Done.
|
| + if options.target_os in ["mac", "ios"]: |
| + if options.executable: |
| + output_file.write(".text\n") |
| + else: |
| + output_file.write(".const\n") |
| + output_file.write(".global _%s\n" % options.symbol_name) |
| + output_file.write(".balign 32\n") |
| + output_file.write("_%s:\n" % options.symbol_name) |
| + elif options.target_os in ["linux", "android", "fuchsia"]: |
| + if options.executable: |
| + output_file.write(".text\n") |
| + else: |
| + output_file.write(".section .rodata\n") |
| + output_file.write(".global %s\n" % options.symbol_name) |
| + output_file.write(".balign 32\n") |
| + output_file.write("%s:\n" % options.symbol_name) |
| + elif options.target_os in ["win"]: |
| + if options.executable: |
| + output_file.write(".text\n") |
| + else: |
| + output_file.write(".rdata\n") |
| + output_file.write(".globl %s\n" % options.symbol_name) |
| + output_file.write(".align 32\n") |
| + output_file.write("%s:\n" % options.symbol_name) |
| + else: |
| + raise Exception("Unknown target_os: %s" % options.target_os) |
| + |
| + |
| + input_file = open(options.input, 'rb') |
|
zra
2017/05/24 16:20:28
with open(options.input, 'rb') as input_file:
rmacnak
2017/05/24 19:26:45
Done.
|
| + for byte in input_file.read(): |
| + output_file.write(".byte %d\n" % ord(byte)) |
| + |
| + input_file.close(); |
| + output_file.close(); |
|
zra
2017/05/24 16:20:29
return 0
rmacnak
2017/05/24 19:26:45
Done.
rmacnak
2017/05/24 19:26:46
Done.
|
| + |
| +if __name__ == '__main__': |
| + sys.exit(Main()) |