]> granicus.if.org Git - clang/blob - lib/CodeGen/CGObjCRuntime.h
Make ObjCInterfaceDecl's const in some more places.
[clang] / lib / CodeGen / CGObjCRuntime.h
1 //===----- CGObjCRuntime.h - Interface to ObjC Runtimes ---------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This provides an abstract class for Objective-C code generation.  Concrete
11 // subclasses of this implement code generation for specific Objective-C
12 // runtime libraries.
13 //
14 //===----------------------------------------------------------------------===//
15
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 <string>
21
22 #include "CGBuilder.h"
23 #include "CGCall.h"
24 #include "CGValue.h"
25
26 namespace llvm {
27   class Constant;
28   class Type;
29   class Value;
30   class Module;
31   class Function;
32 }
33
34 namespace clang {
35 namespace CodeGen {
36   class CodeGenFunction;
37 }
38
39   class ObjCAtTryStmt;
40   class ObjCAtThrowStmt;
41   class ObjCAtSynchronizedStmt;
42   class ObjCContainerDecl;
43   class ObjCCategoryImplDecl;
44   class ObjCImplementationDecl;
45   class ObjCInterfaceDecl;
46   class ObjCMessageExpr;
47   class ObjCMethodDecl;
48   class ObjCProtocolDecl;
49   class Selector;
50   class ObjCIvarDecl;
51   class ObjCStringLiteral;
52
53 namespace CodeGen {
54   class CodeGenModule;
55
56 //FIXME Several methods should be pure virtual but aren't to avoid the
57 //partially-implemented subclass breaking.
58
59 /// Implements runtime-specific code generation functions.
60 class CGObjCRuntime {
61
62 public:
63   virtual ~CGObjCRuntime();
64
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;
68
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,
73                                    Selector Sel) = 0;
74
75   /// Generate a constant string object.
76   virtual llvm::Constant *GenerateConstantString(const ObjCStringLiteral *) = 0;
77
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;
81
82   /// Generate a class stucture for this class.
83   virtual void GenerateClass(const ObjCImplementationDecl *OID) = 0;
84   
85   /// Generate an Objective-C message send operation.
86   virtual CodeGen::RValue 
87   GenerateMessageSend(CodeGen::CodeGenFunction &CGF,
88                       QualType ResultType,
89                       Selector Sel,
90                       llvm::Value *Receiver,
91                       bool IsClassMessage,
92                       const CallArgList &CallArgs) = 0;
93
94   /// Generate an Objective-C message send operation to the super
95   /// class initiated in a method for Class and with the given Self
96   /// object.
97   virtual CodeGen::RValue
98   GenerateMessageSendSuper(CodeGen::CodeGenFunction &CGF,
99                            QualType ResultType,
100                            Selector Sel,
101                            const ObjCInterfaceDecl *Class,
102                            bool isCategoryImpl,
103                            llvm::Value *Self,
104                            bool IsClassMessage,
105                            const CallArgList &CallArgs) = 0;
106
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;
111
112   /// Generate the named protocol.  Protocols contain method metadata but no 
113   /// implementations. 
114   virtual void GenerateProtocol(const ObjCProtocolDecl *OPD) = 0;
115
116   /// Generate a function preamble for a method with the specified
117   /// types.  
118
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;
125
126   /// Return the runtime function for getting properties.
127   virtual llvm::Constant *GetPropertyGetFunction() = 0;
128   
129   /// Return the runtime function for setting properties.
130   virtual llvm::Constant *GetPropertySetFunction() = 0;
131
132   /// GetClass - Return a reference to the class for the given
133   /// interface decl.
134   virtual llvm::Value *GetClass(CGBuilderTy &Builder, 
135                                 const ObjCInterfaceDecl *OID) = 0;
136
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;
140   
141   virtual void EmitTryOrSynchronizedStmt(CodeGen::CodeGenFunction &CGF,
142                                          const Stmt &S) = 0;
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;
155   
156   virtual LValue EmitObjCValueForIvar(CodeGen::CodeGenFunction &CGF,
157                                       QualType ObjectTy,
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;
164 };
165
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);
171 }
172 }
173 #endif