Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1 | //===--- CodeGenTypes.h - Type translation for LLVM CodeGen -----*- C++ -*-===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file was developed by Chris Lattner and is distributed under |
| 6 | // the University of Illinois Open Source License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This is the code that handles AST -> LLVM type lowering. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
| 14 | #ifndef CODEGEN_CODEGENTYPES_H |
| 15 | #define CODEGEN_CODEGENTYPES_H |
| 16 | |
Anders Carlsson | c9e2091 | 2007-08-21 00:21:21 +0000 | [diff] [blame] | 17 | #include "llvm/ADT/DenseMap.h" |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 18 | #include <vector> |
| 19 | |
| 20 | namespace llvm { |
Anders Carlsson | 4e53328 | 2007-08-17 22:00:32 +0000 | [diff] [blame] | 21 | class Module; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 22 | class Type; |
| 23 | } |
| 24 | |
| 25 | namespace clang { |
Chris Lattner | d2d2a11 | 2007-07-14 01:29:45 +0000 | [diff] [blame] | 26 | class ASTContext; |
Anders Carlsson | c9e2091 | 2007-08-21 00:21:21 +0000 | [diff] [blame] | 27 | class TagDecl; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 28 | class TargetInfo; |
| 29 | class QualType; |
| 30 | class FunctionTypeProto; |
Devang Patel | b1e3989 | 2007-10-23 23:26:46 +0000 | [diff] [blame] | 31 | class FieldDecl; |
| 32 | class RecordDecl; |
Devang Patel | b84a06e | 2007-10-23 02:10:49 +0000 | [diff] [blame] | 33 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 34 | namespace CodeGen { |
Devang Patel | b84a06e | 2007-10-23 02:10:49 +0000 | [diff] [blame] | 35 | class CodeGenTypes; |
| 36 | |
Devang Patel | b84a06e | 2007-10-23 02:10:49 +0000 | [diff] [blame] | 37 | /// RecordLayoutInfo - This class handles struct and union layout info while |
| 38 | /// lowering AST types to LLVM types. |
| 39 | class RecordLayoutInfo { |
| 40 | RecordLayoutInfo(); // DO NOT IMPLEMENT |
| 41 | public: |
Devang Patel | 057afdd | 2007-10-24 20:38:06 +0000 | [diff] [blame] | 42 | RecordLayoutInfo(llvm::Type *T) : STy(T) { |
| 43 | // FIXME : Collect info about fields that requires adjustments |
| 44 | // (i.e. fields that do not directly map to llvm struct fields.) |
| 45 | } |
Devang Patel | b84a06e | 2007-10-23 02:10:49 +0000 | [diff] [blame] | 46 | |
| 47 | /// getLLVMType - Return llvm type associated with this record. |
Devang Patel | c4c429a | 2007-10-24 00:56:23 +0000 | [diff] [blame] | 48 | llvm::Type *getLLVMType() const { |
Devang Patel | b84a06e | 2007-10-23 02:10:49 +0000 | [diff] [blame] | 49 | return STy; |
| 50 | } |
| 51 | |
| 52 | private: |
| 53 | llvm::Type *STy; |
| 54 | }; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 55 | |
| 56 | /// CodeGenTypes - This class organizes the cross-module state that is used |
| 57 | /// while lowering AST types to LLVM types. |
| 58 | class CodeGenTypes { |
Chris Lattner | d2d2a11 | 2007-07-14 01:29:45 +0000 | [diff] [blame] | 59 | ASTContext &Context; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 60 | TargetInfo &Target; |
Anders Carlsson | 4e53328 | 2007-08-17 22:00:32 +0000 | [diff] [blame] | 61 | llvm::Module& TheModule; |
Anders Carlsson | c9e2091 | 2007-08-21 00:21:21 +0000 | [diff] [blame] | 62 | |
| 63 | llvm::DenseMap<const TagDecl*, llvm::Type*> TagDeclTypes; |
Devang Patel | b84a06e | 2007-10-23 02:10:49 +0000 | [diff] [blame] | 64 | |
| 65 | /// RecordLayouts - This maps llvm struct type with corresponding |
| 66 | /// record layout info. |
Devang Patel | 71bcb09 | 2007-10-24 00:32:16 +0000 | [diff] [blame] | 67 | /// FIXME : If RecordLayoutInfo is less than 16 bytes then use |
| 68 | /// inline it in the map. |
Devang Patel | b84a06e | 2007-10-23 02:10:49 +0000 | [diff] [blame] | 69 | llvm::DenseMap<const llvm::Type*, RecordLayoutInfo *> RecordLayouts; |
| 70 | |
| 71 | /// FieldInfo - This maps struct field with corresponding llvm struct type |
| 72 | /// field no. This info is populated by record organizer. |
| 73 | llvm::DenseMap<const FieldDecl *, unsigned> FieldInfo; |
| 74 | |
Devang Patel | b1e3989 | 2007-10-23 23:26:46 +0000 | [diff] [blame] | 75 | /// RecordTypesToResolve - This keeps track of record types that are not |
| 76 | /// yet incomplete. One llvm::OpaqueType is associated with each incomplete |
| 77 | /// record. |
| 78 | llvm::DenseMap<const RecordDecl *, llvm::Type *> RecordTypesToResolve; |
| 79 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 80 | public: |
Anders Carlsson | 4e53328 | 2007-08-17 22:00:32 +0000 | [diff] [blame] | 81 | CodeGenTypes(ASTContext &Ctx, llvm::Module &M); |
Devang Patel | b84a06e | 2007-10-23 02:10:49 +0000 | [diff] [blame] | 82 | ~CodeGenTypes(); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 83 | |
| 84 | TargetInfo &getTarget() const { return Target; } |
| 85 | |
| 86 | const llvm::Type *ConvertType(QualType T); |
| 87 | void DecodeArgumentTypes(const FunctionTypeProto &FTP, |
| 88 | std::vector<const llvm::Type*> &ArgTys); |
Devang Patel | b84a06e | 2007-10-23 02:10:49 +0000 | [diff] [blame] | 89 | |
Devang Patel | c4c429a | 2007-10-24 00:56:23 +0000 | [diff] [blame] | 90 | const RecordLayoutInfo *getRecordLayoutInfo(const llvm::Type*) const; |
Devang Patel | b84a06e | 2007-10-23 02:10:49 +0000 | [diff] [blame] | 91 | |
| 92 | /// getLLVMFieldNo - Return llvm::StructType element number |
| 93 | /// that corresponds to the field FD. |
| 94 | unsigned getLLVMFieldNo(const FieldDecl *FD); |
| 95 | |
| 96 | /// addFieldInfo - Assign field number to field FD. |
| 97 | void addFieldInfo(const FieldDecl *FD, unsigned No); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 98 | }; |
Chris Lattner | a7674d8 | 2007-07-13 22:13:22 +0000 | [diff] [blame] | 99 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 100 | } // end namespace CodeGen |
| 101 | } // end namespace clang |
| 102 | |
| 103 | #endif |