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"
20 #include "llvm/Support/IRBuilder.h"
35 class CodeGenFunction;
38 class ObjCCategoryImplDecl;
39 class ObjCImplementationDecl;
40 class ObjCInterfaceDecl;
41 class ObjCMessageExpr;
43 class ObjCProtocolDecl;
49 //FIXME Several methods should be pure virtual but aren't to avoid the
50 //partially-implemented subclass breaking.
52 /// Implements runtime-specific code generation functions.
54 typedef llvm::IRBuilder<> BuilderType;
57 virtual ~CGObjCRuntime();
59 /// Generate the function required to register all Objective-C components in
60 /// this compilation unit with the runtime library.
61 virtual llvm::Function *ModuleInitFunction() = 0;
63 /// Get a selector for the specified name and type values. The
64 /// return value should have the LLVM type for pointer-to
65 /// ASTContext::getObjCSelType().
66 virtual llvm::Value *GetSelector(BuilderType &Builder,
69 /// Generate a constant string object.
70 virtual llvm::Constant *GenerateConstantString(const std::string &String) = 0;
72 /// Generate a category. A category contains a list of methods (and
73 /// accompanying metadata) and a list of protocols.
74 virtual void GenerateCategory(const ObjCCategoryImplDecl *OCD) = 0;
76 /// Generate a class stucture for this class.
77 virtual void GenerateClass(const ObjCImplementationDecl *OID) = 0;
79 /// Generate an Objective-C message send operation.
80 virtual CodeGen::RValue
81 GenerateMessageSend(CodeGen::CodeGenFunction &CGF,
82 const ObjCMessageExpr *E,
83 llvm::Value *Receiver,
84 bool IsClassMessage) = 0;
86 /// Generate an Objective-C message send operation to the super
87 /// class initiated in a method for Class and with the given Self
89 virtual CodeGen::RValue
90 GenerateMessageSendSuper(CodeGen::CodeGenFunction &CGF,
91 const ObjCMessageExpr *E,
92 const ObjCInterfaceDecl *Class,
94 bool IsClassMessage) = 0;
96 /// Emit the code to return the named protocol as an object, as in a
97 /// @protocol expression.
98 virtual llvm::Value *GenerateProtocolRef(llvm::IRBuilder<true> &Builder,
99 const ObjCProtocolDecl *OPD) = 0;
101 /// Generate the named protocol. Protocols contain method metadata but no
103 virtual void GenerateProtocol(const ObjCProtocolDecl *OPD) = 0;
105 /// Generate a function preamble for a method with the specified
108 // FIXME: Current this just generates the Function definition, but
109 // really this should also be generating the loads of the
110 // parameters, as the runtime should have full control over how
111 // parameters are passed.
112 virtual llvm::Function *GenerateMethod(const ObjCMethodDecl *OMD) = 0;
114 /// GetClass - Return a reference to the class for the given
116 virtual llvm::Value *GetClass(BuilderType &Builder,
117 const ObjCInterfaceDecl *OID) = 0;
119 /// If instance variable addresses are determined at runtime then this should
120 /// return true, otherwise instance variables will be accessed directly from
121 /// the structure. If this returns true then @defs is invalid for this
122 /// runtime and a warning should be generated.
123 virtual bool LateBoundIVars() { return false; }
126 /// Creates an instance of an Objective-C runtime class.
127 //TODO: This should include some way of selecting which runtime to target.
128 CGObjCRuntime *CreateGNUObjCRuntime(CodeGenModule &CGM);
129 CGObjCRuntime *CreateMacObjCRuntime(CodeGenModule &CGM);