-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[PowerPC] Update matchRegisterName() to return MCRegister instead of bool #111186
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@llvm/pr-subscribers-backend-powerpc Author: Lei Huang (lei137) ChangesInitial patch to start using TableGen's auto generated function Update Full diff: https://github.com/llvm/llvm-project/pull/111186.diff 1 Files Affected:
diff --git a/llvm/lib/Target/PowerPC/AsmParser/PPCAsmParser.cpp b/llvm/lib/Target/PowerPC/AsmParser/PPCAsmParser.cpp
index 597a976b076a52..0f6efda8b3271e 100644
--- a/llvm/lib/Target/PowerPC/AsmParser/PPCAsmParser.cpp
+++ b/llvm/lib/Target/PowerPC/AsmParser/PPCAsmParser.cpp
@@ -103,7 +103,7 @@ class PPCAsmParser : public MCTargetAsmParser {
bool isPPC64() const { return IsPPC64; }
- bool matchRegisterName(MCRegister &RegNo, int64_t &IntVal);
+ MCRegister matchRegisterName(int64_t &IntVal);
bool parseRegister(MCRegister &Reg, SMLoc &StartLoc, SMLoc &EndLoc) override;
ParseStatus tryParseRegister(MCRegister &Reg, SMLoc &StartLoc,
@@ -1291,13 +1291,14 @@ bool PPCAsmParser::matchAndEmitInstruction(SMLoc IDLoc, unsigned &Opcode,
llvm_unreachable("Implement any new match types added!");
}
-bool PPCAsmParser::matchRegisterName(MCRegister &RegNo, int64_t &IntVal) {
+MCRegister PPCAsmParser::matchRegisterName(int64_t &IntVal) {
if (getParser().getTok().is(AsmToken::Percent))
getParser().Lex(); // Eat the '%'.
if (!getParser().getTok().is(AsmToken::Identifier))
- return true;
+ return PPC::NoRegister;
+ MCRegister RegNo;
StringRef Name = getParser().getTok().getString();
if (Name.equals_insensitive("lr")) {
RegNo = isPPC64() ? PPC::LR8 : PPC::LR;
@@ -1345,9 +1346,10 @@ bool PPCAsmParser::matchRegisterName(MCRegister &RegNo, int64_t &IntVal) {
!Name.substr(3).getAsInteger(10, IntVal) && IntVal < 8) {
RegNo = DMRRegs[IntVal];
} else
- return true;
+ return PPC::NoRegister;
+
getParser().Lex();
- return false;
+ return RegNo;
}
bool PPCAsmParser::parseRegister(MCRegister &Reg, SMLoc &StartLoc,
@@ -1362,9 +1364,9 @@ ParseStatus PPCAsmParser::tryParseRegister(MCRegister &Reg, SMLoc &StartLoc,
const AsmToken &Tok = getParser().getTok();
StartLoc = Tok.getLoc();
EndLoc = Tok.getEndLoc();
- Reg = PPC::NoRegister;
int64_t IntVal;
- if (matchRegisterName(Reg, IntVal))
+ Reg = matchRegisterName(IntVal);
+ if (!Reg)
return ParseStatus::NoMatch;
return ParseStatus::Success;
}
@@ -1541,9 +1543,8 @@ bool PPCAsmParser::parseOperand(OperandVector &Operands) {
// Special handling for register names. These are interpreted
// as immediates corresponding to the register number.
case AsmToken::Percent: {
- MCRegister RegNo;
int64_t IntVal;
- if (matchRegisterName(RegNo, IntVal))
+ if (! matchRegisterName(IntVal))
return Error(S, "invalid register name");
Operands.push_back(PPCOperand::CreateImm(IntVal, S, E, isPPC64()));
@@ -1627,8 +1628,7 @@ bool PPCAsmParser::parseOperand(OperandVector &Operands) {
int64_t IntVal;
switch (getLexer().getKind()) {
case AsmToken::Percent: {
- MCRegister RegNo;
- if (matchRegisterName(RegNo, IntVal))
+ if (! matchRegisterName(IntVal))
return Error(S, "invalid register name");
break;
}
|
✅ With the latest revision this PR passed the C/C++ code formatter. |
if (getParser().getTok().is(AsmToken::Percent)) | ||
getParser().Lex(); // Eat the '%'. | ||
|
||
if (!getParser().getTok().is(AsmToken::Identifier)) | ||
return true; | ||
return PPC::NoRegister; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use MCRegister()
@@ -1345,9 +1346,10 @@ bool PPCAsmParser::matchRegisterName(MCRegister &RegNo, int64_t &IntVal) { | |||
!Name.substr(3).getAsInteger(10, IntVal) && IntVal < 8) { | |||
RegNo = DMRRegs[IntVal]; | |||
} else | |||
return true; | |||
return PPC::NoRegister; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use MCRegister()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Initial patch to start using TableGen's auto generated function
MatchRegisterName()
.Update
PPCAsmParser::matchRegisterName()
implementation to align more with tablegen's auto generated function.