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

Anders Carlsson andersca at mac.com
Fri Aug 17 15:00:32 PDT 2007


Author: andersca
Date: Fri Aug 17 17:00:32 2007
New Revision: 41145

URL: http://llvm.org/viewvc/llvm-project?rev=41145&view=rev
Log:
Add preliminary support for converting struct types.

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

Modified: cfe/trunk/CodeGen/CodeGenModule.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/CodeGen/CodeGenModule.cpp?rev=41145&r1=41144&r2=41145&view=diff

==============================================================================
--- cfe/trunk/CodeGen/CodeGenModule.cpp (original)
+++ cfe/trunk/CodeGen/CodeGenModule.cpp Fri Aug 17 17:00:32 2007
@@ -26,7 +26,7 @@
 
 
 CodeGenModule::CodeGenModule(ASTContext &C, llvm::Module &M)
-  : Context(C), TheModule(M), Types(C) {}
+  : Context(C), TheModule(M), Types(C, M) {}
 
 llvm::Constant *CodeGenModule::GetAddrOfGlobalDecl(const Decl *D) {
   // See if it is already in the map.

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

==============================================================================
--- cfe/trunk/CodeGen/CodeGenTypes.cpp (original)
+++ cfe/trunk/CodeGen/CodeGenTypes.cpp Fri Aug 17 17:00:32 2007
@@ -15,12 +15,13 @@
 #include "clang/Basic/TargetInfo.h"
 #include "clang/AST/AST.h"
 #include "llvm/DerivedTypes.h"
+#include "llvm/Module.h"
 
 using namespace clang;
 using namespace CodeGen;
 
-CodeGenTypes::CodeGenTypes(ASTContext &Ctx)
-  : Context(Ctx), Target(Ctx.Target) {
+CodeGenTypes::CodeGenTypes(ASTContext &Ctx, llvm::Module& M)
+  : Context(Ctx), Target(Ctx.Target), TheModule(M) {
 }
 
 /// ConvertType - Convert the specified type to its LLVM form.
@@ -133,7 +134,29 @@
     return llvm::FunctionType::get(ResultType, ArgTys, isVarArg, 0);
   }
   case Type::Tagged:
-    break;
+    const TagType &TT = cast<TagType>(Ty);
+    const TagDecl *TD = TT.getDecl();
+    llvm::Type *ResultType;
+      
+    if (!TD->isDefinition()) {
+      ResultType = llvm::OpaqueType::get();    
+    } else {
+      if (TD->getKind() == Decl::Struct) {
+        const RecordDecl *RD = cast<const RecordDecl>(TD);
+        std::vector<const llvm::Type*> Fields;
+        for (unsigned i = 0, e = RD->getNumMembers(); i != e; ++i)
+          Fields.push_back(ConvertType(RD->getMember(i)->getType()));
+        ResultType = llvm::StructType::get(Fields);
+      } else 
+        assert(0 && "FIXME: Implement tag decl kind!");
+    }
+          
+    std::string TypeName(TD->getKindName());
+    TypeName += '.';
+    TypeName += TD->getName();
+          
+    TheModule.addTypeName(TypeName, ResultType);  
+    return ResultType;
   }
   
   // FIXME: implement.

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

==============================================================================
--- cfe/trunk/CodeGen/CodeGenTypes.h (original)
+++ cfe/trunk/CodeGen/CodeGenTypes.h Fri Aug 17 17:00:32 2007
@@ -17,6 +17,7 @@
 #include <vector>
 
 namespace llvm {
+  class Module;
   class Type;
 }
 
@@ -33,9 +34,9 @@
 class CodeGenTypes {
   ASTContext &Context;
   TargetInfo &Target;
-  
+  llvm::Module& TheModule;
 public:
-  CodeGenTypes(ASTContext &Ctx);
+  CodeGenTypes(ASTContext &Ctx, llvm::Module &M);
   
   TargetInfo &getTarget() const { return Target; }
   





More information about the cfe-commits mailing list