Skip to content

Commit d909a5e

Browse files
committed
[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 llvm-svn: 358577
1 parent f2879d8 commit d909a5e

File tree

2 files changed

+59
-0
lines changed

2 files changed

+59
-0
lines changed

llvm/include/llvm-c/DebugInfo.h

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -459,6 +459,40 @@ LLVMMetadataRef LLVMDILocationGetScope(LLVMMetadataRef Location);
459459
*/
460460
LLVMMetadataRef LLVMDILocationGetInlinedAt(LLVMMetadataRef Location);
461461

462+
/**
463+
* Get the metadata of the file associated with a given scope.
464+
* \param Scope The scope object.
465+
*
466+
* @see DIScope::getFile()
467+
*/
468+
LLVMMetadataRef LLVMDIScopeGetFile(LLVMMetadataRef Scope);
469+
470+
/**
471+
* Get the directory of a given file.
472+
* \param File The file object.
473+
* \param Len The length of the returned string.
474+
*
475+
* @see DIFile::getDirectory()
476+
*/
477+
const char *LLVMDIFileGetDirectory(LLVMMetadataRef File, unsigned *Len);
478+
479+
/**
480+
* Get the name of a given file.
481+
* \param File The file object.
482+
* \param Len The length of the returned string.
483+
*
484+
* @see DIFile::getFilename()
485+
*/
486+
const char *LLVMDIFileGetFilename(LLVMMetadataRef File, unsigned *Len);
487+
488+
/**
489+
* Get the source of a given file.
490+
* \param File The file object.
491+
* \param Len The length of the returned string.
492+
*
493+
* @see DIFile::getSource()
494+
*/
495+
const char *LLVMDIFileGetSource(LLVMMetadataRef File, unsigned *Len);
462496

463497
/**
464498
* Create a type array.

llvm/lib/IR/DebugInfo.cpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -903,6 +903,31 @@ LLVMMetadataRef LLVMDILocationGetInlinedAt(LLVMMetadataRef Location) {
903903
return wrap(unwrapDI<DILocation>(Location)->getInlinedAt());
904904
}
905905

906+
LLVMMetadataRef LLVMDIScopeGetFile(LLVMMetadataRef Scope) {
907+
return wrap(unwrapDI<DIScope>(Scope)->getFile());
908+
}
909+
910+
const char *LLVMDIFileGetDirectory(LLVMMetadataRef File, unsigned *Len) {
911+
auto Dir = unwrapDI<DIFile>(File)->getDirectory();
912+
*Len = Dir.size();
913+
return Dir.data();
914+
}
915+
916+
const char *LLVMDIFileGetFilename(LLVMMetadataRef File, unsigned *Len) {
917+
auto Name = unwrapDI<DIFile>(File)->getFilename();
918+
*Len = Name.size();
919+
return Name.data();
920+
}
921+
922+
const char *LLVMDIFileGetSource(LLVMMetadataRef File, unsigned *Len) {
923+
if (auto Src = unwrapDI<DIFile>(File)->getSource()) {
924+
*Len = Src->size();
925+
return Src->data();
926+
}
927+
*Len = 0;
928+
return "";
929+
}
930+
906931
LLVMMetadataRef LLVMDIBuilderCreateEnumerator(LLVMDIBuilderRef Builder,
907932
const char *Name, size_t NameLen,
908933
int64_t Value,

0 commit comments

Comments
 (0)