OLD | NEW |
---|---|
(Empty) | |
1 #!/usr/bin/python2 | |
2 # Copyright 2016 The Chromium Authors. All rights reserved. | |
jungshik at Google
2016/05/18 20:51:24
Sorry that I forgot to mention. Please, insert a n
miran.karic
2016/05/19 11:46:33
Done.
| |
3 # Use of this source code is governed by a BSD-style license that can be | |
4 # found in the LICENSE file. | |
5 | |
6 import binascii | |
7 import sys | |
8 | |
9 if len(sys.argv) < 2: | |
10 sys.exit("Usage: %s icu_data_file [output_assembly_file]" % sys.argv[0]) | |
11 | |
12 input_file = sys.argv[1] | |
13 n = input_file.find(".dat") | |
14 if n == -1: | |
15 sys.exit("%s is not an ICU .dat file." % input_file) | |
16 | |
17 if len(sys.argv) < 3: | |
18 output_file = input_file[0:n] + "_dat.S" | |
19 else: | |
20 output_file = sys.argv[2] | |
21 | |
22 n = input_file.find("l.dat") | |
23 if n == -1: | |
jungshik at Google
2016/05/18 20:51:24
nit: if input_file.find("l.dat") == -1:
miran.karic
2016/05/19 11:46:33
Done.
| |
24 n = input_file.find("b.dat") | |
25 if n == -1: | |
jungshik at Google
2016/05/18 20:51:24
same here
miran.karic
2016/05/19 11:46:33
Done.
| |
26 sys.exit("%s has no endianness marker." % input_file) | |
27 else: | |
28 step = 1; | |
jungshik at Google
2016/05/18 20:51:24
You don't need 'else' here because of sys.exit() a
miran.karic
2016/05/19 11:46:33
sys.exit() exits only if there is no 'l' or 'b' be
| |
29 else: | |
30 step = -1; | |
31 | |
32 input_data = open(input_file, 'rb').read() | |
33 n = input_data.find("icudt") | |
34 if n == -1: | |
jungshik at Google
2016/05/18 20:51:24
again, just |if input_data.find("icudt") == -1:| w
miran.karic
2016/05/19 11:46:33
Here I use n below to extract version number
| |
35 sys.exit("Cannot find a version number in %s." % input_file) | |
36 | |
37 version_number = input_data[n + 5:n + 7] | |
38 | |
39 output = open(output_file, 'w') | |
40 output.write(".globl icudt" + version_number + "_dat\n" | |
41 "\t.section .note.GNU-stack,\"\",%progbits\n" | |
42 "\t.section .rodata\n" | |
43 "\t.balign 16\n" | |
44 "#ifdef U_HIDE_DATA_SYMBOL\n" | |
45 "\t.hidden icudt" + version_number + "_dat\n" | |
46 "#endif\n" | |
47 "\t.type icudt" + version_number + "_dat,%object\n" | |
48 "icudt" + version_number + "_dat:\n") | |
49 | |
50 split = [binascii.hexlify(input_data[i:i + 4][::step]).upper().lstrip('0') \ | |
51 for i in range(0, len(input_data), 4)] | |
jungshik at Google
2016/05/18 20:51:24
nit: You don't need '\' at the end.
Please, line
miran.karic
2016/05/19 11:46:33
Done.
| |
52 | |
53 for i in range(len(split)): | |
54 if (len(split[i]) == 0): | |
55 value = '0' | |
56 elif (len(split[i]) == 1): | |
57 if not any((c in '123456789') for c in split[i]): | |
58 value = '0x0' + split[i] | |
59 else: | |
60 value = split[i] | |
61 elif (len(split[i]) % 2 == 1): | |
62 value = '0x0' + split[i] | |
63 else: | |
64 value = '0x' + split[i] | |
65 | |
66 if (i % 32 == 0): | |
67 output.write("\n.long ") | |
68 else: | |
69 output.write(",") | |
70 output.write(value) | |
71 | |
72 output.write("\n") | |
73 output.close() | |
74 print "Generated " + output_file | |
OLD | NEW |