diff options
author | Chris Lattner <sabre@nondot.org> | 2011-10-16 04:47:35 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2011-10-16 04:47:35 +0000 |
commit | d8b7aa26134d2abee777f745c32005e63dea2455 (patch) | |
tree | edc5453a63624cef371ed386f811fb2651024d33 /lib/Target | |
parent | 17730847d59c919d97f097d46a3fcba1888e5300 (diff) | |
download | external_llvm-d8b7aa26134d2abee777f745c32005e63dea2455.zip external_llvm-d8b7aa26134d2abee777f745c32005e63dea2455.tar.gz external_llvm-d8b7aa26134d2abee777f745c32005e63dea2455.tar.bz2 |
Enhance llvm::SourceMgr to support diagnostic ranges, the same way clang does. Enhance
the X86 asmparser to produce ranges in the one case that was annoying me, for example:
test.s:10:15: error: invalid operand for instruction
movl 0(%rax), 0(%edx)
^~~~~~~
It should be straight-forward to enhance filecheck, tblgen, and/or the .ll parser to use
ranges where appropriate if someone is interested.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@142106 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Target')
-rw-r--r-- | lib/Target/X86/AsmParser/X86AsmParser.cpp | 19 |
1 files changed, 13 insertions, 6 deletions
diff --git a/lib/Target/X86/AsmParser/X86AsmParser.cpp b/lib/Target/X86/AsmParser/X86AsmParser.cpp index cb4f15f..eda180e 100644 --- a/lib/Target/X86/AsmParser/X86AsmParser.cpp +++ b/lib/Target/X86/AsmParser/X86AsmParser.cpp @@ -41,7 +41,10 @@ private: MCAsmLexer &getLexer() const { return Parser.getLexer(); } - bool Error(SMLoc L, const Twine &Msg) { return Parser.Error(L, Msg); } + bool Error(SMLoc L, const Twine &Msg, + ArrayRef<SMRange> Ranges = ArrayRef<SMRange>()) { + return Parser.Error(L, Msg, Ranges); + } X86Operand *ParseOperand(); X86Operand *ParseMemOperand(unsigned SegReg, SMLoc StartLoc); @@ -145,6 +148,8 @@ struct X86Operand : public MCParsedAsmOperand { SMLoc getStartLoc() const { return StartLoc; } /// getEndLoc - Get the location of the last token of this operand. SMLoc getEndLoc() const { return EndLoc; } + + SMRange getLocRange() const { return SMRange(StartLoc, EndLoc); } virtual void print(raw_ostream &OS) const {} @@ -1083,16 +1088,19 @@ MatchAndEmitInstruction(SMLoc IDLoc, } // Recover location info for the operand if we know which was the problem. - SMLoc ErrorLoc = IDLoc; if (OrigErrorInfo != ~0U) { if (OrigErrorInfo >= Operands.size()) return Error(IDLoc, "too few operands for instruction"); - ErrorLoc = ((X86Operand*)Operands[OrigErrorInfo])->getStartLoc(); - if (ErrorLoc == SMLoc()) ErrorLoc = IDLoc; + X86Operand *Operand = (X86Operand*)Operands[OrigErrorInfo]; + if (Operand->getStartLoc().isValid()) { + SMRange OperandRange = Operand->getLocRange(); + return Error(Operand->getStartLoc(), "invalid operand for instruction", + OperandRange); + } } - return Error(ErrorLoc, "invalid operand for instruction"); + return Error(IDLoc, "invalid operand for instruction"); } // If one instruction matched with a missing feature, report this as a @@ -1112,7 +1120,6 @@ MatchAndEmitInstruction(SMLoc IDLoc, } // If all of these were an outright failure, report it in a useless way. - // FIXME: We should give nicer diagnostics about the exact failure. Error(IDLoc, "unknown use of instruction mnemonic without a size suffix"); return true; } |