Skip to content

Commit

Permalink
Merge pull request #27413 from JuliaLang/tb/llvm_debuglog
Browse files Browse the repository at this point in the history
Add temporary LLVM C API for accessing source location information.
  • Loading branch information
maleadt authored Jun 5, 2018
2 parents f89921f + 39ff524 commit 2c5aec9
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions src/llvm-api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@
#include <llvm/Analysis/TargetLibraryInfo.h>
#include <llvm/IR/Attributes.h>
#include <llvm/IR/CallSite.h>
#include <llvm/IR/DebugInfo.h>
#include <llvm/IR/Function.h>
#include <llvm/IR/GlobalValue.h>
#include <llvm/IR/Instruction.h>
#include <llvm/IR/LegacyPassManager.h>
#include <llvm/IR/Module.h>
#include <llvm/Support/TargetSelect.h>
Expand Down Expand Up @@ -237,4 +239,36 @@ extern "C" JL_DLLEXPORT void LLVMExtraAddInternalizePassWithExportList(
unwrap(PM)->add(createInternalizePass(PreserveFobj));
}


// Awaiting D46627

extern "C" JL_DLLEXPORT int LLVMExtraGetSourceLocation(LLVMValueRef V, int index,
const char** Name,
const char** Filename,
unsigned int* Line,
unsigned int* Column)
{
if (auto I = dyn_cast<Instruction>(unwrap(V))) {
const DILocation* DIL = I->getDebugLoc();
if (!DIL)
return 0;

for (int i = index; i > 0; i--) {
DIL = DIL->getInlinedAt();
if (!DIL)
return 0;
}

*Name = DIL->getScope()->getName().data();
*Filename = DIL->getScope()->getFilename().data();
*Line = DIL->getLine();
*Column = DIL->getColumn();

return 1;

} else {
jl_exceptionf(jl_argumenterror_type, "Can only get source location information of instructions");
}
}

} // namespace llvm

0 comments on commit 2c5aec9

Please sign in to comment.