[llvm] cd1ed64 - [RISCV] Add version of generateImmOutOfRangeError that takes an SMLoc.
Craig Topper via llvm-commits
llvm-commits at lists.llvm.org
Wed Apr 26 11:10:37 PDT 2023
Author: Craig Topper
Date: 2023-04-26T11:10:08-07:00
New Revision: cd1ed648c4ced256ffaace082ca2a921883cc3a2
URL: https://github.com/llvm/llvm-project/commit/cd1ed648c4ced256ffaace082ca2a921883cc3a2
DIFF: https://github.com/llvm/llvm-project/commit/cd1ed648c4ced256ffaace082ca2a921883cc3a2.diff
LOG: [RISCV] Add version of generateImmOutOfRangeError that takes an SMLoc.
Have the ErrorInfo version call it after looking up ErrorInfo in
the Operands.
Use the new function in a few places that don't have ErrorInfo and
were also generating out of range messages.
Added:
Modified:
llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp b/llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp
index d1982928168d..0df5cddbd79b 100644
--- a/llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp
+++ b/llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp
@@ -87,6 +87,8 @@ class RISCVAsmParser : public MCTargetAsmParser {
bool generateImmOutOfRangeError(OperandVector &Operands, uint64_t ErrorInfo,
int64_t Lower, int64_t Upper,
const Twine &Msg);
+ bool generateImmOutOfRangeError(SMLoc ErrorLoc, int64_t Lower, int64_t Upper,
+ const Twine &Msg);
bool MatchAndEmitInstruction(SMLoc IDLoc, unsigned &Opcode,
OperandVector &Operands, MCStreamer &Out,
@@ -1167,11 +1169,17 @@ unsigned RISCVAsmParser::checkTargetMatchPredicate(MCInst &Inst) {
return Match_Success;
}
+bool RISCVAsmParser::generateImmOutOfRangeError(
+ SMLoc ErrorLoc, int64_t Lower, int64_t Upper,
+ const Twine &Msg = "immediate must be an integer in the range") {
+ return Error(ErrorLoc, Msg + " [" + Twine(Lower) + ", " + Twine(Upper) + "]");
+}
+
bool RISCVAsmParser::generateImmOutOfRangeError(
OperandVector &Operands, uint64_t ErrorInfo, int64_t Lower, int64_t Upper,
const Twine &Msg = "immediate must be an integer in the range") {
SMLoc ErrorLoc = ((RISCVOperand &)*Operands[ErrorInfo]).getStartLoc();
- return Error(ErrorLoc, Msg + " [" + Twine(Lower) + ", " + Twine(Upper) + "]");
+ return generateImmOutOfRangeError(ErrorLoc, Lower, Upper, Msg);
}
bool RISCVAsmParser::MatchAndEmitInstruction(SMLoc IDLoc, unsigned &Opcode,
@@ -1563,8 +1571,9 @@ RISCVAsmParser::parseInsnDirectiveOpcode(OperandVector &Operands) {
break;
}
- Error(S, "opcode must be a valid opcode name or an immediate in the range "
- "[0, 127]");
+ generateImmOutOfRangeError(S, 0, 127,
+ "opcode must be a valid opcode name or an "
+ "immediate in the range");
return MatchOperand_ParseFail;
}
@@ -1624,8 +1633,9 @@ RISCVAsmParser::parseInsnCDirectiveOpcode(OperandVector &Operands) {
}
}
- Error(S, "opcode must be a valid opcode name or an immediate in the range "
- "[0, 2]");
+ generateImmOutOfRangeError(S, 0, 2,
+ "opcode must be a valid opcode name or an "
+ "immediate in the range");
return MatchOperand_ParseFail;
}
@@ -1660,8 +1670,7 @@ RISCVAsmParser::parseCSRSystemRegister(OperandVector &Operands) {
}
}
- Twine Msg = "immediate must be an integer in the range";
- Error(S, Msg + " [" + Twine(0) + ", " + Twine((1 << 12) - 1) + "]");
+ generateImmOutOfRangeError(S, 0, (1 << 12) - 1);
return MatchOperand_ParseFail;
}
case AsmToken::Identifier: {
@@ -1688,15 +1697,14 @@ RISCVAsmParser::parseCSRSystemRegister(OperandVector &Operands) {
return MatchOperand_Success;
}
- Twine Msg = "operand must be a valid system register name "
- "or an integer in the range";
- Error(S, Msg + " [" + Twine(0) + ", " + Twine((1 << 12) - 1) + "]");
+ generateImmOutOfRangeError(S, 0, (1 << 12) - 1,
+ "operand must be a valid system register name "
+ "or an integer in the range");
return MatchOperand_ParseFail;
}
case AsmToken::Percent: {
// Discard operand with modifier.
- Twine Msg = "immediate must be an integer in the range";
- Error(S, Msg + " [" + Twine(0) + ", " + Twine((1 << 12) - 1) + "]");
+ generateImmOutOfRangeError(S, 0, (1 << 12) - 1);
return MatchOperand_ParseFail;
}
}
More information about the llvm-commits
mailing list