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 | |
| 23 | namespace llvm { |
Chris Lattner | 0f98426 | 2008-03-01 08:50:34 +0000 | [diff] [blame] | 24 | class Constant; |
| 25 | class Type; |
| 26 | class Value; |
| 27 | class Module; |
Chris Lattner | 391d77a | 2008-03-30 23:03:07 +0000 | [diff] [blame] | 28 | class Function; |
Chris Lattner | 0f98426 | 2008-03-01 08:50:34 +0000 | [diff] [blame] | 29 | } |
| 30 | |
| 31 | namespace clang { |
Chris Lattner | 8e67b63 | 2008-06-26 04:37:12 +0000 | [diff] [blame] | 32 | class Selector; |
| 33 | |
Chris Lattner | 0f98426 | 2008-03-01 08:50:34 +0000 | [diff] [blame] | 34 | namespace CodeGen { |
Chris Lattner | dce1406 | 2008-06-26 04:19:03 +0000 | [diff] [blame] | 35 | class CodeGenModule; |
Chris Lattner | 0f98426 | 2008-03-01 08:50:34 +0000 | [diff] [blame] | 36 | |
Anton Korobeynikov | 20ff310 | 2008-06-01 14:13:53 +0000 | [diff] [blame] | 37 | //FIXME Several methods should be pure virtual but aren't to avoid the |
| 38 | //partially-implemented subclass breaking. |
| 39 | |
| 40 | /// Implements runtime-specific code generation functions. |
Chris Lattner | 0f98426 | 2008-03-01 08:50:34 +0000 | [diff] [blame] | 41 | class CGObjCRuntime { |
Daniel Dunbar | 58bf610 | 2008-08-11 16:50:21 +0000 | [diff] [blame^] | 42 | typedef llvm::IRBuilder<> BuilderType; |
| 43 | |
Chris Lattner | 0f98426 | 2008-03-01 08:50:34 +0000 | [diff] [blame] | 44 | public: |
| 45 | virtual ~CGObjCRuntime(); |
| 46 | |
Chris Lattner | 391d77a | 2008-03-30 23:03:07 +0000 | [diff] [blame] | 47 | /// Generate an Objective-C message send operation |
Daniel Dunbar | 58bf610 | 2008-08-11 16:50:21 +0000 | [diff] [blame^] | 48 | virtual llvm::Value *GenerateMessageSend(BuilderType &Builder, |
Chris Lattner | 0f98426 | 2008-03-01 08:50:34 +0000 | [diff] [blame] | 49 | const llvm::Type *ReturnTy, |
Chris Lattner | 391d77a | 2008-03-30 23:03:07 +0000 | [diff] [blame] | 50 | llvm::Value *Sender, |
Chris Lattner | 0f98426 | 2008-03-01 08:50:34 +0000 | [diff] [blame] | 51 | llvm::Value *Receiver, |
Chris Lattner | 9384c76 | 2008-06-26 04:42:20 +0000 | [diff] [blame] | 52 | Selector Sel, |
Chris Lattner | 0f98426 | 2008-03-01 08:50:34 +0000 | [diff] [blame] | 53 | llvm::Value** ArgV, |
Anton Korobeynikov | 20ff310 | 2008-06-01 14:13:53 +0000 | [diff] [blame] | 54 | unsigned ArgC) =0; |
Chris Lattner | 391d77a | 2008-03-30 23:03:07 +0000 | [diff] [blame] | 55 | /// Generate the function required to register all Objective-C components in |
| 56 | /// this compilation unit with the runtime library. |
Anton Korobeynikov | 20ff310 | 2008-06-01 14:13:53 +0000 | [diff] [blame] | 57 | virtual llvm::Function *ModuleInitFunction() =0; |
| 58 | /// Get a selector for the specified name and type values |
Daniel Dunbar | 58bf610 | 2008-08-11 16:50:21 +0000 | [diff] [blame^] | 59 | virtual llvm::Value *GetSelector(BuilderType &Builder, |
Chris Lattner | 85e3568 | 2008-08-08 19:57:58 +0000 | [diff] [blame] | 60 | Selector Sel) =0; |
Anton Korobeynikov | 20ff310 | 2008-06-01 14:13:53 +0000 | [diff] [blame] | 61 | /// Generate a constant string object |
Chris Lattner | 42ba3e7 | 2008-06-26 04:38:58 +0000 | [diff] [blame] | 62 | virtual llvm::Constant *GenerateConstantString(const char *String, |
| 63 | const size_t Length) = 0; |
Anton Korobeynikov | 20ff310 | 2008-06-01 14:13:53 +0000 | [diff] [blame] | 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 char *ClassName, const char *CategoryName, |
Chris Lattner | a421007 | 2008-06-26 05:08:00 +0000 | [diff] [blame] | 67 | const llvm::SmallVectorImpl<Selector> &InstanceMethodSels, |
Anton Korobeynikov | 20ff310 | 2008-06-01 14:13:53 +0000 | [diff] [blame] | 68 | const llvm::SmallVectorImpl<llvm::Constant *> &InstanceMethodTypes, |
Chris Lattner | a421007 | 2008-06-26 05:08:00 +0000 | [diff] [blame] | 69 | const llvm::SmallVectorImpl<Selector> &ClassMethodSels, |
Anton Korobeynikov | 20ff310 | 2008-06-01 14:13:53 +0000 | [diff] [blame] | 70 | const llvm::SmallVectorImpl<llvm::Constant *> &ClassMethodTypes, |
| 71 | const llvm::SmallVectorImpl<std::string> &Protocols) =0; |
| 72 | /// Generate a class stucture for this class. |
| 73 | virtual void GenerateClass( |
| 74 | const char *ClassName, |
| 75 | const char *SuperClassName, |
| 76 | const int instanceSize, |
| 77 | const llvm::SmallVectorImpl<llvm::Constant *> &IvarNames, |
| 78 | const llvm::SmallVectorImpl<llvm::Constant *> &IvarTypes, |
| 79 | const llvm::SmallVectorImpl<llvm::Constant *> &IvarOffsets, |
Chris Lattner | a421007 | 2008-06-26 05:08:00 +0000 | [diff] [blame] | 80 | const llvm::SmallVectorImpl<Selector> &InstanceMethodSels, |
Anton Korobeynikov | 20ff310 | 2008-06-01 14:13:53 +0000 | [diff] [blame] | 81 | const llvm::SmallVectorImpl<llvm::Constant *> &InstanceMethodTypes, |
Chris Lattner | a421007 | 2008-06-26 05:08:00 +0000 | [diff] [blame] | 82 | const llvm::SmallVectorImpl<Selector> &ClassMethodSels, |
Anton Korobeynikov | 20ff310 | 2008-06-01 14:13:53 +0000 | [diff] [blame] | 83 | const llvm::SmallVectorImpl<llvm::Constant *> &ClassMethodTypes, |
| 84 | const llvm::SmallVectorImpl<std::string> &Protocols) =0; |
| 85 | /// Generate a reference to the named protocol. |
Chris Lattner | 85e3568 | 2008-08-08 19:57:58 +0000 | [diff] [blame] | 86 | virtual llvm::Value *GenerateProtocolRef(llvm::IRBuilder<true> &Builder, |
Daniel Dunbar | c17a4d3 | 2008-08-11 02:45:11 +0000 | [diff] [blame] | 87 | const char *ProtocolName) = 0; |
Chris Lattner | 85e3568 | 2008-08-08 19:57:58 +0000 | [diff] [blame] | 88 | virtual llvm::Value *GenerateMessageSendSuper(llvm::IRBuilder<true> &Builder, |
Chris Lattner | 8e67b63 | 2008-06-26 04:37:12 +0000 | [diff] [blame] | 89 | const llvm::Type *ReturnTy, |
| 90 | llvm::Value *Sender, |
| 91 | const char *SuperClassName, |
| 92 | llvm::Value *Receiver, |
| 93 | Selector Sel, |
| 94 | llvm::Value** ArgV, |
| 95 | unsigned ArgC) = 0; |
Anton Korobeynikov | 20ff310 | 2008-06-01 14:13:53 +0000 | [diff] [blame] | 96 | /// Generate the named protocol. Protocols contain method metadata but no |
| 97 | /// implementations. |
| 98 | virtual void GenerateProtocol(const char *ProtocolName, |
| 99 | const llvm::SmallVectorImpl<std::string> &Protocols, |
| 100 | const llvm::SmallVectorImpl<llvm::Constant *> &InstanceMethodNames, |
| 101 | const llvm::SmallVectorImpl<llvm::Constant *> &InstanceMethodTypes, |
| 102 | const llvm::SmallVectorImpl<llvm::Constant *> &ClassMethodNames, |
| 103 | const llvm::SmallVectorImpl<llvm::Constant *> &ClassMethodTypes) =0; |
Chris Lattner | 391d77a | 2008-03-30 23:03:07 +0000 | [diff] [blame] | 104 | /// Generate a function preamble for a method with the specified types |
Anton Korobeynikov | 20ff310 | 2008-06-01 14:13:53 +0000 | [diff] [blame] | 105 | virtual llvm::Function *MethodPreamble( |
| 106 | const std::string &ClassName, |
| 107 | const std::string &CategoryName, |
| 108 | const std::string &MethodName, |
| 109 | const llvm::Type *ReturnTy, |
Chris Lattner | 391d77a | 2008-03-30 23:03:07 +0000 | [diff] [blame] | 110 | const llvm::Type *SelfTy, |
| 111 | const llvm::Type **ArgTy, |
| 112 | unsigned ArgC, |
Anton Korobeynikov | 20ff310 | 2008-06-01 14:13:53 +0000 | [diff] [blame] | 113 | bool isClassMethod, |
Chris Lattner | 391d77a | 2008-03-30 23:03:07 +0000 | [diff] [blame] | 114 | bool isVarArg) = 0; |
Anton Korobeynikov | 20ff310 | 2008-06-01 14:13:53 +0000 | [diff] [blame] | 115 | /// Look up the class for the specified name |
Daniel Dunbar | 58bf610 | 2008-08-11 16:50:21 +0000 | [diff] [blame^] | 116 | virtual llvm::Value *LookupClass(BuilderType &Builder, |
Chris Lattner | 85e3568 | 2008-08-08 19:57:58 +0000 | [diff] [blame] | 117 | llvm::Value *ClassName) =0; |
Chris Lattner | 391d77a | 2008-03-30 23:03:07 +0000 | [diff] [blame] | 118 | /// If instance variable addresses are determined at runtime then this should |
| 119 | /// return true, otherwise instance variables will be accessed directly from |
| 120 | /// the structure. If this returns true then @defs is invalid for this |
| 121 | /// runtime and a warning should be generated. |
| 122 | virtual bool LateBoundIVars() { return false; } |
Chris Lattner | 0f98426 | 2008-03-01 08:50:34 +0000 | [diff] [blame] | 123 | }; |
| 124 | |
Chris Lattner | 391d77a | 2008-03-30 23:03:07 +0000 | [diff] [blame] | 125 | /// Creates an instance of an Objective-C runtime class. |
| 126 | //TODO: This should include some way of selecting which runtime to target. |
Daniel Dunbar | c17a4d3 | 2008-08-11 02:45:11 +0000 | [diff] [blame] | 127 | CGObjCRuntime *CreateGNUObjCRuntime(CodeGenModule &CGM); |
| 128 | CGObjCRuntime *CreateMacObjCRuntime(CodeGenModule &CGM); |
Chris Lattner | 0f98426 | 2008-03-01 08:50:34 +0000 | [diff] [blame] | 129 | } |
| 130 | } |
| 131 | #endif |