2010-03-31 02:26:10 +04:00
|
|
|
//===--- CGRecordLayout.h - LLVM Record Layout Information ------*- C++ -*-===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef CLANG_CODEGEN_CGRECORDLAYOUT_H
|
|
|
|
#define CLANG_CODEGEN_CGRECORDLAYOUT_H
|
|
|
|
|
2010-03-31 05:09:11 +04:00
|
|
|
#include "llvm/ADT/DenseMap.h"
|
|
|
|
#include "clang/AST/Decl.h"
|
2010-03-31 04:11:27 +04:00
|
|
|
namespace llvm {
|
|
|
|
class Type;
|
|
|
|
}
|
|
|
|
|
2010-03-31 02:26:10 +04:00
|
|
|
namespace clang {
|
|
|
|
namespace CodeGen {
|
|
|
|
|
2010-04-05 20:20:44 +04:00
|
|
|
class CGBitFieldInfo {
|
|
|
|
public:
|
2010-04-06 05:07:44 +04:00
|
|
|
CGBitFieldInfo(unsigned FieldNo, unsigned Start, unsigned Size,
|
|
|
|
bool IsSigned)
|
|
|
|
: FieldNo(FieldNo), Start(Start), Size(Size), IsSigned(IsSigned) {}
|
2010-04-05 20:20:44 +04:00
|
|
|
|
|
|
|
unsigned FieldNo;
|
|
|
|
unsigned Start;
|
|
|
|
unsigned Size;
|
2010-04-06 05:07:44 +04:00
|
|
|
bool IsSigned : 1;
|
2010-04-05 20:20:44 +04:00
|
|
|
};
|
|
|
|
|
2010-03-31 02:26:10 +04:00
|
|
|
/// CGRecordLayout - This class handles struct and union layout info while
|
|
|
|
/// lowering AST types to LLVM types.
|
2010-03-31 05:09:11 +04:00
|
|
|
///
|
|
|
|
/// These layout objects are only created on demand as IR generation requires.
|
2010-03-31 02:26:10 +04:00
|
|
|
class CGRecordLayout {
|
2010-03-31 05:09:11 +04:00
|
|
|
friend class CodeGenTypes;
|
|
|
|
|
2010-03-31 02:26:10 +04:00
|
|
|
CGRecordLayout(const CGRecordLayout&); // DO NOT IMPLEMENT
|
|
|
|
void operator=(const CGRecordLayout&); // DO NOT IMPLEMENT
|
|
|
|
|
2010-03-31 05:09:11 +04:00
|
|
|
private:
|
2010-03-31 02:26:10 +04:00
|
|
|
/// The LLVMType corresponding to this record layout.
|
|
|
|
const llvm::Type *LLVMType;
|
|
|
|
|
2010-03-31 05:09:11 +04:00
|
|
|
/// Map from (non-bit-field) struct field to the corresponding llvm struct
|
|
|
|
/// type field no. This info is populated by record builder.
|
|
|
|
llvm::DenseMap<const FieldDecl *, unsigned> FieldInfo;
|
|
|
|
|
|
|
|
/// Map from (bit-field) struct field to the corresponding llvm struct type
|
|
|
|
/// field no. This info is populated by record builder.
|
2010-04-05 20:20:44 +04:00
|
|
|
llvm::DenseMap<const FieldDecl *, CGBitFieldInfo> BitFields;
|
2010-03-31 05:09:11 +04:00
|
|
|
|
2010-03-31 02:26:10 +04:00
|
|
|
/// Whether one of the fields in this record layout is a pointer to data
|
|
|
|
/// member, or a struct that contains pointer to data member.
|
2010-03-31 05:09:11 +04:00
|
|
|
bool ContainsPointerToDataMember : 1;
|
2010-03-31 02:26:10 +04:00
|
|
|
|
|
|
|
public:
|
|
|
|
CGRecordLayout(const llvm::Type *T, bool ContainsPointerToDataMember)
|
|
|
|
: LLVMType(T), ContainsPointerToDataMember(ContainsPointerToDataMember) {}
|
|
|
|
|
2010-03-31 05:09:11 +04:00
|
|
|
/// \brief Return the LLVM type associated with this record.
|
2010-03-31 02:26:10 +04:00
|
|
|
const llvm::Type *getLLVMType() const {
|
|
|
|
return LLVMType;
|
|
|
|
}
|
|
|
|
|
2010-03-31 05:09:11 +04:00
|
|
|
/// \brief Check whether this struct contains pointers to data members.
|
2010-03-31 02:26:10 +04:00
|
|
|
bool containsPointerToDataMember() const {
|
|
|
|
return ContainsPointerToDataMember;
|
|
|
|
}
|
2010-03-31 05:09:11 +04:00
|
|
|
|
|
|
|
/// \brief Return the BitFieldInfo that corresponds to the field FD.
|
|
|
|
unsigned getLLVMFieldNo(const FieldDecl *FD) const {
|
|
|
|
assert(!FD->isBitField() && "Invalid call for bit-field decl!");
|
|
|
|
assert(FieldInfo.count(FD) && "Invalid field for record!");
|
|
|
|
return FieldInfo.lookup(FD);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// \brief Return llvm::StructType element number that corresponds to the
|
|
|
|
/// field FD.
|
2010-04-05 20:20:44 +04:00
|
|
|
const CGBitFieldInfo &getBitFieldInfo(const FieldDecl *FD) const {
|
2010-03-31 05:09:11 +04:00
|
|
|
assert(FD->isBitField() && "Invalid call for non bit-field decl!");
|
2010-04-05 20:20:44 +04:00
|
|
|
llvm::DenseMap<const FieldDecl *, CGBitFieldInfo>::const_iterator
|
2010-03-31 05:09:11 +04:00
|
|
|
it = BitFields.find(FD);
|
|
|
|
assert(it != BitFields.end() && "Unable to find bitfield info");
|
|
|
|
return it->second;
|
|
|
|
}
|
2010-03-31 02:26:10 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
} // end namespace CodeGen
|
|
|
|
} // end namespace clang
|
|
|
|
|
|
|
|
#endif
|