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"
37 //FIXME Several methods should be pure virtual but aren't to avoid the
38 //partially-implemented subclass breaking.
40 /// Implements runtime-specific code generation functions.
42 typedef llvm::IRBuilder<> BuilderType;
45 virtual ~CGObjCRuntime();
47 /// Generate an Objective-C message send operation
48 virtual llvm::Value *GenerateMessageSend(BuilderType &Builder,
49 const llvm::Type *ReturnTy,
51 llvm::Value *Receiver,
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,
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,
91 const char *SuperClassName,
92 llvm::Value *Receiver,
96 /// Generate the named protocol. Protocols contain method metadata but no
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,
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; }
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);