zcov: / lib/CodeGen/CGRecordLayoutBuilder.h


Files: 1 Branches Taken: 0.0% 0 / 0
Generated: 2010-02-10 01:31 Branches Executed: 0.0% 0 / 0
Line Coverage: 100.0% 6 / 6


Programs: 1 Runs 2897


       1                 : //===--- CGRecordLayoutBuilder.h - Record builder helper --------*- C++ -*-===//
       2                 : //
       3                 : //                     The LLVM Compiler Infrastructure
       4                 : //
       5                 : // This file is distributed under the University of Illinois Open Source
       6                 : // License. See LICENSE.TXT for details.
       7                 : //
       8                 : //===----------------------------------------------------------------------===//
       9                 : //
      10                 : // This is a helper class used to build CGRecordLayout objects and LLVM types.
      11                 : //
      12                 : //===----------------------------------------------------------------------===//
      13                 : 
      14                 : #ifndef CLANG_CODEGEN_CGRECORDLAYOUTBUILDER_H
      15                 : #define CLANG_CODEGEN_CGRECORDLAYOUTBUILDER_H
      16                 : 
      17                 : #include "llvm/ADT/SmallVector.h"
      18                 : #include "llvm/System/DataTypes.h"
      19                 : #include <vector>
      20                 : 
      21                 : namespace llvm {
      22                 :   class Type;
      23                 : }
      24                 : 
      25                 : namespace clang {
      26                 :   class ASTRecordLayout;
      27                 :   class CXXRecordDecl;
      28                 :   class FieldDecl;
      29                 :   class RecordDecl;
      30                 :   class QualType;
      31                 : 
      32                 : namespace CodeGen {
      33                 :   class CGRecordLayout;
      34                 :   class CodeGenTypes;
      35                 : 
      36             1341: class CGRecordLayoutBuilder {
      37                 :   CodeGenTypes &Types;
      38                 : 
      39                 :   /// Packed - Whether the resulting LLVM struct will be packed or not.
      40                 :   bool Packed;
      41                 : 
      42                 :   /// ContainsPointerToDataMember - Whether one of the fields in this record 
      43                 :   /// layout is a pointer to data member, or a struct that contains pointer to
      44                 :   /// data member.
      45                 :   bool ContainsPointerToDataMember;
      46                 : 
      47                 :   /// Alignment - Contains the alignment of the RecordDecl.
      48                 :   unsigned Alignment;
      49                 : 
      50                 :   /// AlignmentAsLLVMStruct - Will contain the maximum alignment of all the
      51                 :   /// LLVM types.
      52                 :   unsigned AlignmentAsLLVMStruct;
      53                 : 
      54                 :   /// BitsAvailableInLastField - If a bit field spans only part of a LLVM field,
      55                 :   /// this will have the number of bits still available in the field.
      56                 :   char BitsAvailableInLastField;
      57                 : 
      58                 :   /// NextFieldOffsetInBytes - Holds the next field offset in bytes.
      59                 :   uint64_t NextFieldOffsetInBytes;
      60                 : 
      61                 :   /// FieldTypes - Holds the LLVM types that the struct is created from.
      62                 :   std::vector<const llvm::Type *> FieldTypes;
      63                 : 
      64                 :   /// LLVMFieldInfo - Holds a field and its corresponding LLVM field number.
      65                 :   typedef std::pair<const FieldDecl *, unsigned> LLVMFieldInfo;
      66                 :   llvm::SmallVector<LLVMFieldInfo, 16> LLVMFields;
      67                 : 
      68                 :   /// LLVMBitFieldInfo - Holds location and size information about a bit field.
      69               95:   struct LLVMBitFieldInfo {
      70                 :     LLVMBitFieldInfo(const FieldDecl *FD, unsigned FieldNo, unsigned Start,
      71               95:                      unsigned Size)
      72               95:       : FD(FD), FieldNo(FieldNo), Start(Start), Size(Size) { }
      73                 : 
      74                 :     const FieldDecl *FD;
      75                 : 
      76                 :     unsigned FieldNo;
      77                 :     unsigned Start;
      78                 :     unsigned Size;
      79                 :   };
      80                 :   llvm::SmallVector<LLVMBitFieldInfo, 16> LLVMBitFields;
      81                 : 
      82             1341:   CGRecordLayoutBuilder(CodeGenTypes &Types)
      83                 :     : Types(Types), Packed(false), ContainsPointerToDataMember(false)
      84                 :     , Alignment(0), AlignmentAsLLVMStruct(1)
      85             1341:     , BitsAvailableInLastField(0), NextFieldOffsetInBytes(0) { }
      86                 : 
      87                 :   /// Layout - Will layout a RecordDecl.
      88                 :   void Layout(const RecordDecl *D);
      89                 : 
      90                 :   /// LayoutUnion - Will layout a union RecordDecl.
      91                 :   void LayoutUnion(const RecordDecl *D);
      92                 : 
      93                 :   /// LayoutField - try to layout all fields in the record decl.
      94                 :   /// Returns false if the operation failed because the struct is not packed.
      95                 :   bool LayoutFields(const RecordDecl *D);
      96                 : 
      97                 :   /// LayoutBases - layout the bases and vtable pointer of a record decl.
      98                 :   void LayoutBases(const CXXRecordDecl *RD, const ASTRecordLayout &Layout);
      99                 :   
     100                 :   /// LayoutField - layout a single field. Returns false if the operation failed
     101                 :   /// because the current struct is not packed.
     102                 :   bool LayoutField(const FieldDecl *D, uint64_t FieldOffset);
     103                 : 
     104                 :   /// LayoutBitField - layout a single bit field.
     105                 :   void LayoutBitField(const FieldDecl *D, uint64_t FieldOffset);
     106                 : 
     107                 :   /// AppendField - Appends a field with the given offset and type.
     108                 :   void AppendField(uint64_t FieldOffsetInBytes, const llvm::Type *FieldTy);
     109                 : 
     110                 :   /// AppendPadding - Appends enough padding bytes so that the total struct
     111                 :   /// size matches the alignment of the passed in type.
     112                 :   void AppendPadding(uint64_t FieldOffsetInBytes, const llvm::Type *FieldTy);
     113                 : 
     114                 :   /// AppendPadding - Appends enough padding bytes so that the total
     115                 :   /// struct size is a multiple of the field alignment.
     116                 :   void AppendPadding(uint64_t FieldOffsetInBytes, unsigned FieldAlignment);
     117                 : 
     118                 :   /// AppendBytes - Append a given number of bytes to the record.
     119                 :   void AppendBytes(uint64_t NumBytes);
     120                 : 
     121                 :   /// AppendTailPadding - Append enough tail padding so that the type will have
     122                 :   /// the passed size.
     123                 :   void AppendTailPadding(uint64_t RecordSize);
     124                 : 
     125                 :   unsigned getTypeAlignment(const llvm::Type *Ty) const;
     126                 :   uint64_t getTypeSizeInBytes(const llvm::Type *Ty) const;
     127                 : 
     128                 :   /// CheckForPointerToDataMember - Check if the given type contains a pointer 
     129                 :   /// to data member.
     130                 :   void CheckForPointerToDataMember(QualType T);
     131                 : 
     132                 : public:
     133                 :   /// ComputeLayout - Return the right record layout for a given record decl.
     134                 :   static CGRecordLayout *ComputeLayout(CodeGenTypes &Types,
     135                 :                                        const RecordDecl *D);
     136                 : };
     137                 : 
     138                 : } // end namespace CodeGen
     139                 : } // end namespace clang
     140                 : 
     141                 : 
     142                 : #endif

Generated: 2010-02-10 01:31 by zcov