Chromium Code Reviews| Index: scripts/make_data_assembly.py |
| diff --git a/scripts/make_data_assembly.py b/scripts/make_data_assembly.py |
| new file mode 100755 |
| index 0000000000000000000000000000000000000000..65ca058d9a995e2fc61b1bd4f4b23db446bfae98 |
| --- /dev/null |
| +++ b/scripts/make_data_assembly.py |
| @@ -0,0 +1,57 @@ |
| +#!/usr/bin/env python |
|
jungshik at Google
2016/05/17 18:09:52
Add these 3 lines after the 1st line.
# Copyrigh
|
| + |
| +import binascii |
| +import sys |
| + |
| +if len(sys.argv)<2: |
|
jungshik at Google
2016/05/17 18:09:52
nit: Please, use spaces around a binary operator (
|
| + sys.exit("Provide input file name as argument to use the script!"); |
|
jungshik at Google
2016/05/17 17:51:59
nit: Chromium python style is to use 2-space inde
|
| + |
| +input_file = sys.argv[1] |
| +n = input_file.find(".dat") |
| +if n==-1: |
| + sys.exit("Not a .dat file!"); |
|
jungshik at Google
2016/05/17 17:51:58
sys.exit("%s is not a ICU .dat file." % input_file
|
| + |
| +output_file = input_file[0:n] + "_dat.S" |
|
jungshik at Google
2016/05/17 20:33:12
For use with gyp (automatic generation during a bu
|
| + |
| +input = open(input_file, 'rb').read() |
| +n = input.find("icudt") |
| +if n==-1: |
| + sys.exit("Cannot find version number in the input file!"); |
|
jungshik at Google
2016/05/17 17:51:58
sys.exit("Cannot find a version number in %s." % i
|
| + |
| +version_number = input[n+5:n+7] |
| +output = open(output_file, 'w') |
| + |
| +output.write(".globl icudt" + version_number + "_dat\n" |
| + "\t.section .note.GNU-stack,\"\",%progbits\n" |
|
jungshik at Google
2016/05/17 17:51:58
You can align this and other lines in the string w
|
| + "\t.section .rodata\n" |
| + "\t.balign 16\n" |
| + "#ifdef U_HIDE_DATA_SYMBOL\n" |
| + "\t.hidden icudt" + version_number + "_dat\n" |
| + "#endif\n" |
| + "\t.type icudt" + version_number + "_dat,%object\n" |
| + "icudt" + version_number + "_dat:\n") |
| + |
| +split = [binascii.hexlify(input[i:i+4]).upper().lstrip('0') for i in range(0, len(input), 4)] |
|
jungshik at Google
2016/05/17 17:51:58
nit: each line has to be 80 chars or fewer.
spli
|
| + |
| +for i in range(len(split)): |
| + if (len(split[i])==0): |
| + value='0' |
| + elif (len(split[i])==1): |
| + if not any((c in '123456789') for c in split[i]): |
| + value='0x0'+split[i] |
| + else: |
| + value=split[i] |
| + elif (len(split[i])%2==1): |
| + value='0x0'+split[i] |
| + else: |
| + value='0x'+split[i] |
| + |
| + if (i%32==0): |
| + output.write("\n.long ") |
| + else: |
| + output.write(",") |
| + output.write(value) |
| + |
| +output.write("\n") |
| +output.close() |
| +print "Generated " + output_file |