Daniel Dunbar | c17a4d3 | 2008-08-11 02:45:11 +0000 | [diff] [blame] | 1 | //===----- CGObjCRuntime.h - Interface to ObjC Runtimes ---------*- C++ -*-===// |
Chris Lattner | 0f98426 | 2008-03-01 08:50:34 +0000 | [diff] [blame] | 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 provides an abstract class for Objective-C code generation. Concrete |
| 11 | // subclasses of this implement code generation for specific Objective-C |
| 12 | // runtime libraries. |
| 13 | // |
| 14 | //===----------------------------------------------------------------------===// |
| 15 | |
| 16 | #ifndef CLANG_CODEGEN_OBCJRUNTIME_H |
| 17 | #define CLANG_CODEGEN_OBCJRUNTIME_H |
Daniel Dunbar | e91593e | 2008-08-11 04:54:23 +0000 | [diff] [blame] | 18 | #include "clang/Basic/IdentifierTable.h" // Selector |
Anton Korobeynikov | 20ff310 | 2008-06-01 14:13:53 +0000 | [diff] [blame] | 19 | #include "llvm/ADT/SmallVector.h" |
Argyrios Kyrtzidis | 8ef07c0 | 2008-06-01 21:23:24 +0000 | [diff] [blame] | 20 | #include <string> |
Chris Lattner | 0f98426 | 2008-03-01 08:50:34 +0000 | [diff] [blame] | 21 | |
Daniel Dunbar | 45d196b | 2008-11-01 01:53:16 +0000 | [diff] [blame] | 22 | #include "CGBuilder.h" |
Daniel Dunbar | 46f45b9 | 2008-09-09 01:06:48 +0000 | [diff] [blame] | 23 | #include "CGCall.h" |
Daniel Dunbar | 45d196b | 2008-11-01 01:53:16 +0000 | [diff] [blame] | 24 | #include "CGValue.h" |
Daniel Dunbar | 8f2926b | 2008-08-23 03:46:30 +0000 | [diff] [blame] | 25 | |
Chris Lattner | 0f98426 | 2008-03-01 08:50:34 +0000 | [diff] [blame] | 26 | namespace llvm { |
Chris Lattner | 0f98426 | 2008-03-01 08:50:34 +0000 | [diff] [blame] | 27 | class Constant; |
| 28 | class Type; |
| 29 | class Value; |
| 30 | class Module; |
Chris Lattner | 391d77a | 2008-03-30 23:03:07 +0000 | [diff] [blame] | 31 | class Function; |
Chris Lattner | 0f98426 | 2008-03-01 08:50:34 +0000 | [diff] [blame] | 32 | } |
| 33 | |
| 34 | namespace clang { |
Daniel Dunbar | 46f45b9 | 2008-09-09 01:06:48 +0000 | [diff] [blame] | 35 | namespace CodeGen { |
| 36 | class CodeGenFunction; |
| 37 | } |
Daniel Dunbar | 8f2926b | 2008-08-23 03:46:30 +0000 | [diff] [blame] | 38 | |
Anders Carlsson | 64d5d6c | 2008-09-09 10:04:29 +0000 | [diff] [blame] | 39 | class ObjCAtTryStmt; |
| 40 | class ObjCAtThrowStmt; |
Chris Lattner | 10cac6f | 2008-11-15 21:26:17 +0000 | [diff] [blame] | 41 | class ObjCAtSynchronizedStmt; |
Fariborz Jahanian | 679a502 | 2009-01-10 21:06:09 +0000 | [diff] [blame] | 42 | class ObjCContainerDecl; |
Daniel Dunbar | 7ded7f4 | 2008-08-15 22:20:32 +0000 | [diff] [blame] | 43 | class ObjCCategoryImplDecl; |
| 44 | class ObjCImplementationDecl; |
Daniel Dunbar | ddb2a3d | 2008-08-16 00:25:02 +0000 | [diff] [blame] | 45 | class ObjCInterfaceDecl; |
Daniel Dunbar | 8f2926b | 2008-08-23 03:46:30 +0000 | [diff] [blame] | 46 | class ObjCMessageExpr; |
Daniel Dunbar | 7ded7f4 | 2008-08-15 22:20:32 +0000 | [diff] [blame] | 47 | class ObjCMethodDecl; |
Daniel Dunbar | af2f62c | 2008-08-13 00:59:25 +0000 | [diff] [blame] | 48 | class ObjCProtocolDecl; |
Chris Lattner | 8e67b63 | 2008-06-26 04:37:12 +0000 | [diff] [blame] | 49 | class Selector; |
Fariborz Jahanian | 0bb2036 | 2009-02-02 20:02:29 +0000 | [diff] [blame] | 50 | class ObjCIvarDecl; |
Daniel Dunbar | af2f62c | 2008-08-13 00:59:25 +0000 | [diff] [blame] | 51 | |
Chris Lattner | 0f98426 | 2008-03-01 08:50:34 +0000 | [diff] [blame] | 52 | namespace CodeGen { |
Chris Lattner | dce1406 | 2008-06-26 04:19:03 +0000 | [diff] [blame] | 53 | class CodeGenModule; |
Chris Lattner | 0f98426 | 2008-03-01 08:50:34 +0000 | [diff] [blame] | 54 | |
Anton Korobeynikov | 20ff310 | 2008-06-01 14:13:53 +0000 | [diff] [blame] | 55 | //FIXME Several methods should be pure virtual but aren't to avoid the |
| 56 | //partially-implemented subclass breaking. |
| 57 | |
| 58 | /// Implements runtime-specific code generation functions. |
Chris Lattner | 0f98426 | 2008-03-01 08:50:34 +0000 | [diff] [blame] | 59 | class CGObjCRuntime { |
Daniel Dunbar | 58bf610 | 2008-08-11 16:50:21 +0000 | [diff] [blame] | 60 | |
Chris Lattner | 0f98426 | 2008-03-01 08:50:34 +0000 | [diff] [blame] | 61 | public: |
| 62 | virtual ~CGObjCRuntime(); |
Daniel Dunbar | 7ded7f4 | 2008-08-15 22:20:32 +0000 | [diff] [blame] | 63 | |
| 64 | /// Generate the function required to register all Objective-C components in |
| 65 | /// this compilation unit with the runtime library. |
| 66 | virtual llvm::Function *ModuleInitFunction() = 0; |
| 67 | |
| 68 | /// Get a selector for the specified name and type values. The |
| 69 | /// return value should have the LLVM type for pointer-to |
| 70 | /// ASTContext::getObjCSelType(). |
Daniel Dunbar | 45d196b | 2008-11-01 01:53:16 +0000 | [diff] [blame] | 71 | virtual llvm::Value *GetSelector(CGBuilderTy &Builder, |
Daniel Dunbar | 7ded7f4 | 2008-08-15 22:20:32 +0000 | [diff] [blame] | 72 | Selector Sel) = 0; |
| 73 | |
| 74 | /// Generate a constant string object. |
| 75 | virtual llvm::Constant *GenerateConstantString(const std::string &String) = 0; |
| 76 | |
| 77 | /// Generate a category. A category contains a list of methods (and |
| 78 | /// accompanying metadata) and a list of protocols. |
| 79 | virtual void GenerateCategory(const ObjCCategoryImplDecl *OCD) = 0; |
| 80 | |
| 81 | /// Generate a class stucture for this class. |
| 82 | virtual void GenerateClass(const ObjCImplementationDecl *OID) = 0; |
Chris Lattner | 0f98426 | 2008-03-01 08:50:34 +0000 | [diff] [blame] | 83 | |
Daniel Dunbar | 7ded7f4 | 2008-08-15 22:20:32 +0000 | [diff] [blame] | 84 | /// Generate an Objective-C message send operation. |
Daniel Dunbar | 8f2926b | 2008-08-23 03:46:30 +0000 | [diff] [blame] | 85 | virtual CodeGen::RValue |
| 86 | GenerateMessageSend(CodeGen::CodeGenFunction &CGF, |
Daniel Dunbar | 7f8ea5c | 2008-08-30 05:35:15 +0000 | [diff] [blame] | 87 | QualType ResultType, |
| 88 | Selector Sel, |
Daniel Dunbar | f56f191 | 2008-08-25 08:19:24 +0000 | [diff] [blame] | 89 | llvm::Value *Receiver, |
Daniel Dunbar | 19cd87e | 2008-08-30 03:02:31 +0000 | [diff] [blame] | 90 | bool IsClassMessage, |
| 91 | const CallArgList &CallArgs) = 0; |
Daniel Dunbar | af2f62c | 2008-08-13 00:59:25 +0000 | [diff] [blame] | 92 | |
Daniel Dunbar | 7ded7f4 | 2008-08-15 22:20:32 +0000 | [diff] [blame] | 93 | /// Generate an Objective-C message send operation to the super |
Daniel Dunbar | f56f191 | 2008-08-25 08:19:24 +0000 | [diff] [blame] | 94 | /// class initiated in a method for Class and with the given Self |
| 95 | /// object. |
Daniel Dunbar | 8f2926b | 2008-08-23 03:46:30 +0000 | [diff] [blame] | 96 | virtual CodeGen::RValue |
| 97 | GenerateMessageSendSuper(CodeGen::CodeGenFunction &CGF, |
Daniel Dunbar | 7f8ea5c | 2008-08-30 05:35:15 +0000 | [diff] [blame] | 98 | QualType ResultType, |
| 99 | Selector Sel, |
Daniel Dunbar | f56f191 | 2008-08-25 08:19:24 +0000 | [diff] [blame] | 100 | const ObjCInterfaceDecl *Class, |
| 101 | llvm::Value *Self, |
Daniel Dunbar | 19cd87e | 2008-08-30 03:02:31 +0000 | [diff] [blame] | 102 | bool IsClassMessage, |
| 103 | const CallArgList &CallArgs) = 0; |
Daniel Dunbar | 98c5ead | 2008-08-12 05:08:18 +0000 | [diff] [blame] | 104 | |
| 105 | /// Emit the code to return the named protocol as an object, as in a |
| 106 | /// @protocol expression. |
Daniel Dunbar | 45d196b | 2008-11-01 01:53:16 +0000 | [diff] [blame] | 107 | virtual llvm::Value *GenerateProtocolRef(CGBuilderTy &Builder, |
Daniel Dunbar | 7ded7f4 | 2008-08-15 22:20:32 +0000 | [diff] [blame] | 108 | const ObjCProtocolDecl *OPD) = 0; |
Daniel Dunbar | 98c5ead | 2008-08-12 05:08:18 +0000 | [diff] [blame] | 109 | |
Anton Korobeynikov | 20ff310 | 2008-06-01 14:13:53 +0000 | [diff] [blame] | 110 | /// Generate the named protocol. Protocols contain method metadata but no |
| 111 | /// implementations. |
Daniel Dunbar | 7ded7f4 | 2008-08-15 22:20:32 +0000 | [diff] [blame] | 112 | virtual void GenerateProtocol(const ObjCProtocolDecl *OPD) = 0; |
Daniel Dunbar | af2f62c | 2008-08-13 00:59:25 +0000 | [diff] [blame] | 113 | |
Daniel Dunbar | 7ded7f4 | 2008-08-15 22:20:32 +0000 | [diff] [blame] | 114 | /// Generate a function preamble for a method with the specified |
| 115 | /// types. |
| 116 | |
| 117 | // FIXME: Current this just generates the Function definition, but |
| 118 | // really this should also be generating the loads of the |
| 119 | // parameters, as the runtime should have full control over how |
| 120 | // parameters are passed. |
Fariborz Jahanian | 679a502 | 2009-01-10 21:06:09 +0000 | [diff] [blame] | 121 | virtual llvm::Function *GenerateMethod(const ObjCMethodDecl *OMD, |
| 122 | const ObjCContainerDecl *CD) = 0; |
Daniel Dunbar | af2f62c | 2008-08-13 00:59:25 +0000 | [diff] [blame] | 123 | |
Daniel Dunbar | 49f6602 | 2008-09-24 03:38:44 +0000 | [diff] [blame] | 124 | /// Return the runtime function for getting properties. |
| 125 | virtual llvm::Function *GetPropertyGetFunction() = 0; |
| 126 | |
| 127 | /// Return the runtime function for setting properties. |
| 128 | virtual llvm::Function *GetPropertySetFunction() = 0; |
| 129 | |
Daniel Dunbar | ddb2a3d | 2008-08-16 00:25:02 +0000 | [diff] [blame] | 130 | /// GetClass - Return a reference to the class for the given |
| 131 | /// interface decl. |
Daniel Dunbar | 45d196b | 2008-11-01 01:53:16 +0000 | [diff] [blame] | 132 | virtual llvm::Value *GetClass(CGBuilderTy &Builder, |
Daniel Dunbar | ddb2a3d | 2008-08-16 00:25:02 +0000 | [diff] [blame] | 133 | const ObjCInterfaceDecl *OID) = 0; |
Daniel Dunbar | af2f62c | 2008-08-13 00:59:25 +0000 | [diff] [blame] | 134 | |
Anders Carlsson | 2abd89c | 2008-08-31 04:05:03 +0000 | [diff] [blame] | 135 | /// EnumerationMutationFunction - Return the function that's called by the |
| 136 | /// compiler when a mutation is detected during foreach iteration. |
| 137 | virtual llvm::Function *EnumerationMutationFunction() = 0; |
| 138 | |
Chris Lattner | 391d77a | 2008-03-30 23:03:07 +0000 | [diff] [blame] | 139 | /// If instance variable addresses are determined at runtime then this should |
| 140 | /// return true, otherwise instance variables will be accessed directly from |
| 141 | /// the structure. If this returns true then @defs is invalid for this |
| 142 | /// runtime and a warning should be generated. |
Daniel Dunbar | 19cd87e | 2008-08-30 03:02:31 +0000 | [diff] [blame] | 143 | virtual bool LateBoundIVars() const { return false; } |
Anders Carlsson | 64d5d6c | 2008-09-09 10:04:29 +0000 | [diff] [blame] | 144 | |
Fariborz Jahanian | bd71be4 | 2008-11-21 00:49:24 +0000 | [diff] [blame] | 145 | virtual void EmitTryOrSynchronizedStmt(CodeGen::CodeGenFunction &CGF, |
| 146 | const Stmt &S) = 0; |
Anders Carlsson | 64d5d6c | 2008-09-09 10:04:29 +0000 | [diff] [blame] | 147 | virtual void EmitThrowStmt(CodeGen::CodeGenFunction &CGF, |
| 148 | const ObjCAtThrowStmt &S) = 0; |
Fariborz Jahanian | 3e283e3 | 2008-11-18 22:37:34 +0000 | [diff] [blame] | 149 | virtual llvm::Value * EmitObjCWeakRead(CodeGen::CodeGenFunction &CGF, |
Nate Begeman | fea8685 | 2008-12-16 19:57:09 +0000 | [diff] [blame] | 150 | llvm::Value *AddrWeakObj) = 0; |
Fariborz Jahanian | 3e283e3 | 2008-11-18 22:37:34 +0000 | [diff] [blame] | 151 | virtual void EmitObjCWeakAssign(CodeGen::CodeGenFunction &CGF, |
| 152 | llvm::Value *src, llvm::Value *dest) = 0; |
Fariborz Jahanian | 5862650 | 2008-11-19 00:59:10 +0000 | [diff] [blame] | 153 | virtual void EmitObjCGlobalAssign(CodeGen::CodeGenFunction &CGF, |
| 154 | llvm::Value *src, llvm::Value *dest) = 0; |
Fariborz Jahanian | 7eda836 | 2008-11-20 19:23:36 +0000 | [diff] [blame] | 155 | virtual void EmitObjCIvarAssign(CodeGen::CodeGenFunction &CGF, |
| 156 | llvm::Value *src, llvm::Value *dest) = 0; |
Fariborz Jahanian | 5862650 | 2008-11-19 00:59:10 +0000 | [diff] [blame] | 157 | virtual void EmitObjCStrongCastAssign(CodeGen::CodeGenFunction &CGF, |
| 158 | llvm::Value *src, llvm::Value *dest) = 0; |
Fariborz Jahanian | 0bb2036 | 2009-02-02 20:02:29 +0000 | [diff] [blame] | 159 | |
| 160 | virtual llvm::Value *EmitObjCValueForIvar(CodeGen::CodeGenFunction &CGF, |
Fariborz Jahanian | 45012a7 | 2009-02-03 00:09:52 +0000 | [diff] [blame^] | 161 | QualType ObjectTy, |
Fariborz Jahanian | 0bb2036 | 2009-02-02 20:02:29 +0000 | [diff] [blame] | 162 | llvm::Value *BaseValue, |
| 163 | const ObjCIvarDecl *Ivar, |
| 164 | const FieldDecl *Field, |
| 165 | unsigned CVRQualifiers) = 0; |
Chris Lattner | 0f98426 | 2008-03-01 08:50:34 +0000 | [diff] [blame] | 166 | }; |
| 167 | |
Chris Lattner | 391d77a | 2008-03-30 23:03:07 +0000 | [diff] [blame] | 168 | /// Creates an instance of an Objective-C runtime class. |
| 169 | //TODO: This should include some way of selecting which runtime to target. |
Daniel Dunbar | c17a4d3 | 2008-08-11 02:45:11 +0000 | [diff] [blame] | 170 | CGObjCRuntime *CreateGNUObjCRuntime(CodeGenModule &CGM); |
| 171 | CGObjCRuntime *CreateMacObjCRuntime(CodeGenModule &CGM); |
Fariborz Jahanian | 30bc571 | 2009-01-22 23:02:58 +0000 | [diff] [blame] | 172 | CGObjCRuntime *CreateMacNonFragileABIObjCRuntime(CodeGenModule &CGM); |
Chris Lattner | 0f98426 | 2008-03-01 08:50:34 +0000 | [diff] [blame] | 173 | } |
| 174 | } |
| 175 | #endif |