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;
46 typedef llvm::SmallVector<std::pair<llvm::Value*, QualType>, 16> CallArgList;
51 //FIXME Several methods should be pure virtual but aren't to avoid the
52 //partially-implemented subclass breaking.
54 /// Implements runtime-specific code generation functions.
56 typedef llvm::IRBuilder<> BuilderType;
59 virtual ~CGObjCRuntime();
61 /// Generate the function required to register all Objective-C components in
62 /// this compilation unit with the runtime library.
63 virtual llvm::Function *ModuleInitFunction() = 0;
65 /// Get a selector for the specified name and type values. The
66 /// return value should have the LLVM type for pointer-to
67 /// ASTContext::getObjCSelType().
68 virtual llvm::Value *GetSelector(BuilderType &Builder,
71 /// Generate a constant string object.
72 virtual llvm::Constant *GenerateConstantString(const std::string &String) = 0;
74 /// Generate a category. A category contains a list of methods (and
75 /// accompanying metadata) and a list of protocols.
76 virtual void GenerateCategory(const ObjCCategoryImplDecl *OCD) = 0;
78 /// Generate a class stucture for this class.
79 virtual void GenerateClass(const ObjCImplementationDecl *OID) = 0;
81 /// Generate an Objective-C message send operation.
82 virtual CodeGen::RValue
83 GenerateMessageSend(CodeGen::CodeGenFunction &CGF,
84 const ObjCMessageExpr *E,
85 llvm::Value *Receiver,
87 const CallArgList &CallArgs) = 0;
89 /// Generate an Objective-C message send operation to the super
90 /// class initiated in a method for Class and with the given Self
92 virtual CodeGen::RValue
93 GenerateMessageSendSuper(CodeGen::CodeGenFunction &CGF,
94 const ObjCMessageExpr *E,
95 const ObjCInterfaceDecl *Class,
98 const CallArgList &CallArgs) = 0;
100 /// Emit the code to return the named protocol as an object, as in a
101 /// @protocol expression.
102 virtual llvm::Value *GenerateProtocolRef(llvm::IRBuilder<true> &Builder,
103 const ObjCProtocolDecl *OPD) = 0;
105 /// Generate the named protocol. Protocols contain method metadata but no
107 virtual void GenerateProtocol(const ObjCProtocolDecl *OPD) = 0;
109 /// Generate a function preamble for a method with the specified
112 // FIXME: Current this just generates the Function definition, but
113 // really this should also be generating the loads of the
114 // parameters, as the runtime should have full control over how
115 // parameters are passed.
116 virtual llvm::Function *GenerateMethod(const ObjCMethodDecl *OMD) = 0;
118 /// GetClass - Return a reference to the class for the given
120 virtual llvm::Value *GetClass(BuilderType &Builder,
121 const ObjCInterfaceDecl *OID) = 0;
123 /// If instance variable addresses are determined at runtime then this should
124 /// return true, otherwise instance variables will be accessed directly from
125 /// the structure. If this returns true then @defs is invalid for this
126 /// runtime and a warning should be generated.
127 virtual bool LateBoundIVars() const { return false; }
130 /// Creates an instance of an Objective-C runtime class.
131 //TODO: This should include some way of selecting which runtime to target.
132 CGObjCRuntime *CreateGNUObjCRuntime(CodeGenModule &CGM);
133 CGObjCRuntime *CreateMacObjCRuntime(CodeGenModule &CGM);