diff options
Diffstat (limited to 'CodeGen/CodeGenTypes.h')
-rw-r--r-- | CodeGen/CodeGenTypes.h | 71 |
1 files changed, 70 insertions, 1 deletions
diff --git a/CodeGen/CodeGenTypes.h b/CodeGen/CodeGenTypes.h index 1f6cbd8701..998175537b 100644 --- a/CodeGen/CodeGenTypes.h +++ b/CodeGen/CodeGenTypes.h @@ -15,6 +15,7 @@ #define CODEGEN_CODEGENTYPES_H #include "llvm/ADT/DenseMap.h" +#include "llvm/ADT/SmallVector.h" #include <vector> namespace llvm { @@ -28,8 +29,57 @@ namespace clang { class TargetInfo; class QualType; class FunctionTypeProto; - + class FieldDecl; + namespace CodeGen { + 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() { + return STy; + } + + private: + llvm::Type *STy; + llvm::SmallVector<const FieldDecl *, 8> FieldDecls; + }; + + /// RecordLayoutInfo - This class handles struct and union layout info while + /// lowering AST types to LLVM types. + class RecordLayoutInfo { + RecordLayoutInfo(); // DO NOT IMPLEMENT + public: + RecordLayoutInfo(RecordOrganizer *RO); + + /// getLLVMType - Return llvm type associated with this record. + llvm::Type *getLLVMType() { + return STy; + } + + private: + llvm::Type *STy; + }; /// CodeGenTypes - This class organizes the cross-module state that is used /// while lowering AST types to LLVM types. @@ -39,14 +89,33 @@ class CodeGenTypes { llvm::Module& TheModule; llvm::DenseMap<const TagDecl*, llvm::Type*> TagDeclTypes; + + /// RecordLayouts - This maps llvm struct type with corresponding + /// record layout info. + llvm::DenseMap<const llvm::Type*, RecordLayoutInfo *> RecordLayouts; + + /// FieldInfo - This maps struct field with corresponding llvm struct type + /// field no. This info is populated by record organizer. + llvm::DenseMap<const FieldDecl *, unsigned> FieldInfo; + public: CodeGenTypes(ASTContext &Ctx, llvm::Module &M); + ~CodeGenTypes(); TargetInfo &getTarget() const { return Target; } const llvm::Type *ConvertType(QualType T); void DecodeArgumentTypes(const FunctionTypeProto &FTP, std::vector<const llvm::Type*> &ArgTys); + + RecordLayoutInfo *getRecordLayoutInfo(const llvm::Type*); + + /// getLLVMFieldNo - Return llvm::StructType element number + /// that corresponds to the field FD. + unsigned getLLVMFieldNo(const FieldDecl *FD); + + /// addFieldInfo - Assign field number to field FD. + void addFieldInfo(const FieldDecl *FD, unsigned No); }; } // end namespace CodeGen |