1 //===----- CGObjCRuntime.h - Interface to ObjC Runtimes ---------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This provides an abstract class for Objective-C code generation. Concrete
11 // subclasses of this implement code generation for specific Objective-C
14 //===----------------------------------------------------------------------===//
16 #ifndef CLANG_CODEGEN_OBCJRUNTIME_H
17 #define CLANG_CODEGEN_OBCJRUNTIME_H
18 #include "clang/Basic/IdentifierTable.h" // Selector
19 #include "llvm/ADT/SmallVector.h"
22 #include "CGBuilder.h"
36 class CodeGenFunction;
40 class ObjCAtThrowStmt;
41 class ObjCAtSynchronizedStmt;
42 class ObjCContainerDecl;
43 class ObjCCategoryImplDecl;
44 class ObjCImplementationDecl;
45 class ObjCInterfaceDecl;
46 class ObjCMessageExpr;
48 class ObjCProtocolDecl;
54 //FIXME Several methods should be pure virtual but aren't to avoid the
55 //partially-implemented subclass breaking.
57 /// Implements runtime-specific code generation functions.
61 virtual ~CGObjCRuntime();
63 /// Generate the function required to register all Objective-C components in
64 /// this compilation unit with the runtime library.
65 virtual llvm::Function *ModuleInitFunction() = 0;
67 /// Get a selector for the specified name and type values. The
68 /// return value should have the LLVM type for pointer-to
69 /// ASTContext::getObjCSelType().
70 virtual llvm::Value *GetSelector(CGBuilderTy &Builder,
73 /// Generate a constant string object.
74 virtual llvm::Constant *GenerateConstantString(const std::string &String) = 0;
76 /// Generate a category. A category contains a list of methods (and
77 /// accompanying metadata) and a list of protocols.
78 virtual void GenerateCategory(const ObjCCategoryImplDecl *OCD) = 0;
80 /// Generate a class stucture for this class.
81 virtual void GenerateClass(const ObjCImplementationDecl *OID) = 0;
83 /// Generate an Objective-C message send operation.
84 virtual CodeGen::RValue
85 GenerateMessageSend(CodeGen::CodeGenFunction &CGF,
88 llvm::Value *Receiver,
90 const CallArgList &CallArgs) = 0;
92 /// Generate an Objective-C message send operation to the super
93 /// class initiated in a method for Class and with the given Self
95 virtual CodeGen::RValue
96 GenerateMessageSendSuper(CodeGen::CodeGenFunction &CGF,
99 const ObjCInterfaceDecl *Class,
102 const CallArgList &CallArgs) = 0;
104 /// Emit the code to return the named protocol as an object, as in a
105 /// @protocol expression.
106 virtual llvm::Value *GenerateProtocolRef(CGBuilderTy &Builder,
107 const ObjCProtocolDecl *OPD) = 0;
109 /// Generate the named protocol. Protocols contain method metadata but no
111 virtual void GenerateProtocol(const ObjCProtocolDecl *OPD) = 0;
113 /// Generate a function preamble for a method with the specified
116 // FIXME: Current this just generates the Function definition, but
117 // really this should also be generating the loads of the
118 // parameters, as the runtime should have full control over how
119 // parameters are passed.
120 virtual llvm::Function *GenerateMethod(const ObjCMethodDecl *OMD,
121 const ObjCContainerDecl *CD) = 0;
123 /// Return the runtime function for getting properties.
124 virtual llvm::Function *GetPropertyGetFunction() = 0;
126 /// Return the runtime function for setting properties.
127 virtual llvm::Function *GetPropertySetFunction() = 0;
129 /// GetClass - Return a reference to the class for the given
131 virtual llvm::Value *GetClass(CGBuilderTy &Builder,
132 const ObjCInterfaceDecl *OID) = 0;
134 /// EnumerationMutationFunction - Return the function that's called by the
135 /// compiler when a mutation is detected during foreach iteration.
136 virtual llvm::Function *EnumerationMutationFunction() = 0;
138 /// If instance variable addresses are determined at runtime then this should
139 /// return true, otherwise instance variables will be accessed directly from
140 /// the structure. If this returns true then @defs is invalid for this
141 /// runtime and a warning should be generated.
142 virtual bool LateBoundIVars() const { return false; }
144 virtual void EmitTryOrSynchronizedStmt(CodeGen::CodeGenFunction &CGF,
146 virtual void EmitThrowStmt(CodeGen::CodeGenFunction &CGF,
147 const ObjCAtThrowStmt &S) = 0;
148 virtual llvm::Value * EmitObjCWeakRead(CodeGen::CodeGenFunction &CGF,
149 llvm::Value *AddrWeakObj) = 0;
150 virtual void EmitObjCWeakAssign(CodeGen::CodeGenFunction &CGF,
151 llvm::Value *src, llvm::Value *dest) = 0;
152 virtual void EmitObjCGlobalAssign(CodeGen::CodeGenFunction &CGF,
153 llvm::Value *src, llvm::Value *dest) = 0;
154 virtual void EmitObjCIvarAssign(CodeGen::CodeGenFunction &CGF,
155 llvm::Value *src, llvm::Value *dest) = 0;
156 virtual void EmitObjCStrongCastAssign(CodeGen::CodeGenFunction &CGF,
157 llvm::Value *src, llvm::Value *dest) = 0;
160 /// Creates an instance of an Objective-C runtime class.
161 //TODO: This should include some way of selecting which runtime to target.
162 CGObjCRuntime *CreateGNUObjCRuntime(CodeGenModule &CGM);
163 CGObjCRuntime *CreateMacObjCRuntime(CodeGenModule &CGM);
164 CGObjCRuntime *CreateMacModernObjCRuntime(CodeGenModule &CGM);