blob: a5d88c38f92fee2cda2a2357f345ebc0e46f11a4 [file] [log] [blame]
Chris Lattner0f984262008-03-01 08:50:34 +00001//===----- CGObjCRuntime.h - Emit LLVM Code from ASTs for a Module --------===//
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
Anton Korobeynikov20ff3102008-06-01 14:13:53 +000018#include "llvm/ADT/SmallVector.h"
Argyrios Kyrtzidis8ef07c02008-06-01 21:23:24 +000019#include <string>
Chris Lattner0f984262008-03-01 08:50:34 +000020
21namespace llvm {
Chris Lattner50b36742008-04-13 07:32:11 +000022 class IRBuilder;
Chris Lattner0f984262008-03-01 08:50:34 +000023 class Constant;
24 class Type;
25 class Value;
26 class Module;
Chris Lattner391d77a2008-03-30 23:03:07 +000027 class Function;
Chris Lattner0f984262008-03-01 08:50:34 +000028}
29
30namespace clang {
Chris Lattner8e67b632008-06-26 04:37:12 +000031 class Selector;
32
Chris Lattner0f984262008-03-01 08:50:34 +000033namespace CodeGen {
Chris Lattnerdce14062008-06-26 04:19:03 +000034 class CodeGenModule;
Chris Lattner0f984262008-03-01 08:50:34 +000035
Anton Korobeynikov20ff3102008-06-01 14:13:53 +000036//FIXME Several methods should be pure virtual but aren't to avoid the
37//partially-implemented subclass breaking.
38
39/// Implements runtime-specific code generation functions.
Chris Lattner0f984262008-03-01 08:50:34 +000040class CGObjCRuntime {
41public:
42 virtual ~CGObjCRuntime();
43
Chris Lattner391d77a2008-03-30 23:03:07 +000044 /// Generate an Objective-C message send operation
Anton Korobeynikov20ff3102008-06-01 14:13:53 +000045 virtual llvm::Value *GenerateMessageSend(llvm::IRBuilder &Builder,
Chris Lattner0f984262008-03-01 08:50:34 +000046 const llvm::Type *ReturnTy,
Chris Lattner391d77a2008-03-30 23:03:07 +000047 llvm::Value *Sender,
Chris Lattner0f984262008-03-01 08:50:34 +000048 llvm::Value *Receiver,
Chris Lattner9384c762008-06-26 04:42:20 +000049 Selector Sel,
Chris Lattner0f984262008-03-01 08:50:34 +000050 llvm::Value** ArgV,
Anton Korobeynikov20ff3102008-06-01 14:13:53 +000051 unsigned ArgC) =0;
Chris Lattner391d77a2008-03-30 23:03:07 +000052 /// Generate the function required to register all Objective-C components in
53 /// this compilation unit with the runtime library.
Anton Korobeynikov20ff3102008-06-01 14:13:53 +000054 virtual llvm::Function *ModuleInitFunction() =0;
55 /// Get a selector for the specified name and type values
Chris Lattner42ba3e72008-06-26 04:38:58 +000056 virtual llvm::Value *GetSelector(llvm::IRBuilder &Builder, Selector Sel) = 0;
Anton Korobeynikov20ff3102008-06-01 14:13:53 +000057 /// Generate a constant string object
Chris Lattner42ba3e72008-06-26 04:38:58 +000058 virtual llvm::Constant *GenerateConstantString(const char *String,
59 const size_t Length) = 0;
Anton Korobeynikov20ff3102008-06-01 14:13:53 +000060 /// Generate a category. A category contains a list of methods (and
61 /// accompanying metadata) and a list of protocols.
62 virtual void GenerateCategory(const char *ClassName, const char *CategoryName,
Chris Lattnera4210072008-06-26 05:08:00 +000063 const llvm::SmallVectorImpl<Selector> &InstanceMethodSels,
Anton Korobeynikov20ff3102008-06-01 14:13:53 +000064 const llvm::SmallVectorImpl<llvm::Constant *> &InstanceMethodTypes,
Chris Lattnera4210072008-06-26 05:08:00 +000065 const llvm::SmallVectorImpl<Selector> &ClassMethodSels,
Anton Korobeynikov20ff3102008-06-01 14:13:53 +000066 const llvm::SmallVectorImpl<llvm::Constant *> &ClassMethodTypes,
67 const llvm::SmallVectorImpl<std::string> &Protocols) =0;
68 /// Generate a class stucture for this class.
69 virtual void GenerateClass(
70 const char *ClassName,
71 const char *SuperClassName,
72 const int instanceSize,
73 const llvm::SmallVectorImpl<llvm::Constant *> &IvarNames,
74 const llvm::SmallVectorImpl<llvm::Constant *> &IvarTypes,
75 const llvm::SmallVectorImpl<llvm::Constant *> &IvarOffsets,
Chris Lattnera4210072008-06-26 05:08:00 +000076 const llvm::SmallVectorImpl<Selector> &InstanceMethodSels,
Anton Korobeynikov20ff3102008-06-01 14:13:53 +000077 const llvm::SmallVectorImpl<llvm::Constant *> &InstanceMethodTypes,
Chris Lattnera4210072008-06-26 05:08:00 +000078 const llvm::SmallVectorImpl<Selector> &ClassMethodSels,
Anton Korobeynikov20ff3102008-06-01 14:13:53 +000079 const llvm::SmallVectorImpl<llvm::Constant *> &ClassMethodTypes,
80 const llvm::SmallVectorImpl<std::string> &Protocols) =0;
81 /// Generate a reference to the named protocol.
82 virtual llvm::Value *GenerateProtocolRef(llvm::IRBuilder &Builder, const char
83 *ProtocolName) =0;
84 virtual llvm::Value *GenerateMessageSendSuper(llvm::IRBuilder &Builder,
Chris Lattner8e67b632008-06-26 04:37:12 +000085 const llvm::Type *ReturnTy,
86 llvm::Value *Sender,
87 const char *SuperClassName,
88 llvm::Value *Receiver,
89 Selector Sel,
90 llvm::Value** ArgV,
91 unsigned ArgC) = 0;
Anton Korobeynikov20ff3102008-06-01 14:13:53 +000092 /// Generate the named protocol. Protocols contain method metadata but no
93 /// implementations.
94 virtual void GenerateProtocol(const char *ProtocolName,
95 const llvm::SmallVectorImpl<std::string> &Protocols,
96 const llvm::SmallVectorImpl<llvm::Constant *> &InstanceMethodNames,
97 const llvm::SmallVectorImpl<llvm::Constant *> &InstanceMethodTypes,
98 const llvm::SmallVectorImpl<llvm::Constant *> &ClassMethodNames,
99 const llvm::SmallVectorImpl<llvm::Constant *> &ClassMethodTypes) =0;
Chris Lattner391d77a2008-03-30 23:03:07 +0000100 /// Generate a function preamble for a method with the specified types
Anton Korobeynikov20ff3102008-06-01 14:13:53 +0000101 virtual llvm::Function *MethodPreamble(
102 const std::string &ClassName,
103 const std::string &CategoryName,
104 const std::string &MethodName,
105 const llvm::Type *ReturnTy,
Chris Lattner391d77a2008-03-30 23:03:07 +0000106 const llvm::Type *SelfTy,
107 const llvm::Type **ArgTy,
108 unsigned ArgC,
Anton Korobeynikov20ff3102008-06-01 14:13:53 +0000109 bool isClassMethod,
Chris Lattner391d77a2008-03-30 23:03:07 +0000110 bool isVarArg) = 0;
Anton Korobeynikov20ff3102008-06-01 14:13:53 +0000111 /// Look up the class for the specified name
112 virtual llvm::Value *LookupClass(llvm::IRBuilder &Builder, llvm::Value
113 *ClassName) =0;
Chris Lattner391d77a2008-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 Lattner0f984262008-03-01 08:50:34 +0000119};
120
Chris Lattner391d77a2008-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.
Chris Lattnerdce14062008-06-26 04:19:03 +0000123CGObjCRuntime *CreateObjCRuntime(CodeGenModule &CGM);
Chris Lattner0f984262008-03-01 08:50:34 +0000124}
125}
126#endif