]> granicus.if.org Git - clang/blob - lib/CodeGen/CGObjCRuntime.h
Update for IRBuilder template change (update LLVM!)
[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 "llvm/Support/IRBuilder.h"
21 #include <string>
22
23 namespace llvm {
24   class Constant;
25   class Type;
26   class Value;
27   class Module;
28   class Function;
29 }
30
31 namespace clang {
32   class Selector;
33   
34 namespace CodeGen {
35   class CodeGenModule;
36
37 //FIXME Several methods should be pure virtual but aren't to avoid the
38 //partially-implemented subclass breaking.
39
40 /// Implements runtime-specific code generation functions.
41 class CGObjCRuntime {
42   typedef llvm::IRBuilder<> BuilderType;
43
44 public:
45   virtual ~CGObjCRuntime();
46   
47   /// Generate an Objective-C message send operation
48   virtual llvm::Value *GenerateMessageSend(BuilderType &Builder,
49                                            const llvm::Type *ReturnTy,
50                                            llvm::Value *Sender,
51                                            llvm::Value *Receiver,
52                                            Selector Sel,
53                                            llvm::Value** ArgV,
54                                            unsigned ArgC) =0;
55   /// Generate the function required to register all Objective-C components in
56   /// this compilation unit with the runtime library.
57   virtual llvm::Function *ModuleInitFunction() =0;
58   /// Get a selector for the specified name and type values
59   virtual llvm::Value *GetSelector(BuilderType &Builder,
60                                    Selector Sel) =0;
61   /// Generate a constant string object
62   virtual llvm::Constant *GenerateConstantString(const char *String,
63                                                  const size_t Length) = 0;
64   /// Generate a category.  A category contains a list of methods (and
65   /// accompanying metadata) and a list of protocols.
66   virtual void GenerateCategory(const char *ClassName, const char *CategoryName,
67              const llvm::SmallVectorImpl<Selector>  &InstanceMethodSels,
68              const llvm::SmallVectorImpl<llvm::Constant *>  &InstanceMethodTypes,
69              const llvm::SmallVectorImpl<Selector>  &ClassMethodSels,
70              const llvm::SmallVectorImpl<llvm::Constant *>  &ClassMethodTypes,
71              const llvm::SmallVectorImpl<std::string> &Protocols) =0;
72   /// Generate a class stucture for this class.
73   virtual void GenerateClass(
74              const char *ClassName,
75              const char *SuperClassName,
76              const int instanceSize,
77              const llvm::SmallVectorImpl<llvm::Constant *>  &IvarNames,
78              const llvm::SmallVectorImpl<llvm::Constant *>  &IvarTypes,
79              const llvm::SmallVectorImpl<llvm::Constant *>  &IvarOffsets,
80              const llvm::SmallVectorImpl<Selector>  &InstanceMethodSels,
81              const llvm::SmallVectorImpl<llvm::Constant *>  &InstanceMethodTypes,
82              const llvm::SmallVectorImpl<Selector>  &ClassMethodSels,
83              const llvm::SmallVectorImpl<llvm::Constant *>  &ClassMethodTypes,
84              const llvm::SmallVectorImpl<std::string> &Protocols) =0;
85   /// Generate a reference to the named protocol.
86   virtual llvm::Value *GenerateProtocolRef(llvm::IRBuilder<true> &Builder,
87                                            const char *ProtocolName) = 0;
88   virtual llvm::Value *GenerateMessageSendSuper(llvm::IRBuilder<true> &Builder,
89                                                 const llvm::Type *ReturnTy,
90                                                 llvm::Value *Sender,
91                                                 const char *SuperClassName,
92                                                 llvm::Value *Receiver,
93                                                 Selector Sel,
94                                                 llvm::Value** ArgV,
95                                                 unsigned ArgC) = 0;
96   /// Generate the named protocol.  Protocols contain method metadata but no 
97   /// implementations. 
98   virtual void GenerateProtocol(const char *ProtocolName,
99     const llvm::SmallVectorImpl<std::string> &Protocols,
100     const llvm::SmallVectorImpl<llvm::Constant *>  &InstanceMethodNames,
101     const llvm::SmallVectorImpl<llvm::Constant *>  &InstanceMethodTypes,
102     const llvm::SmallVectorImpl<llvm::Constant *>  &ClassMethodNames,
103     const llvm::SmallVectorImpl<llvm::Constant *>  &ClassMethodTypes) =0;
104   /// Generate a function preamble for a method with the specified types
105   virtual llvm::Function *MethodPreamble(
106                                          const std::string &ClassName,
107                                          const std::string &CategoryName,
108                                          const std::string &MethodName,
109                                          const llvm::Type *ReturnTy,
110                                          const llvm::Type *SelfTy,
111                                          const llvm::Type **ArgTy,
112                                          unsigned ArgC,
113                                          bool isClassMethod,
114                                          bool isVarArg) = 0;
115   /// Look up the class for the specified name
116   virtual llvm::Value *LookupClass(BuilderType &Builder, 
117                                    llvm::Value *ClassName) =0;
118   /// If instance variable addresses are determined at runtime then this should
119   /// return true, otherwise instance variables will be accessed directly from
120   /// the structure.  If this returns true then @defs is invalid for this
121   /// runtime and a warning should be generated.
122   virtual bool LateBoundIVars() { return false; }
123 };
124
125 /// Creates an instance of an Objective-C runtime class.  
126 //TODO: This should include some way of selecting which runtime to target.
127 CGObjCRuntime *CreateGNUObjCRuntime(CodeGenModule &CGM);
128 CGObjCRuntime *CreateMacObjCRuntime(CodeGenModule &CGM);
129 }
130 }
131 #endif