Chromium Code Reviews| OLD | NEW | 
|---|---|
| (Empty) | |
| 1 #!/usr/bin/env python | |
| 
 
jungshik at Google
2016/05/17 18:09:52
Add these 3 lines after the 1st line. 
# Copyrigh
 
 | |
| 2 | |
| 3 import binascii | |
| 4 import sys | |
| 5 | |
| 6 if len(sys.argv)<2: | |
| 
 
jungshik at Google
2016/05/17 18:09:52
nit: Please, use spaces around a binary operator (
 
 | |
| 7 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
 
 | |
| 8 | |
| 9 input_file = sys.argv[1] | |
| 10 n = input_file.find(".dat") | |
| 11 if n==-1: | |
| 12 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
 
 | |
| 13 | |
| 14 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
 
 | |
| 15 | |
| 16 input = open(input_file, 'rb').read() | |
| 17 n = input.find("icudt") | |
| 18 if n==-1: | |
| 19 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
 
 | |
| 20 | |
| 21 version_number = input[n+5:n+7] | |
| 22 output = open(output_file, 'w') | |
| 23 | |
| 24 output.write(".globl icudt" + version_number + "_dat\n" | |
| 25 "\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
 
 | |
| 26 "\t.section .rodata\n" | |
| 27 "\t.balign 16\n" | |
| 28 "#ifdef U_HIDE_DATA_SYMBOL\n" | |
| 29 "\t.hidden icudt" + version_number + "_dat\n" | |
| 30 "#endif\n" | |
| 31 "\t.type icudt" + version_number + "_dat,%object\n" | |
| 32 "icudt" + version_number + "_dat:\n") | |
| 33 | |
| 34 split = [binascii.hexlify(input[i:i+4]).upper().lstrip('0') for i in range(0, le n(input), 4)] | |
| 
 
jungshik at Google
2016/05/17 17:51:58
nit: each line has to be 80 chars or fewer. 
spli
 
 | |
| 35 | |
| 36 for i in range(len(split)): | |
| 37 if (len(split[i])==0): | |
| 38 value='0' | |
| 39 elif (len(split[i])==1): | |
| 40 if not any((c in '123456789') for c in split[i]): | |
| 41 value='0x0'+split[i] | |
| 42 else: | |
| 43 value=split[i] | |
| 44 elif (len(split[i])%2==1): | |
| 45 value='0x0'+split[i] | |
| 46 else: | |
| 47 value='0x'+split[i] | |
| 48 | |
| 49 if (i%32==0): | |
| 50 output.write("\n.long ") | |
| 51 else: | |
| 52 output.write(",") | |
| 53 output.write(value) | |
| 54 | |
| 55 output.write("\n") | |
| 56 output.close() | |
| 57 print "Generated " + output_file | |
| OLD | NEW |