Skip to content

Commit 3e5b436

Browse files
committed
[MC][AsmParser] Make MatchRegisterName return MCRegister
`MCRegister` is preferred over `unsigned` nowadays.
1 parent 1a8c613 commit 3e5b436

File tree

7 files changed

+27
-22
lines changed

7 files changed

+27
-22
lines changed

llvm/lib/Target/AArch64/AsmParser/AArch64AsmParser.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2600,7 +2600,7 @@ void AArch64Operand::print(raw_ostream &OS) const {
26002600
/// @name Auto-generated Match Functions
26012601
/// {
26022602

2603-
static unsigned MatchRegisterName(StringRef Name);
2603+
static MCRegister MatchRegisterName(StringRef Name);
26042604

26052605
/// }
26062606

llvm/lib/Target/ARM/AsmParser/ARMAsmParser.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4045,7 +4045,7 @@ void ARMOperand::print(raw_ostream &OS) const {
40454045
/// @name Auto-generated Match Functions
40464046
/// {
40474047

4048-
static unsigned MatchRegisterName(StringRef Name);
4048+
static MCRegister MatchRegisterName(StringRef Name);
40494049

40504050
/// }
40514051

llvm/lib/Target/AVR/AsmParser/AVRAsmParser.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ class AVRAsmParser : public MCTargetAsmParser {
6868
ParseStatus parseMemriOperand(OperandVector &Operands);
6969

7070
bool parseOperand(OperandVector &Operands, bool maybeReg);
71-
int parseRegisterName(unsigned (*matchFn)(StringRef));
71+
int parseRegisterName(MCRegister (*matchFn)(StringRef));
7272
int parseRegisterName();
7373
int parseRegister(bool RestoreOnFailure = false);
7474
bool tryParseRegisterOperand(OperandVector &Operands);
@@ -276,11 +276,11 @@ class AVROperand : public MCParsedAsmOperand {
276276

277277
/// Maps from the set of all register names to a register number.
278278
/// \note Generated by TableGen.
279-
static unsigned MatchRegisterName(StringRef Name);
279+
static MCRegister MatchRegisterName(StringRef Name);
280280

281281
/// Maps from the set of all alternative registernames to a register number.
282282
/// \note Generated by TableGen.
283-
static unsigned MatchRegisterAltName(StringRef Name);
283+
static MCRegister MatchRegisterAltName(StringRef Name);
284284

285285
bool AVRAsmParser::invalidOperand(SMLoc const &Loc,
286286
OperandVector const &Operands,
@@ -346,7 +346,7 @@ bool AVRAsmParser::MatchAndEmitInstruction(SMLoc Loc, unsigned &Opcode,
346346

347347
/// Parses a register name using a given matching function.
348348
/// Checks for lowercase or uppercase if necessary.
349-
int AVRAsmParser::parseRegisterName(unsigned (*matchFn)(StringRef)) {
349+
int AVRAsmParser::parseRegisterName(MCRegister (*matchFn)(StringRef)) {
350350
StringRef Name = Parser.getTok().getString();
351351

352352
int RegNum = matchFn(Name);

llvm/lib/Target/Lanai/AsmParser/LanaiAsmParser.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
using namespace llvm;
4141

4242
// Auto-generated by TableGen
43-
static unsigned MatchRegisterName(StringRef Name);
43+
static MCRegister MatchRegisterName(StringRef Name);
4444

4545
namespace {
4646

llvm/lib/Target/MSP430/AsmParser/MSP430AsmParser.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -286,8 +286,8 @@ bool MSP430AsmParser::MatchAndEmitInstruction(SMLoc Loc, unsigned &Opcode,
286286
}
287287

288288
// Auto-generated by TableGen
289-
static unsigned MatchRegisterName(StringRef Name);
290-
static unsigned MatchRegisterAltName(StringRef Name);
289+
static MCRegister MatchRegisterName(StringRef Name);
290+
static MCRegister MatchRegisterAltName(StringRef Name);
291291

292292
bool MSP430AsmParser::parseRegister(MCRegister &Reg, SMLoc &StartLoc,
293293
SMLoc &EndLoc) {

llvm/lib/Target/VE/AsmParser/VEAsmParser.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ class VEAsmParser : public MCTargetAsmParser {
5656
uint64_t &ErrorInfo,
5757
bool MatchingInlineAsm) override;
5858
bool parseRegister(MCRegister &Reg, SMLoc &StartLoc, SMLoc &EndLoc) override;
59-
int parseRegisterName(unsigned (*matchFn)(StringRef));
59+
int parseRegisterName(MCRegister (*matchFn)(StringRef));
6060
ParseStatus tryParseRegister(MCRegister &Reg, SMLoc &StartLoc,
6161
SMLoc &EndLoc) override;
6262
bool ParseInstruction(ParseInstructionInfo &Info, StringRef Name,
@@ -805,7 +805,7 @@ bool VEAsmParser::parseRegister(MCRegister &Reg, SMLoc &StartLoc,
805805

806806
/// Parses a register name using a given matching function.
807807
/// Checks for lowercase or uppercase if necessary.
808-
int VEAsmParser::parseRegisterName(unsigned (*matchFn)(StringRef)) {
808+
int VEAsmParser::parseRegisterName(MCRegister (*matchFn)(StringRef)) {
809809
StringRef Name = Parser.getTok().getString();
810810

811811
int RegNum = matchFn(Name);
@@ -821,11 +821,11 @@ int VEAsmParser::parseRegisterName(unsigned (*matchFn)(StringRef)) {
821821

822822
/// Maps from the set of all register names to a register number.
823823
/// \note Generated by TableGen.
824-
static unsigned MatchRegisterName(StringRef Name);
824+
static MCRegister MatchRegisterName(StringRef Name);
825825

826826
/// Maps from the set of all alternative registernames to a register number.
827827
/// \note Generated by TableGen.
828-
static unsigned MatchRegisterAltName(StringRef Name);
828+
static MCRegister MatchRegisterAltName(StringRef Name);
829829

830830
ParseStatus VEAsmParser::tryParseRegister(MCRegister &Reg, SMLoc &StartLoc,
831831
SMLoc &EndLoc) {

llvm/utils/TableGen/AsmMatcherEmitter.cpp

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2617,21 +2617,24 @@ static void emitMatchRegisterName(CodeGenTarget &Target, Record *AsmParser,
26172617
// Construct the match list.
26182618
std::vector<StringMatcher::StringPair> Matches;
26192619
const auto &Regs = Target.getRegBank().getRegisters();
2620+
std::string Namespace =
2621+
Regs.front().TheDef->getValueAsString("Namespace").str();
26202622
for (const CodeGenRegister &Reg : Regs) {
2621-
if (Reg.TheDef->getValueAsString("AsmName").empty())
2623+
StringRef AsmName = Reg.TheDef->getValueAsString("AsmName");
2624+
if (AsmName.empty())
26222625
continue;
26232626

2624-
Matches.emplace_back(std::string(Reg.TheDef->getValueAsString("AsmName")),
2625-
"return " + utostr(Reg.EnumValue) + ";");
2627+
Matches.emplace_back(AsmName.str(), "return " + Namespace +
2628+
"::" + Reg.getName().str() + ';');
26262629
}
26272630

2628-
OS << "static unsigned MatchRegisterName(StringRef Name) {\n";
2631+
OS << "static MCRegister MatchRegisterName(StringRef Name) {\n";
26292632

26302633
bool IgnoreDuplicates =
26312634
AsmParser->getValueAsBit("AllowDuplicateRegisterNames");
26322635
StringMatcher("Name", Matches, OS).Emit(0, IgnoreDuplicates);
26332636

2634-
OS << " return 0;\n";
2637+
OS << " return " << Namespace << "::NoRegister;\n";
26352638
OS << "}\n\n";
26362639
}
26372640

@@ -2642,6 +2645,8 @@ static void emitMatchRegisterAltName(CodeGenTarget &Target, Record *AsmParser,
26422645
// Construct the match list.
26432646
std::vector<StringMatcher::StringPair> Matches;
26442647
const auto &Regs = Target.getRegBank().getRegisters();
2648+
std::string Namespace =
2649+
Regs.front().TheDef->getValueAsString("Namespace").str();
26452650
for (const CodeGenRegister &Reg : Regs) {
26462651

26472652
auto AltNames = Reg.TheDef->getValueAsListOfStrings("AltNames");
@@ -2653,18 +2658,18 @@ static void emitMatchRegisterAltName(CodeGenTarget &Target, Record *AsmParser,
26532658
if (AltName.empty())
26542659
continue;
26552660

2656-
Matches.emplace_back(std::string(AltName),
2657-
"return " + utostr(Reg.EnumValue) + ";");
2661+
Matches.emplace_back(AltName.str(), "return " + Namespace +
2662+
"::" + Reg.getName().str() + ';');
26582663
}
26592664
}
26602665

2661-
OS << "static unsigned MatchRegisterAltName(StringRef Name) {\n";
2666+
OS << "static MCRegister MatchRegisterAltName(StringRef Name) {\n";
26622667

26632668
bool IgnoreDuplicates =
26642669
AsmParser->getValueAsBit("AllowDuplicateRegisterNames");
26652670
StringMatcher("Name", Matches, OS).Emit(0, IgnoreDuplicates);
26662671

2667-
OS << " return 0;\n";
2672+
OS << " return " << Namespace << "::NoRegister;\n";
26682673
OS << "}\n\n";
26692674
}
26702675

0 commit comments

Comments
 (0)