Daniel Dunbar | 8c85fac | 2008-08-11 02:45:11 +0000 | [diff] [blame] | 1 | //===----- CGObjCRuntime.h - Interface to ObjC Runtimes ---------*- C++ -*-===// |
Chris Lattner | a0fd5ee | 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 | de30073 | 2008-08-11 04:54:23 +0000 | [diff] [blame] | 18 | #include "clang/Basic/IdentifierTable.h" // Selector |
Anton Korobeynikov | cd5d08d | 2008-06-01 14:13:53 +0000 | [diff] [blame] | 19 | #include "llvm/ADT/SmallVector.h" |
Daniel Dunbar | fd2ff6c | 2008-08-11 16:50:21 +0000 | [diff] [blame] | 20 | #include "llvm/Support/IRBuilder.h" |
Argiris Kirtzidis | 0560bcf | 2008-06-01 21:23:24 +0000 | [diff] [blame] | 21 | #include <string> |
Chris Lattner | a0fd5ee | 2008-03-01 08:50:34 +0000 | [diff] [blame] | 22 | |
| 23 | namespace llvm { |
Chris Lattner | a0fd5ee | 2008-03-01 08:50:34 +0000 | [diff] [blame] | 24 | class Constant; |
| 25 | class Type; |
| 26 | class Value; |
| 27 | class Module; |
Chris Lattner | b326b17 | 2008-03-30 23:03:07 +0000 | [diff] [blame] | 28 | class Function; |
Chris Lattner | a0fd5ee | 2008-03-01 08:50:34 +0000 | [diff] [blame] | 29 | } |
| 30 | |
| 31 | namespace clang { |
Daniel Dunbar | ac93e47 | 2008-08-15 22:20:32 +0000 | [diff] [blame^] | 32 | class ObjCCategoryImplDecl; |
| 33 | class ObjCImplementationDecl; |
| 34 | class ObjCMethodDecl; |
Daniel Dunbar | 84bb85f | 2008-08-13 00:59:25 +0000 | [diff] [blame] | 35 | class ObjCProtocolDecl; |
Chris Lattner | d71288e | 2008-06-26 04:37:12 +0000 | [diff] [blame] | 36 | class Selector; |
Daniel Dunbar | 84bb85f | 2008-08-13 00:59:25 +0000 | [diff] [blame] | 37 | |
Chris Lattner | a0fd5ee | 2008-03-01 08:50:34 +0000 | [diff] [blame] | 38 | namespace CodeGen { |
Chris Lattner | 547907c | 2008-06-26 04:19:03 +0000 | [diff] [blame] | 39 | class CodeGenModule; |
Chris Lattner | a0fd5ee | 2008-03-01 08:50:34 +0000 | [diff] [blame] | 40 | |
Anton Korobeynikov | cd5d08d | 2008-06-01 14:13:53 +0000 | [diff] [blame] | 41 | //FIXME Several methods should be pure virtual but aren't to avoid the |
| 42 | //partially-implemented subclass breaking. |
| 43 | |
| 44 | /// Implements runtime-specific code generation functions. |
Chris Lattner | a0fd5ee | 2008-03-01 08:50:34 +0000 | [diff] [blame] | 45 | class CGObjCRuntime { |
Daniel Dunbar | fd2ff6c | 2008-08-11 16:50:21 +0000 | [diff] [blame] | 46 | typedef llvm::IRBuilder<> BuilderType; |
| 47 | |
Chris Lattner | a0fd5ee | 2008-03-01 08:50:34 +0000 | [diff] [blame] | 48 | public: |
| 49 | virtual ~CGObjCRuntime(); |
Daniel Dunbar | ac93e47 | 2008-08-15 22:20:32 +0000 | [diff] [blame^] | 50 | |
| 51 | /// Generate the function required to register all Objective-C components in |
| 52 | /// this compilation unit with the runtime library. |
| 53 | virtual llvm::Function *ModuleInitFunction() = 0; |
| 54 | |
| 55 | /// Get a selector for the specified name and type values. The |
| 56 | /// return value should have the LLVM type for pointer-to |
| 57 | /// ASTContext::getObjCSelType(). |
| 58 | virtual llvm::Value *GetSelector(BuilderType &Builder, |
| 59 | Selector Sel) = 0; |
| 60 | |
| 61 | /// Generate a constant string object. |
| 62 | virtual llvm::Constant *GenerateConstantString(const std::string &String) = 0; |
| 63 | |
| 64 | /// Generate a category. A category contains a list of methods (and |
| 65 | /// accompanying metadata) and a list of protocols. |
| 66 | virtual void GenerateCategory(const ObjCCategoryImplDecl *OCD) = 0; |
| 67 | |
| 68 | /// Generate a class stucture for this class. |
| 69 | virtual void GenerateClass(const ObjCImplementationDecl *OID) = 0; |
Chris Lattner | a0fd5ee | 2008-03-01 08:50:34 +0000 | [diff] [blame] | 70 | |
Daniel Dunbar | ac93e47 | 2008-08-15 22:20:32 +0000 | [diff] [blame^] | 71 | /// Generate an Objective-C message send operation. |
Daniel Dunbar | fd2ff6c | 2008-08-11 16:50:21 +0000 | [diff] [blame] | 72 | virtual llvm::Value *GenerateMessageSend(BuilderType &Builder, |
Chris Lattner | a0fd5ee | 2008-03-01 08:50:34 +0000 | [diff] [blame] | 73 | const llvm::Type *ReturnTy, |
| 74 | llvm::Value *Receiver, |
Chris Lattner | 8384c14 | 2008-06-26 04:42:20 +0000 | [diff] [blame] | 75 | Selector Sel, |
Chris Lattner | a0fd5ee | 2008-03-01 08:50:34 +0000 | [diff] [blame] | 76 | llvm::Value** ArgV, |
Daniel Dunbar | ac93e47 | 2008-08-15 22:20:32 +0000 | [diff] [blame^] | 77 | unsigned ArgC) = 0; |
Daniel Dunbar | 84bb85f | 2008-08-13 00:59:25 +0000 | [diff] [blame] | 78 | |
Daniel Dunbar | ac93e47 | 2008-08-15 22:20:32 +0000 | [diff] [blame^] | 79 | /// Generate an Objective-C message send operation to the super |
| 80 | /// class. |
Chris Lattner | faf23db | 2008-08-08 19:57:58 +0000 | [diff] [blame] | 81 | virtual llvm::Value *GenerateMessageSendSuper(llvm::IRBuilder<true> &Builder, |
Chris Lattner | d71288e | 2008-06-26 04:37:12 +0000 | [diff] [blame] | 82 | const llvm::Type *ReturnTy, |
Chris Lattner | d71288e | 2008-06-26 04:37:12 +0000 | [diff] [blame] | 83 | const char *SuperClassName, |
| 84 | llvm::Value *Receiver, |
| 85 | Selector Sel, |
| 86 | llvm::Value** ArgV, |
| 87 | unsigned ArgC) = 0; |
Daniel Dunbar | fa45624 | 2008-08-12 05:08:18 +0000 | [diff] [blame] | 88 | |
| 89 | /// Emit the code to return the named protocol as an object, as in a |
| 90 | /// @protocol expression. |
| 91 | virtual llvm::Value *GenerateProtocolRef(llvm::IRBuilder<true> &Builder, |
Daniel Dunbar | ac93e47 | 2008-08-15 22:20:32 +0000 | [diff] [blame^] | 92 | const ObjCProtocolDecl *OPD) = 0; |
Daniel Dunbar | fa45624 | 2008-08-12 05:08:18 +0000 | [diff] [blame] | 93 | |
Anton Korobeynikov | cd5d08d | 2008-06-01 14:13:53 +0000 | [diff] [blame] | 94 | /// Generate the named protocol. Protocols contain method metadata but no |
| 95 | /// implementations. |
Daniel Dunbar | ac93e47 | 2008-08-15 22:20:32 +0000 | [diff] [blame^] | 96 | virtual void GenerateProtocol(const ObjCProtocolDecl *OPD) = 0; |
Daniel Dunbar | 84bb85f | 2008-08-13 00:59:25 +0000 | [diff] [blame] | 97 | |
Daniel Dunbar | ac93e47 | 2008-08-15 22:20:32 +0000 | [diff] [blame^] | 98 | /// Generate a function preamble for a method with the specified |
| 99 | /// types. |
| 100 | |
| 101 | // FIXME: Current this just generates the Function definition, but |
| 102 | // really this should also be generating the loads of the |
| 103 | // parameters, as the runtime should have full control over how |
| 104 | // parameters are passed. |
| 105 | virtual llvm::Function *GenerateMethod(const ObjCMethodDecl *OMD) = 0; |
Daniel Dunbar | 84bb85f | 2008-08-13 00:59:25 +0000 | [diff] [blame] | 106 | |
Anton Korobeynikov | cd5d08d | 2008-06-01 14:13:53 +0000 | [diff] [blame] | 107 | /// Look up the class for the specified name |
Daniel Dunbar | fd2ff6c | 2008-08-11 16:50:21 +0000 | [diff] [blame] | 108 | virtual llvm::Value *LookupClass(BuilderType &Builder, |
Daniel Dunbar | ac93e47 | 2008-08-15 22:20:32 +0000 | [diff] [blame^] | 109 | llvm::Value *ClassName) = 0; |
Daniel Dunbar | 84bb85f | 2008-08-13 00:59:25 +0000 | [diff] [blame] | 110 | |
Chris Lattner | b326b17 | 2008-03-30 23:03:07 +0000 | [diff] [blame] | 111 | /// If instance variable addresses are determined at runtime then this should |
| 112 | /// return true, otherwise instance variables will be accessed directly from |
| 113 | /// the structure. If this returns true then @defs is invalid for this |
| 114 | /// runtime and a warning should be generated. |
| 115 | virtual bool LateBoundIVars() { return false; } |
Chris Lattner | a0fd5ee | 2008-03-01 08:50:34 +0000 | [diff] [blame] | 116 | }; |
| 117 | |
Chris Lattner | b326b17 | 2008-03-30 23:03:07 +0000 | [diff] [blame] | 118 | /// Creates an instance of an Objective-C runtime class. |
| 119 | //TODO: This should include some way of selecting which runtime to target. |
Daniel Dunbar | 8c85fac | 2008-08-11 02:45:11 +0000 | [diff] [blame] | 120 | CGObjCRuntime *CreateGNUObjCRuntime(CodeGenModule &CGM); |
| 121 | CGObjCRuntime *CreateMacObjCRuntime(CodeGenModule &CGM); |
Chris Lattner | a0fd5ee | 2008-03-01 08:50:34 +0000 | [diff] [blame] | 122 | } |
| 123 | } |
| 124 | #endif |