Skip to content

Commit 5b860b8

Browse files
committed
[MC][AsmParser] Make MatchRegisterName return MCRegister
`MCRegister` is preferred over `unsigned` nowadays.
1 parent 5932fcc commit 5b860b8

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
@@ -2619,21 +2619,24 @@ static void emitMatchRegisterName(CodeGenTarget &Target, Record *AsmParser,
26192619
// Construct the match list.
26202620
std::vector<StringMatcher::StringPair> Matches;
26212621
const auto &Regs = Target.getRegBank().getRegisters();
2622+
std::string Namespace =
2623+
Regs.front().TheDef->getValueAsString("Namespace").str();
26222624
for (const CodeGenRegister &Reg : Regs) {
2623-
if (Reg.TheDef->getValueAsString("AsmName").empty())
2625+
StringRef AsmName = Reg.TheDef->getValueAsString("AsmName");
2626+
if (AsmName.empty())
26242627
continue;
26252628

2626-
Matches.emplace_back(std::string(Reg.TheDef->getValueAsString("AsmName")),
2627-
"return " + utostr(Reg.EnumValue) + ";");
2629+
Matches.emplace_back(AsmName.str(), "return " + Namespace +
2630+
"::" + Reg.getName().str() + ';');
26282631
}
26292632

2630-
OS << "static unsigned MatchRegisterName(StringRef Name) {\n";
2633+
OS << "static MCRegister MatchRegisterName(StringRef Name) {\n";
26312634

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

2636-
OS << " return 0;\n";
2639+
OS << " return " << Namespace << "::NoRegister;\n";
26372640
OS << "}\n\n";
26382641
}
26392642

@@ -2644,6 +2647,8 @@ static void emitMatchRegisterAltName(CodeGenTarget &Target, Record *AsmParser,
26442647
// Construct the match list.
26452648
std::vector<StringMatcher::StringPair> Matches;
26462649
const auto &Regs = Target.getRegBank().getRegisters();
2650+
std::string Namespace =
2651+
Regs.front().TheDef->getValueAsString("Namespace").str();
26472652
for (const CodeGenRegister &Reg : Regs) {
26482653

26492654
auto AltNames = Reg.TheDef->getValueAsListOfStrings("AltNames");
@@ -2655,18 +2660,18 @@ static void emitMatchRegisterAltName(CodeGenTarget &Target, Record *AsmParser,
26552660
if (AltName.empty())
26562661
continue;
26572662

2658-
Matches.emplace_back(std::string(AltName),
2659-
"return " + utostr(Reg.EnumValue) + ";");
2663+
Matches.emplace_back(AltName.str(), "return " + Namespace +
2664+
"::" + Reg.getName().str() + ';');
26602665
}
26612666
}
26622667

2663-
OS << "static unsigned MatchRegisterAltName(StringRef Name) {\n";
2668+
OS << "static MCRegister MatchRegisterAltName(StringRef Name) {\n";
26642669

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

2669-
OS << " return 0;\n";
2674+
OS << " return " << Namespace << "::NoRegister;\n";
26702675
OS << "}\n\n";
26712676
}
26722677

0 commit comments

Comments
 (0)