AppendBytes(NumBytesToAppend);
+ AlignmentAsLLVMStruct = std::max(AlignmentAsLLVMStruct, getTypeAlignment(Ty));
+
BitsAvailableInLastField =
getNextFieldOffsetInBytes() * 8 - (FieldOffset + FieldSize);
}
}
// Append tail padding if necessary.
- if (Layout.getSize() / 8 > getNextFieldOffsetInBytes())
- AppendPadding(getNextFieldOffsetInBytes(), AlignmentAsLLVMStruct);
+ AppendTailPadding(Layout.getSize());
return true;
}
+void CGRecordLayoutBuilder::AppendTailPadding(uint64_t RecordSize) {
+ assert(RecordSize % 8 == 0 && "Invalid record size!");
+
+ uint64_t RecordSizeInBytes = RecordSize / 8;
+ assert(getNextFieldOffsetInBytes() <= RecordSizeInBytes && "Size mismatch!");
+
+ unsigned NumPadBytes = RecordSizeInBytes - getNextFieldOffsetInBytes();
+ AppendBytes(NumPadBytes);
+}
+
+
void CGRecordLayoutBuilder::AppendField(uint64_t FieldOffsetInBytes,
const llvm::Type *FieldTy) {
AlignmentAsLLVMStruct = std::max(AlignmentAsLLVMStruct,
return;
const llvm::Type *Ty = llvm::Type::Int8Ty;
- if (NumBytes > 1) {
- // FIXME: Use a VMContext.
+ if (NumBytes > 1)
Ty = llvm::ArrayType::get(Ty, NumBytes);
- }
// Append the padding field
AppendField(getNextFieldOffsetInBytes(), Ty);
// FIXME: Once this works well enough, enable it.
return 0;
- // FIXME: Use a VMContext.
const llvm::Type *Ty = llvm::StructType::get(Builder.FieldTypes,
Builder.Packed);
/// AppendBytes - Append a given number of bytes to the record.
void AppendBytes(uint64_t NumBytes);
+ /// AppendTailPadding - Append enough tail padding so that the type will have
+ /// the passed size.
+ void AppendTailPadding(uint64_t RecordSize);
+
/// getNextFieldOffsetInBytes - returns where the next field offset is.
uint64_t getNextFieldOffsetInBytes() const;