Debian Codegraph @

suite/synctools/systemoperand.py

raw symbols SCIP
1 #!/usr/bin/python
2 # convert LLVM GenSystemOperands.inc of AArch64 for Capstone disassembler.
3 # by Nguyen Anh Quynh, 2019
4
5 import sys
6
7 if len(sys.argv) == 1:
8 print("Syntax: %s <GenSystemOperands.inc> <GenSystemOperands.inc> <GenSystemOperands_enum.inc>" %sys.argv[0])
9 sys.exit(1)
10
11 f = open(sys.argv[1])
12 lines = f.readlines()
13 f.close()
14
15 f1 = open(sys.argv[2], 'w+')
16
17 f2 = open(sys.argv[3], 'w+')
18
19 f1.write("/* Capstone Disassembly Engine, http://www.capstone-engine.org */\n")
20 f1.write("/* By Nguyen Anh Quynh <[email protected]>, 2013-2019 */\n")
21 f1.write("\n")
22
23 f2.write("/* Capstone Disassembly Engine, http://www.capstone-engine.org */\n")
24 f2.write("/* By Nguyen Anh Quynh <[email protected]>, 2013-2019 */\n")
25 f2.write("\n")
26
27 # extract PStateValues enum
28 count = 0
29 for 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
51 def print_line(line):
52 f1.write(line + "\n")
53
54 # extract ExactFPImmValues enum
55 count = 0
56 for 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[]
79 count = 0
80 c = 0
81 for line in lines:
82 line = line.rstrip()
83
84 if len(line.strip()) == 0:
85 continue
86
87 if line.strip() == 'constexpr 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
108 count = 0
109 for 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
133 print_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[]
144 count = 0
145 for line in lines:
146 line = line.rstrip()
147
148 if len(line.strip()) == 0:
149 continue
150
151 if line.strip() == 'constexpr 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
170 count = 0
171 for 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
195 print_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[]
206 count = 0
207 c = 0
208 for line in lines:
209 line = line.rstrip()
210
211 if len(line.strip()) == 0:
212 continue
213
214 if line.strip() == 'constexpr 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
235 count = 0
236 for 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
260 print_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
271 count = 0
272 c = 0
273 for line in lines:
274 line = line.rstrip()
275
276 if len(line.strip()) == 0:
277 continue
278
279 if line.strip() == 'constexpr 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
301 count = 0
302 for 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
326 print_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
337 count = 0
338 c = 0
339 for line in lines:
340 line = line.rstrip()
341
342 if len(line.strip()) == 0:
343 continue
344
345 if line.strip() == 'constexpr TLBI TLBITable[] = {':
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
367 count = 0
368 for 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
392 print_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
402 count = 0
403 c = 0
404 for line in lines:
405 line = line.rstrip()
406
407 if len(line.strip()) == 0:
408 continue
409
410 if line.strip() == 'constexpr 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
432 count = 0
433 for 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
457 print_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
468 count = 0
469 c = 0
470 for line in lines:
471 line = line.rstrip()
472
473 if len(line.strip()) == 0:
474 continue
475
476 if line.strip() == 'constexpr 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
498 count = 0
499 for 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
523 print_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
534 count = 0
535 c = 0
536 for line in lines:
537 line = line.rstrip()
538
539 if len(line.strip()) == 0:
540 continue
541
542 if line.strip() == 'constexpr 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
564 count = 0
565 for 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 *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
589 print_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
600 count = 0
601 c = 0
602 for line in lines:
603 line = line.rstrip()
604
605 if len(line.strip()) == 0:
606 continue
607
608 if line.strip() == 'constexpr 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
630 count = 0
631 for 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
655 print_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
666 count = 0
667 c = 0
668 for line in lines:
669 line = line.rstrip()
670
671 if len(line.strip()) == 0:
672 continue
673
674 if line.strip() == 'constexpr 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
696 count = 0
697 for 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
720 print_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
730 count = 0
731 c = 0
732 for line in lines:
733 line = line.rstrip()
734
735 if len(line.strip()) == 0:
736 continue
737
738 if line.strip() == 'constexpr 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[2], tmp[3], tmp[4], c))
756 #print_line(" %s" %line.lower())
757 c += 1
758
759 # lookupSysRegByEncoding
760 count = 0
761 for 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
785 print_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
795 count = 0
796 c = 0
797 for line in lines:
798 line = line.rstrip()
799
800 if len(line.strip()) == 0:
801 continue
802
803 if line.strip() == 'constexpr 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
825 count = 0
826 for 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
850 print_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
860 count = 0
861 c = 0
862 for line in lines:
863 line = line.rstrip()
864
865 if len(line.strip()) == 0:
866 continue
867
868 if line.strip() == 'constexpr 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
890 count = 0
891 for 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
915 print_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 # extract SVCRsList
925 count = 0
926 c = 0
927 for line in lines:
928 line = line.rstrip()
929
930 if len(line.strip()) == 0:
931 continue
932
933 if line.strip() == 'constexpr SVCR SVCRsList[] = {':
934 count += 1
935 print_line('static const SVCR SVCRsList[] = {')
936 continue
937
938 line = line.strip()
939 if count == 1:
940 if line == '};':
941 # done with first enum
942 print_line('};\n')
943 break
944 else:
945 # skip pseudo instructions
946 line = line.replace('::', '_')
947 #line = line.replace('{}', '{ 0 }')
948 line = line.replace('{}', '')
949 tmp = line.split(',')
950 print_line(" %s, %s }, // %u" %(tmp[0].lower(), tmp[1], c))
951 c += 1
952
953 # lookupSVCRByEncoding
954 count = 0
955 for line in lines:
956 line = line.rstrip()
957
958 if len(line.strip()) == 0:
959 continue
960
961 if 'lookupSVCRByEncoding' in line and '{' in line:
962 count += 1
963 print_line('const SVCR *lookupSVCRByEncoding(uint8_t Encoding)\n{')
964 print_line(' unsigned int i;')
965 continue
966
967 if count == 1 and 'IndexType Index[] = {' in line:
968 count += 1
969
970 if count == 2:
971 if line.strip() == '};':
972 # done with array, or this function?
973 print_line(line)
974 break
975 else:
976 # enum items
977 print_line(line)
978
979 print_line("""
980 i = binsearch_IndexTypeEncoding(Index, ARR_SIZE(Index), Encoding);
981 if (i == -1)
982 return NULL;
983 else
984 return &SVCRsList[Index[i].index];
985 }
986 """)
987
988 # extract BTIsList
989 count = 0
990 c = 0
991 for line in lines:
992 line = line.rstrip()
993
994 if len(line.strip()) == 0:
995 continue
996
997 if line.strip() == 'constexpr BTI BTIsList[] = {':
998 count += 1
999 print_line('static const BTI BTIsList[] = {')
1000 continue
1001
1002 line = line.strip()
1003 if count == 1:
1004 if line == '};':
1005 # done with first enum
1006 print_line('};\n')
1007 break
1008 else:
1009 # skip pseudo instructions
1010 line = line.replace('::', '_')
1011 #line = line.replace('{}', '{ 0 }')
1012 line = line.replace('{}', '')
1013 tmp = line.split(',')
1014 print_line(" %s, %s, // %u" %(tmp[0].lower(), tmp[1], c))
1015 c += 1
1016
1017 # lookupBTIByEncoding
1018 count = 0
1019 for line in lines:
1020 line = line.rstrip()
1021
1022 if len(line.strip()) == 0:
1023 continue
1024
1025 if 'lookupBTIByEncoding' in line and '{' in line:
1026 count += 1
1027 print_line('const BTI *lookupBTIByEncoding(uint8_t Encoding)\n{')
1028 print_line(' unsigned int i;')
1029 continue
1030
1031 if count == 1 and 'IndexType Index[] = {' in line:
1032 count += 1
1033
1034 if count == 2:
1035 if line.strip() == '};':
1036 # done with array, or this function?
1037 print_line(line)
1038 break
1039 else:
1040 # enum items
1041 print_line(line)
1042
1043 print_line("""
1044 i = binsearch_IndexTypeEncoding(Index, ARR_SIZE(Index), Encoding);
1045 if (i == -1)
1046 return NULL;
1047 else
1048 return &BTIsList[Index[i].index];
1049 }
1050 """)
1051
1052
1053 # extract DBnXSsList
1054 count = 0
1055 c = 0
1056 for line in lines:
1057 line = line.rstrip()
1058
1059 if len(line.strip()) == 0:
1060 continue
1061
1062 if line.strip() == 'constexpr DBnXS DBnXSsList[] = {':
1063 count += 1
1064 print_line('static const DBnXS DBnXSsList[] = {')
1065 continue
1066
1067 line = line.strip()
1068 if count == 1:
1069 if line == '};':
1070 # done with first enum
1071 print_line('};\n')
1072 break
1073 else:
1074 # skip pseudo instructions
1075 line = line.replace('::', '_')
1076 #line = line.replace('{}', '{ 0 }')
1077 line = line.replace('{}', '')
1078 tmp = line.split(',')
1079 print_line(" %s, %s, %s}, // %u" %(tmp[0].lower(), tmp[1], tmp[2], c))
1080 c += 1
1081
1082 # lookupDBnXSByEncoding
1083 count = 0
1084 for line in lines:
1085 line = line.rstrip()
1086
1087 if len(line.strip()) == 0:
1088 continue
1089
1090 if 'lookupDBnXSByEncoding' in line and '{' in line:
1091 count += 1
1092 print_line('const DBnXS *lookupDBnXSByEncoding(uint8_t Encoding)\n{')
1093 print_line(' unsigned int i;')
1094 continue
1095
1096 if count == 1 and 'IndexType Index[] = {' in line:
1097 count += 1
1098
1099 if count == 2:
1100 if line.strip() == '};':
1101 # done with array, or this function?
1102 print_line(line)
1103 break
1104 else:
1105 # enum items
1106 print_line(line)
1107
1108 print_line("""
1109 i = binsearch_IndexTypeEncoding(Index, ARR_SIZE(Index), Encoding);
1110 if (i == -1)
1111 return NULL;
1112 else
1113 return &DBnXSsList[Index[i].index];
1114 }
1115 """)
1116
1117 # extract ExactFPImmsList
1118 count = 0
1119 c = 0
1120 for line in lines:
1121 line = line.rstrip()
1122
1123 if len(line.strip()) == 0:
1124 continue
1125
1126 if line.strip() == 'constexpr ExactFPImm ExactFPImmsList[] = {':
1127 count += 1
1128 print_line('static const ExactFPImm ExactFPImmsList[] = {')
1129 continue
1130
1131 line = line.strip()
1132 if count == 1:
1133 if line == '};':
1134 # done with first enum
1135 print_line('};\n')
1136 break
1137 else:
1138 # skip pseudo instructions
1139 line = line.replace('::', '_')
1140 #line = line.replace('{}', '{ 0 }')
1141 line = line.replace('{}', '')
1142 tmp = line.split(',')
1143 #print_line(" %s, %s }, // %u" %(tmp[0].lower(), tmp[1], c))
1144 print_line(" %s" %line.lower())
1145 c += 1
1146
1147 # lookupExactFPImmByEnum
1148 count = 0
1149 for line in lines:
1150 line = line.rstrip()
1151
1152 if len(line.strip()) == 0:
1153 continue
1154
1155 if 'lookupExactFPImmByEnum' in line and '{' in line:
1156 count += 1
1157 print_line('const ExactFPImm *lookupExactFPImmByEnum(uint16_t Encoding)\n{')
1158 continue
1159
1160 if count == 1 and 'IndexType Index[] = {' in line:
1161 count += 1
1162
1163 if count == 2:
1164 if line.strip() == '};':
1165 # done with array, or this function?
1166 print_line(line)
1167 break
1168 else:
1169 # enum items
1170 print_line(line)
1171
1172 print_line("""
1173 if (Encoding >= ARR_SIZE(ExactFPImmsList))
1174 return NULL;
1175 else
1176 return &ExactFPImmsList[Index[Encoding].index];
1177 }
1178 """)
1179