Skip to content

Commit 260b581

Browse files
committed
[LLVM-C] Add Accessors for Common DIType and DILocation Properties
Summary: - Adds getters for the line, column, and scope of a DILocation - Adds getters for the name, size in bits, offset in bits, alignment in bits, line, and flags of a DIType Reviewers: whitequark, harlanhaskins, deadalnix Reviewed By: whitequark Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D46627 llvm-svn: 332014
1 parent 6684476 commit 260b581

File tree

2 files changed

+115
-0
lines changed

2 files changed

+115
-0
lines changed

llvm/include/llvm-c/DebugInfo.h

+73
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,30 @@ LLVMDIBuilderCreateDebugLocation(LLVMContextRef Ctx, unsigned Line,
384384
unsigned Column, LLVMMetadataRef Scope,
385385
LLVMMetadataRef InlinedAt);
386386

387+
/**
388+
* Get the line number of this debug location.
389+
* \param Location The debug location.
390+
*
391+
* @see DILocation::getLine()
392+
*/
393+
unsigned LLVMDILocationGetLine(LLVMMetadataRef Location);
394+
395+
/**
396+
* Get the column number of this debug location.
397+
* \param Location The debug location.
398+
*
399+
* @see DILocation::getColumn()
400+
*/
401+
unsigned LLVMDILocationGetColumn(LLVMMetadataRef Location);
402+
403+
/**
404+
* Get the local scope associated with this debug location.
405+
* \param Location The debug location.
406+
*
407+
* @see DILocation::getScope()
408+
*/
409+
LLVMMetadataRef LLVMDILocationGetScope(LLVMMetadataRef Location);
410+
387411
/**
388412
* Create a type array.
389413
* \param Builder The DIBuilder.
@@ -760,6 +784,55 @@ LLVMMetadataRef
760784
LLVMDIBuilderCreateArtificialType(LLVMDIBuilderRef Builder,
761785
LLVMMetadataRef Type);
762786

787+
/**
788+
* Get the name of this DIType.
789+
* \param DType The DIType.
790+
* \param Length The length of the returned string.
791+
*
792+
* @see DIType::getName()
793+
*/
794+
const char *LLVMDITypeGetName(LLVMMetadataRef DType, size_t *Length);
795+
796+
/**
797+
* Get the size of this DIType in bits.
798+
* \param DType The DIType.
799+
*
800+
* @see DIType::getSizeInBits()
801+
*/
802+
uint64_t LLVMDITypeGetSizeInBits(LLVMMetadataRef DType);
803+
804+
/**
805+
* Get the offset of this DIType in bits.
806+
* \param DType The DIType.
807+
*
808+
* @see DIType::getOffsetInBits()
809+
*/
810+
uint64_t LLVMDITypeGetOffsetInBits(LLVMMetadataRef DType);
811+
812+
/**
813+
* Get the alignment of this DIType in bits.
814+
* \param DType The DIType.
815+
*
816+
* @see DIType::getAlignInBits()
817+
*/
818+
uint32_t LLVMDITypeGetAlignInBits(LLVMMetadataRef DType);
819+
820+
/**
821+
* Get the source line where this DIType is declared.
822+
* \param DType The DIType.
823+
*
824+
* @see DIType::getLine()
825+
*/
826+
unsigned LLVMDITypeGetLine(LLVMMetadataRef DType);
827+
828+
/**
829+
* Get the flags associated with this DIType.
830+
* \param DType The DIType.
831+
*
832+
* @see DIType::getFlags()
833+
*/
834+
LLVMDIFlags LLVMDITypeGetFlags(LLVMMetadataRef DType);
835+
763836
/**
764837
* Create a descriptor for a value range.
765838
* \param Builder The DIBuilder.

llvm/lib/IR/DebugInfo.cpp

+42
Original file line numberDiff line numberDiff line change
@@ -721,6 +721,10 @@ static DINode::DIFlags map_from_llvmDIFlags(LLVMDIFlags Flags) {
721721
return static_cast<DINode::DIFlags>(Flags);
722722
}
723723

724+
static LLVMDIFlags map_to_llvmDIFlags(DINode::DIFlags Flags) {
725+
return static_cast<LLVMDIFlags>(Flags);
726+
}
727+
724728
unsigned LLVMDebugMetadataVersion() {
725729
return DEBUG_METADATA_VERSION;
726730
}
@@ -885,6 +889,18 @@ LLVMDIBuilderCreateDebugLocation(LLVMContextRef Ctx, unsigned Line,
885889
unwrap(InlinedAt)));
886890
}
887891

892+
unsigned LLVMDILocationGetLine(LLVMMetadataRef Location) {
893+
return unwrapDI<DILocation>(Location)->getLine();
894+
}
895+
896+
unsigned LLVMDILocationGetColumn(LLVMMetadataRef Location) {
897+
return unwrapDI<DILocation>(Location)->getColumn();
898+
}
899+
900+
LLVMMetadataRef LLVMDILocationGetScope(LLVMMetadataRef Location) {
901+
return wrap(unwrapDI<DILocation>(Location)->getScope());
902+
}
903+
888904
LLVMMetadataRef LLVMDIBuilderCreateEnumerationType(
889905
LLVMDIBuilderRef Builder, LLVMMetadataRef Scope, const char *Name,
890906
size_t NameLen, LLVMMetadataRef File, unsigned LineNumber,
@@ -1102,6 +1118,32 @@ LLVMDIBuilderCreateArtificialType(LLVMDIBuilderRef Builder,
11021118
return wrap(unwrap(Builder)->createArtificialType(unwrapDI<DIType>(Type)));
11031119
}
11041120

1121+
const char *LLVMDITypeGetName(LLVMMetadataRef DType, size_t *Length) {
1122+
StringRef Str = unwrap<DIType>(DType)->getName();
1123+
*Length = Str.size();
1124+
return Str.data();
1125+
}
1126+
1127+
uint64_t LLVMDITypeGetSizeInBits(LLVMMetadataRef DType) {
1128+
return unwrapDI<DIType>(DType)->getSizeInBits();
1129+
}
1130+
1131+
uint64_t LLVMDITypeGetOffsetInBits(LLVMMetadataRef DType) {
1132+
return unwrapDI<DIType>(DType)->getOffsetInBits();
1133+
}
1134+
1135+
uint32_t LLVMDITypeGetAlignInBits(LLVMMetadataRef DType) {
1136+
return unwrapDI<DIType>(DType)->getAlignInBits();
1137+
}
1138+
1139+
unsigned LLVMDITypeGetLine(LLVMMetadataRef DType) {
1140+
return unwrapDI<DIType>(DType)->getLine();
1141+
}
1142+
1143+
LLVMDIFlags LLVMDITypeGetFlags(LLVMMetadataRef DType) {
1144+
return map_to_llvmDIFlags(unwrapDI<DIType>(DType)->getFlags());
1145+
}
1146+
11051147
LLVMMetadataRef LLVMDIBuilderGetOrCreateTypeArray(LLVMDIBuilderRef Builder,
11061148
LLVMMetadataRef *Types,
11071149
size_t Length) {

0 commit comments

Comments
 (0)