Move RecordOrganizer into CodeGenTypes.cpp
llvm-svn: 43310
This commit is contained in:
parent
4d06391c47
commit
bc50aab635
|
@ -20,6 +20,41 @@
|
||||||
using namespace clang;
|
using namespace clang;
|
||||||
using namespace CodeGen;
|
using namespace CodeGen;
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
/// RecordOrganizer - This helper class, used by RecordLayoutInfo, layouts
|
||||||
|
/// structs and unions. It manages transient information used during layout.
|
||||||
|
/// FIXME : At the moment assume
|
||||||
|
/// - one to one mapping between AST FieldDecls and
|
||||||
|
/// llvm::StructType elements.
|
||||||
|
/// - Ignore bit fields
|
||||||
|
/// - Ignore field aligments
|
||||||
|
/// - Ignore packed structs
|
||||||
|
class RecordOrganizer {
|
||||||
|
public:
|
||||||
|
RecordOrganizer() : STy(NULL) {}
|
||||||
|
|
||||||
|
/// addField - Add new field.
|
||||||
|
void addField(const FieldDecl *FD);
|
||||||
|
|
||||||
|
/// layoutFields - Do the actual work and lay out all fields. Create
|
||||||
|
/// corresponding llvm struct type. This should be invoked only after
|
||||||
|
/// all fields are added.
|
||||||
|
void layoutFields(CodeGenTypes &CGT);
|
||||||
|
|
||||||
|
/// getLLVMType - Return associated llvm struct type. This may be NULL
|
||||||
|
/// if fields are not laid out.
|
||||||
|
llvm::Type *getLLVMType() const {
|
||||||
|
return STy;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Clear private data so that this object can be reused.
|
||||||
|
void clear();
|
||||||
|
private:
|
||||||
|
llvm::Type *STy;
|
||||||
|
llvm::SmallVector<const FieldDecl *, 8> FieldDecls;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
CodeGenTypes::CodeGenTypes(ASTContext &Ctx, llvm::Module& M)
|
CodeGenTypes::CodeGenTypes(ASTContext &Ctx, llvm::Module& M)
|
||||||
: Context(Ctx), Target(Ctx.Target), TheModule(M) {
|
: Context(Ctx), Target(Ctx.Target), TheModule(M) {
|
||||||
}
|
}
|
||||||
|
@ -188,7 +223,7 @@ const llvm::Type *CodeGenTypes::ConvertType(QualType T) {
|
||||||
RO.layoutFields(*this);
|
RO.layoutFields(*this);
|
||||||
|
|
||||||
// Get llvm::StructType.
|
// Get llvm::StructType.
|
||||||
RecordLayoutInfo *RLI = new RecordLayoutInfo(&RO);
|
RecordLayoutInfo *RLI = new RecordLayoutInfo(RO.getLLVMType());
|
||||||
ResultType = RLI->getLLVMType();
|
ResultType = RLI->getLLVMType();
|
||||||
RecordLayouts[ResultType] = RLI;
|
RecordLayouts[ResultType] = RLI;
|
||||||
|
|
||||||
|
@ -275,16 +310,6 @@ CodeGenTypes::getRecordLayoutInfo(const llvm::Type* Ty) const {
|
||||||
return I->second;
|
return I->second;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// RecordLayoutInfo - Construct record layout info object using layout
|
|
||||||
/// organized by record organizer.
|
|
||||||
RecordLayoutInfo::RecordLayoutInfo(RecordOrganizer *RO) {
|
|
||||||
STy = RO->getLLVMType();
|
|
||||||
assert (STy && "Record layout is incomplete to determine llvm::Type");
|
|
||||||
// FIXME : Collect info about fields that requires adjustments
|
|
||||||
// (i.e. fields that do not directly map to llvm struct fields.)
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/// addField - Add new field.
|
/// addField - Add new field.
|
||||||
void RecordOrganizer::addField(const FieldDecl *FD) {
|
void RecordOrganizer::addField(const FieldDecl *FD) {
|
||||||
assert (!STy && "Record fields are already laid out");
|
assert (!STy && "Record fields are already laid out");
|
||||||
|
|
|
@ -36,45 +36,15 @@ namespace clang {
|
||||||
namespace CodeGen {
|
namespace CodeGen {
|
||||||
class CodeGenTypes;
|
class CodeGenTypes;
|
||||||
|
|
||||||
/// RecordOrganizer - This helper class, used by RecordLayoutInfo, layouts
|
|
||||||
/// structs and unions. It manages transient information used during layout.
|
|
||||||
/// FIXME : At the moment assume
|
|
||||||
/// - one to one mapping between AST FieldDecls and
|
|
||||||
/// llvm::StructType elements.
|
|
||||||
/// - Ignore bit fields
|
|
||||||
/// - Ignore field aligments
|
|
||||||
/// - Ignore packed structs
|
|
||||||
class RecordOrganizer {
|
|
||||||
public:
|
|
||||||
RecordOrganizer() : STy(NULL) {}
|
|
||||||
|
|
||||||
/// addField - Add new field.
|
|
||||||
void addField(const FieldDecl *FD);
|
|
||||||
|
|
||||||
/// layoutFields - Do the actual work and lay out all fields. Create
|
|
||||||
/// corresponding llvm struct type. This should be invoked only after
|
|
||||||
/// all fields are added.
|
|
||||||
void layoutFields(CodeGenTypes &CGT);
|
|
||||||
|
|
||||||
/// getLLVMType - Return associated llvm struct type. This may be NULL
|
|
||||||
/// if fields are not laid out.
|
|
||||||
llvm::Type *getLLVMType() const {
|
|
||||||
return STy;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Clear private data so that this object can be reused.
|
|
||||||
void clear();
|
|
||||||
private:
|
|
||||||
llvm::Type *STy;
|
|
||||||
llvm::SmallVector<const FieldDecl *, 8> FieldDecls;
|
|
||||||
};
|
|
||||||
|
|
||||||
/// RecordLayoutInfo - This class handles struct and union layout info while
|
/// RecordLayoutInfo - This class handles struct and union layout info while
|
||||||
/// lowering AST types to LLVM types.
|
/// lowering AST types to LLVM types.
|
||||||
class RecordLayoutInfo {
|
class RecordLayoutInfo {
|
||||||
RecordLayoutInfo(); // DO NOT IMPLEMENT
|
RecordLayoutInfo(); // DO NOT IMPLEMENT
|
||||||
public:
|
public:
|
||||||
RecordLayoutInfo(RecordOrganizer *RO);
|
RecordLayoutInfo(llvm::Type *T) : STy(T) {
|
||||||
|
// FIXME : Collect info about fields that requires adjustments
|
||||||
|
// (i.e. fields that do not directly map to llvm struct fields.)
|
||||||
|
}
|
||||||
|
|
||||||
/// getLLVMType - Return llvm type associated with this record.
|
/// getLLVMType - Return llvm type associated with this record.
|
||||||
llvm::Type *getLLVMType() const {
|
llvm::Type *getLLVMType() const {
|
||||||
|
|
Loading…
Reference in New Issue