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..fa95b943fbee28b93d0394ea2c1c61f12b378835 |
| --- /dev/null |
| +++ b/scripts/make_data_assembly.py |
| @@ -0,0 +1,57 @@ |
| +#!/usr/bin/env python |
| + |
| +import binascii |
| +import sys |
| + |
| +if len(sys.argv)<2: |
| + print "Provide input file name as argument to use the script!" |
|
jungshik at Google
2016/05/17 00:32:01
Instead of a series of nested 'if - else', please
|
| +else: |
| + input_file = sys.argv[1] |
| + n = input_file.find(".dat") |
| + if n==-1: |
| + print "Not a .dat file!" |
| + else: |
| + output_file = input_file[0:n] + "_dat.S" |
| + |
| + input = open(input_file, 'rb').read() |
| + n = input.find("icudt") |
| + if n==-1: |
| + print "Cannot find version number in the input file!" |
| + else: |
| + version_number = input[n+5:n+7] |
| + output = open(output_file, 'w') |
| + |
| + output.write(".globl icudt" + version_number + "_dat\n") |
| + output.write("\t.section .note.GNU-stack,\"\",%progbits\n") |
| + output.write("\t.section .rodata\n") |
| + output.write("\t.balign 16\n") |
| + output.write("#ifdef U_HIDE_DATA_SYMBOL\n") |
| + output.write("\t.hidden icudt" + version_number + "_dat\n") |
| + output.write("#endif\n") |
| + output.write("\t.type icudt" + version_number + "_dat,%object\n") |
| + output.write("icudt" + version_number + "_dat:\n") |
|
jungshik at Google
2016/05/17 00:32:01
How about just using a multiline string with a sin
|
| + |
| + split = [binascii.hexlify(input[i:i+4]).upper().lstrip('0') for i in range(0, len(input), 4)] |
| + |
| + 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 |