CGObjCRuntime.h revision 3aba07c84f12f244283ebfa94095a49810e00c2f
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 18#include "llvm/ADT/SmallVector.h" 19#include <string> 20 21namespace llvm { 22 class IRBuilder; 23 class Constant; 24 class Type; 25 class Value; 26 class Module; 27 class Function; 28} 29 30namespace clang { 31namespace CodeGen { 32 class CodeGenModule; 33 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. 38class CGObjCRuntime { 39public: 40 virtual ~CGObjCRuntime(); 41 42 /// Generate an Objective-C message send operation 43 virtual llvm::Value *GenerateMessageSend(llvm::IRBuilder &Builder, 44 const llvm::Type *ReturnTy, 45 llvm::Value *Sender, 46 llvm::Value *Receiver, 47 llvm::Value *Selector, 48 llvm::Value** ArgV, 49 unsigned ArgC) =0; 50 /// Generate the function required to register all Objective-C components in 51 /// this compilation unit with the runtime library. 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, 55 llvm::Value *SelName, 56 llvm::Value *SelTypes) = 0; 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; 100 /// Generate a function preamble for a method with the specified types 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, 106 const llvm::Type *SelfTy, 107 const llvm::Type **ArgTy, 108 unsigned ArgC, 109 bool isClassMethod, 110 bool isVarArg) = 0; 111 /// Look up the class for the specified name 112 virtual llvm::Value *LookupClass(llvm::IRBuilder &Builder, llvm::Value 113 *ClassName) =0; 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; } 119}; 120 121/// Creates an instance of an Objective-C runtime class. 122//TODO: This should include some way of selecting which runtime to target. 123CGObjCRuntime *CreateObjCRuntime(CodeGenModule &CGM); 124} 125} 126#endif 127