Best Python code snippet using lemoncheesecake
asmwriter.py
Source:asmwriter.py
...84 if '<' in line:85 return line[:line.index('<')] + line[line.index('>') + 1:]86 else:87 return line88def print_line(line):89 line = line.replace('::', '_')90 line = line.replace('nullptr', 'NULL')91 if not skip_printing:92 if in_getRegisterName:93 f2.write(line + "\n")94 else:95 f1.write(line + "\n")96for line in lines:97 line = line.rstrip()98 #print("@", line)99 # skip Alias100 if arch.upper() == 'X86':101 if 'PRINT_ALIAS_INSTR' in line:102 # done103 break104 if skip_line:105 skip_count += 1106 if skip_count <= skip_line:107 # skip this line108 continue109 else:110 # skip enough number of lines, reset counters111 skip_line = 0112 skip_count = 0113 if "::printInstruction" in line:114 if arch.upper() in ('AARCH64', 'ARM64'):115 #print_line("static void printInstruction(MCInst *MI, SStream *O, MCRegisterInfo *MRI)\n{")116 print_line("static void printInstruction(MCInst *MI, SStream *O)\n{")117 else:118 print_line("static void printInstruction(MCInst *MI, SStream *O)\n{")119 elif 'const char *AArch64InstPrinter::' in line:120 continue121 elif 'getRegisterName(' in line:122 if 'unsigned AltIdx' in line:123 print_line("static const char *getRegisterName(unsigned RegNo, unsigned AltIdx)\n{")124 else:125 print_line("static const char *getRegisterName(unsigned RegNo)\n{")126 elif 'getRegisterName' in line:127 in_getRegisterName = True128 print_line(line)129 elif '::printAliasInstr' in line:130 if arch.upper() in ('AARCH64', 'PPC'):131 print_line("static char *printAliasInstr(MCInst *MI, SStream *OS, MCRegisterInfo *MRI)\n{")132 print_line(' #define GETREGCLASS_CONTAIN(_class, _reg) MCRegisterClass_contains(MCRegisterInfo_getRegClass(MRI, _class), MCOperand_getReg(MCInst_getOperand(MI, _reg)))')133 else:134 print_line("static bool printAliasInstr(MCInst *MI, SStream *OS)\n{")135 print_line(" unsigned int I = 0, OpIdx, PrintMethodIdx;")136 print_line(" char *tmpString;")137 in_printAliasInstr = True138 elif 'STI.getFeatureBits()[' in line:139 if arch.upper() == 'ARM':140 line2 = line.replace('STI.getFeatureBits()[', 'ARM_getFeatureBits(MI->csh->mode, ')141 elif arch.upper() == 'AARCH64':142 line2 = line.replace('STI.getFeatureBits()[', 'AArch64_getFeatureBits(')143 line2 = line2.replace(']', ')')144 print_line(line2)145 elif ', STI, ' in line:146 line2 = line.replace(', STI, ', ', ')147 if 'printSVELogicalImm<' in line:148 if 'int16' in line:149 line2 = line2.replace('printSVELogicalImm', 'printSVELogicalImm16')150 line2 = line2.replace('<int16_t>', '')151 elif 'int32' in line: 152 line2 = line2.replace('printSVELogicalImm', 'printSVELogicalImm32')153 line2 = line2.replace('<int32_t>', '')154 else:155 line2 = line2.replace('printSVELogicalImm', 'printSVELogicalImm64')156 line2 = line2.replace('<int64_t>', '')157 if 'MI->getOperand(' in line:158 line2 = replace_getOp(line2)159 # C++ template160 if 'printPrefetchOp' in line2:161 param = extract_brackets(line2)162 if param == '':163 param = 'false'164 line2 = del_brackets(line2)165 line2 = line2.replace(', O);', ', O, %s);' %param)166 line2 = line2.replace(', OS);', ', OS, %s);' %param)167 elif '<false>' in line2:168 line2 = line2.replace('<false>', '')169 line2 = line2.replace(', O);', ', O, false);')170 line2 = line2.replace('STI, ', '')171 elif '<true>' in line:172 line2 = line2.replace('<true>', '')173 line2 = line2.replace(', O);', ', O, true);')174 line2 = line2.replace('STI, ', '')175 elif 'printAdrLabelOperand' in line:176 # C++ template177 if '<0>' in line:178 line2 = line2.replace('<0>', '')179 line2 = line2.replace(', O);', ', O, 0);')180 elif '<1>' in line:181 line2 = line2.replace('<1>', '')182 line2 = line2.replace(', O);', ', O, 1);')183 elif '<2>' in line:184 line2 = line2.replace('<2>', '')185 line2 = line2.replace(', O);', ', O, 2);')186 elif 'printImm8OptLsl' in line2:187 param = extract_brackets(line2)188 line2 = del_brackets(line2)189 if '8' in param or '16' in param or '32' in param:190 line2 = line2.replace('printImm8OptLsl', 'printImm8OptLsl32')191 elif '64' in param:192 line2 = line2.replace('printImm8OptLsl', 'printImm8OptLsl64')193 elif 'printLogicalImm' in line2:194 param = extract_brackets(line2)195 line2 = del_brackets(line2)196 if '8' in param or '16' in param or '32' in param:197 line2 = line2.replace('printLogicalImm', 'printLogicalImm32')198 elif '64' in param:199 line2 = line2.replace('printLogicalImm', 'printLogicalImm64')200 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:201 param = extract_brackets(line2)202 if param == '':203 param = '0'204 line2 = del_brackets(line2)205 line2 = line2.replace(', O);', ', O, %s);' %param)206 line2 = line2.replace(', OS);', ', OS, %s);' %param)207 elif 'printComplexRotationOp' in line:208 # printComplexRotationOp<90, 0>(MI, 5, STI, O);209 bracket_content = line2[line2.index('<') + 1 : line2.index('>')]210 line2 = line2.replace('<' + bracket_content + '>', '')211 line2 = line2.replace(' O);', ' O, %s);' %bracket_content)212 print_line(line2)213 elif "static const char AsmStrs[]" in line:214 print_line("#ifndef CAPSTONE_DIET")215 print_line(" static const char AsmStrs[] = {")216 need_endif = True217 elif "static const char AsmStrsNoRegAltName[]" in line:218 print_line("#ifndef CAPSTONE_DIET")219 print_line(" static const char AsmStrsNoRegAltName[] = {")220 need_endif = True221 elif line == ' O << "\\t";':222 print_line(" unsigned int opcode = MCInst_getOpcode(MI);")223 print_line(' // printf("opcode = %u\\n", opcode);');224 elif 'MI->getOpcode()' in line:225 if 'switch' in line:226 line2 = line.replace('MI->getOpcode()', 'MCInst_getOpcode(MI)')227 else:228 line2 = line.replace('MI->getOpcode()', 'opcode')229 print_line(line2)230 elif 'O << ' in line:231 if '"' in line:232 line2 = line.lower()233 line2 = line2.replace('o << ', 'SStream_concat0(O, ');234 else:235 line2 = line.replace('O << ', 'SStream_concat0(O, ');236 line2 = line2.replace("'", '"')237 line2 = line2.replace(';', ');')238 if '" : "' in line2: # "segment : offset" in X86239 line2 = line2.replace('" : "', '":"')240 # ARM241 print_line(line2)242 if '", #0"' in line2:243 print_line(' op_addImm(MI, 0);')244 if '", #1"' in line2:245 print_line(' op_addImm(MI, 1);')246 # PowerPC247 if '", 268"' in line2:248 print_line(' op_addImm(MI, 268);')249 elif '", 256"' in line2:250 print_line(' op_addImm(MI, 256);')251 elif '", 0, "' in line2 or '", 0"' in line2:252 print_line(' op_addImm(MI, 0);')253 elif '", -1"' in line2:254 print_line(' op_addImm(MI, -1);')255 if '[' in line2:256 if not '[]' in line2:257 print_line(' set_mem_access(MI, true);')258 if ']' in line2:259 if not '[]' in line2:260 print_line(' set_mem_access(MI, false);')261 if '".f64\\t"' in line2:262 print_line(' ARM_addVectorDataType(MI, ARM_VECTORDATA_F64);')263 elif '".f32\\t"' in line2:264 print_line(' ARM_addVectorDataType(MI, ARM_VECTORDATA_F32);')265 elif '".f16\\t"' in line2:266 print_line(' ARM_addVectorDataType(MI, ARM_VECTORDATA_F16);')267 elif '".s64\\t"' in line2:268 print_line(' ARM_addVectorDataType(MI, ARM_VECTORDATA_S64);')269 elif '".s32\\t"' in line2:270 print_line(' ARM_addVectorDataType(MI, ARM_VECTORDATA_S32);')271 elif '".s16\\t"' in line2:272 print_line(' ARM_addVectorDataType(MI, ARM_VECTORDATA_S16);')273 elif '".s8\\t"' in line2:274 print_line(' ARM_addVectorDataType(MI, ARM_VECTORDATA_S8);')275 elif '".u64\\t"' in line2:276 print_line(' ARM_addVectorDataType(MI, ARM_VECTORDATA_U64);')277 elif '".u32\\t"' in line2:278 print_line(' ARM_addVectorDataType(MI, ARM_VECTORDATA_U32);')279 elif '".u16\\t"' in line2:280 print_line(' ARM_addVectorDataType(MI, ARM_VECTORDATA_U16);')281 elif '".u8\\t"' in line2:282 print_line(' ARM_addVectorDataType(MI, ARM_VECTORDATA_U8);')283 elif '".i64\\t"' in line2:284 print_line(' ARM_addVectorDataType(MI, ARM_VECTORDATA_I64);')285 elif '".i32\\t"' in line2:286 print_line(' ARM_addVectorDataType(MI, ARM_VECTORDATA_I32);')287 elif '".i16\\t"' in line2:288 print_line(' ARM_addVectorDataType(MI, ARM_VECTORDATA_I16);')289 elif '".i8\\t"' in line2:290 print_line(' ARM_addVectorDataType(MI, ARM_VECTORDATA_I8);')291 elif '".f16.f64\\t"' in line2:292 print_line(' ARM_addVectorDataType(MI, ARM_VECTORDATA_F16F64);')293 elif '".f64.f16\\t"' in line2:294 print_line(' ARM_addVectorDataType(MI, ARM_VECTORDATA_F64F16);')295 elif '".f16.f32\\t"' in line2:296 print_line(' ARM_addVectorDataType(MI, ARM_VECTORDATA_F16F32);')297 elif '".f32.f16\\t"' in line2:298 print_line(' ARM_addVectorDataType(MI, ARM_VECTORDATA_F32F16);')299 elif '".f64.f32\\t"' in line2:300 print_line(' ARM_addVectorDataType(MI, ARM_VECTORDATA_F64F32);')301 elif '".f32.f64\\t"' in line2:302 print_line(' ARM_addVectorDataType(MI, ARM_VECTORDATA_F32F64);')303 elif '".s32.f32\\t"' in line2:304 print_line(' ARM_addVectorDataType(MI, ARM_VECTORDATA_S32F32);')305 elif '".f32.s32\\t"' in line2:306 print_line(' ARM_addVectorDataType(MI, ARM_VECTORDATA_F32S32);')307 elif '".u32.f32\\t"' in line2:308 print_line(' ARM_addVectorDataType(MI, ARM_VECTORDATA_U32F32);')309 elif '".f32.u32\\t"' in line2:310 print_line(' ARM_addVectorDataType(MI, ARM_VECTORDATA_F32U32);')311 elif '".p8\\t"' in line2:312 print_line(' ARM_addVectorDataType(MI, ARM_VECTORDATA_P8);')313 elif '".f64.s16\\t"' in line2:314 print_line(' ARM_addVectorDataType(MI, ARM_VECTORDATA_F64S16);')315 elif '".s16.f64\\t"' in line2:316 print_line(' ARM_addVectorDataType(MI, ARM_VECTORDATA_S16F64);')317 elif '".f32.s16\\t"' in line2:318 print_line(' ARM_addVectorDataType(MI, ARM_VECTORDATA_F32S16);')319 elif '".s16.f32\\t"' in line2:320 print_line(' ARM_addVectorDataType(MI, ARM_VECTORDATA_S16F32);')321 elif '".f64.s32\\t"' in line2:322 print_line(' ARM_addVectorDataType(MI, ARM_VECTORDATA_F64S32);')323 elif '".s32.f64\\t"' in line2:324 print_line(' ARM_addVectorDataType(MI, ARM_VECTORDATA_S32F64);')325 elif '".f64.u16\\t"' in line2:326 print_line(' ARM_addVectorDataType(MI, ARM_VECTORDATA_F64U16);')327 elif '".u16.f64\\t"' in line2:328 print_line(' ARM_addVectorDataType(MI, ARM_VECTORDATA_U16F64);')329 elif '".f32.u16\\t"' in line2:330 print_line(' ARM_addVectorDataType(MI, ARM_VECTORDATA_F32U16);')331 elif '".u16.f32\\t"' in line2:332 print_line(' ARM_addVectorDataType(MI, ARM_VECTORDATA_U16F32);')333 elif '".f64.u32\\t"' in line2:334 print_line(' ARM_addVectorDataType(MI, ARM_VECTORDATA_F64U32);')335 elif '".u32.f64\\t"' in line2:336 print_line(' ARM_addVectorDataType(MI, ARM_VECTORDATA_U32F64);')337 elif '".f16.u32\\t"' in line2:338 print_line(' ARM_addVectorDataType(MI, ARM_VECTORDATA_F16U32);')339 elif '".u32.f16\\t"' in line2:340 print_line(' ARM_addVectorDataType(MI, ARM_VECTORDATA_U32F16);')341 elif '".f16.u16\\t"' in line2:342 print_line(' ARM_addVectorDataType(MI, ARM_VECTORDATA_F16U16);')343 elif '".u16.f16\\t"' in line2:344 print_line(' ARM_addVectorDataType(MI, ARM_VECTORDATA_U16F16);')345 elif '"\\tlr"' in line2:346 print_line(' ARM_addReg(MI, ARM_REG_LR);')347 elif '"\\tapsr_nzcv, fpscr"' in line2:348 print_line(' ARM_addReg(MI, ARM_REG_APSR_NZCV);')349 print_line(' ARM_addReg(MI, ARM_REG_FPSCR);')350 elif '"\\tpc, lr"' in line2:351 print_line(' ARM_addReg(MI, ARM_REG_PC);')352 print_line(' ARM_addReg(MI, ARM_REG_LR);')353 elif '"\\tfpscr, "' in line2:354 print_line(' ARM_addReg(MI, ARM_REG_FPSCR);')355 elif '"\\tfpexc, "' in line2:356 print_line(' ARM_addReg(MI, ARM_REG_FPEXC);')357 elif '"\\tfpinst, "' in line2:358 print_line(' ARM_addReg(MI, ARM_REG_FPINST);')359 elif '"\\tfpinst2, "' in line2:360 print_line(' ARM_addReg(MI, ARM_REG_FPINST2);')361 elif '"\\tfpsid, "' in line2:362 print_line(' ARM_addReg(MI, ARM_REG_FPSID);')363 elif '"\\tsp, "' in line2:364 print_line(' ARM_addReg(MI, ARM_REG_SP);')365 elif '"\\tsp!, "' in line2:366 print_line(' ARM_addReg(MI, ARM_REG_SP);')367 elif '", apsr"' in line2:368 print_line(' ARM_addReg(MI, ARM_REG_APSR);')369 elif '", spsr"' in line2:370 print_line(' ARM_addReg(MI, ARM_REG_SPSR);')371 elif '", fpscr"' in line2:372 print_line(' ARM_addReg(MI, ARM_REG_FPSCR);')373 elif '", fpscr"' in line2:374 print_line(' ARM_addReg(MI, ARM_REG_FPSCR);')375 elif '", fpexc"' in line2:376 print_line(' ARM_addReg(MI, ARM_REG_FPEXC);')377 elif '", fpinst"' in line2:378 print_line(' ARM_addReg(MI, ARM_REG_FPINST);')379 elif '", fpinst2"' in line2:380 print_line(' ARM_addReg(MI, ARM_REG_FPINST2);')381 elif '", fpsid"' in line2:382 print_line(' ARM_addReg(MI, ARM_REG_FPSID);')383 elif '", mvfr0"' in line2:384 print_line(' ARM_addReg(MI, ARM_REG_MVFR0);')385 elif '", mvfr1"' in line2:386 print_line(' ARM_addReg(MI, ARM_REG_MVFR1);')387 elif '", mvfr2"' in line2:388 print_line(' ARM_addReg(MI, ARM_REG_MVFR2);')389 elif '.8\\t' in line2:390 print_line(' ARM_addVectorDataSize(MI, 8);')391 elif '.16\\t' in line2:392 print_line(' ARM_addVectorDataSize(MI, 16);')393 elif '.32\\t' in line2:394 print_line(' ARM_addVectorDataSize(MI, 32);')395 elif '.64\\t' in line2:396 print_line(' ARM_addVectorDataSize(MI, 64);')397 elif '" ^"' in line2:398 print_line(' ARM_addUserMode(MI);')399 if '.16b' in line2:400 print_line(' arm64_op_addVectorArrSpecifier(MI, ARM64_VAS_16B);')401 elif '.8b' in line2:402 print_line(' arm64_op_addVectorArrSpecifier(MI, ARM64_VAS_8B);')403 elif '.4b' in line2:404 print_line(' arm64_op_addVectorArrSpecifier(MI, ARM64_VAS_4B);')405 elif '.b' in line2:406 print_line(' arm64_op_addVectorArrSpecifier(MI, ARM64_VAS_1B);')407 elif '.8h' in line2:408 print_line(' arm64_op_addVectorArrSpecifier(MI, ARM64_VAS_8H);')409 elif '.4h' in line2:410 print_line(' arm64_op_addVectorArrSpecifier(MI, ARM64_VAS_4H);')411 elif '.2h' in line2:412 print_line(' arm64_op_addVectorArrSpecifier(MI, ARM64_VAS_2H);')413 elif '.h' in line2:414 print_line(' arm64_op_addVectorArrSpecifier(MI, ARM64_VAS_1H);')415 elif '.4s' in line2:416 print_line(' arm64_op_addVectorArrSpecifier(MI, ARM64_VAS_4S);')417 elif '.2s' in line2:418 print_line(' arm64_op_addVectorArrSpecifier(MI, ARM64_VAS_2S);')419 elif '.s' in line2:420 print_line(' arm64_op_addVectorArrSpecifier(MI, ARM64_VAS_1S);')421 elif '.2d' in line2:422 print_line(' arm64_op_addVectorArrSpecifier(MI, ARM64_VAS_2D);')423 elif '.1d' in line2:424 print_line(' arm64_op_addVectorArrSpecifier(MI, ARM64_VAS_1D);')425 elif '.1q' in line2:426 print_line(' arm64_op_addVectorArrSpecifier(MI, ARM64_VAS_1Q);')427 if '#0.0' in line2:428 print_line(' arm64_op_addFP(MI, 0);')429 elif '#0' in line2:430 print_line(' arm64_op_addImm(MI, 0);')431 elif '#8' in line2:432 print_line(' arm64_op_addImm(MI, 8);')433 elif '#16' in line2:434 print_line(' arm64_op_addImm(MI, 16);')435 elif '#32' in line2:436 print_line(' arm64_op_addImm(MI, 32);')437 # X86438 if '", %rax"' in line2 or '", rax"' in line2:439 print_line(' op_addReg(MI, X86_REG_RAX);')440 elif '", %eax"' in line2 or '", eax"' in line2:441 print_line(' op_addReg(MI, X86_REG_EAX);')442 elif '", %ax"' in line2 or '", ax"' in line2:443 print_line(' op_addReg(MI, X86_REG_AX);')444 elif '", %al"' in line2 or '", al"' in line2:445 print_line(' op_addReg(MI, X86_REG_AL);')446 elif '", %dx"' in line2 or '", dx"' in line2:447 print_line(' op_addReg(MI, X86_REG_DX);')448 elif '", %st(0)"' in line2 or '", st(0)"' in line2:449 print_line(' op_addReg(MI, X86_REG_ST0);')450 elif '", 1"' in line2:451 print_line(' op_addImm(MI, 1);')452 elif '", cl"' in line2:453 print_line(' op_addReg(MI, X86_REG_CL);')454 elif '"{1to2}, "' in line2:455 print_line(' op_addAvxBroadcast(MI, X86_AVX_BCAST_2);')456 elif '"{1to4}, "' in line2:457 print_line(' op_addAvxBroadcast(MI, X86_AVX_BCAST_4);')458 elif '"{1to8}, "' in line2:459 print_line(' op_addAvxBroadcast(MI, X86_AVX_BCAST_8);')460 elif '"{1to16}, "' in line2:461 print_line(' op_addAvxBroadcast(MI, X86_AVX_BCAST_16);')462 elif '{z}{sae}' in line2:463 print_line(' op_addAvxSae(MI);')464 print_line(' op_addAvxZeroOpmask(MI);')465 elif ('{z}' in line2):466 print_line(' op_addAvxZeroOpmask(MI);')467 elif '{sae}' in line2:468 print_line(' op_addAvxSae(MI);')469 elif 'llvm_unreachable("Invalid command number.");' in line:470 line2 = line.replace('llvm_unreachable("Invalid command number.");', '// unreachable')471 print_line(line2)472 elif ('assert(' in line) or ('assert (' in line):473 pass474 elif 'Invalid alt name index' in line:475 pass476 elif '::' in line and 'case ' in line:477 #print_line(line2)478 print_line(line)479 elif 'MI->getNumOperands()' in line:480 line2 = line.replace('MI->getNumOperands()', 'MCInst_getNumOperands(MI)')481 print_line(line2)482 elif 'const MCOperand &MCOp' in line:483 line2 = line.replace('const MCOperand &MCOp', 'MCOperand *MCOp')484 print_line(line2)485 elif 'MI->getOperand(0).isImm()' in line:486 line2 = line.replace('MI->getOperand(0).isImm()', 'MCOperand_isImm(MCInst_getOperand(MI, 0))')487 print_line(line2)488 elif 'MI->getOperand(1).isImm()' in line:489 line2 = line.replace('MI->getOperand(1).isImm()', 'MCOperand_isImm(MCInst_getOperand(MI, 1))')490 print_line(line2)491 elif 'MI->getOperand(2).isImm()' in line:492 line2 = line.replace('MI->getOperand(2).isImm()', 'MCOperand_isImm(MCInst_getOperand(MI, 2))')493 print_line(line2)494 elif 'MI->getOperand(3).isImm()' in line:495 line2 = line.replace('MI->getOperand(3).isImm()', 'MCOperand_isImm(MCInst_getOperand(MI, 3))')496 print_line(line2)497 elif 'MI->getOperand(4).isImm()' in line:498 line2 = line.replace('MI->getOperand(4).isImm()', 'MCOperand_isImm(MCInst_getOperand(MI, 4))')499 print_line(line2)500 elif 'MI->getOperand(5).isImm()' in line:501 line2 = line.replace('MI->getOperand(5).isImm()', 'MCOperand_isImm(MCInst_getOperand(MI, 5))')502 print_line(line2)503 elif 'MI->getOperand(6).isImm()' in line:504 line2 = line.replace('MI->getOperand(6).isImm()', 'MCOperand_isImm(MCInst_getOperand(MI, 6))')505 print_line(line2)506 elif 'MI->getOperand(7).isImm()' in line:507 line2 = line.replace('MI->getOperand(7).isImm()', 'MCOperand_isImm(MCInst_getOperand(MI, 7))')508 print_line(line2)509 elif 'MI->getOperand(8).isImm()' in line:510 line2 = line.replace('MI->getOperand(8).isImm()', 'MCOperand_isImm(MCInst_getOperand(MI, 8))')511 print_line(line2)512 elif 'MI->getOperand(0).getImm()' in line:513 line2 = line.replace('MI->getOperand(0).getImm()', 'MCOperand_getImm(MCInst_getOperand(MI, 0))')514 print_line(line2)515 elif 'MI->getOperand(1).getImm()' in line:516 line2 = line.replace('MI->getOperand(1).getImm()', 'MCOperand_getImm(MCInst_getOperand(MI, 1))')517 print_line(line2)518 elif 'MI->getOperand(2).getImm()' in line:519 line2 = line.replace('MI->getOperand(2).getImm()', 'MCOperand_getImm(MCInst_getOperand(MI, 2))')520 print_line(line2)521 elif 'MI->getOperand(3).getImm()' in line:522 line2 = line.replace('MI->getOperand(3).getImm()', 'MCOperand_getImm(MCInst_getOperand(MI, 3))')523 print_line(line2)524 elif 'MI->getOperand(4).getImm()' in line:525 line2 = line.replace('MI->getOperand(4).getImm()', 'MCOperand_getImm(MCInst_getOperand(MI, 4))')526 print_line(line2)527 elif 'MI->getOperand(5).getImm()' in line:528 line2 = line.replace('MI->getOperand(5).getImm()', 'MCOperand_getImm(MCInst_getOperand(MI, 5))')529 print_line(line2)530 elif 'MI->getOperand(6).getImm()' in line:531 line2 = line.replace('MI->getOperand(6).getImm()', 'MCOperand_getImm(MCInst_getOperand(MI, 6))')532 print_line(line2)533 elif 'MI->getOperand(7).getImm()' in line:534 line2 = line.replace('MI->getOperand(7).getImm()', 'MCOperand_getImm(MCInst_getOperand(MI, 7))')535 print_line(line2)536 elif 'MI->getOperand(8).getImm()' in line:537 line2 = line.replace('MI->getOperand(8).getImm()', 'MCOperand_getImm(MCInst_getOperand(MI, 8))')538 print_line(line2)539 elif 'MRI.getRegClass(' in line:540 classid = extract_paren(line, 'getRegClass(')541 operand = extract_paren(line, 'getOperand')542 line2 = line.replace('MI->getNumOperands()', 'MCInst_getNumOperands(MI)')543 line2 = ' GETREGCLASS_CONTAIN(%s, %s)' %(classid, operand)544 if line.endswith('())) {'):545 line2 += ') {'546 elif line.endswith(' {'):547 line2 += ' {'548 elif line.endswith(' &&'):549 line2 += ' &&'550 print_line(line2)551 elif 'MI->getOperand(' in line and 'isReg' in line:552 operand = extract_paren(line, 'getOperand')553 line2 = ' MCOperand_isReg(MCInst_getOperand(MI, %s))' %(operand)554 # MI->getOperand(1).isReg() &&555 if line.endswith(' {'):556 line2 += ' {'557 elif line.endswith(' &&'):558 line2 += ' &&'559 print_line(line2)560 elif 'MI->getOperand(' in line and 'getReg' in line:561 line2 = replace_getReg(line)562 # one more time563 line2 = replace_getReg(line2)564 print_line(line2)565 elif ' return false;' in line and in_printAliasInstr:566 print_line(' return NULL;')567 elif 'MCOp.isImm()' in line:568 line2 = line.replace('MCOp.isImm()', 'MCOperand_isImm(MCOp)')569 print_line(line2)570 elif 'MCOp.getImm()' in line:571 line2 = line.replace('MCOp.getImm()', 'MCOperand_getImm(MCOp)')572 if 'int64_t Val =' in line:573 line2 = line2.replace('int64_t Val =', 'Val =')574 print_line(line2)575 elif 'isSVEMaskOfIdenticalElements<' in line:576 if 'int8' in line:577 line2 = line.replace('isSVEMaskOfIdenticalElements', 'isSVEMaskOfIdenticalElements8')578 line2 = line2.replace('<int8_t>', '')579 elif 'int16' in line:580 line2 = line.replace('isSVEMaskOfIdenticalElements', 'isSVEMaskOfIdenticalElements16')581 line2 = line2.replace('<int16_t>', '')582 elif 'int32' in line: 583 line2 = line.replace('isSVEMaskOfIdenticalElements', 'isSVEMaskOfIdenticalElements32')584 line2 = line2.replace('<int32_t>', '')585 else:586 line2 = line.replace('isSVEMaskOfIdenticalElements', 'isSVEMaskOfIdenticalElements64')587 line2 = line2.replace('<int64_t>', '')588 print_line(line2)589 elif 'switch (PredicateIndex) {' in line:590 print_line(' int64_t Val;')591 print_line(line)592 elif 'unsigned I = 0;' in line and in_printAliasInstr:593 print_line("""594 tmpString = cs_strdup(AsmString);595 while (AsmString[I] != ' ' && AsmString[I] != '\\t' &&596 AsmString[I] != '$' && AsmString[I] != '\\0')597 ++I;598 tmpString[I] = 0;599 SStream_concat0(OS, tmpString);600 if (AsmString[I] != '\\0') {601 if (AsmString[I] == ' ' || AsmString[I] == '\\t') {602 SStream_concat0(OS, " ");603 ++I;604 }605 do {606 if (AsmString[I] == '$') {607 ++I;608 if (AsmString[I] == (char)0xff) {609 ++I;610 OpIdx = AsmString[I++] - 1;611 PrintMethodIdx = AsmString[I++] - 1;612 printCustomAliasOperand(MI, OpIdx, PrintMethodIdx, OS);613 } else614 printOperand(MI, (unsigned)(AsmString[I++]) - 1, OS);615 } else {616 SStream_concat1(OS, AsmString[I++]);617 }618 } while (AsmString[I] != '\\0');619 }620 return tmpString;621}622 """)623 in_printAliasInstr = False624 # skip next few lines625 skip_printing = True626 elif '::printCustomAliasOperand' in line:627 # print again628 skip_printing = False629 print_line('static void printCustomAliasOperand(')630 elif 'const MCSubtargetInfo &STI' in line:631 pass632 elif 'const MCInst *MI' in line:633 line2 = line.replace('const MCInst *MI', 'MCInst *MI')634 print_line(line2)635 elif 'llvm_unreachable("' in line:636 if 'default: ' in line:637 print_line(' default:')638 elif 'llvm_unreachable("Unknown MCOperandPredicate kind")' in line:639 print_line(' return false; // never reach')640 else:641 pass642 elif 'raw_ostream &' in line:643 line2 = line.replace('raw_ostream &', 'SStream *')644 if line2.endswith(' {'):645 line2 = line2.replace(' {', '\n{')646 print_line(line2)647 elif 'printPredicateOperand(' in line and 'STI, ' in line:648 line2 = line.replace('STI, ', '')649 print_line(line2)650 elif '// Fragment ' in line:651 # // Fragment 0 encoded into 6 bits for 51 unique commands.652 tmp = line.strip().split(' ')653 fragment_no = tmp[2]654 print_line(line)655 elif ('switch ((' in line or 'if ((' in line) and 'Bits' in line:656 # switch ((Bits >> 14) & 63) {657 bits = line.strip()658 bits = bits.replace('switch ', '')659 bits = bits.replace('if ', '')660 bits = bits.replace('{', '')661 bits = bits.strip()662 print_line(' // printf("Fragment %s: %%"PRIu64"\\n", %s);' %(fragment_no, bits))663 print_line(line)664 elif not skip_printing:665 print_line(line)666 if line == ' };':667 if need_endif and not in_getRegisterName:668 # endif only for AsmStrs when we are not inside getRegisterName()669 print_line("#endif")670 need_endif = False671 elif 'return AsmStrs+RegAsmOffset[RegNo-1];' in line:672 if in_getRegisterName:673 # return NULL for register name on Diet mode674 print_line("#else")675 print_line(" return NULL;")676 print_line("#endif")677 print_line("}")678 need_endif = False679 in_getRegisterName = False680 # skip 1 line681 skip_line = 1682 elif line == ' }':683 # ARM64684 if in_getRegisterName:685 # return NULL for register name on Diet mode686 print_line("#else")687 print_line(" return NULL;")688 print_line("#endif")689 print_line("}")690 need_endif = False691 in_getRegisterName = False692 # skip 1 line693 skip_line = 1694 elif 'default:' in line:695 # ARM64696 if in_getRegisterName:697 # get the size of RegAsmOffsetvreg[]698 print_line(" return (const char *)(sizeof(RegAsmOffsetvreg)/sizeof(RegAsmOffsetvreg[0]));")699f1.close()...
systemoperand.py
Source:systemoperand.py
...35 break36 else:37 # skip pseudo instructions38 f2.write(" AArch64PState_%s\n" %(line))39def print_line(line):40 f1.write(line + "\n")41# extract ExactFPImmValues enum42count = 043for line in lines:44 line = line.rstrip()45 if len(line.strip()) == 0:46 continue47 if line.strip() == 'enum ExactFPImmValues {':48 count += 149 f2.write(line.strip() + "\n")50 continue51 line = line.strip()52 if count == 1:53 if line == '};':54 # done with first enum55 f2.write(line + "\n")56 f2.write("\n")57 break58 else:59 # skip pseudo instructions60 f2.write(" AArch64ExactFPImm_%s\n" %(line))61# extract ATsList[]62count = 063c = 064for line in lines:65 line = line.rstrip()66 if len(line.strip()) == 0:67 continue68 if line.strip() == 'const AT ATsList[] = {':69 count += 170 print_line('static const AT ATsList[] = {')71 continue72 line = line.strip()73 if count == 1:74 if line == '};':75 # done with first enum76 print_line('};\n')77 break78 else:79 # skip pseudo instructions80 line = line.replace('::', '_')81 #line = line.replace('{}', '{ 0 }')82 line = line.replace('{}', '')83 tmp = line.split(',')84 print_line(" %s, %s }, // %u" %(tmp[0].lower(), tmp[1], c))85 c += 186# lookupATByEncoding87count = 088for line in lines:89 line = line.rstrip()90 if len(line.strip()) == 0:91 continue92 if 'lookupATByEncoding' in line and '{' in line:93 count += 194 print_line('const AT *lookupATByEncoding(uint16_t Encoding)\n{')95 print_line(' unsigned int i;')96 continue97 if count == 1 and 'IndexType Index[] = {' in line:98 count += 199 if count == 2:100 if line.strip() == '};':101 # done with array, or this function?102 print_line(line)103 break104 else:105 # enum items106 print_line(line)107print_line("""108 i = binsearch_IndexTypeEncoding(Index, ARR_SIZE(Index), Encoding);109 if (i == -1)110 return NULL;111 else112 return &ATsList[Index[i].index];113}114""")115# extract DBsList[]116count = 0117for line in lines:118 line = line.rstrip()119 if len(line.strip()) == 0:120 continue121 if line.strip() == 'const DB DBsList[] = {':122 count += 1123 print_line('static const DB DBsList[] = {')124 continue125 line = line.strip()126 if count == 1:127 if line == '};':128 # done with first enum129 print_line('};\n')130 break131 else:132 # skip pseudo instructions133 line = line.replace('::', '_')134 #line = line.replace('{}', '{ 0 }')135 line = line.replace('{}', '')136 print_line(" %s" %(line))137# lookupDBByEncoding138count = 0139for line in lines:140 line = line.rstrip()141 if len(line.strip()) == 0:142 continue143 if 'lookupDBByEncoding' in line and '{' in line:144 count += 1145 print_line('const DB *lookupDBByEncoding(uint16_t Encoding)\n{')146 print_line(' unsigned int i;')147 continue148 if count == 1 and 'IndexType Index[] = {' in line:149 count += 1150 if count == 2:151 if line.strip() == '};':152 # done with array, or this function?153 print_line(line)154 break155 else:156 # enum items157 print_line(line)158print_line("""159 i = binsearch_IndexTypeEncoding(Index, ARR_SIZE(Index), Encoding);160 if (i == -1)161 return NULL;162 else163 return &DBsList[Index[i].index];164}165""")166# extract DCsList[]167count = 0168c = 0169for line in lines:170 line = line.rstrip()171 if len(line.strip()) == 0:172 continue173 if line.strip() == 'const DC DCsList[] = {':174 count += 1175 print_line('static const DC DCsList[] = {')176 continue177 line = line.strip()178 if count == 1:179 if line == '};':180 # done with first enum181 print_line('};\n')182 break183 else:184 # skip pseudo instructions185 line = line.replace('::', '_')186 #line = line.replace('{}', '{ 0 }')187 line = line.replace('{}', '')188 tmp = line.split(',')189 print_line(" %s, %s }, // %u" %(tmp[0].lower(), tmp[1], c))190 c += 1191# lookupDCByEncoding192count = 0193for line in lines:194 line = line.rstrip()195 if len(line.strip()) == 0:196 continue197 if 'lookupDCByEncoding' in line and '{' in line:198 count += 1199 print_line('const DC *lookupDCByEncoding(uint16_t Encoding)\n{')200 print_line(' unsigned int i;')201 continue202 if count == 1 and 'IndexType Index[] = {' in line:203 count += 1204 if count == 2:205 if line.strip() == '};':206 # done with array, or this function?207 print_line(line)208 break209 else:210 # enum items211 print_line(line)212print_line("""213 i = binsearch_IndexTypeEncoding(Index, ARR_SIZE(Index), Encoding);214 if (i == -1)215 return NULL;216 else217 return &DCsList[Index[i].index];218}219""")220# extract ICsList221count = 0222c = 0223for line in lines:224 line = line.rstrip()225 if len(line.strip()) == 0:226 continue227 if line.strip() == 'const IC ICsList[] = {':228 count += 1229 print_line('static const IC ICsList[] = {')230 continue231 line = line.strip()232 if count == 1:233 if line == '};':234 # done with first enum235 print_line('};\n')236 break237 else:238 # skip pseudo instructions239 line = line.replace('::', '_')240 #line = line.replace('{}', '{ 0 }')241 line = line.replace('{}', '')242 #tmp = line.split(',')243 #print_line(" %s, %s }, // %u" %(tmp[0].lower(), tmp[1], c))244 print_line(" %s" %line.lower())245 c += 1246# lookupICByEncoding247count = 0248for line in lines:249 line = line.rstrip()250 if len(line.strip()) == 0:251 continue252 if 'lookupICByEncoding' in line and '{' in line:253 count += 1254 print_line('const IC *lookupICByEncoding(uint16_t Encoding)\n{')255 print_line(' unsigned int i;')256 continue257 if count == 1 and 'IndexType Index[] = {' in line:258 count += 1259 if count == 2:260 if line.strip() == '};':261 # done with array, or this function?262 print_line(line)263 break264 else:265 # enum items266 print_line(line)267print_line("""268 i = binsearch_IndexTypeEncoding(Index, ARR_SIZE(Index), Encoding);269 if (i == -1)270 return NULL;271 else272 return &ICsList[Index[i].index];273}274""")275# extract TLBIsList276count = 0277c = 0278for line in lines:279 line = line.rstrip()280 if len(line.strip()) == 0:281 continue282 if line.strip() == 'const TLBI TLBIsList[] = {':283 count += 1284 print_line('static const TLBI TLBIsList[] = {')285 continue286 line = line.strip()287 if count == 1:288 if line == '};':289 # done with first enum290 print_line('};\n')291 break292 else:293 # skip pseudo instructions294 line = line.replace('::', '_')295 #line = line.replace('{}', '{ 0 }')296 line = line.replace('{}', '')297 tmp = line.split(',')298 print_line(" %s, %s, %s }, // %u" %(tmp[0].lower(), tmp[1], tmp[2], c))299 #print_line(" %s" %line.lower())300 c += 1301# lookupTLBIByEncoding302count = 0303for line in lines:304 line = line.rstrip()305 if len(line.strip()) == 0:306 continue307 if 'lookupTLBIByEncoding' in line and '{' in line:308 count += 1309 print_line('const TLBI *lookupTLBIByEncoding(uint16_t Encoding)\n{')310 print_line(' unsigned int i;')311 continue312 if count == 1 and 'IndexType Index[] = {' in line:313 count += 1314 if count == 2:315 if line.strip() == '};':316 # done with array, or this function?317 print_line(line)318 break319 else:320 # enum items321 print_line(line)322print_line("""323 i = binsearch_IndexTypeEncoding(Index, ARR_SIZE(Index), Encoding);324 if (i == -1)325 return NULL;326 else327 return &TLBIsList[Index[i].index];328}329""")330# extract SVEPRFMsList331count = 0332c = 0333for line in lines:334 line = line.rstrip()335 if len(line.strip()) == 0:336 continue337 if line.strip() == 'const SVEPRFM SVEPRFMsList[] = {':338 count += 1339 print_line('static const SVEPRFM SVEPRFMsList[] = {')340 continue341 line = line.strip()342 if count == 1:343 if line == '};':344 # done with first enum345 print_line('};\n')346 break347 else:348 # skip pseudo instructions349 line = line.replace('::', '_')350 #line = line.replace('{}', '{ 0 }')351 line = line.replace('{}', '')352 tmp = line.split(',')353 print_line(" %s, %s }, // %u" %(tmp[0].lower(), tmp[1], c))354 #print_line(" %s" %line.lower())355 c += 1356# lookupSVEPRFMByEncoding357count = 0358for line in lines:359 line = line.rstrip()360 if len(line.strip()) == 0:361 continue362 if 'lookupSVEPRFMByEncoding' in line and '{' in line:363 count += 1364 print_line('const SVEPRFM *lookupSVEPRFMByEncoding(uint16_t Encoding)\n{')365 print_line(' unsigned int i;')366 continue367 if count == 1 and 'IndexType Index[] = {' in line:368 count += 1369 if count == 2:370 if line.strip() == '};':371 # done with array, or this function?372 print_line(line)373 break374 else:375 # enum items376 print_line(line)377print_line("""378 i = binsearch_IndexTypeEncoding(Index, ARR_SIZE(Index), Encoding);379 if (i == -1)380 return NULL;381 else382 return &SVEPRFMsList[Index[i].index];383}384""")385# extract PRFMsList386count = 0387c = 0388for line in lines:389 line = line.rstrip()390 if len(line.strip()) == 0:391 continue392 if line.strip() == 'const PRFM PRFMsList[] = {':393 count += 1394 print_line('static const PRFM PRFMsList[] = {')395 continue396 line = line.strip()397 if count == 1:398 if line == '};':399 # done with first enum400 print_line('};\n')401 break402 else:403 # skip pseudo instructions404 line = line.replace('::', '_')405 #line = line.replace('{}', '{ 0 }')406 line = line.replace('{}', '')407 #tmp = line.split(',')408 #print_line(" %s, %s }, // %u" %(tmp[0].lower(), tmp[1], c))409 print_line(" %s" %line.lower())410 c += 1411# lookupPRFMByEncoding412count = 0413for line in lines:414 line = line.rstrip()415 if len(line.strip()) == 0:416 continue417 if 'lookupPRFMByEncoding' in line and '{' in line:418 count += 1419 print_line('const PRFM *lookupPRFMByEncoding(uint16_t Encoding)\n{')420 print_line(' unsigned int i;')421 continue422 if count == 1 and 'IndexType Index[] = {' in line:423 count += 1424 if count == 2:425 if line.strip() == '};':426 # done with array, or this function?427 print_line(line)428 break429 else:430 # enum items431 print_line(line)432print_line("""433 i = binsearch_IndexTypeEncoding(Index, ARR_SIZE(Index), Encoding);434 if (i == -1)435 return NULL;436 else437 return &PRFMsList[Index[i].index];438}439""")440# extract PSBsList441count = 0442c = 0443for line in lines:444 line = line.rstrip()445 if len(line.strip()) == 0:446 continue447 if line.strip() == 'const PSB PSBsList[] = {':448 count += 1449 print_line('static const PSB PSBsList[] = {')450 continue451 line = line.strip()452 if count == 1:453 if line == '};':454 # done with first enum455 print_line('};\n')456 break457 else:458 # skip pseudo instructions459 line = line.replace('::', '_')460 #line = line.replace('{}', '{ 0 }')461 line = line.replace('{}', '')462 #tmp = line.split(',')463 #print_line(" %s, %s }, // %u" %(tmp[0].lower(), tmp[1], c))464 print_line(" %s" %line.lower())465 c += 1466# lookupPSBByEncoding467count = 0468for line in lines:469 line = line.rstrip()470 if len(line.strip()) == 0:471 continue472 if 'lookupPSBByEncoding' in line and '{' in line:473 count += 1474 print_line('const PSB *AArch64PSBHint_lookupPSBByEncoding(uint16_t Encoding)\n{')475 print_line(' unsigned int i;')476 continue477 if count == 1 and 'IndexType Index[] = {' in line:478 count += 1479 if count == 2:480 if line.strip() == '};':481 # done with array, or this function?482 print_line(line)483 break484 else:485 # enum items486 print_line(line)487print_line("""488 i = binsearch_IndexTypeEncoding(Index, ARR_SIZE(Index), Encoding);489 if (i == -1)490 return NULL;491 else492 return &PSBsList[Index[i].index];493}494""")495# extract ISBsList496count = 0497c = 0498for line in lines:499 line = line.rstrip()500 if len(line.strip()) == 0:501 continue502 if line.strip() == 'const ISB ISBsList[] = {':503 count += 1504 print_line('static const ISB ISBsList[] = {')505 continue506 line = line.strip()507 if count == 1:508 if line == '};':509 # done with first enum510 print_line('};\n')511 break512 else:513 # skip pseudo instructions514 line = line.replace('::', '_')515 #line = line.replace('{}', '{ 0 }')516 line = line.replace('{}', '')517 #tmp = line.split(',')518 #print_line(" %s, %s }, // %u" %(tmp[0].lower(), tmp[1], c))519 print_line(" %s" %line.lower())520 c += 1521# lookupISBByName522count = 0523for line in lines:524 line = line.rstrip()525 if len(line.strip()) == 0:526 continue527 if 'lookupISBByEncoding' in line and '{' in line:528 count += 1529 print_line('const ISB *lookupISBByEncoding(uint16_t Encoding)\n{')530 print_line(' unsigned int i;')531 continue532 if count == 1 and 'IndexType Index[] = {' in line:533 count += 1534 if count == 2:535 if line.strip() == '};':536 # done with array, or this function?537 print_line(line)538 break539 else:540 # enum items541 print_line(line)542print_line("""543 i = binsearch_IndexTypeEncoding(Index, ARR_SIZE(Index), Encoding);544 if (i == -1)545 return NULL;546 else547 return &ISBsList[Index[i].index];548}549""")550# extract TSBsList551count = 0552c = 0553for line in lines:554 line = line.rstrip()555 if len(line.strip()) == 0:556 continue557 if line.strip() == 'const TSB TSBsList[] = {':558 count += 1559 print_line('static const TSB TSBsList[] = {')560 continue561 line = line.strip()562 if count == 1:563 if line == '};':564 # done with first enum565 print_line('};\n')566 break567 else:568 # skip pseudo instructions569 line = line.replace('::', '_')570 #line = line.replace('{}', '{ 0 }')571 line = line.replace('{}', '')572 tmp = line.split(',')573 print_line(" %s, %s }, // %u" %(tmp[0].lower(), tmp[1], c))574 #print_line(" %s" %line.lower())575 c += 1576# lookupTSBByEncoding577count = 0578for line in lines:579 line = line.rstrip()580 if len(line.strip()) == 0:581 continue582 if 'lookupTSBByEncoding' in line and '{' in line:583 count += 1584 print_line('const TSB *lookupTSBByEncoding(uint16_t Encoding)\n{')585 continue586 if count == 1 and 'IndexType Index[] = {' in line:587 count += 1588 if count == 2:589 if line.strip() == '};':590 # done with array, or this function?591 print_line(line)592 break593 else:594 # enum items595 print_line(line)596print_line("""597 if (Encoding >= ARR_SIZE(TSBsList))598 return NULL;599 else600 return &TSBsList[Index[Encoding].index];601}602""")603# extract SysRegsList604count = 0605c = 0606for line in lines:607 line = line.rstrip()608 if len(line.strip()) == 0:609 continue610 if line.strip() == 'const SysReg SysRegsList[] = {':611 count += 1612 print_line('static const SysReg SysRegsList[] = {')613 continue614 line = line.strip()615 if count == 1:616 if line == '};':617 # done with first enum618 print_line('};\n')619 break620 else:621 # skip pseudo instructions622 line = line.replace('::', '_')623 #line = line.replace('{}', '{ 0 }')624 line = line.replace('{}', '')625 tmp = line.split(',')626 print_line(" %s, %s, %s, %s }, // %u" %(tmp[0].lower(), tmp[1], tmp[2], tmp[3], c))627 #print_line(" %s" %line.lower())628 c += 1629# lookupSysRegByEncoding630count = 0631for line in lines:632 line = line.rstrip()633 if len(line.strip()) == 0:634 continue635 if 'lookupSysRegByEncoding' in line and '{' in line:636 count += 1637 print_line('const SysReg *lookupSysRegByEncoding(uint16_t Encoding)\n{')638 print_line(' unsigned int i;')639 continue640 if count == 1 and 'IndexType Index[] = {' in line:641 count += 1642 if count == 2:643 if line.strip() == '};':644 # done with array, or this function?645 print_line(line)646 break647 else:648 # enum items649 print_line(line)650print_line("""651 i = binsearch_IndexTypeEncoding(Index, ARR_SIZE(Index), Encoding);652 if (i == -1)653 return NULL;654 else655 return &SysRegsList[Index[i].index];656}657""")658# extract PStatesList659count = 0660c = 0661for line in lines:662 line = line.rstrip()663 if len(line.strip()) == 0:664 continue665 if line.strip() == 'const PState PStatesList[] = {':666 count += 1667 print_line('static const PState PStatesList[] = {')668 continue669 line = line.strip()670 if count == 1:671 if line == '};':672 # done with first enum673 print_line('};\n')674 break675 else:676 # skip pseudo instructions677 line = line.replace('::', '_')678 #line = line.replace('{}', '{ 0 }')679 line = line.replace('{}', '')680 tmp = line.split(',')681 print_line(" %s, %s }, // %u" %(tmp[0].lower(), tmp[1], c))682 #print_line(" %s" %line.lower())683 c += 1684# lookupPStateByEncoding685count = 0686for line in lines:687 line = line.rstrip()688 if len(line.strip()) == 0:689 continue690 if 'lookupPStateByEncoding' in line and '{' in line:691 count += 1692 print_line('const PState *lookupPStateByEncoding(uint16_t Encoding)\n{')693 print_line(' unsigned int i;')694 continue695 if count == 1 and 'IndexType Index[] = {' in line:696 count += 1697 if count == 2:698 if line.strip() == '};':699 # done with array, or this function?700 print_line(line)701 break702 else:703 # enum items704 print_line(line)705print_line("""706 i = binsearch_IndexTypeEncoding(Index, ARR_SIZE(Index), Encoding);707 if (i == -1)708 return NULL;709 else710 return &PStatesList[Index[i].index];711}712""")713# extract SVEPREDPATsList714count = 0715c = 0716for line in lines:717 line = line.rstrip()718 if len(line.strip()) == 0:719 continue720 if line.strip() == 'const SVEPREDPAT SVEPREDPATsList[] = {':721 count += 1722 print_line('static const SVEPREDPAT SVEPREDPATsList[] = {')723 continue724 line = line.strip()725 if count == 1:726 if line == '};':727 # done with first enum728 print_line('};\n')729 break730 else:731 # skip pseudo instructions732 line = line.replace('::', '_')733 #line = line.replace('{}', '{ 0 }')734 line = line.replace('{}', '')735 tmp = line.split(',')736 #print_line(" %s, %s }, // %u" %(tmp[0].lower(), tmp[1], c))737 print_line(" %s" %line.lower())738 c += 1739# lookupSVEPREDPATByEncoding740count = 0741for line in lines:742 line = line.rstrip()743 if len(line.strip()) == 0:744 continue745 if 'lookupSVEPREDPATByEncoding' in line and '{' in line:746 count += 1747 print_line('const SVEPREDPAT *lookupSVEPREDPATByEncoding(uint16_t Encoding)\n{')748 print_line(' unsigned int i;')749 continue750 if count == 1 and 'IndexType Index[] = {' in line:751 count += 1752 if count == 2:753 if line.strip() == '};':754 # done with array, or this function?755 print_line(line)756 break757 else:758 # enum items759 print_line(line)760print_line("""761 i = binsearch_IndexTypeEncoding(Index, ARR_SIZE(Index), Encoding);762 if (i == -1)763 return NULL;764 else765 return &SVEPREDPATsList[Index[i].index];766}767""")768# extract ExactFPImmsList769count = 0770c = 0771for line in lines:772 line = line.rstrip()773 if len(line.strip()) == 0:774 continue775 if line.strip() == 'const ExactFPImm ExactFPImmsList[] = {':776 count += 1777 print_line('static const ExactFPImm ExactFPImmsList[] = {')778 continue779 line = line.strip()780 if count == 1:781 if line == '};':782 # done with first enum783 print_line('};\n')784 break785 else:786 # skip pseudo instructions787 line = line.replace('::', '_')788 #line = line.replace('{}', '{ 0 }')789 line = line.replace('{}', '')790 tmp = line.split(',')791 #print_line(" %s, %s }, // %u" %(tmp[0].lower(), tmp[1], c))792 print_line(" %s" %line.lower())793 c += 1794# lookupExactFPImmByEnum795count = 0796for line in lines:797 line = line.rstrip()798 if len(line.strip()) == 0:799 continue800 if 'lookupExactFPImmByEnum' in line and '{' in line:801 count += 1802 print_line('const ExactFPImm *lookupExactFPImmByEnum(uint16_t Encoding)\n{')803 continue804 if count == 1 and 'IndexType Index[] = {' in line:805 count += 1806 if count == 2:807 if line.strip() == '};':808 # done with array, or this function?809 print_line(line)810 break811 else:812 # enum items813 print_line(line)814print_line("""815 if (Encoding >= ARR_SIZE(ExactFPImmsList))816 return NULL;817 else818 return &ExactFPImmsList[Index[Encoding].index];819}...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!