Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(245)

Side by Side Diff: runtime/tools/bin_to_assembly.py

Issue 2901163002: Use assembly instead of C array literals to link the core snapshot into the VM. (Closed)
Patch Set: . Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 #!/usr/bin/env python
2 #
3 # Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file
4 # for details. All rights reserved. Use of this source code is governed by a
5 # BSD-style license that can be found in the LICENSE file.
6
zra 2017/05/24 16:20:30 Please add a comment explaining what this script d
rmacnak 2017/05/24 19:26:45 Done.
7 import os
8 import sys
9 from optparse import OptionParser
10
11 def Main():
12 parser = OptionParser()
13 parser.add_option("--output",
14 action="store", type="string",
15 help="output assembly file name")
16 parser.add_option("--input",
17 action="store", type="string",
18 help="input binary blob file")
19 parser.add_option("--symbol_name",
20 action="store", type="string")
21 parser.add_option("--executable",
22 action="store_true")
23 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.
24 parser.add_option("--target_os",
25 action="store", type="string")
26
27 (options, args) = parser.parse_args()
28 if not options.output:
29 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.
30 return -1
31 if not options.input:
zra 2017/05/24 16:20:27 or not os.path.isfile(options.input)
32 sys.stderr.write('--input not specified\n')
zra 2017/05/24 16:20:29 parser.print_help()
33 return -1
34 if not options.symbol_name:
35 sys.stderr.write('--symbol_name not specified\n')
zra 2017/05/24 16:20:27 ditto
36 return -1
37 if not options.target_os:
zra 2017/05/24 16:20:27 or options.target_os not in [...]:
38 sys.stderr.write('--target_os not specified\n')
zra 2017/05/24 16:20:28 parser.print_help()
39 return -1
40
41 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.
42 if options.target_os in ["mac", "ios"]:
43 if options.executable:
44 output_file.write(".text\n")
45 else:
46 output_file.write(".const\n")
47 output_file.write(".global _%s\n" % options.symbol_name)
48 output_file.write(".balign 32\n")
49 output_file.write("_%s:\n" % options.symbol_name)
50 elif options.target_os in ["linux", "android", "fuchsia"]:
51 if options.executable:
52 output_file.write(".text\n")
53 else:
54 output_file.write(".section .rodata\n")
55 output_file.write(".global %s\n" % options.symbol_name)
56 output_file.write(".balign 32\n")
57 output_file.write("%s:\n" % options.symbol_name)
58 elif options.target_os in ["win"]:
59 if options.executable:
60 output_file.write(".text\n")
61 else:
62 output_file.write(".rdata\n")
63 output_file.write(".globl %s\n" % options.symbol_name)
64 output_file.write(".align 32\n")
65 output_file.write("%s:\n" % options.symbol_name)
66 else:
67 raise Exception("Unknown target_os: %s" % options.target_os)
68
69
70 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.
71 for byte in input_file.read():
72 output_file.write(".byte %d\n" % ord(byte))
73
74 input_file.close();
75 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.
76
77 if __name__ == '__main__':
78 sys.exit(Main())
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698