[cfe-commits] r43573 - in /cfe/trunk/CodeGen: CodeGenTypes.cpp CodeGenTypes.h

Devang Patel dpatel at apple.com
Wed Oct 31 13:08:22 PDT 2007


Author: dpatel
Date: Wed Oct 31 15:08:22 2007
New Revision: 43573

URL: http://llvm.org/viewvc/llvm-project?rev=43573&view=rev
Log:
Keep track of field offsets during structure layout.
Take 2.

Modified:
    cfe/trunk/CodeGen/CodeGenTypes.cpp
    cfe/trunk/CodeGen/CodeGenTypes.h

Modified: cfe/trunk/CodeGen/CodeGenTypes.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/CodeGen/CodeGenTypes.cpp?rev=43573&r1=43572&r2=43573&view=diff

==============================================================================
--- cfe/trunk/CodeGen/CodeGenTypes.cpp (original)
+++ cfe/trunk/CodeGen/CodeGenTypes.cpp Wed Oct 31 15:08:22 2007
@@ -16,6 +16,7 @@
 #include "clang/AST/AST.h"
 #include "llvm/DerivedTypes.h"
 #include "llvm/Module.h"
+#include "llvm/Target/TargetData.h"
 
 using namespace clang;
 using namespace CodeGen;
@@ -39,7 +40,7 @@
     /// layoutStructFields - 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 layoutStructFields(CodeGenTypes &CGT);
+    void layoutStructFields(CodeGenTypes &CGT, const RecordLayout &RL);
 
     /// layoutUnionFields - Do the actual work and lay out all fields. Create
     /// corresponding llvm struct type.  This should be invoked only after
@@ -246,7 +247,8 @@
       RecordOrganizer RO;
       for (unsigned i = 0, e = RD->getNumMembers(); i != e; ++i)
         RO.addField(RD->getMember(i));
-      RO.layoutStructFields(*this);
+      const RecordLayout &RL = Context.getRecordLayout(RD, SourceLocation());
+      RO.layoutStructFields(*this, RL);
 
       // Get llvm::StructType.
       RecordLayoutInfo *RLI = new RecordLayoutInfo(RO.getLLVMType());
@@ -353,16 +355,21 @@
 ///    - Ignore bit fields
 ///    - Ignore field aligments
 ///    - Ignore packed structs
-void RecordOrganizer::layoutStructFields(CodeGenTypes &CGT) {
+void RecordOrganizer::layoutStructFields(CodeGenTypes &CGT,
+                                         const RecordLayout &RL) {
   // FIXME : Use SmallVector
   std::vector<const llvm::Type*> Fields;
   unsigned FieldNo = 0;
+  uint64_t Cursor = 0;
+
   for (llvm::SmallVector<const FieldDecl *, 8>::iterator I = FieldDecls.begin(),
          E = FieldDecls.end(); I != E; ++I) {
     const FieldDecl *FD = *I;
     const llvm::Type *Ty = CGT.ConvertType(FD->getType());
 
-    // FIXME : Layout FieldDecl FD
+    uint64_t Offset = RL.getFieldOffset(FieldNo);
+    assert (Offset == Cursor && "FIXME Invalid struct layout");
+    Cursor += CGT.getTargetData().getTypeSizeInBits(Ty);
 
     Fields.push_back(Ty);
     CGT.addFieldInfo(FD, FieldNo++);

Modified: cfe/trunk/CodeGen/CodeGenTypes.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/CodeGen/CodeGenTypes.h?rev=43573&r1=43572&r2=43573&view=diff

==============================================================================
--- cfe/trunk/CodeGen/CodeGenTypes.h (original)
+++ cfe/trunk/CodeGen/CodeGenTypes.h Wed Oct 31 15:08:22 2007
@@ -96,6 +96,7 @@
   CodeGenTypes(ASTContext &Ctx, llvm::Module &M, const llvm::TargetData &TD);
   ~CodeGenTypes();
   
+  const llvm::TargetData &getTargetData() const { return TheTargetData; }
   TargetInfo &getTarget() const { return Target; }
   ASTContext &getContext() const { return Context; }
 





More information about the cfe-commits mailing list