]> granicus.if.org Git - clang/blob - lib/CodeGen/CGObjCRuntime.h
Start implementing support for @synchonized with the darwin ObjC API.
[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 ObjCCategoryImplDecl;
43   class ObjCImplementationDecl;
44   class ObjCInterfaceDecl;
45   class ObjCMessageExpr;
46   class ObjCMethodDecl;
47   class ObjCProtocolDecl;
48   class Selector;
49
50 namespace CodeGen {
51   class CodeGenModule;
52
53 //FIXME Several methods should be pure virtual but aren't to avoid the
54 //partially-implemented subclass breaking.
55
56 /// Implements runtime-specific code generation functions.
57 class CGObjCRuntime {
58
59 public:
60   virtual ~CGObjCRuntime();
61
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;
65
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,
70                                    Selector Sel) = 0;
71
72   /// Generate a constant string object.
73   virtual llvm::Constant *GenerateConstantString(const std::string &String) = 0;
74
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;
78
79   /// Generate a class stucture for this class.
80   virtual void GenerateClass(const ObjCImplementationDecl *OID) = 0;
81   
82   /// Generate an Objective-C message send operation.
83   virtual CodeGen::RValue 
84   GenerateMessageSend(CodeGen::CodeGenFunction &CGF,
85                       QualType ResultType,
86                       Selector Sel,
87                       llvm::Value *Receiver,
88                       bool IsClassMessage,
89                       const CallArgList &CallArgs) = 0;
90
91   /// Generate an Objective-C message send operation to the super
92   /// class initiated in a method for Class and with the given Self
93   /// object.
94   virtual CodeGen::RValue
95   GenerateMessageSendSuper(CodeGen::CodeGenFunction &CGF,
96                            QualType ResultType,
97                            Selector Sel,
98                            const ObjCInterfaceDecl *Class,
99                            llvm::Value *Self,
100                            bool IsClassMessage,
101                            const CallArgList &CallArgs) = 0;
102
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;
107
108   /// Generate the named protocol.  Protocols contain method metadata but no 
109   /// implementations. 
110   virtual void GenerateProtocol(const ObjCProtocolDecl *OPD) = 0;
111
112   /// Generate a function preamble for a method with the specified
113   /// types.  
114
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;
120
121   /// Return the runtime function for getting properties.
122   virtual llvm::Function *GetPropertyGetFunction() = 0;
123   
124   /// Return the runtime function for setting properties.
125   virtual llvm::Function *GetPropertySetFunction() = 0;
126
127   /// GetClass - Return a reference to the class for the given
128   /// interface decl.
129   virtual llvm::Value *GetClass(CGBuilderTy &Builder, 
130                                 const ObjCInterfaceDecl *OID) = 0;
131
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;
135     
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; }
141
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 };
149
150 /// Creates an instance of an Objective-C runtime class.  
151 //TODO: This should include some way of selecting which runtime to target.
152 CGObjCRuntime *CreateGNUObjCRuntime(CodeGenModule &CGM);
153 CGObjCRuntime *CreateMacObjCRuntime(CodeGenModule &CGM);
154 }
155 }
156 #endif