aboutsummaryrefslogtreecommitdiff
path: root/CodeGen/CodeGenTypes.cpp
diff options
context:
space:
mode:
authorDevang Patel <dpatel@apple.com>2007-10-24 20:38:06 +0000
committerDevang Patel <dpatel@apple.com>2007-10-24 20:38:06 +0000
commit057afddf0fab91d979d6a750667d56a345225c96 (patch)
tree92c50ff3262cb5540439a7097eac4d30f2b5c5f5 /CodeGen/CodeGenTypes.cpp
parent2e6d935930867d93d84d234ada30d93a0371754d (diff)
Move RecordOrganizer into CodeGenTypes.cpp
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@43310 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'CodeGen/CodeGenTypes.cpp')
-rw-r--r--CodeGen/CodeGenTypes.cpp47
1 files changed, 36 insertions, 11 deletions
diff --git a/CodeGen/CodeGenTypes.cpp b/CodeGen/CodeGenTypes.cpp
index ec8b69ecb4..31c76b3306 100644
--- a/CodeGen/CodeGenTypes.cpp
+++ b/CodeGen/CodeGenTypes.cpp
@@ -20,6 +20,41 @@
using namespace clang;
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)
: Context(Ctx), Target(Ctx.Target), TheModule(M) {
}
@@ -188,7 +223,7 @@ const llvm::Type *CodeGenTypes::ConvertType(QualType T) {
RO.layoutFields(*this);
// Get llvm::StructType.
- RecordLayoutInfo *RLI = new RecordLayoutInfo(&RO);
+ RecordLayoutInfo *RLI = new RecordLayoutInfo(RO.getLLVMType());
ResultType = RLI->getLLVMType();
RecordLayouts[ResultType] = RLI;
@@ -275,16 +310,6 @@ CodeGenTypes::getRecordLayoutInfo(const llvm::Type* Ty) const {
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.
void RecordOrganizer::addField(const FieldDecl *FD) {
assert (!STy && "Record fields are already laid out");