OLD | NEW |
| (Empty) |
1 #!/usr/bin/env python | |
2 # | |
3 # Copyright (c) 2011, 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 # Script to create snapshot files. | |
8 | |
9 import getopt | |
10 import optparse | |
11 import string | |
12 import subprocess | |
13 import sys | |
14 import utils | |
15 | |
16 | |
17 HOST_OS = utils.GuessOS() | |
18 HOST_CPUS = utils.GuessCpus() | |
19 | |
20 | |
21 def BuildOptions(): | |
22 result = optparse.OptionParser() | |
23 result.add_option("--vm_input_bin", | |
24 action="store", type="string", | |
25 help="input file name of the vm isolate snapshot in binary form") | |
26 result.add_option("--input_bin", | |
27 action="store", type="string", | |
28 help="input file name of the isolate snapshot in binary form") | |
29 result.add_option("--input_cc", | |
30 action="store", type="string", | |
31 help="input file name which contains the C buffer template") | |
32 result.add_option("--output", | |
33 action="store", type="string", | |
34 help="output file name into which snapshot in C buffer form is generated") | |
35 result.add_option("-v", "--verbose", | |
36 help='Verbose output.', | |
37 default=False, action="store_true") | |
38 return result | |
39 | |
40 | |
41 def ProcessOptions(options): | |
42 if not options.vm_input_bin: | |
43 sys.stderr.write('--vm_input_bin not specified\n') | |
44 return False | |
45 if not options.input_bin: | |
46 sys.stderr.write('--input_bin not specified\n') | |
47 return False | |
48 if not options.input_cc: | |
49 sys.stderr.write('--input_cc not specified\n') | |
50 return False | |
51 if not options.output: | |
52 sys.stderr.write('--output not specified\n') | |
53 return False | |
54 return True | |
55 | |
56 | |
57 def makeString(input_file): | |
58 result = ' ' | |
59 fileHandle = open(input_file, 'rb') | |
60 lineCounter = 0 | |
61 for byte in fileHandle.read(): | |
62 result += ' %d,' % ord(byte) | |
63 lineCounter += 1 | |
64 if lineCounter == 10: | |
65 result += '\n ' | |
66 lineCounter = 0 | |
67 if lineCounter != 0: | |
68 result += '\n ' | |
69 return result | |
70 | |
71 | |
72 def makeFile(output_file, input_cc_file, | |
73 vm_isolate_input_file, isolate_input_file): | |
74 snapshot_cc_text = open(input_cc_file).read() | |
75 snapshot_cc_text = snapshot_cc_text % (makeString(vm_isolate_input_file), | |
76 makeString(isolate_input_file)) | |
77 open(output_file, 'w').write(snapshot_cc_text) | |
78 return True | |
79 | |
80 | |
81 def Main(): | |
82 # Parse options. | |
83 parser = BuildOptions() | |
84 (options, args) = parser.parse_args() | |
85 if not ProcessOptions(options): | |
86 parser.print_help() | |
87 return 1 | |
88 | |
89 # If there are additional arguments, report error and exit. | |
90 if args: | |
91 parser.print_help() | |
92 return 1 | |
93 | |
94 if not makeFile(options.output, options.input_cc, | |
95 options.vm_input_bin, options.input_bin): | |
96 print "Unable to generate snapshot in C buffer form" | |
97 return -1 | |
98 | |
99 return 0 | |
100 | |
101 if __name__ == '__main__': | |
102 sys.exit(Main()) | |
OLD | NEW |