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 ObjCCategoryImplDecl;
43 class ObjCImplementationDecl;
44 class ObjCInterfaceDecl;
45 class ObjCMessageExpr;
47 class ObjCProtocolDecl;
53 //FIXME Several methods should be pure virtual but aren't to avoid the
54 //partially-implemented subclass breaking.
56 /// Implements runtime-specific code generation functions.
60 virtual ~CGObjCRuntime();
62 /// Generate the function required to register all Objective-C components in
63 /// this compilation unit with the runtime library.
64 virtual llvm::Function *ModuleInitFunction() = 0;
66 /// Get a selector for the specified name and type values. The
67 /// return value should have the LLVM type for pointer-to
68 /// ASTContext::getObjCSelType().
69 virtual llvm::Value *GetSelector(CGBuilderTy &Builder,
72 /// Generate a constant string object.
73 virtual llvm::Constant *GenerateConstantString(const std::string &String) = 0;
75 /// Generate a category. A category contains a list of methods (and
76 /// accompanying metadata) and a list of protocols.
77 virtual void GenerateCategory(const ObjCCategoryImplDecl *OCD) = 0;
79 /// Generate a class stucture for this class.
80 virtual void GenerateClass(const ObjCImplementationDecl *OID) = 0;
82 /// Generate an Objective-C message send operation.
83 virtual CodeGen::RValue
84 GenerateMessageSend(CodeGen::CodeGenFunction &CGF,
87 llvm::Value *Receiver,
89 const CallArgList &CallArgs) = 0;
91 /// Generate an Objective-C message send operation to the super
92 /// class initiated in a method for Class and with the given Self
94 virtual CodeGen::RValue
95 GenerateMessageSendSuper(CodeGen::CodeGenFunction &CGF,
98 const ObjCInterfaceDecl *Class,
101 const CallArgList &CallArgs) = 0;
103 /// Emit the code to return the named protocol as an object, as in a
104 /// @protocol expression.
105 virtual llvm::Value *GenerateProtocolRef(CGBuilderTy &Builder,
106 const ObjCProtocolDecl *OPD) = 0;
108 /// Generate the named protocol. Protocols contain method metadata but no
110 virtual void GenerateProtocol(const ObjCProtocolDecl *OPD) = 0;
112 /// Generate a function preamble for a method with the specified
115 // FIXME: Current this just generates the Function definition, but
116 // really this should also be generating the loads of the
117 // parameters, as the runtime should have full control over how
118 // parameters are passed.
119 virtual llvm::Function *GenerateMethod(const ObjCMethodDecl *OMD) = 0;
121 /// Return the runtime function for getting properties.
122 virtual llvm::Function *GetPropertyGetFunction() = 0;
124 /// Return the runtime function for setting properties.
125 virtual llvm::Function *GetPropertySetFunction() = 0;
127 /// GetClass - Return a reference to the class for the given
129 virtual llvm::Value *GetClass(CGBuilderTy &Builder,
130 const ObjCInterfaceDecl *OID) = 0;
132 /// EnumerationMutationFunction - Return the function that's called by the
133 /// compiler when a mutation is detected during foreach iteration.
134 virtual llvm::Function *EnumerationMutationFunction() = 0;
136 /// If instance variable addresses are determined at runtime then this should
137 /// return true, otherwise instance variables will be accessed directly from
138 /// the structure. If this returns true then @defs is invalid for this
139 /// runtime and a warning should be generated.
140 virtual bool LateBoundIVars() const { return false; }
142 virtual void EmitTryStmt(CodeGen::CodeGenFunction &CGF,
143 const ObjCAtTryStmt &S) = 0;
144 virtual void EmitThrowStmt(CodeGen::CodeGenFunction &CGF,
145 const ObjCAtThrowStmt &S) = 0;
146 virtual void EmitSynchronizedStmt(CodeGen::CodeGenFunction &CGF,
147 const ObjCAtSynchronizedStmt &S) = 0;
148 virtual llvm::Value * EmitObjCWeakCall(CodeGen::CodeGenFunction &CGF,
149 llvm::Value *AddrWeakObj) = 0;
152 /// Creates an instance of an Objective-C runtime class.
153 //TODO: This should include some way of selecting which runtime to target.
154 CGObjCRuntime *CreateGNUObjCRuntime(CodeGenModule &CGM);
155 CGObjCRuntime *CreateMacObjCRuntime(CodeGenModule &CGM);