From 67f575b6a4f6eb7a058eb8ebed7eabbdb4809899 Mon Sep 17 00:00:00 2001 From: Robert Widmann Date: Wed, 17 Apr 2019 13:29:14 +0000 Subject: [PATCH] [LLVM-C] Add DIFile Field Accesssors Summary: Add accessors for the file, directory, source file name (curiously, an `Optional` value?), of a DIFile. This is intended to replace the LLVMValueRef-based accessors used in D52239 Reviewers: whitequark, jberdine, deadalnix Reviewed By: whitequark, jberdine Subscribers: hiraditya, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D60489 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@358577 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm-c/DebugInfo.h | 34 ++++++++++++++++++++++++++++++++++ lib/IR/DebugInfo.cpp | 25 +++++++++++++++++++++++++ 2 files changed, 59 insertions(+) diff --git a/include/llvm-c/DebugInfo.h b/include/llvm-c/DebugInfo.h index 414a5bf0805..33c8110a863 100644 --- a/include/llvm-c/DebugInfo.h +++ b/include/llvm-c/DebugInfo.h @@ -459,6 +459,40 @@ LLVMMetadataRef LLVMDILocationGetScope(LLVMMetadataRef Location); */ LLVMMetadataRef LLVMDILocationGetInlinedAt(LLVMMetadataRef Location); +/** + * Get the metadata of the file associated with a given scope. + * \param Scope The scope object. + * + * @see DIScope::getFile() + */ +LLVMMetadataRef LLVMDIScopeGetFile(LLVMMetadataRef Scope); + +/** + * Get the directory of a given file. + * \param File The file object. + * \param Len The length of the returned string. + * + * @see DIFile::getDirectory() + */ +const char *LLVMDIFileGetDirectory(LLVMMetadataRef File, unsigned *Len); + +/** + * Get the name of a given file. + * \param File The file object. + * \param Len The length of the returned string. + * + * @see DIFile::getFilename() + */ +const char *LLVMDIFileGetFilename(LLVMMetadataRef File, unsigned *Len); + +/** + * Get the source of a given file. + * \param File The file object. + * \param Len The length of the returned string. + * + * @see DIFile::getSource() + */ +const char *LLVMDIFileGetSource(LLVMMetadataRef File, unsigned *Len); /** * Create a type array. diff --git a/lib/IR/DebugInfo.cpp b/lib/IR/DebugInfo.cpp index 124462355cd..69579047976 100644 --- a/lib/IR/DebugInfo.cpp +++ b/lib/IR/DebugInfo.cpp @@ -903,6 +903,31 @@ LLVMMetadataRef LLVMDILocationGetInlinedAt(LLVMMetadataRef Location) { return wrap(unwrapDI(Location)->getInlinedAt()); } +LLVMMetadataRef LLVMDIScopeGetFile(LLVMMetadataRef Scope) { + return wrap(unwrapDI(Scope)->getFile()); +} + +const char *LLVMDIFileGetDirectory(LLVMMetadataRef File, unsigned *Len) { + auto Dir = unwrapDI(File)->getDirectory(); + *Len = Dir.size(); + return Dir.data(); +} + +const char *LLVMDIFileGetFilename(LLVMMetadataRef File, unsigned *Len) { + auto Name = unwrapDI(File)->getFilename(); + *Len = Name.size(); + return Name.data(); +} + +const char *LLVMDIFileGetSource(LLVMMetadataRef File, unsigned *Len) { + if (auto Src = unwrapDI(File)->getSource()) { + *Len = Src->size(); + return Src->data(); + } + *Len = 0; + return ""; +} + LLVMMetadataRef LLVMDIBuilderCreateEnumerator(LLVMDIBuilderRef Builder, const char *Name, size_t NameLen, int64_t Value, -- 2.11.0