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/MC/MCParser/AsmParser.cpp | |
parent | 17730847d59c919d97f097d46a3fcba1888e5300 (diff) |
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/MC/MCParser/AsmParser.cpp')
-rw-r--r-- | lib/MC/MCParser/AsmParser.cpp | 38 |
1 files changed, 19 insertions, 19 deletions
diff --git a/lib/MC/MCParser/AsmParser.cpp b/lib/MC/MCParser/AsmParser.cpp index 311c3347a5..25f404c703 100644 --- a/lib/MC/MCParser/AsmParser.cpp +++ b/lib/MC/MCParser/AsmParser.cpp @@ -142,8 +142,10 @@ public: virtual MCContext &getContext() { return Ctx; } virtual MCStreamer &getStreamer() { return Out; } - virtual bool Warning(SMLoc L, const Twine &Msg); - virtual bool Error(SMLoc L, const Twine &Msg); + virtual bool Warning(SMLoc L, const Twine &Msg, + ArrayRef<SMRange> Ranges = ArrayRef<SMRange>()); + virtual bool Error(SMLoc L, const Twine &Msg, + ArrayRef<SMRange> Ranges = ArrayRef<SMRange>()); const AsmToken &Lex(); @@ -170,8 +172,9 @@ private: void PrintMacroInstantiations(); void PrintMessage(SMLoc Loc, const Twine &Msg, const char *Type, + ArrayRef<SMRange> Ranges = ArrayRef<SMRange>(), bool ShowLine = true) const { - SrcMgr.PrintMessage(Loc, Msg, Type, ShowLine); + SrcMgr.PrintMessage(Loc, Msg, Type, Ranges, ShowLine); } static void DiagHandler(const SMDiagnostic &Diag, void *Context); @@ -393,17 +396,17 @@ void AsmParser::PrintMacroInstantiations() { "note"); } -bool AsmParser::Warning(SMLoc L, const Twine &Msg) { +bool AsmParser::Warning(SMLoc L, const Twine &Msg, ArrayRef<SMRange> Ranges) { if (FatalAssemblerWarnings) - return Error(L, Msg); - PrintMessage(L, Msg, "warning"); + return Error(L, Msg, Ranges); + PrintMessage(L, Msg, "warning", Ranges); PrintMacroInstantiations(); return false; } -bool AsmParser::Error(SMLoc L, const Twine &Msg) { +bool AsmParser::Error(SMLoc L, const Twine &Msg, ArrayRef<SMRange> Ranges) { HadError = true; - PrintMessage(L, Msg, "error"); + PrintMessage(L, Msg, "error", Ranges); PrintMacroInstantiations(); return true; } @@ -496,7 +499,8 @@ bool AsmParser::Run(bool NoInitialTextSection, bool NoFinalize) { // first referenced for a source location. We need to add something // to track that. Currently, we just point to the end of the file. PrintMessage(getLexer().getLoc(), "assembler local symbol '" + - Sym->getName() + "' not defined", "error", false); + Sym->getName() + "' not defined", "error", + ArrayRef<SMRange>(), false); } } @@ -1284,7 +1288,7 @@ void AsmParser::DiagHandler(const SMDiagnostic &Diag, void *Context) { if (!Parser->CppHashLineNumber || &DiagSrcMgr != &Parser->SrcMgr || DiagBuf != CppHashBuf) { - Diag.Print(0, OS); + Diag.print(0, OS); return; } @@ -1299,16 +1303,12 @@ void AsmParser::DiagHandler(const SMDiagnostic &Diag, void *Context) { int LineNo = Parser->CppHashLineNumber - 1 + (DiagLocLineNo - CppHashLocLineNo); - SMDiagnostic NewDiag(*Diag.getSourceMgr(), - Diag.getLoc(), - Filename, - LineNo, - Diag.getColumnNo(), - Diag.getMessage(), - Diag.getLineContents(), - Diag.getShowLine()); + SMDiagnostic NewDiag(*Diag.getSourceMgr(), Diag.getLoc(), + Filename, LineNo, Diag.getColumnNo(), + Diag.getMessage(), Diag.getLineContents(), + Diag.getRanges(), Diag.getShowLine()); - NewDiag.Print(0, OS); + NewDiag.print(0, OS); } bool AsmParser::expandMacro(SmallString<256> &Buf, StringRef Body, |