OLD | NEW |
---|---|
1 #!/usr/bin/python2 | 1 #!/usr/bin/python2 |
2 | 2 |
3 # Copyright 2016 The Chromium Authors. All rights reserved. | 3 # Copyright 2016 The Chromium Authors. All rights reserved. |
4 # Use of this source code is governed by a BSD-style license that can be | 4 # Use of this source code is governed by a BSD-style license that can be |
5 # found in the LICENSE file. | 5 # found in the LICENSE file. |
6 | 6 |
7 import binascii | 7 import binascii |
8 import optparse | |
8 import sys | 9 import sys |
9 | 10 |
10 if len(sys.argv) < 2: | 11 parser = optparse.OptionParser() |
11 sys.exit("Usage: %s icu_data_file [output_assembly_file]" % sys.argv[0]) | 12 parser.add_option("--mac", |
13 help="generate assembly file for Mac/iOS (default: False)", | |
14 action="store_true", default=False) | |
15 parser.set_usage("""make_data_assembly icu_data [assembly_file] [--mac] | |
16 icu_data: ICU data file to generate assembly from. | |
17 assembly_file: Output file converted from icu_data file.""") | |
18 (options, args) = parser.parse_args() | |
12 | 19 |
13 input_file = sys.argv[1] | 20 if len(args) < 1: |
21 parser.error("ICU data file is not given.") | |
22 | |
23 input_file = args[0] | |
14 n = input_file.find(".dat") | 24 n = input_file.find(".dat") |
15 if n == -1: | 25 if n == -1: |
16 sys.exit("%s is not an ICU .dat file." % input_file) | 26 sys.exit("%s is not an ICU .dat file." % input_file) |
17 | 27 |
18 if len(sys.argv) < 3: | 28 if len(args) < 2: |
19 output_file = input_file[0:n] + "_dat.S" | 29 output_file = input_file[0:n] + "_dat.S" |
20 else: | 30 else: |
21 output_file = sys.argv[2] | 31 output_file = args[1] |
22 | 32 |
23 if input_file.find("l.dat") == -1: | 33 if input_file.find("l.dat") == -1: |
24 if input_file.find("b.dat") == -1: | 34 if input_file.find("b.dat") == -1: |
25 sys.exit("%s has no endianness marker." % input_file) | 35 sys.exit("%s has no endianness marker." % input_file) |
26 else: | 36 else: |
27 step = 1 | 37 step = 1 |
28 else: | 38 else: |
29 step = -1 | 39 step = -1 |
30 | 40 |
31 input_data = open(input_file, 'rb').read() | 41 input_data = open(input_file, 'rb').read() |
32 n = input_data.find("icudt") | 42 n = input_data.find("icudt") |
33 if n == -1: | 43 if n == -1: |
34 sys.exit("Cannot find a version number in %s." % input_file) | 44 sys.exit("Cannot find a version number in %s." % input_file) |
35 | 45 |
36 version_number = input_data[n + 5:n + 7] | 46 version_number = input_data[n + 5:n + 7] |
37 | 47 |
38 output = open(output_file, 'w') | 48 output = open(output_file, 'w') |
39 output.write(".globl icudt" + version_number + "_dat\n" | 49 |
40 "\t.section .note.GNU-stack,\"\",%progbits\n" | 50 if options.mac: |
41 "\t.section .rodata\n" | 51 output.write(".globl _icudt%s_dat\n" |
Michael Achenbach
2016/07/22 07:34:08
I have no idea about this and can only rubber stam
jungshik at Google
2016/07/22 20:31:13
Thanks. Don't worry. It comes from scripts/make_ma
| |
42 "\t.balign 16\n" | 52 "#ifdef U_HIDE_DATA_SYMBOL\n" |
43 "#ifdef U_HIDE_DATA_SYMBOL\n" | 53 "\t.private_extern _icudt%s_dat\n" |
44 "\t.hidden icudt" + version_number + "_dat\n" | 54 "#endif\n" |
45 "#endif\n" | 55 "\t.data\n" |
46 "\t.type icudt" + version_number + "_dat,%object\n" | 56 "\t.const\n" |
47 "icudt" + version_number + "_dat:\n") | 57 "\t.align 4\n" |
58 "_icudt%s_dat:\n" %tuple([version_number] * 3)) | |
59 else: | |
60 output.write(".globl icudt%s_dat\n" | |
61 "\t.section .note.GNU-stack,\"\",%%progbits\n" | |
62 "\t.section .rodata\n" | |
63 "\t.balign 16\n" | |
64 "#ifdef U_HIDE_DATA_SYMBOL\n" | |
65 "\t.hidden icudt%s_dat\n" | |
66 "#endif\n" | |
67 "\t.type icudt%s_dat,%%object\n" | |
68 "icudt%s_dat:\n" % tuple([version_number] * 4)) | |
48 | 69 |
49 split = [binascii.hexlify(input_data[i:i + 4][::step]).upper().lstrip('0') | 70 split = [binascii.hexlify(input_data[i:i + 4][::step]).upper().lstrip('0') |
50 for i in range(0, len(input_data), 4)] | 71 for i in range(0, len(input_data), 4)] |
51 | 72 |
52 for i in range(len(split)): | 73 for i in range(len(split)): |
53 if (len(split[i]) == 0): | 74 if (len(split[i]) == 0): |
54 value = '0' | 75 value = '0' |
55 elif (len(split[i]) == 1): | 76 elif (len(split[i]) == 1): |
56 if not any((c in '123456789') for c in split[i]): | 77 if not any((c in '123456789') for c in split[i]): |
57 value = '0x0' + split[i] | 78 value = '0x0' + split[i] |
58 else: | 79 else: |
59 value = split[i] | 80 value = split[i] |
60 elif (len(split[i]) % 2 == 1): | 81 elif (len(split[i]) % 2 == 1): |
61 value = '0x0' + split[i] | 82 value = '0x0' + split[i] |
62 else: | 83 else: |
63 value = '0x' + split[i] | 84 value = '0x' + split[i] |
64 | 85 |
65 if (i % 32 == 0): | 86 if (i % 32 == 0): |
66 output.write("\n.long ") | 87 output.write("\n.long ") |
67 else: | 88 else: |
68 output.write(",") | 89 output.write(",") |
69 output.write(value) | 90 output.write(value) |
70 | 91 |
71 output.write("\n") | 92 output.write("\n") |
72 output.close() | 93 output.close() |
73 print "Generated " + output_file | 94 print "Generated " + output_file |
OLD | NEW |