Mike Stump | d883d84 | 2009-03-04 15:35:22 +0000 | [diff] [blame] | 1 | //===-- CGBlocks.h - state for LLVM CodeGen for blocks ----------*- 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 the internal state used for llvm translation for block literals. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
| 14 | #ifndef CLANG_CODEGEN_CGBLOCKS_H |
| 15 | #define CLANG_CODEGEN_CGBLOCKS_H |
| 16 | |
Mike Stump | 2a99814 | 2009-03-04 18:17:45 +0000 | [diff] [blame^] | 17 | #include "CodeGenTypes.h" |
| 18 | #include "clang/AST/Type.h" |
| 19 | #include "llvm/ADT/DenseMap.h" |
| 20 | #include "llvm/ADT/SmallVector.h" |
| 21 | #include "clang/Basic/TargetInfo.h" |
| 22 | #include "clang/AST/Expr.h" |
| 23 | #include "clang/AST/ExprCXX.h" |
| 24 | #include "clang/AST/ExprObjC.h" |
| 25 | |
| 26 | #include <vector> |
| 27 | #include <map> |
| 28 | |
| 29 | #include "CGBuilder.h" |
| 30 | #include "CGCall.h" |
| 31 | #include "CGValue.h" |
| 32 | |
| 33 | namespace llvm { |
| 34 | class Module; |
| 35 | class Constant; |
| 36 | class Function; |
| 37 | class GlobalValue; |
| 38 | class TargetData; |
| 39 | class FunctionType; |
| 40 | class Value; |
| 41 | } |
| 42 | |
Mike Stump | d883d84 | 2009-03-04 15:35:22 +0000 | [diff] [blame] | 43 | namespace clang { |
| 44 | |
| 45 | namespace CodeGen { |
| 46 | |
| 47 | class BlockBase { |
| 48 | public: |
| 49 | enum { |
| 50 | BLOCK_NEEDS_FREE = (1 << 24), |
| 51 | BLOCK_HAS_COPY_DISPOSE = (1 << 25), |
| 52 | BLOCK_HAS_CXX_OBJ = (1 << 26), |
| 53 | BLOCK_IS_GC = (1 << 27), |
| 54 | BLOCK_IS_GLOBAL = (1 << 28), |
| 55 | BLOCK_HAS_DESCRIPTOR = (1 << 29) |
| 56 | }; |
| 57 | }; |
| 58 | |
| 59 | class BlockModule : public BlockBase { |
Mike Stump | 2a99814 | 2009-03-04 18:17:45 +0000 | [diff] [blame^] | 60 | ASTContext &Context; |
| 61 | llvm::Module &TheModule; |
| 62 | CodeGenTypes &Types; |
| 63 | |
| 64 | ASTContext &getContext() const { return Context; } |
| 65 | llvm::Module &getModule() const { return TheModule; } |
| 66 | CodeGenTypes &getTypes() { return Types; } |
| 67 | public: |
| 68 | llvm::Constant *getNSConcreteGlobalBlock(); |
| 69 | llvm::Constant *getNSConcreteStackBlock(); |
| 70 | int getGlobalUniqueCount() { return ++Block.GlobalUniqueCount; } |
| 71 | const llvm::Type *getBlockDescriptorType(); |
| 72 | |
| 73 | const llvm::Type *getGenericBlockLiteralType(); |
| 74 | const llvm::Type *getGenericExtendedBlockLiteralType(); |
| 75 | |
| 76 | /// NSConcreteGlobalBlock - Cached reference to the class pointer for global |
| 77 | /// blocks. |
| 78 | llvm::Constant *NSConcreteGlobalBlock; |
| 79 | |
| 80 | /// NSConcreteStackBlock - Cached reference to the class poinnter for stack |
| 81 | /// blocks. |
| 82 | llvm::Constant *NSConcreteStackBlock; |
| 83 | |
| 84 | const llvm::Type *BlockDescriptorType; |
| 85 | const llvm::Type *GenericBlockLiteralType; |
| 86 | const llvm::Type *GenericExtendedBlockLiteralType; |
| 87 | struct { |
| 88 | int GlobalUniqueCount; |
| 89 | } Block; |
| 90 | |
| 91 | BlockModule(ASTContext &C, llvm::Module &M, CodeGenTypes &T) |
| 92 | : Context(C), TheModule(M), Types(T), NSConcreteGlobalBlock(0), |
| 93 | NSConcreteStackBlock(0), BlockDescriptorType(0), |
| 94 | GenericBlockLiteralType(0) { |
| 95 | Block.GlobalUniqueCount = 0; |
| 96 | } |
Mike Stump | d883d84 | 2009-03-04 15:35:22 +0000 | [diff] [blame] | 97 | }; |
| 98 | |
| 99 | class BlockFunction : public BlockBase { |
| 100 | public: |
| 101 | enum { |
| 102 | BLOCK_FIELD_IS_OBJECT = 3, /* id, NSObject, __attribute__((NSObject)), |
| 103 | block, ... */ |
| 104 | BLOCK_FIELD_IS_BLOCK = 7, /* a block variable */ |
| 105 | BLOCK_FIELD_IS_BYREF = 8, /* the on stack structure holding the __block |
| 106 | variable */ |
| 107 | BLOCK_FIELD_IS_WEAK = 16, /* declared __weak, only used in byref copy |
| 108 | helpers */ |
| 109 | BLOCK_BYREF_CALLER = 128 /* called from __block (byref) copy/dispose |
| 110 | support routines */ |
| 111 | }; |
| 112 | }; |
| 113 | |
| 114 | } // end namespace CodeGen |
| 115 | } // end namespace clang |
| 116 | |
| 117 | #endif |