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