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;
51 class ObjCStringLiteral;
56 //FIXME Several methods should be pure virtual but aren't to avoid the
57 //partially-implemented subclass breaking.
59 /// Implements runtime-specific code generation functions.
63 virtual ~CGObjCRuntime();
65 /// Generate the function required to register all Objective-C components in
66 /// this compilation unit with the runtime library.
67 virtual llvm::Function *ModuleInitFunction() = 0;
69 /// Get a selector for the specified name and type values. The
70 /// return value should have the LLVM type for pointer-to
71 /// ASTContext::getObjCSelType().
72 virtual llvm::Value *GetSelector(CGBuilderTy &Builder,
75 /// Generate a constant string object.
76 virtual llvm::Constant *GenerateConstantString(const ObjCStringLiteral *) = 0;
78 /// Generate a category. A category contains a list of methods (and
79 /// accompanying metadata) and a list of protocols.
80 virtual void GenerateCategory(const ObjCCategoryImplDecl *OCD) = 0;
82 /// Generate a class stucture for this class.
83 virtual void GenerateClass(const ObjCImplementationDecl *OID) = 0;
85 /// Generate an Objective-C message send operation.
86 virtual CodeGen::RValue
87 GenerateMessageSend(CodeGen::CodeGenFunction &CGF,
90 llvm::Value *Receiver,
92 const CallArgList &CallArgs) = 0;
94 /// Generate an Objective-C message send operation to the super
95 /// class initiated in a method for Class and with the given Self
97 virtual CodeGen::RValue
98 GenerateMessageSendSuper(CodeGen::CodeGenFunction &CGF,
101 const ObjCInterfaceDecl *Class,
105 const CallArgList &CallArgs) = 0;
107 /// Emit the code to return the named protocol as an object, as in a
108 /// @protocol expression.
109 virtual llvm::Value *GenerateProtocolRef(CGBuilderTy &Builder,
110 const ObjCProtocolDecl *OPD) = 0;
112 /// Generate the named protocol. Protocols contain method metadata but no
114 virtual void GenerateProtocol(const ObjCProtocolDecl *OPD) = 0;
116 /// Generate a function preamble for a method with the specified
119 // FIXME: Current this just generates the Function definition, but
120 // really this should also be generating the loads of the
121 // parameters, as the runtime should have full control over how
122 // parameters are passed.
123 virtual llvm::Function *GenerateMethod(const ObjCMethodDecl *OMD,
124 const ObjCContainerDecl *CD) = 0;
126 /// Return the runtime function for getting properties.
127 virtual llvm::Constant *GetPropertyGetFunction() = 0;
129 /// Return the runtime function for setting properties.
130 virtual llvm::Constant *GetPropertySetFunction() = 0;
132 /// GetClass - Return a reference to the class for the given
134 virtual llvm::Value *GetClass(CGBuilderTy &Builder,
135 const ObjCInterfaceDecl *OID) = 0;
137 /// EnumerationMutationFunction - Return the function that's called by the
138 /// compiler when a mutation is detected during foreach iteration.
139 virtual llvm::Constant *EnumerationMutationFunction() = 0;
141 virtual void EmitTryOrSynchronizedStmt(CodeGen::CodeGenFunction &CGF,
143 virtual void EmitThrowStmt(CodeGen::CodeGenFunction &CGF,
144 const ObjCAtThrowStmt &S) = 0;
145 virtual llvm::Value *EmitObjCWeakRead(CodeGen::CodeGenFunction &CGF,
146 llvm::Value *AddrWeakObj) = 0;
147 virtual void EmitObjCWeakAssign(CodeGen::CodeGenFunction &CGF,
148 llvm::Value *src, llvm::Value *dest) = 0;
149 virtual void EmitObjCGlobalAssign(CodeGen::CodeGenFunction &CGF,
150 llvm::Value *src, llvm::Value *dest) = 0;
151 virtual void EmitObjCIvarAssign(CodeGen::CodeGenFunction &CGF,
152 llvm::Value *src, llvm::Value *dest) = 0;
153 virtual void EmitObjCStrongCastAssign(CodeGen::CodeGenFunction &CGF,
154 llvm::Value *src, llvm::Value *dest) = 0;
156 virtual LValue EmitObjCValueForIvar(CodeGen::CodeGenFunction &CGF,
158 llvm::Value *BaseValue,
159 const ObjCIvarDecl *Ivar,
160 unsigned CVRQualifiers) = 0;
161 virtual llvm::Value *EmitIvarOffset(CodeGen::CodeGenFunction &CGF,
162 const ObjCInterfaceDecl *Interface,
163 const ObjCIvarDecl *Ivar) = 0;
166 /// Creates an instance of an Objective-C runtime class.
167 //TODO: This should include some way of selecting which runtime to target.
168 CGObjCRuntime *CreateGNUObjCRuntime(CodeGenModule &CGM);
169 CGObjCRuntime *CreateMacObjCRuntime(CodeGenModule &CGM);
170 CGObjCRuntime *CreateMacNonFragileABIObjCRuntime(CodeGenModule &CGM);