本文整理汇总了C++中StructType::getStructElementType方法的典型用法代码示例。如果您正苦于以下问题:C++ StructType::getStructElementType方法的具体用法?C++ StructType::getStructElementType怎么用?C++ StructType::getStructElementType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类StructType
的用法示例。
在下文中一共展示了StructType::getStructElementType方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: getGcPointers
void GcInfo::getGcPointers(StructType *StructTy, const DataLayout &DataLayout,
SmallVector<uint32_t, 4> &Pointers) {
assert(StructTy->isSized());
const uint32_t PointerSize = DataLayout.getPointerSize();
const uint32_t TypeSize = DataLayout.getTypeStoreSize(StructTy);
const StructLayout *MainStructLayout = DataLayout.getStructLayout(StructTy);
// Walk through the type in pointer-sized jumps.
for (uint32_t GcOffset = 0; GcOffset < TypeSize; GcOffset += PointerSize) {
const uint32_t FieldIndex =
MainStructLayout->getElementContainingOffset(GcOffset);
Type *FieldTy = StructTy->getStructElementType(FieldIndex);
// If the field is a value class we need to dive in
// to its fields and so on, until we reach a primitive type.
if (FieldTy->isStructTy()) {
// Prepare to loop through the nesting.
const StructLayout *OuterStructLayout = MainStructLayout;
uint32_t OuterOffset = GcOffset;
uint32_t OuterIndex = FieldIndex;
while (FieldTy->isStructTy()) {
// Offset of the Inner class within the outer class
const uint32_t InnerBaseOffset =
OuterStructLayout->getElementOffset(OuterIndex);
// Inner class should start at or before the outer offset
assert(InnerBaseOffset <= OuterOffset);
// Determine target offset relative to this inner class.
const uint32_t InnerOffset = OuterOffset - InnerBaseOffset;
// Get the inner class layout
StructType *InnerStructTy = cast<StructType>(FieldTy);
const StructLayout *InnerStructLayout =
DataLayout.getStructLayout(InnerStructTy);
// Find the field at that target offset.
const uint32_t InnerIndex =
InnerStructLayout->getElementContainingOffset(InnerOffset);
// Update for next iteration.
FieldTy = InnerStructTy->getStructElementType(InnerIndex);
OuterStructLayout = InnerStructLayout;
OuterOffset = InnerOffset;
OuterIndex = InnerIndex;
}
}
if (GcInfo::isGcPointer(FieldTy)) {
Pointers.push_back(GcOffset);
}
}
}