diff --git a/llvm/include/llvm-c/DebugInfo.h b/llvm/include/llvm-c/DebugInfo.h --- a/llvm/include/llvm-c/DebugInfo.h +++ b/llvm/include/llvm-c/DebugInfo.h @@ -451,6 +451,41 @@ */ LLVMMetadataRef LLVMDILocationGetScope(LLVMMetadataRef Location); +/** + * Get the directory of the file associated with a given scope. + * \param Scope The scope object. + * \param Len The length of the returned string. + * + * @see DIScope::getDirectory() + */ +const char *LLVMDIScopeGetDirectory(LLVMMetadataRef Scope, unsigned *Len); + +/** + * Get the directory of the file associated with a given scope. + * \param Scope The scope object. + * \param Len The length of the returned string. + * + * @see DIScope::getFilename() + */ +const char *LLVMDIScopeGetFilename(LLVMMetadataRef Scope, unsigned *Len); + +/** + * Get the directory of the file associated with a given scope. + * \param Scope The scope object. + * \param Len The length of the returned string. + * + * @see DIScope::getSource() + */ +const char *LLVMDIScopeGetSource(LLVMMetadataRef Scope, unsigned *Len); + +/** + * Get the metadata of the file associated with a given scope. + * \param Scope The scope object. + * + * @see DIScope::getFile() + */ +LLVMMetadataRef LLVMDIScopeGetFile(LLVMMetadataRef Scope); + /** * Create a type array. * \param Builder The DIBuilder. diff --git a/llvm/lib/IR/DebugInfo.cpp b/llvm/lib/IR/DebugInfo.cpp --- a/llvm/lib/IR/DebugInfo.cpp +++ b/llvm/lib/IR/DebugInfo.cpp @@ -899,6 +899,31 @@ return wrap(unwrapDI(Location)->getScope()); } +const char *LLVMDIScopeGetDirectory(LLVMMetadataRef Scope, unsigned *Len) { + auto Dir = unwrapDI(Scope)->getDirectory(); + *Len = Dir.size(); + return Dir.data(); +} + +const char *LLVMDIScopeGetFilename(LLVMMetadataRef Scope, unsigned *Len) { + auto Dir = unwrapDI(Scope)->getFilename(); + *Len = Dir.size(); + return Dir.data(); +} + +const char *LLVMDIScopeGetSource(LLVMMetadataRef Scope, unsigned *Len) { + if (auto Dir = unwrapDI(Scope)->getSource()) { + *Len = Dir->size(); + return Dir->data(); + } + *Len = 0; + return ""; +} + +LLVMMetadataRef LLVMDIScopeGetFile(LLVMMetadataRef Scope) { + return wrap(unwrapDI(Scope)->getFile()); +} + LLVMMetadataRef LLVMDIBuilderCreateEnumerator(LLVMDIBuilderRef Builder, const char *Name, size_t NameLen, int64_t Value,