[PATCH] D60489: [LLVM-C] Add DIFile Field Accesssors

Robert Widmann via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Apr 9 16:01:34 PDT 2019


CodaFi updated this revision to Diff 194415.
CodaFi retitled this revision from "[LLVM-C] Add DIScope Field Accesssors" to "[LLVM-C] Add DIFile Field Accesssors".
CodaFi edited the summary of this revision.
CodaFi added a comment.

Retarget from DIScope to DIFile since we can retrieve the file object for a scope now.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D60489/new/

https://reviews.llvm.org/D60489

Files:
  llvm/include/llvm-c/DebugInfo.h
  llvm/lib/IR/DebugInfo.cpp


Index: llvm/lib/IR/DebugInfo.cpp
===================================================================
--- llvm/lib/IR/DebugInfo.cpp
+++ llvm/lib/IR/DebugInfo.cpp
@@ -899,6 +899,31 @@
   return wrap(unwrapDI<DILocation>(Location)->getScope());
 }
 
+LLVMMetadataRef LLVMDIScopeGetFile(LLVMMetadataRef Scope) {
+  return wrap(unwrapDI<DIScope>(Scope)->getFile());
+}
+
+const char *LLVMDIFileGetDirectory(LLVMMetadataRef File, unsigned *Len) {
+  auto Dir = unwrapDI<DIFile>(File)->getDirectory();
+  *Len = Dir.size();
+  return Dir.data();
+}
+
+const char *LLVMDIFileGetFilename(LLVMMetadataRef File, unsigned *Len) {
+  auto Dir = unwrapDI<DIFile>(File)->getFilename();
+  *Len = Dir.size();
+  return Dir.data();
+}
+
+const char *LLVMDIFileGetSource(LLVMMetadataRef File, unsigned *Len) {
+  if (auto Dir = unwrapDI<DIFile>(File)->getSource()) {
+    *Len = Dir->size();
+    return Dir->data();
+  }
+  *Len = 0;
+  return "";
+}
+
 LLVMMetadataRef LLVMDIBuilderCreateEnumerator(LLVMDIBuilderRef Builder,
                                               const char *Name, size_t NameLen,
                                               int64_t Value,
Index: llvm/include/llvm-c/DebugInfo.h
===================================================================
--- llvm/include/llvm-c/DebugInfo.h
+++ llvm/include/llvm-c/DebugInfo.h
@@ -451,6 +451,41 @@
  */
 LLVMMetadataRef LLVMDILocationGetScope(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 Scope     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 Scope     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 Scope     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.
  * \param Builder        The DIBuilder.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D60489.194415.patch
Type: text/x-patch
Size: 2453 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190409/73f8954e/attachment.bin>


More information about the llvm-commits mailing list