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