1#!/usr/bin/python
2# convert LLVM GenSystemOperands.inc of AArch64 for Capstone disassembler.
3# by Nguyen Anh Quynh, 2019
4
5import sys
6
7if len(sys.argv) == 1:
8    print("Syntax: %s <GenSystemOperands.inc> <GenSystemOperands.inc> <GenSystemOperands_enum.inc>" %sys.argv[0])
9    sys.exit(1)
10
11f = open(sys.argv[1])
12lines = f.readlines()
13f.close()
14
15f1 = open(sys.argv[2], 'w+')
16
17f2 = open(sys.argv[3], 'w+')
18
19f1.write("/* Capstone Disassembly Engine, http://www.capstone-engine.org */\n")
20f1.write("/* By Nguyen Anh Quynh <aquynh@gmail.com>, 2013-2019 */\n")
21f1.write("\n")
22
23f2.write("/* Capstone Disassembly Engine, http://www.capstone-engine.org */\n")
24f2.write("/* By Nguyen Anh Quynh <aquynh@gmail.com>, 2013-2019 */\n")
25f2.write("\n")
26
27# extract PStateValues enum
28count = 0
29for line in lines:
30    line = line.rstrip()
31
32    if len(line.strip()) == 0:
33        continue
34
35    if line.strip() == 'enum PStateValues {':
36        count += 1
37        f2.write(line.strip() + "\n")
38        continue
39
40    line = line.strip()
41    if count == 1:
42        if line == '};':
43            # done with first enum
44            f2.write(line + "\n")
45            f2.write("\n")
46            break
47        else:
48            # skip pseudo instructions
49            f2.write("  AArch64PState_%s\n" %(line))
50
51def print_line(line):
52    f1.write(line + "\n")
53
54# extract ExactFPImmValues enum
55count = 0
56for line in lines:
57    line = line.rstrip()
58
59    if len(line.strip()) == 0:
60        continue
61
62    if line.strip() == 'enum ExactFPImmValues {':
63        count += 1
64        f2.write(line.strip() + "\n")
65        continue
66
67    line = line.strip()
68    if count == 1:
69        if line == '};':
70            # done with first enum
71            f2.write(line + "\n")
72            f2.write("\n")
73            break
74        else:
75            # skip pseudo instructions
76            f2.write("  AArch64ExactFPImm_%s\n" %(line))
77
78# extract ATsList[]
79count = 0
80c = 0
81for line in lines:
82    line = line.rstrip()
83
84    if len(line.strip()) == 0:
85        continue
86
87    if line.strip() == 'const AT ATsList[] = {':
88        count += 1
89        print_line('static const AT ATsList[] = {')
90        continue
91
92    line = line.strip()
93    if count == 1:
94        if line == '};':
95            # done with first enum
96            print_line('};\n')
97            break
98        else:
99            # skip pseudo instructions
100            line = line.replace('::', '_')
101            #line = line.replace('{}', '{ 0 }')
102            line = line.replace('{}', '')
103            tmp = line.split(',')
104            print_line("  %s, %s }, // %u" %(tmp[0].lower(), tmp[1], c))
105            c += 1
106
107# lookupATByEncoding
108count = 0
109for line in lines:
110    line = line.rstrip()
111
112    if len(line.strip()) == 0:
113        continue
114
115    if 'lookupATByEncoding' in line and '{' in line:
116        count += 1
117        print_line('const AT *lookupATByEncoding(uint16_t Encoding)\n{')
118        print_line('  unsigned int i;')
119        continue
120
121    if count == 1 and 'IndexType Index[] = {' in line:
122        count += 1
123
124    if count == 2:
125        if line.strip() == '};':
126            # done with array, or this function?
127            print_line(line)
128            break
129        else:
130            # enum items
131            print_line(line)
132
133print_line("""
134  i = binsearch_IndexTypeEncoding(Index, ARR_SIZE(Index), Encoding);
135  if (i == -1)
136    return NULL;
137  else
138    return &ATsList[Index[i].index];
139}
140""")
141
142
143# extract DBsList[]
144count = 0
145for line in lines:
146    line = line.rstrip()
147
148    if len(line.strip()) == 0:
149        continue
150
151    if line.strip() == 'const DB DBsList[] = {':
152        count += 1
153        print_line('static const DB DBsList[] = {')
154        continue
155
156    line = line.strip()
157    if count == 1:
158        if line == '};':
159            # done with first enum
160            print_line('};\n')
161            break
162        else:
163            # skip pseudo instructions
164            line = line.replace('::', '_')
165            #line = line.replace('{}', '{ 0 }')
166            line = line.replace('{}', '')
167            print_line("  %s" %(line))
168
169# lookupDBByEncoding
170count = 0
171for line in lines:
172    line = line.rstrip()
173
174    if len(line.strip()) == 0:
175        continue
176
177    if 'lookupDBByEncoding' in line and '{' in line:
178        count += 1
179        print_line('const DB *lookupDBByEncoding(uint16_t Encoding)\n{')
180        print_line('  unsigned int i;')
181        continue
182
183    if count == 1 and 'IndexType Index[] = {' in line:
184        count += 1
185
186    if count == 2:
187        if line.strip() == '};':
188            # done with array, or this function?
189            print_line(line)
190            break
191        else:
192            # enum items
193            print_line(line)
194
195print_line("""
196  i = binsearch_IndexTypeEncoding(Index, ARR_SIZE(Index), Encoding);
197  if (i == -1)
198    return NULL;
199  else
200    return &DBsList[Index[i].index];
201}
202""")
203
204
205# extract DCsList[]
206count = 0
207c = 0
208for line in lines:
209    line = line.rstrip()
210
211    if len(line.strip()) == 0:
212        continue
213
214    if line.strip() == 'const DC DCsList[] = {':
215        count += 1
216        print_line('static const DC DCsList[] = {')
217        continue
218
219    line = line.strip()
220    if count == 1:
221        if line == '};':
222            # done with first enum
223            print_line('};\n')
224            break
225        else:
226            # skip pseudo instructions
227            line = line.replace('::', '_')
228            #line = line.replace('{}', '{ 0 }')
229            line = line.replace('{}', '')
230            tmp = line.split(',')
231            print_line("  %s, %s }, // %u" %(tmp[0].lower(), tmp[1], c))
232            c += 1
233
234# lookupDCByEncoding
235count = 0
236for line in lines:
237    line = line.rstrip()
238
239    if len(line.strip()) == 0:
240        continue
241
242    if 'lookupDCByEncoding' in line and '{' in line:
243        count += 1
244        print_line('const DC *lookupDCByEncoding(uint16_t Encoding)\n{')
245        print_line('  unsigned int i;')
246        continue
247
248    if count == 1 and 'IndexType Index[] = {' in line:
249        count += 1
250
251    if count == 2:
252        if line.strip() == '};':
253            # done with array, or this function?
254            print_line(line)
255            break
256        else:
257            # enum items
258            print_line(line)
259
260print_line("""
261  i = binsearch_IndexTypeEncoding(Index, ARR_SIZE(Index), Encoding);
262  if (i == -1)
263    return NULL;
264  else
265    return &DCsList[Index[i].index];
266}
267""")
268
269
270# extract ICsList
271count = 0
272c = 0
273for line in lines:
274    line = line.rstrip()
275
276    if len(line.strip()) == 0:
277        continue
278
279    if line.strip() == 'const IC ICsList[] = {':
280        count += 1
281        print_line('static const IC ICsList[] = {')
282        continue
283
284    line = line.strip()
285    if count == 1:
286        if line == '};':
287            # done with first enum
288            print_line('};\n')
289            break
290        else:
291            # skip pseudo instructions
292            line = line.replace('::', '_')
293            #line = line.replace('{}', '{ 0 }')
294            line = line.replace('{}', '')
295            #tmp = line.split(',')
296            #print_line("  %s, %s }, // %u" %(tmp[0].lower(), tmp[1], c))
297            print_line("  %s" %line.lower())
298            c += 1
299
300# lookupICByEncoding
301count = 0
302for line in lines:
303    line = line.rstrip()
304
305    if len(line.strip()) == 0:
306        continue
307
308    if 'lookupICByEncoding' in line and '{' in line:
309        count += 1
310        print_line('const IC *lookupICByEncoding(uint16_t Encoding)\n{')
311        print_line('  unsigned int i;')
312        continue
313
314    if count == 1 and 'IndexType Index[] = {' in line:
315        count += 1
316
317    if count == 2:
318        if line.strip() == '};':
319            # done with array, or this function?
320            print_line(line)
321            break
322        else:
323            # enum items
324            print_line(line)
325
326print_line("""
327  i = binsearch_IndexTypeEncoding(Index, ARR_SIZE(Index), Encoding);
328  if (i == -1)
329    return NULL;
330  else
331    return &ICsList[Index[i].index];
332}
333""")
334
335
336# extract TLBIsList
337count = 0
338c = 0
339for line in lines:
340    line = line.rstrip()
341
342    if len(line.strip()) == 0:
343        continue
344
345    if line.strip() == 'const TLBI TLBIsList[] = {':
346        count += 1
347        print_line('static const TLBI TLBIsList[] = {')
348        continue
349
350    line = line.strip()
351    if count == 1:
352        if line == '};':
353            # done with first enum
354            print_line('};\n')
355            break
356        else:
357            # skip pseudo instructions
358            line = line.replace('::', '_')
359            #line = line.replace('{}', '{ 0 }')
360            line = line.replace('{}', '')
361            tmp = line.split(',')
362            print_line("  %s, %s, %s }, // %u" %(tmp[0].lower(), tmp[1], tmp[2], c))
363            #print_line("  %s" %line.lower())
364            c += 1
365
366# lookupTLBIByEncoding
367count = 0
368for line in lines:
369    line = line.rstrip()
370
371    if len(line.strip()) == 0:
372        continue
373
374    if 'lookupTLBIByEncoding' in line and '{' in line:
375        count += 1
376        print_line('const TLBI *lookupTLBIByEncoding(uint16_t Encoding)\n{')
377        print_line('  unsigned int i;')
378        continue
379
380    if count == 1 and 'IndexType Index[] = {' in line:
381        count += 1
382
383    if count == 2:
384        if line.strip() == '};':
385            # done with array, or this function?
386            print_line(line)
387            break
388        else:
389            # enum items
390            print_line(line)
391
392print_line("""
393  i = binsearch_IndexTypeEncoding(Index, ARR_SIZE(Index), Encoding);
394  if (i == -1)
395    return NULL;
396  else
397    return &TLBIsList[Index[i].index];
398}
399""")
400
401# extract SVEPRFMsList
402count = 0
403c = 0
404for line in lines:
405    line = line.rstrip()
406
407    if len(line.strip()) == 0:
408        continue
409
410    if line.strip() == 'const SVEPRFM SVEPRFMsList[] = {':
411        count += 1
412        print_line('static const SVEPRFM SVEPRFMsList[] = {')
413        continue
414
415    line = line.strip()
416    if count == 1:
417        if line == '};':
418            # done with first enum
419            print_line('};\n')
420            break
421        else:
422            # skip pseudo instructions
423            line = line.replace('::', '_')
424            #line = line.replace('{}', '{ 0 }')
425            line = line.replace('{}', '')
426            tmp = line.split(',')
427            print_line("  %s, %s }, // %u" %(tmp[0].lower(), tmp[1], c))
428            #print_line("  %s" %line.lower())
429            c += 1
430
431# lookupSVEPRFMByEncoding
432count = 0
433for line in lines:
434    line = line.rstrip()
435
436    if len(line.strip()) == 0:
437        continue
438
439    if 'lookupSVEPRFMByEncoding' in line and '{' in line:
440        count += 1
441        print_line('const SVEPRFM *lookupSVEPRFMByEncoding(uint16_t Encoding)\n{')
442        print_line('  unsigned int i;')
443        continue
444
445    if count == 1 and 'IndexType Index[] = {' in line:
446        count += 1
447
448    if count == 2:
449        if line.strip() == '};':
450            # done with array, or this function?
451            print_line(line)
452            break
453        else:
454            # enum items
455            print_line(line)
456
457print_line("""
458  i = binsearch_IndexTypeEncoding(Index, ARR_SIZE(Index), Encoding);
459  if (i == -1)
460    return NULL;
461  else
462    return &SVEPRFMsList[Index[i].index];
463}
464""")
465
466
467# extract PRFMsList
468count = 0
469c = 0
470for line in lines:
471    line = line.rstrip()
472
473    if len(line.strip()) == 0:
474        continue
475
476    if line.strip() == 'const PRFM PRFMsList[] = {':
477        count += 1
478        print_line('static const PRFM PRFMsList[] = {')
479        continue
480
481    line = line.strip()
482    if count == 1:
483        if line == '};':
484            # done with first enum
485            print_line('};\n')
486            break
487        else:
488            # skip pseudo instructions
489            line = line.replace('::', '_')
490            #line = line.replace('{}', '{ 0 }')
491            line = line.replace('{}', '')
492            #tmp = line.split(',')
493            #print_line("  %s, %s }, // %u" %(tmp[0].lower(), tmp[1], c))
494            print_line("  %s" %line.lower())
495            c += 1
496
497# lookupPRFMByEncoding
498count = 0
499for line in lines:
500    line = line.rstrip()
501
502    if len(line.strip()) == 0:
503        continue
504
505    if 'lookupPRFMByEncoding' in line and '{' in line:
506        count += 1
507        print_line('const PRFM *lookupPRFMByEncoding(uint16_t Encoding)\n{')
508        print_line('  unsigned int i;')
509        continue
510
511    if count == 1 and 'IndexType Index[] = {' in line:
512        count += 1
513
514    if count == 2:
515        if line.strip() == '};':
516            # done with array, or this function?
517            print_line(line)
518            break
519        else:
520            # enum items
521            print_line(line)
522
523print_line("""
524  i = binsearch_IndexTypeEncoding(Index, ARR_SIZE(Index), Encoding);
525  if (i == -1)
526    return NULL;
527  else
528    return &PRFMsList[Index[i].index];
529}
530""")
531
532
533# extract PSBsList
534count = 0
535c = 0
536for line in lines:
537    line = line.rstrip()
538
539    if len(line.strip()) == 0:
540        continue
541
542    if line.strip() == 'const PSB PSBsList[] = {':
543        count += 1
544        print_line('static const PSB PSBsList[] = {')
545        continue
546
547    line = line.strip()
548    if count == 1:
549        if line == '};':
550            # done with first enum
551            print_line('};\n')
552            break
553        else:
554            # skip pseudo instructions
555            line = line.replace('::', '_')
556            #line = line.replace('{}', '{ 0 }')
557            line = line.replace('{}', '')
558            #tmp = line.split(',')
559            #print_line("  %s, %s }, // %u" %(tmp[0].lower(), tmp[1], c))
560            print_line("  %s" %line.lower())
561            c += 1
562
563# lookupPSBByEncoding
564count = 0
565for line in lines:
566    line = line.rstrip()
567
568    if len(line.strip()) == 0:
569        continue
570
571    if 'lookupPSBByEncoding' in line and '{' in line:
572        count += 1
573        print_line('const PSB *AArch64PSBHint_lookupPSBByEncoding(uint16_t Encoding)\n{')
574        print_line('  unsigned int i;')
575        continue
576
577    if count == 1 and 'IndexType Index[] = {' in line:
578        count += 1
579
580    if count == 2:
581        if line.strip() == '};':
582            # done with array, or this function?
583            print_line(line)
584            break
585        else:
586            # enum items
587            print_line(line)
588
589print_line("""
590  i = binsearch_IndexTypeEncoding(Index, ARR_SIZE(Index), Encoding);
591  if (i == -1)
592    return NULL;
593  else
594    return &PSBsList[Index[i].index];
595}
596""")
597
598
599# extract ISBsList
600count = 0
601c = 0
602for line in lines:
603    line = line.rstrip()
604
605    if len(line.strip()) == 0:
606        continue
607
608    if line.strip() == 'const ISB ISBsList[] = {':
609        count += 1
610        print_line('static const ISB ISBsList[] = {')
611        continue
612
613    line = line.strip()
614    if count == 1:
615        if line == '};':
616            # done with first enum
617            print_line('};\n')
618            break
619        else:
620            # skip pseudo instructions
621            line = line.replace('::', '_')
622            #line = line.replace('{}', '{ 0 }')
623            line = line.replace('{}', '')
624            #tmp = line.split(',')
625            #print_line("  %s, %s }, // %u" %(tmp[0].lower(), tmp[1], c))
626            print_line("  %s" %line.lower())
627            c += 1
628
629# lookupISBByName
630count = 0
631for line in lines:
632    line = line.rstrip()
633
634    if len(line.strip()) == 0:
635        continue
636
637    if 'lookupISBByEncoding' in line and '{' in line:
638        count += 1
639        print_line('const ISB *lookupISBByEncoding(uint16_t Encoding)\n{')
640        print_line('  unsigned int i;')
641        continue
642
643    if count == 1 and 'IndexType Index[] = {' in line:
644        count += 1
645
646    if count == 2:
647        if line.strip() == '};':
648            # done with array, or this function?
649            print_line(line)
650            break
651        else:
652            # enum items
653            print_line(line)
654
655print_line("""
656  i = binsearch_IndexTypeEncoding(Index, ARR_SIZE(Index), Encoding);
657  if (i == -1)
658    return NULL;
659  else
660    return &ISBsList[Index[i].index];
661}
662""")
663
664
665# extract TSBsList
666count = 0
667c = 0
668for line in lines:
669    line = line.rstrip()
670
671    if len(line.strip()) == 0:
672        continue
673
674    if line.strip() == 'const TSB TSBsList[] = {':
675        count += 1
676        print_line('static const TSB TSBsList[] = {')
677        continue
678
679    line = line.strip()
680    if count == 1:
681        if line == '};':
682            # done with first enum
683            print_line('};\n')
684            break
685        else:
686            # skip pseudo instructions
687            line = line.replace('::', '_')
688            #line = line.replace('{}', '{ 0 }')
689            line = line.replace('{}', '')
690            tmp = line.split(',')
691            print_line("  %s, %s }, // %u" %(tmp[0].lower(), tmp[1], c))
692            #print_line("  %s" %line.lower())
693            c += 1
694
695# lookupTSBByEncoding
696count = 0
697for line in lines:
698    line = line.rstrip()
699
700    if len(line.strip()) == 0:
701        continue
702
703    if 'lookupTSBByEncoding' in line and '{' in line:
704        count += 1
705        print_line('const TSB *lookupTSBByEncoding(uint16_t Encoding)\n{')
706        continue
707
708    if count == 1 and 'IndexType Index[] = {' in line:
709        count += 1
710
711    if count == 2:
712        if line.strip() == '};':
713            # done with array, or this function?
714            print_line(line)
715            break
716        else:
717            # enum items
718            print_line(line)
719
720print_line("""
721  if (Encoding >= ARR_SIZE(TSBsList))
722    return NULL;
723  else
724    return &TSBsList[Index[Encoding].index];
725}
726""")
727
728
729# extract SysRegsList
730count = 0
731c = 0
732for line in lines:
733    line = line.rstrip()
734
735    if len(line.strip()) == 0:
736        continue
737
738    if line.strip() == 'const SysReg SysRegsList[] = {':
739        count += 1
740        print_line('static const SysReg SysRegsList[] = {')
741        continue
742
743    line = line.strip()
744    if count == 1:
745        if line == '};':
746            # done with first enum
747            print_line('};\n')
748            break
749        else:
750            # skip pseudo instructions
751            line = line.replace('::', '_')
752            #line = line.replace('{}', '{ 0 }')
753            line = line.replace('{}', '')
754            tmp = line.split(',')
755            print_line("  %s, %s, %s, %s }, // %u" %(tmp[0].lower(), tmp[1], tmp[2], tmp[3], c))
756            #print_line("  %s" %line.lower())
757            c += 1
758
759# lookupSysRegByEncoding
760count = 0
761for line in lines:
762    line = line.rstrip()
763
764    if len(line.strip()) == 0:
765        continue
766
767    if 'lookupSysRegByEncoding' in line and '{' in line:
768        count += 1
769        print_line('const SysReg *lookupSysRegByEncoding(uint16_t Encoding)\n{')
770        print_line('  unsigned int i;')
771        continue
772
773    if count == 1 and 'IndexType Index[] = {' in line:
774        count += 1
775
776    if count == 2:
777        if line.strip() == '};':
778            # done with array, or this function?
779            print_line(line)
780            break
781        else:
782            # enum items
783            print_line(line)
784
785print_line("""
786  i = binsearch_IndexTypeEncoding(Index, ARR_SIZE(Index), Encoding);
787  if (i == -1)
788    return NULL;
789  else
790    return &SysRegsList[Index[i].index];
791}
792""")
793
794# extract PStatesList
795count = 0
796c = 0
797for line in lines:
798    line = line.rstrip()
799
800    if len(line.strip()) == 0:
801        continue
802
803    if line.strip() == 'const PState PStatesList[] = {':
804        count += 1
805        print_line('static const PState PStatesList[] = {')
806        continue
807
808    line = line.strip()
809    if count == 1:
810        if line == '};':
811            # done with first enum
812            print_line('};\n')
813            break
814        else:
815            # skip pseudo instructions
816            line = line.replace('::', '_')
817            #line = line.replace('{}', '{ 0 }')
818            line = line.replace('{}', '')
819            tmp = line.split(',')
820            print_line("  %s, %s }, // %u" %(tmp[0].lower(), tmp[1], c))
821            #print_line("  %s" %line.lower())
822            c += 1
823
824# lookupPStateByEncoding
825count = 0
826for line in lines:
827    line = line.rstrip()
828
829    if len(line.strip()) == 0:
830        continue
831
832    if 'lookupPStateByEncoding' in line and '{' in line:
833        count += 1
834        print_line('const PState *lookupPStateByEncoding(uint16_t Encoding)\n{')
835        print_line('  unsigned int i;')
836        continue
837
838    if count == 1 and 'IndexType Index[] = {' in line:
839        count += 1
840
841    if count == 2:
842        if line.strip() == '};':
843            # done with array, or this function?
844            print_line(line)
845            break
846        else:
847            # enum items
848            print_line(line)
849
850print_line("""
851  i = binsearch_IndexTypeEncoding(Index, ARR_SIZE(Index), Encoding);
852  if (i == -1)
853    return NULL;
854  else
855    return &PStatesList[Index[i].index];
856}
857""")
858
859# extract SVEPREDPATsList
860count = 0
861c = 0
862for line in lines:
863    line = line.rstrip()
864
865    if len(line.strip()) == 0:
866        continue
867
868    if line.strip() == 'const SVEPREDPAT SVEPREDPATsList[] = {':
869        count += 1
870        print_line('static const SVEPREDPAT SVEPREDPATsList[] = {')
871        continue
872
873    line = line.strip()
874    if count == 1:
875        if line == '};':
876            # done with first enum
877            print_line('};\n')
878            break
879        else:
880            # skip pseudo instructions
881            line = line.replace('::', '_')
882            #line = line.replace('{}', '{ 0 }')
883            line = line.replace('{}', '')
884            tmp = line.split(',')
885            #print_line("  %s, %s }, // %u" %(tmp[0].lower(), tmp[1], c))
886            print_line("  %s" %line.lower())
887            c += 1
888
889# lookupSVEPREDPATByEncoding
890count = 0
891for line in lines:
892    line = line.rstrip()
893
894    if len(line.strip()) == 0:
895        continue
896
897    if 'lookupSVEPREDPATByEncoding' in line and '{' in line:
898        count += 1
899        print_line('const SVEPREDPAT *lookupSVEPREDPATByEncoding(uint16_t Encoding)\n{')
900        print_line('  unsigned int i;')
901        continue
902
903    if count == 1 and 'IndexType Index[] = {' in line:
904        count += 1
905
906    if count == 2:
907        if line.strip() == '};':
908            # done with array, or this function?
909            print_line(line)
910            break
911        else:
912            # enum items
913            print_line(line)
914
915print_line("""
916  i = binsearch_IndexTypeEncoding(Index, ARR_SIZE(Index), Encoding);
917  if (i == -1)
918    return NULL;
919  else
920    return &SVEPREDPATsList[Index[i].index];
921}
922""")
923
924
925# extract ExactFPImmsList
926count = 0
927c = 0
928for line in lines:
929    line = line.rstrip()
930
931    if len(line.strip()) == 0:
932        continue
933
934    if line.strip() == 'const ExactFPImm ExactFPImmsList[] = {':
935        count += 1
936        print_line('static const ExactFPImm ExactFPImmsList[] = {')
937        continue
938
939    line = line.strip()
940    if count == 1:
941        if line == '};':
942            # done with first enum
943            print_line('};\n')
944            break
945        else:
946            # skip pseudo instructions
947            line = line.replace('::', '_')
948            #line = line.replace('{}', '{ 0 }')
949            line = line.replace('{}', '')
950            tmp = line.split(',')
951            #print_line("  %s, %s }, // %u" %(tmp[0].lower(), tmp[1], c))
952            print_line("  %s" %line.lower())
953            c += 1
954
955# lookupExactFPImmByEnum
956count = 0
957for line in lines:
958    line = line.rstrip()
959
960    if len(line.strip()) == 0:
961        continue
962
963    if 'lookupExactFPImmByEnum' in line and '{' in line:
964        count += 1
965        print_line('const ExactFPImm *lookupExactFPImmByEnum(uint16_t Encoding)\n{')
966        continue
967
968    if count == 1 and 'IndexType Index[] = {' in line:
969        count += 1
970
971    if count == 2:
972        if line.strip() == '};':
973            # done with array, or this function?
974            print_line(line)
975            break
976        else:
977            # enum items
978            print_line(line)
979
980print_line("""
981  if (Encoding >= ARR_SIZE(ExactFPImmsList))
982    return NULL;
983  else
984    return &ExactFPImmsList[Index[Encoding].index];
985}
986""")
987
988