[llvm] r344202 - llvm-c: Add C APIs to access DebugLoc info
Saleem Abdulrasool via llvm-commits
llvm-commits at lists.llvm.org
Wed Oct 10 16:53:12 PDT 2018
Author: compnerd
Date: Wed Oct 10 16:53:12 2018
New Revision: 344202
URL: http://llvm.org/viewvc/llvm-project?rev=344202&view=rev
Log:
llvm-c: Add C APIs to access DebugLoc info
Add thin shims to C interface to provide access to DebugLoc info for
Instructions, GlobalVariables and Functions. Patch by Josh Berdine!
Modified:
llvm/trunk/include/llvm-c/Core.h
llvm/trunk/lib/IR/Core.cpp
Modified: llvm/trunk/include/llvm-c/Core.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm-c/Core.h?rev=344202&r1=344201&r2=344202&view=diff
==============================================================================
--- llvm/trunk/include/llvm-c/Core.h (original)
+++ llvm/trunk/include/llvm-c/Core.h Wed Oct 10 16:53:12 2018
@@ -930,6 +930,44 @@ void LLVMAddNamedMetadataOperand(LLVMMod
LLVMValueRef Val);
/**
+ * Return the directory of the debug location for this value, which must be
+ * an llvm::Instruction, llvm::GlobalVariable, or llvm::Function.
+ *
+ * @see llvm::Instruction::getDebugLoc()
+ * @see llvm::GlobalVariable::getDebugInfo()
+ * @see llvm::Function::getSubprogram()
+ */
+const char *LLVMGetDebugLocDirectory(LLVMValueRef Val, unsigned *Length);
+
+/**
+ * Return the filename of the debug location for this value, which must be
+ * an llvm::Instruction, llvm::GlobalVariable, or llvm::Function.
+ *
+ * @see llvm::Instruction::getDebugLoc()
+ * @see llvm::GlobalVariable::getDebugInfo()
+ * @see llvm::Function::getSubprogram()
+ */
+const char *LLVMGetDebugLocFilename(LLVMValueRef Val, unsigned *Length);
+
+/**
+ * Return the line number of the debug location for this value, which must be
+ * an llvm::Instruction, llvm::GlobalVariable, or llvm::Function.
+ *
+ * @see llvm::Instruction::getDebugLoc()
+ * @see llvm::GlobalVariable::getDebugInfo()
+ * @see llvm::Function::getSubprogram()
+ */
+unsigned LLVMGetDebugLocLine(LLVMValueRef Val);
+
+/**
+ * Return the column number of the debug location for this value, which must be
+ * an llvm::Instruction.
+ *
+ * @see llvm::Instruction::getDebugLoc()
+ */
+unsigned LLVMGetDebugLocColumn(LLVMValueRef Val);
+
+/**
* Add a function to a module under a specified name.
*
* @see llvm::Function::Create()
Modified: llvm/trunk/lib/IR/Core.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/Core.cpp?rev=344202&r1=344201&r2=344202&view=diff
==============================================================================
--- llvm/trunk/lib/IR/Core.cpp (original)
+++ llvm/trunk/lib/IR/Core.cpp Wed Oct 10 16:53:12 2018
@@ -17,6 +17,7 @@
#include "llvm/IR/Attributes.h"
#include "llvm/IR/CallSite.h"
#include "llvm/IR/Constants.h"
+#include "llvm/IR/DebugInfoMetadata.h"
#include "llvm/IR/DerivedTypes.h"
#include "llvm/IR/DiagnosticInfo.h"
#include "llvm/IR/DiagnosticPrinter.h"
@@ -1189,6 +1190,78 @@ void LLVMAddNamedMetadataOperand(LLVMMod
N->addOperand(extractMDNode(unwrap<MetadataAsValue>(Val)));
}
+const char *LLVMGetDebugLocDirectory(LLVMValueRef Val, unsigned *Length) {
+ if (!Length) return nullptr;
+ StringRef S;
+ if (const auto *I = unwrap<Instruction>(Val)) {
+ S = I->getDebugLoc()->getDirectory();
+ } else if (const auto *GV = unwrap<GlobalVariable>(Val)) {
+ SmallVector<DIGlobalVariableExpression *, 1> GVEs;
+ GV->getDebugInfo(GVEs);
+ if (GVEs.size())
+ if (const DIGlobalVariable *DGV = GVEs[0]->getVariable())
+ S = DGV->getDirectory();
+ } else if (const auto *F = unwrap<Function>(Val)) {
+ if (const DISubprogram *DSP = F->getSubprogram())
+ S = DSP->getDirectory();
+ } else {
+ assert(0 && "Expected Instruction, GlobalVariable or Function");
+ return nullptr;
+ }
+ *Length = S.size();
+ return S.data();
+}
+
+const char *LLVMGetDebugLocFilename(LLVMValueRef Val, unsigned *Length) {
+ if (!Length) return nullptr;
+ StringRef S;
+ if (const auto *I = unwrap<Instruction>(Val)) {
+ S = I->getDebugLoc()->getFilename();
+ } else if (const auto *GV = unwrap<GlobalVariable>(Val)) {
+ SmallVector<DIGlobalVariableExpression *, 1> GVEs;
+ GV->getDebugInfo(GVEs);
+ if (GVEs.size())
+ if (const DIGlobalVariable *DGV = GVEs[0]->getVariable())
+ S = DGV->getFilename();
+ } else if (const auto *F = unwrap<Function>(Val)) {
+ if (const DISubprogram *DSP = F->getSubprogram())
+ S = DSP->getFilename();
+ } else {
+ assert(0 && "Expected Instruction, GlobalVariable or Function");
+ return nullptr;
+ }
+ *Length = S.size();
+ return S.data();
+}
+
+unsigned LLVMGetDebugLocLine(LLVMValueRef Val) {
+ unsigned L = 0;
+ if (const auto *I = unwrap<Instruction>(Val)) {
+ L = I->getDebugLoc()->getLine();
+ } else if (const auto *GV = unwrap<GlobalVariable>(Val)) {
+ SmallVector<DIGlobalVariableExpression *, 1> GVEs;
+ GV->getDebugInfo(GVEs);
+ if (GVEs.size())
+ if (const DIGlobalVariable *DGV = GVEs[0]->getVariable())
+ L = DGV->getLine();
+ } else if (const auto *F = unwrap<Function>(Val)) {
+ if (const DISubprogram *DSP = F->getSubprogram())
+ L = DSP->getLine();
+ } else {
+ assert(0 && "Expected Instruction, GlobalVariable or Function");
+ return -1;
+ }
+ return L;
+}
+
+unsigned LLVMGetDebugLocColumn(LLVMValueRef Val) {
+ unsigned C = 0;
+ if (const auto *I = unwrap<Instruction>(Val))
+ if (const auto &L = I->getDebugLoc())
+ C = L->getColumn();
+ return C;
+}
+
/*--.. Operations on scalar constants ......................................--*/
LLVMValueRef LLVMConstInt(LLVMTypeRef IntTy, unsigned long long N,
More information about the llvm-commits
mailing list