@@ -658,14 +658,20 @@ std::string edgeCaseTemplArg(std::string &Code) {
658658 PrintFatalNote (" Edge case for C++ code not handled: " + Code);
659659}
660660
661- static std::string handleDefaultArg (std::string &Code) {
661+ static std::string handleDefaultArg (const std::string &TargetName,
662+ std::string &Code) {
662663 static SmallVector<std::pair<std::string, std::string>>
663- TemplFuncWithDefaults = {// Default is 1
664- {" printVectorIndex" , " 1" },
665- // Default is false == 0
666- {" printPrefetchOp" , " 0" }};
664+ AArch64TemplFuncWithDefaults = {// Default is 1
665+ {" printVectorIndex" , " 1" },
666+ // Default is false == 0
667+ {" printPrefetchOp" , " 0" }};
668+ SmallVector<std::pair<std::string, std::string>> *TemplFuncWithDefaults;
669+ if (TargetName == " AArch64" )
670+ TemplFuncWithDefaults = &AArch64TemplFuncWithDefaults;
671+ else
672+ return Code;
667673
668- for (std::pair Func : TemplFuncWithDefaults) {
674+ for (std::pair Func : * TemplFuncWithDefaults) {
669675 if (Code.find (Func.first ) != std::string::npos) {
670676 unsigned long const B =
671677 Code.find (Func.first ) + std::string (Func.first ).size ();
@@ -681,11 +687,12 @@ static std::string handleDefaultArg(std::string &Code) {
681687 return Code;
682688}
683689
684- static void patchTemplateArgs (std::string &Code) {
690+ static void patchTemplateArgs (const std::string &TargetName,
691+ std::string &Code) {
685692 unsigned long const B = Code.find_first_of (" <" );
686693 unsigned long const E = Code.find (" >" );
687694 if (B == std::string::npos) {
688- Code = handleDefaultArg (Code);
695+ Code = handleDefaultArg (TargetName, Code);
689696 return ;
690697 }
691698 std::string const &DecName = Code.substr (0 , B);
@@ -707,12 +714,13 @@ static void patchTemplateArgs(std::string &Code) {
707714 Code = DecName + " _" + Args + Rest;
708715}
709716
710- std::string PrinterCapstone::translateToC (std::string const &Code) {
717+ std::string PrinterCapstone::translateToC (std::string const &TargetName,
718+ std::string const &Code) {
711719 std::string PatchedCode (Code);
712720 patchQualifier (PatchedCode);
713721 patchNullptr (PatchedCode);
714722 patchIsGetImmReg (PatchedCode);
715- patchTemplateArgs (PatchedCode);
723+ patchTemplateArgs (TargetName, PatchedCode);
716724 return PatchedCode;
717725}
718726
@@ -721,7 +729,7 @@ void PrinterCapstone::decoderEmitterEmitOpDecoder(raw_ostream &DecoderOS,
721729 unsigned const Indent = 4 ;
722730 DecoderOS.indent (Indent) << GuardPrefix;
723731 if (Op.Decoder .find (" <" ) != std::string::npos) {
724- DecoderOS << translateToC (Op.Decoder );
732+ DecoderOS << translateToC (TargetName, Op.Decoder );
725733 } else {
726734 DecoderOS << Op.Decoder ;
727735 }
@@ -735,7 +743,7 @@ void PrinterCapstone::decoderEmitterEmitOpBinaryParser(
735743 raw_ostream &DecOS, const OperandInfo &OpInfo) const {
736744 unsigned const Indent = 4 ;
737745 const std::string &Decoder = (OpInfo.Decoder .find (" <" ) != std::string::npos)
738- ? translateToC (OpInfo.Decoder )
746+ ? translateToC (TargetName, OpInfo.Decoder )
739747 : OpInfo.Decoder ;
740748
741749 bool const UseInsertBits = OpInfo.numFields () != 1 || OpInfo.InitValue != 0 ;
@@ -1387,11 +1395,11 @@ void PrinterCapstone::asmWriterEmitPrintInstruction(
13871395 // Emit two possibilitys with if/else.
13881396 OS << " if ((Bits >> " << (OpcodeInfoBits - BitsLeft) << " ) & "
13891397 << ((1 << NumBits) - 1 ) << " ) {\n "
1390- << translateToC (Commands[1 ]) << " } else {\n "
1391- << translateToC (Commands[0 ]) << " }\n\n " ;
1398+ << translateToC (TargetName, Commands[1 ]) << " } else {\n "
1399+ << translateToC (TargetName, Commands[0 ]) << " }\n\n " ;
13921400 } else if (Commands.size () == 1 ) {
13931401 // Emit a single possibility.
1394- OS << translateToC (Commands[0 ]) << " \n\n " ;
1402+ OS << translateToC (TargetName, Commands[0 ]) << " \n\n " ;
13951403 } else {
13961404 OS << " switch ((Bits >> " << (OpcodeInfoBits - BitsLeft) << " ) & "
13971405 << ((1 << NumBits) - 1 ) << " ) {\n "
@@ -1400,7 +1408,7 @@ void PrinterCapstone::asmWriterEmitPrintInstruction(
14001408 // Print out all the cases.
14011409 for (unsigned J = 0 , F = Commands.size (); J != F; ++J) {
14021410 OS << " case " << J << " :\n " ;
1403- OS << translateToC (Commands[J]);
1411+ OS << translateToC (TargetName, Commands[J]);
14041412 OS << " break;\n " ;
14051413 }
14061414 OS << " }\n\n " ;
@@ -1425,7 +1433,7 @@ void PrinterCapstone::asmWriterEmitOpCases(
14251433 }
14261434
14271435 // Finally, emit the code.
1428- OS << " \n " << TheOp.getCode (PassSubtarget);
1436+ OS << " \n " << translateToC (TargetName, TheOp.getCode (PassSubtarget) );
14291437 OS << " \n break;\n " ;
14301438}
14311439
@@ -1459,7 +1467,7 @@ void PrinterCapstone::asmWriterEmitInstruction(
14591467 for (unsigned I = 0 , E = FirstInst.Operands .size (); I != E; ++I) {
14601468 if (I != DifferingOperand) {
14611469 // If the operand is the same for all instructions, just print it.
1462- OS << " " << FirstInst.Operands [I].getCode (PassSubtarget);
1470+ OS << " " << translateToC (TargetName, FirstInst.Operands [I].getCode (PassSubtarget) );
14631471 } else {
14641472 // If this is the operand that varies between all of the instructions,
14651473 // emit a switch for just this operand now.
@@ -1768,7 +1776,7 @@ void PrinterCapstone::asmWriterEmitPrintAliasOp(
17681776 for (unsigned I = 0 ; I < PrintMethods.size (); ++I) {
17691777 OS << " case " << I << " :\n " ;
17701778 std::string PrintMethod =
1771- PrinterCapstone::translateToC (PrintMethods[I].first );
1779+ PrinterCapstone::translateToC (TargetName, PrintMethods[I].first );
17721780 OS << " " << PrintMethod << " (MI, "
17731781 << (PrintMethods[I].second ? " Address, " : " " ) << " OpIdx, "
17741782 << " OS);\n "
@@ -1796,7 +1804,8 @@ void PrinterCapstone::asmWriterEmitPrintMC(
17961804 StringRef const MCOpPred =
17971805 MCOpPredicates[I]->getValueAsString (" MCOperandPredicate" );
17981806 OS << " case " << I + 1 << " : {\n " ;
1799- std::string PrintMethod = PrinterCapstone::translateToC (MCOpPred.data ());
1807+ std::string PrintMethod =
1808+ PrinterCapstone::translateToC (TargetName, MCOpPred.data ());
18001809 OS << PrintMethod << " \n "
18011810 << " }\n " ;
18021811 }
@@ -2908,7 +2917,8 @@ void printOpPrintGroupEnum(StringRef const &TargetName,
29082917
29092918 for (const CGIOperandList::OperandInfo &Op : CGI->Operands ) {
29102919 std::string OpGroup =
2911- PrinterCapstone::translateToC (Op.PrinterMethodName ).substr (5 );
2920+ PrinterCapstone::translateToC (TargetName.str (), Op.PrinterMethodName )
2921+ .substr (5 );
29122922 if (OpGroups.find (OpGroup) != OpGroups.end ())
29132923 continue ;
29142924 OpGroupEnum.indent (2 ) << TargetName + " _OP_GROUP_" + OpGroup + " = "
0 commit comments