Skip to content
This repository was archived by the owner on Mar 28, 2020. It is now read-only.

Commit e1b56f0

Browse files
committed
[AsmParser][TableGen] Add VariantID argument to the generated mnemonic spell check function so it can use the correct table based on variant.
I'm considering implementing the mnemonic spell checker for x86, and that would require the separate intel and att variants. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@316641 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent 939e970 commit e1b56f0

File tree

4 files changed

+21
-8
lines changed

4 files changed

+21
-8
lines changed

lib/Target/AArch64/AsmParser/AArch64AsmParser.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3297,7 +3297,8 @@ bool AArch64AsmParser::validateInstruction(MCInst &Inst,
32973297
}
32983298
}
32993299

3300-
static std::string AArch64MnemonicSpellCheck(StringRef S, uint64_t FBS);
3300+
static std::string AArch64MnemonicSpellCheck(StringRef S, uint64_t FBS,
3301+
unsigned VariantID = 0);
33013302

33023303
bool AArch64AsmParser::showMatchError(SMLoc Loc, unsigned ErrCode,
33033304
OperandVector &Operands) {

lib/Target/ARM/AsmParser/ARMAsmParser.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9040,7 +9040,8 @@ unsigned ARMAsmParser::MatchInstruction(OperandVector &Operands, MCInst &Inst,
90409040
return PlainMatchResult;
90419041
}
90429042

9043-
static std::string ARMMnemonicSpellCheck(StringRef S, uint64_t FBS);
9043+
static std::string ARMMnemonicSpellCheck(StringRef S, uint64_t FBS,
9044+
unsigned VariantID = 0);
90449045

90459046
static const char *getSubtargetFeatureName(uint64_t Val);
90469047
bool ARMAsmParser::MatchAndEmitInstruction(SMLoc IDLoc, unsigned &Opcode,

lib/Target/SystemZ/AsmParser/SystemZAsmParser.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1169,7 +1169,8 @@ bool SystemZAsmParser::parseOperand(OperandVector &Operands,
11691169
return false;
11701170
}
11711171

1172-
static std::string SystemZMnemonicSpellCheck(StringRef S, uint64_t FBS);
1172+
static std::string SystemZMnemonicSpellCheck(StringRef S, uint64_t FBS,
1173+
unsigned VariantID = 0);
11731174

11741175
bool SystemZAsmParser::MatchAndEmitInstruction(SMLoc IDLoc, unsigned &Opcode,
11751176
OperandVector &Operands,

utils/TableGen/AsmMatcherEmitter.cpp

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2824,16 +2824,26 @@ static void emitCustomOperandParsing(raw_ostream &OS, CodeGenTarget &Target,
28242824
static void emitMnemonicSpellChecker(raw_ostream &OS, CodeGenTarget &Target,
28252825
unsigned VariantCount) {
28262826
OS << "static std::string " << Target.getName()
2827-
<< "MnemonicSpellCheck(StringRef S, uint64_t FBS) {\n";
2827+
<< "MnemonicSpellCheck(StringRef S, uint64_t FBS, unsigned VariantID) {\n";
28282828
if (!VariantCount)
28292829
OS << " return \"\";";
28302830
else {
28312831
OS << " const unsigned MaxEditDist = 2;\n";
28322832
OS << " std::vector<StringRef> Candidates;\n";
2833-
OS << " StringRef Prev = \"\";\n";
2834-
OS << " auto End = std::end(MatchTable0);\n";
2835-
OS << "\n";
2836-
OS << " for (auto I = std::begin(MatchTable0); I < End; I++) {\n";
2833+
OS << " StringRef Prev = \"\";\n\n";
2834+
2835+
OS << " // Find the appropriate table for this asm variant.\n";
2836+
OS << " const MatchEntry *Start, *End;\n";
2837+
OS << " switch (VariantID) {\n";
2838+
OS << " default: llvm_unreachable(\"invalid variant!\");\n";
2839+
for (unsigned VC = 0; VC != VariantCount; ++VC) {
2840+
Record *AsmVariant = Target.getAsmParserVariant(VC);
2841+
int AsmVariantNo = AsmVariant->getValueAsInt("Variant");
2842+
OS << " case " << AsmVariantNo << ": Start = std::begin(MatchTable" << VC
2843+
<< "); End = std::end(MatchTable" << VC << "); break;\n";
2844+
}
2845+
OS << " }\n\n";
2846+
OS << " for (auto I = Start; I < End; I++) {\n";
28372847
OS << " // Ignore unsupported instructions.\n";
28382848
OS << " if ((FBS & I->RequiredFeatures) != I->RequiredFeatures)\n";
28392849
OS << " continue;\n";

0 commit comments

Comments
 (0)