Updated synctool scripts to extract new functions and match type/formatting changes in LLVM 14.0.5 tablegen files.

- asmwriter.py : As well as new functions, recognition of new SME index printing was added. The printAliasInstr function also required a re-write to match its counter-part and changes in logic in LLVM 14.0.5
 - disassemblertables-arch.py : Minor type changes for some functions, as well as adding support for new SME decode functions.
 - mapping_insn-arch.py : Minor change to correct incorrect instruction aliasing in generated AArch64MappingInsn.inc etc.
 - registerinfo.py : minor change to reflect change in LLVM 14.0.5
 - systemoperand.py : corrected minor type changes made in LLVM 14.0.5 and added extraction of SVCR, BTI, DBnXS lists and encoding functions.
This commit is contained in:
Finn Wilkinson 2022-09-30 15:34:50 +01:00
parent 437a7fc469
commit 3ef5bb6b79
5 changed files with 365 additions and 34 deletions

View File

@ -138,6 +138,21 @@ for line in lines:
print_line("static void printInstruction(MCInst *MI, SStream *O)\n{") print_line("static void printInstruction(MCInst *MI, SStream *O)\n{")
else: else:
print_line("static void printInstruction(MCInst *MI, SStream *O)\n{") print_line("static void printInstruction(MCInst *MI, SStream *O)\n{")
elif 'LLVM_NO_PROFILE_INSTRUMENT_FUNCTION' in line:
continue
elif 'AArch64InstPrinter::getMnemonic' in line:
print_line("static uint64_t getMnemonic(MCInst *MI, SStream *O, unsigned int opcode) {")
elif 'return {AsmStrs+(Bits' in line:
tmp = line.split(',')
prntStr = tmp[0].split('{')[1]
print_line("\tSStream_concat0(O, " + prntStr + ");")
print_line("\treturn Bits;")
elif 'MnemonicInfo = getMnemonic(' in line:
continue
elif 'O << MnemonicInfo' in line:
continue
elif 'uint64_t Bits = MnemonicInfo' in line:
print_line("\tuint64_t Bits = getMnemonic(MI, O, opcode);")
elif 'const char *AArch64InstPrinter::' in line: elif 'const char *AArch64InstPrinter::' in line:
continue continue
elif 'getRegisterName(' in line: elif 'getRegisterName(' in line:
@ -164,6 +179,14 @@ for line in lines:
line2 = line.replace('STI.getFeatureBits()[', 'AArch64_getFeatureBits(') line2 = line.replace('STI.getFeatureBits()[', 'AArch64_getFeatureBits(')
line2 = line2.replace(']', ')') line2 = line2.replace(']', ')')
print_line(line2) print_line(line2)
elif 'lookupBTIByEncoding' in line:
line = line.replace('AArch64BTIHint::', '')
line = line.replace('MCOp.getImm()', 'MCOperand_getImm(MCOp)')
print_line(line)
elif 'lookupPSBByEncoding' in line:
line = line.replace('AArch64PSBHint::', '')
line = line.replace('MCOp.getImm()', 'MCOperand_getImm(MCOp)')
print_line(line)
elif ', STI, ' in line: elif ', STI, ' in line:
line2 = line.replace(', STI, ', ', ') line2 = line.replace(', STI, ', ', ')
@ -222,7 +245,7 @@ for line in lines:
line2 = line2.replace('printLogicalImm', 'printLogicalImm32') line2 = line2.replace('printLogicalImm', 'printLogicalImm32')
elif '64' in param: elif '64' in param:
line2 = line2.replace('printLogicalImm', 'printLogicalImm64') line2 = line2.replace('printLogicalImm', 'printLogicalImm64')
elif 'printSVERegOp' in line2 or 'printGPRSeqPairsClassOperand' in line2 or 'printTypedVectorList' in line2 or 'printPostIncOperand' in line2 or 'printImmScale' in line2 or 'printRegWithShiftExtend' in line2 or 'printUImm12Offset' in line2 or 'printExactFPImm' in line2 or 'printMemExtend' in line2 or 'printZPRasFPR' in line2: elif 'printSVERegOp' in line2 or 'printGPRSeqPairsClassOperand' in line2 or 'printTypedVectorList' in line2 or 'printPostIncOperand' in line2 or 'printImmScale' in line2 or 'printRegWithShiftExtend' in line2 or 'printUImm12Offset' in line2 or 'printExactFPImm' in line2 or 'printMemExtend' in line2 or 'printZPRasFPR' in line2 or 'printMatrixTileVector' in line2 or 'printMatrix<' in line2 or 'printSImm' in line2:
param = extract_brackets(line2) param = extract_brackets(line2)
if param == '': if param == '':
param = '0' param = '0'
@ -234,6 +257,8 @@ for line in lines:
bracket_content = line2[line2.index('<') + 1 : line2.index('>')] bracket_content = line2[line2.index('<') + 1 : line2.index('>')]
line2 = line2.replace('<' + bracket_content + '>', '') line2 = line2.replace('<' + bracket_content + '>', '')
line2 = line2.replace(' O);', ' O, %s);' %bracket_content) line2 = line2.replace(' O);', ' O, %s);' %bracket_content)
elif 'printAlignedLabel' in line2 or 'printAdrpLabel' in line2:
line2 = line2.replace('Address, ', '')
print_line(line2) print_line(line2)
elif "static const char AsmStrs[]" in line: elif "static const char AsmStrs[]" in line:
@ -286,12 +311,21 @@ for line in lines:
elif '", -1"' in line2: elif '", -1"' in line2:
print_line(' op_addImm(MI, -1);') print_line(' op_addImm(MI, -1);')
if '[' in line2: if '], [' in line2 or ']!, [' in line2:
print_line(' set_mem_access(MI, false);')
print_line(' set_mem_access(MI, true);')
elif "\"[\"" in line2:
# Check for SME_Index specific string of only "["
print_line(' set_sme_index(MI, true);')
elif '[' in line2:
if not '[]' in line2: if not '[]' in line2:
print_line(' set_mem_access(MI, true);') print_line(' set_mem_access(MI, true);')
if ']' in line2: elif ']' in line2:
if not '[]' in line2: if not '[]' in line2:
print_line(' set_mem_access(MI, false);') print_line(' set_mem_access(MI, false);')
@ -629,12 +663,100 @@ for line in lines:
elif 'switch (PredicateIndex) {' in line: elif 'switch (PredicateIndex) {' in line:
print_line(' int64_t Val;') print_line(' int64_t Val;')
print_line(line) print_line(line)
elif 'unsigned I = 0;' in line and in_printAliasInstr: elif 'uint32_t(' in line and in_printAliasInstr:
line = line.replace('uint32_t(', '')
line = line.replace(')', '')
print_line(line)
elif '#ifndef NDEBUG' in line and in_printAliasInstr:
print_line(""" print_line("""
char *AsmString;
const size_t OpToSize = sizeof(OpToPatterns) / sizeof(PatternsForOpcode);
const unsigned opcode = MCInst_getOpcode(MI);
// Check for alias
int OpToIndex = 0;
for(int i = 0; i < OpToSize; i++){
if(OpToPatterns[i].Opcode == opcode){
OpToIndex = i;
break;
}
}
// Chech for match
if(opcode != OpToPatterns[OpToIndex].Opcode)
return NULL;
const PatternsForOpcode opToPat = OpToPatterns[OpToIndex];
// Try all patterns for this opcode
uint32_t AsmStrOffset = ~0U;
int patIdx = opToPat.PatternStart;
while(patIdx < (opToPat.PatternStart + opToPat.NumPatterns)){
// Check operand count first
if(MCInst_getNumOperands(MI) != Patterns[patIdx].NumOperands)
return NULL;
// Test all conditions for this pattern
int condIdx = Patterns[patIdx].AliasCondStart;
int opIdx = 0;
bool allPass = true;
while(condIdx < (Patterns[patIdx].AliasCondStart + Patterns[patIdx].NumConds)){
MCOperand *opnd = MCInst_getOperand(MI, opIdx);
opIdx++;
// Not concerned with any Feature related conditions as STI is disregarded
switch (Conds[condIdx].Kind)
{
case AliasPatternCond_K_Ignore :
// Operand can be anything.
break;
case AliasPatternCond_K_Reg :
// Operand must be a specific register.
allPass = allPass && (MCOperand_isReg(opnd) && MCOperand_getReg(opnd) == Conds[condIdx].Value);
break;
case AliasPatternCond_K_TiedReg :
// Operand must match the register of another operand.
allPass = allPass && (MCOperand_isReg(opnd) && MCOperand_getReg(opnd) ==
MCOperand_getReg(MCInst_getOperand(MI, Conds[condIdx].Value)));
break;
case AliasPatternCond_K_Imm :
// Operand must be a specific immediate.
allPass = allPass && (MCOperand_isImm(opnd) && MCOperand_getImm(opnd) == Conds[condIdx].Value);
break;
case AliasPatternCond_K_RegClass :
// Operand must be a register in this class. Value is a register class id.
allPass = allPass && (MCOperand_isReg(opnd) && GETREGCLASS_CONTAIN(Conds[condIdx].Value, (opIdx-1)));
break;
case AliasPatternCond_K_Custom :
// Operand must match some custom criteria.
allPass = allPass && AArch64InstPrinterValidateMCOperand(opnd, Conds[condIdx].Value);
break;
case AliasPatternCond_K_Feature :
case AliasPatternCond_K_NegFeature :
case AliasPatternCond_K_OrFeature :
case AliasPatternCond_K_OrNegFeature :
case AliasPatternCond_K_EndOrFeatures :
default :
break;
}
condIdx++;
}
if(allPass){
AsmStrOffset = Patterns[patIdx].AsmStrOffset;
break;
}
patIdx++;
}
// If no alias matched, don't print an alias.
if (AsmStrOffset == ~0U)
return NULL;
AsmString = cs_strdup(&AsmStrings[AsmStrOffset]);
tmpString = cs_strdup(AsmString); tmpString = cs_strdup(AsmString);
while (AsmString[I] != ' ' && AsmString[I] != '\\t' && while (AsmString[I] != ' ' && AsmString[I] != '\\t' &&
AsmString[I] != '$' && AsmString[I] != '\\0') AsmString[I] != '$' && AsmString[I] != '\\0')
++I; ++I;
tmpString[I] = 0; tmpString[I] = 0;
@ -653,15 +775,20 @@ for line in lines:
++I; ++I;
OpIdx = AsmString[I++] - 1; OpIdx = AsmString[I++] - 1;
PrintMethodIdx = AsmString[I++] - 1; PrintMethodIdx = AsmString[I++] - 1;
printCustomAliasOperand(MI, OpIdx, PrintMethodIdx, OS); printCustomAliasOperand(MI, 0, OpIdx, PrintMethodIdx, OS);
} else } else
printOperand(MI, (unsigned)(AsmString[I++]) - 1, OS); printOperand(MI, (unsigned)(AsmString[I++]) - 1, OS);
} else { } else {
SStream_concat1(OS, AsmString[I++]); if (AsmString[I] == '[') {
set_mem_access(MI, true);
} else if (AsmString[I] == ']') {
set_mem_access(MI, false);
}
SStream_concat1(OS, AsmString[I++]);
} }
} while (AsmString[I] != '\\0'); } while (AsmString[I] != '\\0');
} }
free(AsmString);
return tmpString; return tmpString;
} }
""") """)

