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

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: windows 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
« no previous file with comments | « runtime/bin/snapshot_in.cc ('k') | runtime/tools/empty.bin » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
7 # Generates an assembly source file the defines a symbol with the bytes from
8 # a given file.
9
10 import os
11 import sys
12 from optparse import OptionParser
13
14 def Main():
15 parser = OptionParser()
16 parser.add_option("--output",
17 action="store", type="string",
18 help="output assembly file name")
19 parser.add_option("--input",
20 action="store", type="string",
21 help="input binary blob file")
22 parser.add_option("--symbol_name",
23 action="store", type="string")
24 parser.add_option("--executable",
25 action="store_true", default=False)
26 parser.add_option("--target_os",
27 action="store", type="string")
28
29 (options, args) = parser.parse_args()
30 if not options.output:
31 sys.stderr.write("--output not specified\n")
32 parser.print_help();
33 return -1
34 if not options.input:
35 sys.stderr.write("--input not specified\n")
36 parser.print_help();
37 return -1
38 if not os.path.isfile(options.input):
39 sys.stderr.write("input file does not exist: %s\n" % options.input)
40 parser.print_help();
41 return -1
42 if not options.symbol_name:
43 sys.stderr.write("--symbol_name not specified\n")
44 parser.print_help();
45 return -1
46 if not options.target_os:
47 sys.stderr.write("--target_os not specified\n")
48 parser.print_help();
49 return -1
50
51 with open(options.output, "w") as output_file:
52 if options.target_os in ["mac", "ios"]:
53 if options.executable:
54 output_file.write(".text\n")
55 else:
56 output_file.write(".const\n")
57 output_file.write(".global _%s\n" % options.symbol_name)
58 output_file.write(".balign 32\n")
59 output_file.write("_%s:\n" % options.symbol_name)
60 elif options.target_os in ["linux", "android", "fuchsia"]:
61 if options.executable:
62 output_file.write(".text\n")
63 else:
64 output_file.write(".section .rodata\n")
65 output_file.write(".global %s\n" % options.symbol_name)
66 output_file.write(".balign 32\n")
67 output_file.write("%s:\n" % options.symbol_name)
68 elif options.target_os in ["win"]:
69 output_file.write("ifndef _ML64_X64\n")
70 output_file.write(".model flat, C\n")
71 output_file.write("endif\n")
72 if options.executable:
73 output_file.write(".code\n")
74 else:
75 output_file.write(".const\n")
76 output_file.write("public %s\n" % options.symbol_name)
77 output_file.write("%s label byte\n" % options.symbol_name)
78 else:
79 sys.stderr.write("Unknown target_os: %s" % options.target_os)
80 return -1
81
82 with open(options.input, "rb") as input_file:
83 if options.target_os in ["win"]:
84 for byte in input_file.read():
85 output_file.write("byte %d\n" % ord(byte))
86 output_file.write("end\n")
87 else:
88 for byte in input_file.read():
89 output_file.write(".byte %d\n" % ord(byte))
90
91 return 0
92
93 if __name__ == "__main__":
94 sys.exit(Main())
OLDNEW
« no previous file with comments | « runtime/bin/snapshot_in.cc ('k') | runtime/tools/empty.bin » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698