diff options
| author | Alex Lorenz <arphaman@gmail.com> | 2015-06-23 22:39:23 +0000 |
|---|---|---|
| committer | Alex Lorenz <arphaman@gmail.com> | 2015-06-23 22:39:23 +0000 |
| commit | 51af160f4c2d09282a73af00b04cb6a49da51aa7 (patch) | |
| tree | 3f1da2d04fde7a88ebda378be85bffbd6062cf73 /llvm/lib/CodeGen/MIRParser | |
| parent | adbde27d2d1bae85d8a7949ee4f7a5579c5493c2 (diff) | |
| download | bcm5719-llvm-51af160f4c2d09282a73af00b04cb6a49da51aa7.tar.gz bcm5719-llvm-51af160f4c2d09282a73af00b04cb6a49da51aa7.zip | |
MIR Parser: Use correct source locations for machine instruction diagnostics.
This commit translates the source locations for MIParser diagnostics from
the locations in the machine instruction string to the locations in the
MIR file.
Reviewers: Duncan P. N. Exon Smith
Differential Revision: http://reviews.llvm.org/D10574
llvm-svn: 240474
Diffstat (limited to 'llvm/lib/CodeGen/MIRParser')
| -rw-r--r-- | llvm/lib/CodeGen/MIRParser/MIRParser.cpp | 25 |
1 files changed, 23 insertions, 2 deletions
diff --git a/llvm/lib/CodeGen/MIRParser/MIRParser.cpp b/llvm/lib/CodeGen/MIRParser/MIRParser.cpp index 1ba7f1f1df2..57ecacf7dce 100644 --- a/llvm/lib/CodeGen/MIRParser/MIRParser.cpp +++ b/llvm/lib/CodeGen/MIRParser/MIRParser.cpp @@ -84,6 +84,10 @@ public: const yaml::MachineBasicBlock &YamlMBB); private: + /// Return a MIR diagnostic converted from an MI string diagnostic. + SMDiagnostic diagFromMIStringDiag(const SMDiagnostic &Error, + SMRange SourceRange); + /// Return a MIR diagnostic converted from an LLVM assembly diagnostic. SMDiagnostic diagFromLLVMAssemblyDiag(const SMDiagnostic &Error, SMRange SourceRange); @@ -129,6 +133,7 @@ static void handleYAMLDiag(const SMDiagnostic &Diag, void *Context) { std::unique_ptr<Module> MIRParserImpl::parse() { yaml::Input In(SM.getMemoryBuffer(SM.getMainFileID())->getBuffer(), /*Ctxt=*/nullptr, handleYAMLDiag, this); + In.setContext(&In); if (!In.setCurrentDocument()) { if (In.error()) @@ -235,16 +240,32 @@ bool MIRParserImpl::initializeMachineBasicBlock( // Parse the instructions. for (const auto &MISource : YamlMBB.Instructions) { SMDiagnostic Error; - if (auto *MI = parseMachineInstr(SM, MF, MISource, Error)) { + if (auto *MI = parseMachineInstr(SM, MF, MISource.Value, Error)) { MBB.insert(MBB.end(), MI); continue; } - reportDiagnostic(Error); + reportDiagnostic(diagFromMIStringDiag(Error, MISource.SourceRange)); return true; } return false; } +SMDiagnostic MIRParserImpl::diagFromMIStringDiag(const SMDiagnostic &Error, + SMRange SourceRange) { + assert(SourceRange.isValid() && "Invalid source range"); + SMLoc Loc = SourceRange.Start; + bool HasQuote = Loc.getPointer() < SourceRange.End.getPointer() && + *Loc.getPointer() == '\''; + // Translate the location of the error from the location in the MI string to + // the corresponding location in the MIR file. + Loc = Loc.getFromPointer(Loc.getPointer() + Error.getColumnNo() + + (HasQuote ? 1 : 0)); + + // TODO: Translate any source ranges as well. + return SM.GetMessage(Loc, Error.getKind(), Error.getMessage(), None, + Error.getFixIts()); +} + SMDiagnostic MIRParserImpl::diagFromLLVMAssemblyDiag(const SMDiagnostic &Error, SMRange SourceRange) { assert(SourceRange.isValid()); |

