diff options
| author | Chris Lattner <sabre@nondot.org> | 2010-04-08 00:23:06 +0000 |
|---|---|---|
| committer | Chris Lattner <sabre@nondot.org> | 2010-04-08 00:23:06 +0000 |
| commit | 79f67a7495057878a1a3711859596611b0364c57 (patch) | |
| tree | b8350948a24781a12a94b8ed93c35521ebbf389d /clang | |
| parent | 3a65ef4504443ccdd84b14a31e781607e09af024 (diff) | |
| download | bcm5719-llvm-79f67a7495057878a1a3711859596611b0364c57.tar.gz bcm5719-llvm-79f67a7495057878a1a3711859596611b0364c57.zip | |
refactor out a function.
llvm-svn: 100733
Diffstat (limited to 'clang')
| -rw-r--r-- | clang/lib/Frontend/CodeGenAction.cpp | 53 |
1 files changed, 29 insertions, 24 deletions
diff --git a/clang/lib/Frontend/CodeGenAction.cpp b/clang/lib/Frontend/CodeGenAction.cpp index d55688026ab..7ed702ed511 100644 --- a/clang/lib/Frontend/CodeGenAction.cpp +++ b/clang/lib/Frontend/CodeGenAction.cpp @@ -468,6 +468,33 @@ void BackendConsumer::EmitAssembly() { } } +/// ConvertBackendLocation - Convert a location in a temporary llvm::SourceMgr +/// buffer to be a valid FullSourceLoc. +static FullSourceLoc ConvertBackendLocation(const llvm::SMDiagnostic &D, + SourceManager &CSM) { + // Get both the clang and llvm source managers. The location is relative to + // a memory buffer that the LLVM Source Manager is handling, we need to add + // a copy to the Clang source manager. + const llvm::SourceMgr &LSM = *D.getSourceMgr(); + + // We need to copy the underlying LLVM memory buffer because llvm::SourceMgr + // already owns its one and clang::SourceManager wants to own its one. + const MemoryBuffer *LBuf = + LSM.getMemoryBuffer(LSM.FindBufferContainingLoc(D.getLoc())); + + // Create the copy and transfer ownership to clang::SourceManager. + llvm::MemoryBuffer *CBuf = + llvm::MemoryBuffer::getMemBufferCopy(LBuf->getBuffer(), + LBuf->getBufferIdentifier()); + FileID FID = CSM.createFileIDForMemBuffer(CBuf); + + // Translate the offset into the file. + unsigned Offset = D.getLoc().getPointer() - LBuf->getBufferStart(); + SourceLocation NewLoc = + CSM.getLocForStartOfFile(FID).getFileLocWithOffset(Offset); + return FullSourceLoc(NewLoc, CSM); +} + /// InlineAsmDiagHandler2 - This function is invoked when the backend hits an /// error parsing inline asm. The SMDiagnostic indicates the error relative to @@ -485,30 +512,8 @@ void BackendConsumer::InlineAsmDiagHandler2(const llvm::SMDiagnostic &D, // There are two cases: the SMDiagnostic could have a inline asm source // location or it might not. If it does, translate the location. FullSourceLoc Loc; - if (D.getLoc() != SMLoc()) { - // Get both the clang and llvm source managers. The location is relative to - // a memory buffer that the LLVM Source Manager is handling, we need to add - // a copy to the Clang source manager. - SourceManager &CSM = Context->getSourceManager(); - const llvm::SourceMgr &LSM = *D.getSourceMgr(); - - // We need to copy the underlying LLVM memory buffer because llvm::SourceMgr - // already owns its one and clang::SourceManager wants to own its one. - const MemoryBuffer *LBuf = - LSM.getMemoryBuffer(LSM.FindBufferContainingLoc(D.getLoc())); - - // Create the copy and transfer ownership to clang::SourceManager. - llvm::MemoryBuffer *CBuf = - llvm::MemoryBuffer::getMemBufferCopy(LBuf->getBuffer(), - LBuf->getBufferIdentifier()); - FileID FID = CSM.createFileIDForMemBuffer(CBuf); - - // Translate the offset into the file. - unsigned Offset = D.getLoc().getPointer() - LBuf->getBufferStart(); - SourceLocation NewLoc = - CSM.getLocForStartOfFile(FID).getFileLocWithOffset(Offset); - Loc = FullSourceLoc(NewLoc, CSM); - } + if (D.getLoc() != SMLoc()) + Loc = ConvertBackendLocation(D, Context->getSourceManager()); Diags.Report(Loc, diag::err_fe_inline_asm).AddString(Message); // This could be a problem with no clang-level source location information. |

