1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-25 04:02:41 +01:00

[TableGen] Allow mnemonics aliases with uppercase

Differential Revision: https://reviews.llvm.org/D96691
This commit is contained in:
paperchalice 2021-04-16 09:55:42 -04:00 committed by Paul C. Anagnostopoulos
parent 7e3cf86c11
commit 76d74ee926
2 changed files with 24 additions and 3 deletions

View File

@ -1,5 +1,6 @@
// RUN: llvm-tblgen -gen-asm-matcher -I %p/../../include %s | FileCheck %s --check-prefix=MATCHER
// RUN: llvm-tblgen -gen-asm-writer -I %p/../../include %s | FileCheck %s --check-prefix=WRITER
// RUN: llvm-tblgen -gen-asm-matcher -I %p/../../include %s | FileCheck %s --check-prefix=ALIAS
// Check that an instruction that uses mixed upper/lower case in its mnemonic
// is printed as-is, and is parsed in its "canonicalized" lowercase form.
@ -35,6 +36,9 @@ def AlphabeticallyFirstInst : Instruction {
let AsmString = "aInst";
}
def :MnemonicAlias<"Insta", "aInst">;
def :MnemonicAlias<"InstB", "BInst">;
// Check that the matcher lower()s the mnemonics it matches.
// MATCHER: static const char *const MnemonicTable =
// MATCHER-NEXT: "\005ainst\005binst";
@ -53,3 +57,20 @@ def AlphabeticallyFirstInst : Instruction {
// WRITER-NEXT: "aInst\0"
// WRITER-NEXT: };
// ALIAS: static void applyMnemonicAliases(StringRef &Mnemonic, const FeatureBitset &Features, unsigned VariantID) {
// ALIAS-NEXT switch (VariantID) {
// ALIAS-NEXT case 0:
// ALIAS-NEXT switch (Mnemonic.size()) {
// ALIAS-NEXT default: break;
// ALIAS-NEXT case 5: // 2 strings to match.
// ALIAS-NEXT if (memcmp(Mnemonic.data()+0, "inst", 4) != 0)
// ALIAS-NEXT break;
// ALIAS-NEXT switch (Mnemonic[4]) {
// ALIAS-NEXT default: break;
// ALIAS-NEXT case 'a': // 1 string to match.
// ALIAS-NEXT Mnemonic = "ainst"; // "insta"
// ALIAS-NEXT return;
// ALIAS-NEXT case 'b': // 1 string to match.
// ALIAS-NEXT Mnemonic = "binst"; // "instb"
// ALIAS-NEXT return;

View File

@ -2726,7 +2726,7 @@ static void emitMnemonicAliasVariant(raw_ostream &OS,const AsmMatcherInfo &Info,
StringRef AsmVariantName = R->getValueAsString("AsmVariantName");
if (AsmVariantName != AsmParserVariantName)
continue;
AliasesFromMnemonic[std::string(R->getValueAsString("FromMnemonic"))]
AliasesFromMnemonic[R->getValueAsString("FromMnemonic").lower()]
.push_back(R);
}
if (AliasesFromMnemonic.empty())
@ -2768,7 +2768,7 @@ static void emitMnemonicAliasVariant(raw_ostream &OS,const AsmMatcherInfo &Info,
MatchCode += "else ";
MatchCode += "if (" + FeatureMask + ")\n";
MatchCode += " Mnemonic = \"";
MatchCode += R->getValueAsString("ToMnemonic");
MatchCode += R->getValueAsString("ToMnemonic").lower();
MatchCode += "\";\n";
}
@ -2777,7 +2777,7 @@ static void emitMnemonicAliasVariant(raw_ostream &OS,const AsmMatcherInfo &Info,
if (!MatchCode.empty())
MatchCode += "else\n ";
MatchCode += "Mnemonic = \"";
MatchCode += R->getValueAsString("ToMnemonic");
MatchCode += R->getValueAsString("ToMnemonic").lower();
MatchCode += "\";\n";
}