View File

@ -84,7 +84,7 @@ for line in lines:
elif skip_print and 'static const uint8_t DecoderTable' in line2: elif skip_print and 'static const uint8_t DecoderTable' in line2:
skip_print = False skip_print = False
elif 'End llvm namespace' in line2: elif 'end namespace llvm' in line2:
# done # done
break break
@ -103,13 +103,13 @@ for line in lines:
line2 = line2.replace('Bits[', 'AArch64_getFeatureBits(') line2 = line2.replace('Bits[', 'AArch64_getFeatureBits(')
line2 = line2.replace(']', ')') line2 = line2.replace(']', ')')
elif 'static bool checkDecoderPredicate(unsigned Idx, const FeatureBitset& Bits) {' in line2: elif 'static bool checkDecoderPredicate(unsigned Idx, const FeatureBitset &Bits) {' in line2:
line2 = 'static bool checkDecoderPredicate(unsigned Idx, MCInst *MI)\n{' line2 = 'static bool checkDecoderPredicate(unsigned Idx, MCInst *MI)\n{'
elif 'checkDecoderPredicate(PIdx, ' in line2: elif 'checkDecoderPredicate(PIdx, ' in line2:
line2 = line2.replace(', Bits)', ', MI)') line2 = line2.replace(', Bits)', ', MI)')
elif 'template<typename InsnType>' in line2: elif 'template <typename InsnType>' in line2:
continue continue
elif 'static DecodeStatus decodeToMCInst' in line2: elif 'static DecodeStatus decodeToMCInst' in line2:
@ -122,6 +122,10 @@ for line in lines:
line2 = line2.replace('fieldFromInstruction', 'fieldname') line2 = line2.replace('fieldFromInstruction', 'fieldname')
if 'InsnType FieldValue' in line2: if 'InsnType FieldValue' in line2:
line2 = line2.replace('InsnType ', '') line2 = line2.replace('InsnType ', '')
if 'insertBits(tmp,' in line2:
line2 = line2.replace('insertBits(', '')
tmpLn = line2.split(',')
line2 = tmpLn[0] + ' |=' + tmpLn[1] + ',' + tmpLn[2] + ',' + tmpLn[3] + ' <<' + tmpLn[4] + ';'
elif 'DecodeComplete = true;' in line2: elif 'DecodeComplete = true;' in line2:
# dead code # dead code
@ -184,8 +188,8 @@ for line in lines:
line2 = line2.replace('InsnType ', '') line2 = line2.replace('InsnType ', '')
elif 'InsnType NegativeMask =' in line2: elif 'InsnType NegativeMask =' in line2:
line2 = line2.replace('InsnType ', '') line2 = line2.replace('InsnType ', '')
elif 'uint32_t ExpectedValue' in line2: elif 'InsnType ExpectedValue' in line2:
line2 = line2.replace('uint32_t ', '') line2 = line2.replace('InsnType ', '')
elif 'ptrdiff_t Loc = ' in line2: elif 'ptrdiff_t Loc = ' in line2:
continue continue
elif 'LLVM_DEBUG(' in line2: elif 'LLVM_DEBUG(' in line2:
@ -223,6 +227,10 @@ for line in lines:
param = extract_brackets(line2) param = extract_brackets(line2)
line2 = del_brackets(line2) line2 = del_brackets(line2)
line2 = line2.replace(', Decoder)', ', Decoder, %s)' %param) line2 = line2.replace(', Decoder)', ', Decoder, %s)' %param)
elif 'DecodeMatrixTile<' in line2:
param = extract_brackets(line2)
line2 = del_brackets(line2)
line2 = line2.replace(', Decoder)', ', Decoder, %s)' %param)
if 'DecodeComplete = false; ' in line2: if 'DecodeComplete = false; ' in line2:
line2 = line2.replace('DecodeComplete = false; ', '') line2 = line2.replace('DecodeComplete = false; ', '')
elif 'decodeUImmOperand<' in line2 or 'decodeSImmOperand<' in line2 : elif 'decodeUImmOperand<' in line2 or 'decodeSImmOperand<' in line2 :
@ -235,6 +243,10 @@ for line in lines:
elif 'MI = TmpMI;' in line2: elif 'MI = TmpMI;' in line2:
line2 = '' line2 = ''
#line2 = line2.replace('TmpMI', '&TmpMI') #line2 = line2.replace('TmpMI', '&TmpMI')
elif 'using TmpType = std::conditional' in line2:
continue
elif 'TmpType tmp;' in line2:
line2 = line2.replace('TmpType', 'InsnType')
line2 = line2.replace('::', '_') line2 = line2.replace('::', '_')
print_line(line2) print_line(line2)

