blob: 368e5ae105984da35da4f1f871a770bcdcfc165c [file] [log] [blame]
Daniel Dunbar8c85fac2008-08-11 02:45:11 +00001//===----- CGObjCRuntime.h - Interface to ObjC Runtimes ---------*- C++ -*-===//
Chris Lattnera0fd5ee2008-03-01 08:50:34 +00002//
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
Daniel Dunbarde300732008-08-11 04:54:23 +000018#include "clang/Basic/IdentifierTable.h" // Selector
Anton Korobeynikovcd5d08d2008-06-01 14:13:53 +000019#include "llvm/ADT/SmallVector.h"
Daniel Dunbarfd2ff6c2008-08-11 16:50:21 +000020#include "llvm/Support/IRBuilder.h"
Argiris Kirtzidis0560bcf2008-06-01 21:23:24 +000021#include <string>
Chris Lattnera0fd5ee2008-03-01 08:50:34 +000022
23namespace llvm {
Chris Lattnera0fd5ee2008-03-01 08:50:34 +000024 class Constant;
25 class Type;
26 class Value;
27 class Module;
Chris Lattnerb326b172008-03-30 23:03:07 +000028 class Function;
Chris Lattnera0fd5ee2008-03-01 08:50:34 +000029}
30
31namespace clang {
Daniel Dunbarac93e472008-08-15 22:20:32 +000032 class ObjCCategoryImplDecl;
33 class ObjCImplementationDecl;
Daniel Dunbar434627a2008-08-16 00:25:02 +000034 class ObjCInterfaceDecl;
Daniel Dunbarac93e472008-08-15 22:20:32 +000035 class ObjCMethodDecl;
Daniel Dunbar84bb85f2008-08-13 00:59:25 +000036 class ObjCProtocolDecl;
Chris Lattnerd71288e2008-06-26 04:37:12 +000037 class Selector;
Daniel Dunbar84bb85f2008-08-13 00:59:25 +000038
Chris Lattnera0fd5ee2008-03-01 08:50:34 +000039namespace CodeGen {
Chris Lattner547907c2008-06-26 04:19:03 +000040 class CodeGenModule;
Chris Lattnera0fd5ee2008-03-01 08:50:34 +000041
Anton Korobeynikovcd5d08d2008-06-01 14:13:53 +000042//FIXME Several methods should be pure virtual but aren't to avoid the
43//partially-implemented subclass breaking.
44
45/// Implements runtime-specific code generation functions.
Chris Lattnera0fd5ee2008-03-01 08:50:34 +000046class CGObjCRuntime {
Daniel Dunbarfd2ff6c2008-08-11 16:50:21 +000047 typedef llvm::IRBuilder<> BuilderType;
48
Chris Lattnera0fd5ee2008-03-01 08:50:34 +000049public:
50 virtual ~CGObjCRuntime();
Daniel Dunbarac93e472008-08-15 22:20:32 +000051
52 /// Generate the function required to register all Objective-C components in
53 /// this compilation unit with the runtime library.
54 virtual llvm::Function *ModuleInitFunction() = 0;
55
56 /// Get a selector for the specified name and type values. The
57 /// return value should have the LLVM type for pointer-to
58 /// ASTContext::getObjCSelType().
59 virtual llvm::Value *GetSelector(BuilderType &Builder,
60 Selector Sel) = 0;
61
62 /// Generate a constant string object.
63 virtual llvm::Constant *GenerateConstantString(const std::string &String) = 0;
64
65 /// Generate a category. A category contains a list of methods (and
66 /// accompanying metadata) and a list of protocols.
67 virtual void GenerateCategory(const ObjCCategoryImplDecl *OCD) = 0;
68
69 /// Generate a class stucture for this class.
70 virtual void GenerateClass(const ObjCImplementationDecl *OID) = 0;
Chris Lattnera0fd5ee2008-03-01 08:50:34 +000071
Daniel Dunbarac93e472008-08-15 22:20:32 +000072 /// Generate an Objective-C message send operation.
Daniel Dunbarfd2ff6c2008-08-11 16:50:21 +000073 virtual llvm::Value *GenerateMessageSend(BuilderType &Builder,
Chris Lattnera0fd5ee2008-03-01 08:50:34 +000074 const llvm::Type *ReturnTy,
75 llvm::Value *Receiver,
Chris Lattner8384c142008-06-26 04:42:20 +000076 Selector Sel,
Chris Lattnera0fd5ee2008-03-01 08:50:34 +000077 llvm::Value** ArgV,
Daniel Dunbarac93e472008-08-15 22:20:32 +000078 unsigned ArgC) = 0;
Daniel Dunbar84bb85f2008-08-13 00:59:25 +000079
Daniel Dunbarac93e472008-08-15 22:20:32 +000080 /// Generate an Objective-C message send operation to the super
81 /// class.
Daniel Dunbar434627a2008-08-16 00:25:02 +000082 virtual llvm::Value *
83 GenerateMessageSendSuper(llvm::IRBuilder<true> &Builder,
84 const llvm::Type *ReturnTy,
85 const ObjCInterfaceDecl *SuperClassName,
86 llvm::Value *Receiver,
87 Selector Sel,
88 llvm::Value** ArgV,
89 unsigned ArgC) = 0;
Daniel Dunbarfa456242008-08-12 05:08:18 +000090
91 /// Emit the code to return the named protocol as an object, as in a
92 /// @protocol expression.
93 virtual llvm::Value *GenerateProtocolRef(llvm::IRBuilder<true> &Builder,
Daniel Dunbarac93e472008-08-15 22:20:32 +000094 const ObjCProtocolDecl *OPD) = 0;
Daniel Dunbarfa456242008-08-12 05:08:18 +000095
Anton Korobeynikovcd5d08d2008-06-01 14:13:53 +000096 /// Generate the named protocol. Protocols contain method metadata but no
97 /// implementations.
Daniel Dunbarac93e472008-08-15 22:20:32 +000098 virtual void GenerateProtocol(const ObjCProtocolDecl *OPD) = 0;
Daniel Dunbar84bb85f2008-08-13 00:59:25 +000099
Daniel Dunbarac93e472008-08-15 22:20:32 +0000100 /// Generate a function preamble for a method with the specified
101 /// types.
102
103 // FIXME: Current this just generates the Function definition, but
104 // really this should also be generating the loads of the
105 // parameters, as the runtime should have full control over how
106 // parameters are passed.
107 virtual llvm::Function *GenerateMethod(const ObjCMethodDecl *OMD) = 0;
Daniel Dunbar84bb85f2008-08-13 00:59:25 +0000108
Daniel Dunbar434627a2008-08-16 00:25:02 +0000109 /// GetClass - Return a reference to the class for the given
110 /// interface decl.
111 virtual llvm::Value *GetClass(BuilderType &Builder,
112 const ObjCInterfaceDecl *OID) = 0;
Daniel Dunbar84bb85f2008-08-13 00:59:25 +0000113
Chris Lattnerb326b172008-03-30 23:03:07 +0000114 /// If instance variable addresses are determined at runtime then this should
115 /// return true, otherwise instance variables will be accessed directly from
116 /// the structure. If this returns true then @defs is invalid for this
117 /// runtime and a warning should be generated.
118 virtual bool LateBoundIVars() { return false; }
Chris Lattnera0fd5ee2008-03-01 08:50:34 +0000119};
120
Chris Lattnerb326b172008-03-30 23:03:07 +0000121/// Creates an instance of an Objective-C runtime class.
122//TODO: This should include some way of selecting which runtime to target.
Daniel Dunbar8c85fac2008-08-11 02:45:11 +0000123CGObjCRuntime *CreateGNUObjCRuntime(CodeGenModule &CGM);
124CGObjCRuntime *CreateMacObjCRuntime(CodeGenModule &CGM);
Chris Lattnera0fd5ee2008-03-01 08:50:34 +0000125}
126}
127#endif