OLD | NEW |
(Empty) | |
| 1 #!/usr/bin/python2 |
| 2 |
| 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 |
| 5 # found in the LICENSE file. |
| 6 |
| 7 import binascii |
| 8 import sys |
| 9 |
| 10 if len(sys.argv) < 2: |
| 11 sys.exit("Usage: %s icu_data_file [output_assembly_file]" % sys.argv[0]) |
| 12 |
| 13 input_file = sys.argv[1] |
| 14 n = input_file.find(".dat") |
| 15 if n == -1: |
| 16 sys.exit("%s is not an ICU .dat file." % input_file) |
| 17 |
| 18 if len(sys.argv) < 3: |
| 19 output_file = input_file[0:n] + "_dat.S" |
| 20 else: |
| 21 output_file = sys.argv[2] |
| 22 |
| 23 if input_file.find("l.dat") == -1: |
| 24 if input_file.find("b.dat") == -1: |
| 25 sys.exit("%s has no endianness marker." % input_file) |
| 26 else: |
| 27 step = 1 |
| 28 else: |
| 29 step = -1 |
| 30 |
| 31 input_data = open(input_file, 'rb').read() |
| 32 n = input_data.find("icudt") |
| 33 if n == -1: |
| 34 sys.exit("Cannot find a version number in %s." % input_file) |
| 35 |
| 36 version_number = input_data[n + 5:n + 7] |
| 37 |
| 38 output = open(output_file, 'w') |
| 39 output.write(".globl icudt" + version_number + "_dat\n" |
| 40 "\t.section .note.GNU-stack,\"\",%progbits\n" |
| 41 "\t.section .rodata\n" |
| 42 "\t.balign 16\n" |
| 43 "#ifdef U_HIDE_DATA_SYMBOL\n" |
| 44 "\t.hidden icudt" + version_number + "_dat\n" |
| 45 "#endif\n" |
| 46 "\t.type icudt" + version_number + "_dat,%object\n" |
| 47 "icudt" + version_number + "_dat:\n") |
| 48 |
| 49 split = [binascii.hexlify(input_data[i:i + 4][::step]).upper().lstrip('0') |
| 50 for i in range(0, len(input_data), 4)] |
| 51 |
| 52 for i in range(len(split)): |
| 53 if (len(split[i]) == 0): |
| 54 value = '0' |
| 55 elif (len(split[i]) == 1): |
| 56 if not any((c in '123456789') for c in split[i]): |
| 57 value = '0x0' + split[i] |
| 58 else: |
| 59 value = split[i] |
| 60 elif (len(split[i]) % 2 == 1): |
| 61 value = '0x0' + split[i] |
| 62 else: |
| 63 value = '0x' + split[i] |
| 64 |
| 65 if (i % 32 == 0): |
| 66 output.write("\n.long ") |
| 67 else: |
| 68 output.write(",") |
| 69 output.write(value) |
| 70 |
| 71 output.write("\n") |
| 72 output.close() |
| 73 print "Generated " + output_file |
OLD | NEW |