summaryrefslogtreecommitdiffstats
path: root/llvm/lib
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2010-09-06 22:11:18 +0000
committerChris Lattner <sabre@nondot.org>2010-09-06 22:11:18 +0000
commit339cc7bfef4842f7cbbcd03a8febdb1cc42104c1 (patch)
tree4fa292777b268c2126574dca7cf02e017222e92b /llvm/lib
parent03483613c2986a61181d08c8719d16790a9ad0b3 (diff)
downloadbcm5719-llvm-339cc7bfef4842f7cbbcd03a8febdb1cc42104c1.tar.gz
bcm5719-llvm-339cc7bfef4842f7cbbcd03a8febdb1cc42104c1.zip
in the case where an instruction only has one implementation
of a mneumonic, report operand errors with better location info. For example, we now report: t.s:6:14: error: invalid operand for instruction cwtl $1 ^ but we fail for common cases like: t.s:11:4: error: invalid operand for instruction addl $1, $1 ^ because we don't know if this is supposed to be the reg/imm or imm/reg form. llvm-svn: 113178
Diffstat (limited to 'llvm/lib')
-rw-r--r--llvm/lib/Target/ARM/AsmParser/ARMAsmParser.cpp3
-rw-r--r--llvm/lib/Target/X86/AsmParser/X86AsmParser.cpp27
2 files changed, 21 insertions, 9 deletions
diff --git a/llvm/lib/Target/ARM/AsmParser/ARMAsmParser.cpp b/llvm/lib/Target/ARM/AsmParser/ARMAsmParser.cpp
index 8507070fc66..f2099d29386 100644
--- a/llvm/lib/Target/ARM/AsmParser/ARMAsmParser.cpp
+++ b/llvm/lib/Target/ARM/AsmParser/ARMAsmParser.cpp
@@ -83,7 +83,8 @@ private:
bool MatchInstruction(SMLoc IDLoc,
const SmallVectorImpl<MCParsedAsmOperand*> &Operands,
MCInst &Inst) {
- if (MatchInstructionImpl(Operands, Inst) == Match_Success)
+ unsigned ErrorInfo;
+ if (MatchInstructionImpl(Operands, Inst, ErrorInfo) == Match_Success)
return false;
// FIXME: We should give nicer diagnostics about the exact failure.
diff --git a/llvm/lib/Target/X86/AsmParser/X86AsmParser.cpp b/llvm/lib/Target/X86/AsmParser/X86AsmParser.cpp
index 20ed232eccd..2aa632d4298 100644
--- a/llvm/lib/Target/X86/AsmParser/X86AsmParser.cpp
+++ b/llvm/lib/Target/X86/AsmParser/X86AsmParser.cpp
@@ -863,9 +863,10 @@ X86ATTAsmParser::MatchInstruction(SMLoc IDLoc,
assert(!Operands.empty() && "Unexpect empty operand list!");
bool WasOriginallyInvalidOperand = false;
+ unsigned OrigErrorInfo;
// First, try a direct match.
- switch (MatchInstructionImpl(Operands, Inst)) {
+ switch (MatchInstructionImpl(Operands, Inst, OrigErrorInfo)) {
case Match_Success:
return false;
case Match_MissingFeature:
@@ -895,13 +896,14 @@ X86ATTAsmParser::MatchInstruction(SMLoc IDLoc,
// Check for the various suffix matches.
Tmp[Base.size()] = 'b';
- MatchResultTy MatchB = MatchInstructionImpl(Operands, Inst);
+ unsigned BErrorInfo, WErrorInfo, LErrorInfo, QErrorInfo;
+ MatchResultTy MatchB = MatchInstructionImpl(Operands, Inst, BErrorInfo);
Tmp[Base.size()] = 'w';
- MatchResultTy MatchW = MatchInstructionImpl(Operands, Inst);
+ MatchResultTy MatchW = MatchInstructionImpl(Operands, Inst, WErrorInfo);
Tmp[Base.size()] = 'l';
- MatchResultTy MatchL = MatchInstructionImpl(Operands, Inst);
+ MatchResultTy MatchL = MatchInstructionImpl(Operands, Inst, LErrorInfo);
Tmp[Base.size()] = 'q';
- MatchResultTy MatchQ = MatchInstructionImpl(Operands, Inst);
+ MatchResultTy MatchQ = MatchInstructionImpl(Operands, Inst, QErrorInfo);
// Restore the old token.
Op->setTokenValue(Base);
@@ -952,10 +954,19 @@ X86ATTAsmParser::MatchInstruction(SMLoc IDLoc,
// mnemonic was invalid.
if ((MatchB == Match_MnemonicFail) && (MatchW == Match_MnemonicFail) &&
(MatchL == Match_MnemonicFail) && (MatchQ == Match_MnemonicFail)) {
- if (WasOriginallyInvalidOperand)
- Error(IDLoc, "invalid operand for instruction");
- else
+ if (!WasOriginallyInvalidOperand) {
Error(IDLoc, "invalid instruction mnemonic '" + Base + "'");
+ return true;
+ }
+
+ // Recover location info for the operand if we know which was the problem.
+ SMLoc ErrorLoc = IDLoc;
+ if (OrigErrorInfo != ~0U) {
+ ErrorLoc = ((X86Operand*)Operands[OrigErrorInfo])->getStartLoc();
+ if (ErrorLoc == SMLoc()) ErrorLoc = IDLoc;
+ }
+
+ Error(ErrorLoc, "invalid operand for instruction");
return true;
}
OpenPOWER on IntegriCloud