View File

@ -92,7 +92,7 @@ def extract_matcher(filename):
if not first_insn: if not first_insn:
arch, first_insn = _arch, insn_id arch, first_insn = _arch, insn_id
if not insn_id in insn_id_list: if not insn_id in insn_id_list and mnem.upper() in insn_id:
# save this # save this
insn_id_list[insn_id] = mnem insn_id_list[insn_id] = mnem
@ -175,7 +175,7 @@ lines = f.readlines()
f.close() f.close()
count = 0 count = 0
last_mnem = None last_mnem = ''
# 1st enum is register enum # 1st enum is register enum
for line in lines: for line in lines:

View File

@ -136,10 +136,10 @@ if arch.upper() == 'AARCH64':
if len(line.strip()) == 0: if len(line.strip()) == 0:
continue continue
if line.strip() == 'enum {': if line.strip() == 'enum {' or 'enum :' in line.strip():
enum_count += 1 enum_count += 1
if enum_count == 4: if enum_count == 4:
print(line) print('enum {')
continue continue
if enum_count == 4: if enum_count == 4:

View File

@ -84,7 +84,7 @@ for line in lines:
if len(line.strip()) == 0: if len(line.strip()) == 0:
continue continue
if line.strip() == 'const AT ATsList[] = {': if line.strip() == 'constexpr AT ATsList[] = {':
count += 1 count += 1
print_line('static const AT ATsList[] = {') print_line('static const AT ATsList[] = {')
continue continue
@ -148,7 +148,7 @@ for line in lines:
if len(line.strip()) == 0: if len(line.strip()) == 0:
continue continue
if line.strip() == 'const DB DBsList[] = {': if line.strip() == 'constexpr DB DBsList[] = {':
count += 1 count += 1
print_line('static const DB DBsList[] = {') print_line('static const DB DBsList[] = {')
continue continue
@ -211,7 +211,7 @@ for line in lines:
if len(line.strip()) == 0: if len(line.strip()) == 0:
continue continue
if line.strip() == 'const DC DCsList[] = {': if line.strip() == 'constexpr DC DCsList[] = {':
count += 1 count += 1
print_line('static const DC DCsList[] = {') print_line('static const DC DCsList[] = {')
continue continue
@ -276,7 +276,7 @@ for line in lines:
if len(line.strip()) == 0: if len(line.strip()) == 0:
continue continue
if line.strip() == 'const IC ICsList[] = {': if line.strip() == 'constexpr IC ICsList[] = {':
count += 1 count += 1
print_line('static const IC ICsList[] = {') print_line('static const IC ICsList[] = {')
continue continue
@ -342,7 +342,7 @@ for line in lines:
if len(line.strip()) == 0: if len(line.strip()) == 0:
continue continue
if line.strip() == 'const TLBI TLBIsList[] = {': if line.strip() == 'constexpr TLBI TLBITable[] = {':
count += 1 count += 1
print_line('static const TLBI TLBIsList[] = {') print_line('static const TLBI TLBIsList[] = {')
continue continue
@ -407,7 +407,7 @@ for line in lines:
if len(line.strip()) == 0: if len(line.strip()) == 0:
continue continue
if line.strip() == 'const SVEPRFM SVEPRFMsList[] = {': if line.strip() == 'constexpr SVEPRFM SVEPRFMsList[] = {':
count += 1 count += 1
print_line('static const SVEPRFM SVEPRFMsList[] = {') print_line('static const SVEPRFM SVEPRFMsList[] = {')
continue continue
@ -473,7 +473,7 @@ for line in lines:
if len(line.strip()) == 0: if len(line.strip()) == 0:
continue continue
if line.strip() == 'const PRFM PRFMsList[] = {': if line.strip() == 'constexpr PRFM PRFMsList[] = {':
count += 1 count += 1
print_line('static const PRFM PRFMsList[] = {') print_line('static const PRFM PRFMsList[] = {')
continue continue
@ -539,7 +539,7 @@ for line in lines:
if len(line.strip()) == 0: if len(line.strip()) == 0:
continue continue
if line.strip() == 'const PSB PSBsList[] = {': if line.strip() == 'constexpr PSB PSBsList[] = {':
count += 1 count += 1
print_line('static const PSB PSBsList[] = {') print_line('static const PSB PSBsList[] = {')
continue continue
@ -570,7 +570,7 @@ for line in lines:
if 'lookupPSBByEncoding' in line and '{' in line: if 'lookupPSBByEncoding' in line and '{' in line:
count += 1 count += 1
print_line('const PSB *AArch64PSBHint_lookupPSBByEncoding(uint16_t Encoding)\n{') print_line('const PSB *lookupPSBByEncoding(uint16_t Encoding)\n{')
print_line(' unsigned int i;') print_line(' unsigned int i;')
continue continue
@ -605,7 +605,7 @@ for line in lines:
if len(line.strip()) == 0: if len(line.strip()) == 0:
continue continue
if line.strip() == 'const ISB ISBsList[] = {': if line.strip() == 'constexpr ISB ISBsList[] = {':
count += 1 count += 1
print_line('static const ISB ISBsList[] = {') print_line('static const ISB ISBsList[] = {')
continue continue
@ -671,7 +671,7 @@ for line in lines:
if len(line.strip()) == 0: if len(line.strip()) == 0:
continue continue
if line.strip() == 'const TSB TSBsList[] = {': if line.strip() == 'constexpr TSB TSBsList[] = {':
count += 1 count += 1
print_line('static const TSB TSBsList[] = {') print_line('static const TSB TSBsList[] = {')
continue continue
@ -735,7 +735,7 @@ for line in lines:
if len(line.strip()) == 0: if len(line.strip()) == 0:
continue continue
if line.strip() == 'const SysReg SysRegsList[] = {': if line.strip() == 'constexpr SysReg SysRegsList[] = {':
count += 1 count += 1
print_line('static const SysReg SysRegsList[] = {') print_line('static const SysReg SysRegsList[] = {')
continue continue
@ -752,7 +752,7 @@ for line in lines:
#line = line.replace('{}', '{ 0 }') #line = line.replace('{}', '{ 0 }')
line = line.replace('{}', '') line = line.replace('{}', '')
tmp = line.split(',') tmp = line.split(',')
print_line(" %s, %s, %s, %s }, // %u" %(tmp[0].lower(), tmp[1], tmp[2], tmp[3], c)) print_line(" %s, %s, %s, %s }, // %u" %(tmp[0].lower(), tmp[2], tmp[3], tmp[4], c))
#print_line(" %s" %line.lower()) #print_line(" %s" %line.lower())
c += 1 c += 1
@ -800,7 +800,7 @@ for line in lines:
if len(line.strip()) == 0: if len(line.strip()) == 0:
continue continue
if line.strip() == 'const PState PStatesList[] = {': if line.strip() == 'constexpr PState PStatesList[] = {':
count += 1 count += 1
print_line('static const PState PStatesList[] = {') print_line('static const PState PStatesList[] = {')
continue continue
@ -865,7 +865,7 @@ for line in lines:
if len(line.strip()) == 0: if len(line.strip()) == 0:
continue continue
if line.strip() == 'const SVEPREDPAT SVEPREDPATsList[] = {': if line.strip() == 'constexpr SVEPREDPAT SVEPREDPATsList[] = {':
count += 1 count += 1
print_line('static const SVEPREDPAT SVEPREDPATsList[] = {') print_line('static const SVEPREDPAT SVEPREDPATsList[] = {')
continue continue
@ -921,6 +921,198 @@ print_line("""
} }
""") """)
# extract SVCRsList
count = 0
c = 0
for line in lines:
line = line.rstrip()
if len(line.strip()) == 0:
continue
if line.strip() == 'constexpr SVCR SVCRsList[] = {':
count += 1
print_line('static const SVCR SVCRsList[] = {')
continue
line = line.strip()
if count == 1:
if line == '};':
# done with first enum
print_line('};\n')
break
else:
# skip pseudo instructions
line = line.replace('::', '_')
#line = line.replace('{}', '{ 0 }')
line = line.replace('{}', '')
tmp = line.split(',')
print_line(" %s, %s }, // %u" %(tmp[0].lower(), tmp[1], c))
c += 1
# lookupSVCRByEncoding
count = 0
for line in lines:
line = line.rstrip()
if len(line.strip()) == 0:
continue
if 'lookupSVCRByEncoding' in line and '{' in line:
count += 1
print_line('const SVCR *lookupSVCRByEncoding(uint8_t Encoding)\n{')
print_line(' unsigned int i;')
continue
if count == 1 and 'IndexType Index[] = {' in line:
count += 1
if count == 2:
if line.strip() == '};':
# done with array, or this function?
print_line(line)
break
else:
# enum items
print_line(line)
print_line("""
i = binsearch_IndexTypeEncoding(Index, ARR_SIZE(Index), Encoding);
if (i == -1)
return NULL;
else
return &SVCRsList[Index[i].index];
}
""")
# extract BTIsList
count = 0
c = 0
for line in lines:
line = line.rstrip()
if len(line.strip()) == 0:
continue
if line.strip() == 'constexpr BTI BTIsList[] = {':
count += 1
print_line('static const BTI BTIsList[] = {')
continue
line = line.strip()
if count == 1:
if line == '};':
# done with first enum
print_line('};\n')
break
else:
# skip pseudo instructions
line = line.replace('::', '_')
#line = line.replace('{}', '{ 0 }')
line = line.replace('{}', '')
tmp = line.split(',')
print_line(" %s, %s, // %u" %(tmp[0].lower(), tmp[1], c))
c += 1
# lookupBTIByEncoding
count = 0
for line in lines:
line = line.rstrip()
if len(line.strip()) == 0:
continue
if 'lookupBTIByEncoding' in line and '{' in line:
count += 1
print_line('const BTI *lookupBTIByEncoding(uint8_t Encoding)\n{')
print_line(' unsigned int i;')
continue
if count == 1 and 'IndexType Index[] = {' in line:
count += 1
if count == 2:
if line.strip() == '};':
# done with array, or this function?
print_line(line)
break
else:
# enum items
print_line(line)
print_line("""
i = binsearch_IndexTypeEncoding(Index, ARR_SIZE(Index), Encoding);
if (i == -1)
return NULL;
else
return &BTIsList[Index[i].index];
}
""")
# extract DBnXSsList
count = 0
c = 0
for line in lines:
line = line.rstrip()
if len(line.strip()) == 0:
continue
if line.strip() == 'constexpr DBnXS DBnXSsList[] = {':
count += 1
print_line('static const DBnXS DBnXSsList[] = {')
continue
line = line.strip()
if count == 1:
if line == '};':
# done with first enum
print_line('};\n')
break
else:
# skip pseudo instructions
line = line.replace('::', '_')
#line = line.replace('{}', '{ 0 }')
line = line.replace('{}', '')
tmp = line.split(',')
print_line(" %s, %s, %s}, // %u" %(tmp[0].lower(), tmp[1], tmp[2], c))
c += 1
# lookupDBnXSByEncoding
count = 0
for line in lines:
line = line.rstrip()
if len(line.strip()) == 0:
continue
if 'lookupDBnXSByEncoding' in line and '{' in line:
count += 1
print_line('const DBnXS *lookupDBnXSByEncoding(uint8_t Encoding)\n{')
print_line(' unsigned int i;')
continue
if count == 1 and 'IndexType Index[] = {' in line:
count += 1
if count == 2:
if line.strip() == '};':
# done with array, or this function?
print_line(line)
break
else:
# enum items
print_line(line)
print_line("""
i = binsearch_IndexTypeEncoding(Index, ARR_SIZE(Index), Encoding);
if (i == -1)
return NULL;
else
return &DBnXSsList[Index[i].index];
}
""")
# extract ExactFPImmsList # extract ExactFPImmsList
count = 0 count = 0
@ -931,7 +1123,7 @@ for line in lines:
if len(line.strip()) == 0: if len(line.strip()) == 0:
continue continue
if line.strip() == 'const ExactFPImm ExactFPImmsList[] = {': if line.strip() == 'constexpr ExactFPImm ExactFPImmsList[] = {':
count += 1 count += 1
print_line('static const ExactFPImm ExactFPImmsList[] = {') print_line('static const ExactFPImm ExactFPImmsList[] = {')
continue continue