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" |
Daniel Dunbar | 58bf610 | 2008-08-11 16:50:21 +0000 | [diff] [blame] | 20 | #include "llvm/Support/IRBuilder.h" |
Argyrios Kyrtzidis | 8ef07c0 | 2008-06-01 21:23:24 +0000 | [diff] [blame] | 21 | #include <string> |
Chris Lattner | 0f98426 | 2008-03-01 08:50:34 +0000 | [diff] [blame] | 22 | |
Daniel Dunbar | 8f2926b | 2008-08-23 03:46:30 +0000 | [diff] [blame] | 23 | #include "CGValue.h" |
| 24 | |
Chris Lattner | 0f98426 | 2008-03-01 08:50:34 +0000 | [diff] [blame] | 25 | namespace llvm { |
Chris Lattner | 0f98426 | 2008-03-01 08:50:34 +0000 | [diff] [blame] | 26 | class Constant; |
| 27 | class Type; |
| 28 | class Value; |
| 29 | class Module; |
Chris Lattner | 391d77a | 2008-03-30 23:03:07 +0000 | [diff] [blame] | 30 | class Function; |
Chris Lattner | 0f98426 | 2008-03-01 08:50:34 +0000 | [diff] [blame] | 31 | } |
| 32 | |
| 33 | namespace clang { |
Daniel Dunbar | 8f2926b | 2008-08-23 03:46:30 +0000 | [diff] [blame] | 34 | namespace CodeGen { |
| 35 | class CodeGenFunction; |
| 36 | } |
| 37 | |
Daniel Dunbar | 7ded7f4 | 2008-08-15 22:20:32 +0000 | [diff] [blame] | 38 | class ObjCCategoryImplDecl; |
| 39 | class ObjCImplementationDecl; |
Daniel Dunbar | ddb2a3d | 2008-08-16 00:25:02 +0000 | [diff] [blame] | 40 | class ObjCInterfaceDecl; |
Daniel Dunbar | 8f2926b | 2008-08-23 03:46:30 +0000 | [diff] [blame] | 41 | class ObjCMessageExpr; |
Daniel Dunbar | 7ded7f4 | 2008-08-15 22:20:32 +0000 | [diff] [blame] | 42 | class ObjCMethodDecl; |
Daniel Dunbar | af2f62c | 2008-08-13 00:59:25 +0000 | [diff] [blame] | 43 | class ObjCProtocolDecl; |
Chris Lattner | 8e67b63 | 2008-06-26 04:37:12 +0000 | [diff] [blame] | 44 | class Selector; |
Daniel Dunbar | af2f62c | 2008-08-13 00:59:25 +0000 | [diff] [blame] | 45 | |
Daniel Dunbar | 19cd87e | 2008-08-30 03:02:31 +0000 | [diff] [blame] | 46 | typedef llvm::SmallVector<std::pair<llvm::Value*, QualType>, 16> CallArgList; |
| 47 | |
Chris Lattner | 0f98426 | 2008-03-01 08:50:34 +0000 | [diff] [blame] | 48 | namespace CodeGen { |
Chris Lattner | dce1406 | 2008-06-26 04:19:03 +0000 | [diff] [blame] | 49 | class CodeGenModule; |
Chris Lattner | 0f98426 | 2008-03-01 08:50:34 +0000 | [diff] [blame] | 50 | |
Anton Korobeynikov | 20ff310 | 2008-06-01 14:13:53 +0000 | [diff] [blame] | 51 | //FIXME Several methods should be pure virtual but aren't to avoid the |
| 52 | //partially-implemented subclass breaking. |
| 53 | |
| 54 | /// Implements runtime-specific code generation functions. |
Chris Lattner | 0f98426 | 2008-03-01 08:50:34 +0000 | [diff] [blame] | 55 | class CGObjCRuntime { |
Daniel Dunbar | 58bf610 | 2008-08-11 16:50:21 +0000 | [diff] [blame] | 56 | typedef llvm::IRBuilder<> BuilderType; |
| 57 | |
Chris Lattner | 0f98426 | 2008-03-01 08:50:34 +0000 | [diff] [blame] | 58 | public: |
| 59 | virtual ~CGObjCRuntime(); |
Daniel Dunbar | 7ded7f4 | 2008-08-15 22:20:32 +0000 | [diff] [blame] | 60 | |
| 61 | /// Generate the function required to register all Objective-C components in |
| 62 | /// this compilation unit with the runtime library. |
| 63 | virtual llvm::Function *ModuleInitFunction() = 0; |
| 64 | |
| 65 | /// Get a selector for the specified name and type values. The |
| 66 | /// return value should have the LLVM type for pointer-to |
| 67 | /// ASTContext::getObjCSelType(). |
| 68 | virtual llvm::Value *GetSelector(BuilderType &Builder, |
| 69 | Selector Sel) = 0; |
| 70 | |
| 71 | /// Generate a constant string object. |
| 72 | virtual llvm::Constant *GenerateConstantString(const std::string &String) = 0; |
| 73 | |
| 74 | /// Generate a category. A category contains a list of methods (and |
| 75 | /// accompanying metadata) and a list of protocols. |
| 76 | virtual void GenerateCategory(const ObjCCategoryImplDecl *OCD) = 0; |
| 77 | |
| 78 | /// Generate a class stucture for this class. |
| 79 | virtual void GenerateClass(const ObjCImplementationDecl *OID) = 0; |
Chris Lattner | 0f98426 | 2008-03-01 08:50:34 +0000 | [diff] [blame] | 80 | |
Daniel Dunbar | 7ded7f4 | 2008-08-15 22:20:32 +0000 | [diff] [blame] | 81 | /// Generate an Objective-C message send operation. |
Daniel Dunbar | 8f2926b | 2008-08-23 03:46:30 +0000 | [diff] [blame] | 82 | virtual CodeGen::RValue |
| 83 | GenerateMessageSend(CodeGen::CodeGenFunction &CGF, |
Daniel Dunbar | 7f8ea5c | 2008-08-30 05:35:15 +0000 | [diff] [blame] | 84 | QualType ResultType, |
| 85 | Selector Sel, |
Daniel Dunbar | f56f191 | 2008-08-25 08:19:24 +0000 | [diff] [blame] | 86 | llvm::Value *Receiver, |
Daniel Dunbar | 19cd87e | 2008-08-30 03:02:31 +0000 | [diff] [blame] | 87 | bool IsClassMessage, |
| 88 | const CallArgList &CallArgs) = 0; |
Daniel Dunbar | af2f62c | 2008-08-13 00:59:25 +0000 | [diff] [blame] | 89 | |
Daniel Dunbar | 7ded7f4 | 2008-08-15 22:20:32 +0000 | [diff] [blame] | 90 | /// Generate an Objective-C message send operation to the super |
Daniel Dunbar | f56f191 | 2008-08-25 08:19:24 +0000 | [diff] [blame] | 91 | /// class initiated in a method for Class and with the given Self |
| 92 | /// object. |
Daniel Dunbar | 8f2926b | 2008-08-23 03:46:30 +0000 | [diff] [blame] | 93 | virtual CodeGen::RValue |
| 94 | GenerateMessageSendSuper(CodeGen::CodeGenFunction &CGF, |
Daniel Dunbar | 7f8ea5c | 2008-08-30 05:35:15 +0000 | [diff] [blame] | 95 | QualType ResultType, |
| 96 | Selector Sel, |
Daniel Dunbar | f56f191 | 2008-08-25 08:19:24 +0000 | [diff] [blame] | 97 | const ObjCInterfaceDecl *Class, |
| 98 | llvm::Value *Self, |
Daniel Dunbar | 19cd87e | 2008-08-30 03:02:31 +0000 | [diff] [blame] | 99 | bool IsClassMessage, |
| 100 | const CallArgList &CallArgs) = 0; |
Daniel Dunbar | 98c5ead | 2008-08-12 05:08:18 +0000 | [diff] [blame] | 101 | |
| 102 | /// Emit the code to return the named protocol as an object, as in a |
| 103 | /// @protocol expression. |
| 104 | virtual llvm::Value *GenerateProtocolRef(llvm::IRBuilder<true> &Builder, |
Daniel Dunbar | 7ded7f4 | 2008-08-15 22:20:32 +0000 | [diff] [blame] | 105 | const ObjCProtocolDecl *OPD) = 0; |
Daniel Dunbar | 98c5ead | 2008-08-12 05:08:18 +0000 | [diff] [blame] | 106 | |
Anton Korobeynikov | 20ff310 | 2008-06-01 14:13:53 +0000 | [diff] [blame] | 107 | /// Generate the named protocol. Protocols contain method metadata but no |
| 108 | /// implementations. |
Daniel Dunbar | 7ded7f4 | 2008-08-15 22:20:32 +0000 | [diff] [blame] | 109 | virtual void GenerateProtocol(const ObjCProtocolDecl *OPD) = 0; |
Daniel Dunbar | af2f62c | 2008-08-13 00:59:25 +0000 | [diff] [blame] | 110 | |
Daniel Dunbar | 7ded7f4 | 2008-08-15 22:20:32 +0000 | [diff] [blame] | 111 | /// Generate a function preamble for a method with the specified |
| 112 | /// types. |
| 113 | |
| 114 | // FIXME: Current this just generates the Function definition, but |
| 115 | // really this should also be generating the loads of the |
| 116 | // parameters, as the runtime should have full control over how |
| 117 | // parameters are passed. |
| 118 | virtual llvm::Function *GenerateMethod(const ObjCMethodDecl *OMD) = 0; |
Daniel Dunbar | af2f62c | 2008-08-13 00:59:25 +0000 | [diff] [blame] | 119 | |
Daniel Dunbar | ddb2a3d | 2008-08-16 00:25:02 +0000 | [diff] [blame] | 120 | /// GetClass - Return a reference to the class for the given |
| 121 | /// interface decl. |
| 122 | virtual llvm::Value *GetClass(BuilderType &Builder, |
| 123 | const ObjCInterfaceDecl *OID) = 0; |
Daniel Dunbar | af2f62c | 2008-08-13 00:59:25 +0000 | [diff] [blame] | 124 | |
Anders Carlsson | 2abd89c | 2008-08-31 04:05:03 +0000 | [diff] [blame^] | 125 | /// EnumerationMutationFunction - Return the function that's called by the |
| 126 | /// compiler when a mutation is detected during foreach iteration. |
| 127 | virtual llvm::Function *EnumerationMutationFunction() = 0; |
| 128 | |
Chris Lattner | 391d77a | 2008-03-30 23:03:07 +0000 | [diff] [blame] | 129 | /// If instance variable addresses are determined at runtime then this should |
| 130 | /// return true, otherwise instance variables will be accessed directly from |
| 131 | /// the structure. If this returns true then @defs is invalid for this |
| 132 | /// runtime and a warning should be generated. |
Daniel Dunbar | 19cd87e | 2008-08-30 03:02:31 +0000 | [diff] [blame] | 133 | virtual bool LateBoundIVars() const { return false; } |
Chris Lattner | 0f98426 | 2008-03-01 08:50:34 +0000 | [diff] [blame] | 134 | }; |
| 135 | |
Chris Lattner | 391d77a | 2008-03-30 23:03:07 +0000 | [diff] [blame] | 136 | /// Creates an instance of an Objective-C runtime class. |
| 137 | //TODO: This should include some way of selecting which runtime to target. |
Daniel Dunbar | c17a4d3 | 2008-08-11 02:45:11 +0000 | [diff] [blame] | 138 | CGObjCRuntime *CreateGNUObjCRuntime(CodeGenModule &CGM); |
| 139 | CGObjCRuntime *CreateMacObjCRuntime(CodeGenModule &CGM); |
Chris Lattner | 0f98426 | 2008-03-01 08:50:34 +0000 | [diff] [blame] | 140 | } |
| 141 | } |
| 142 | #endif |