2008-03-01 16:50:34 +08:00
|
|
|
//===----- CGObjCRuntime.h - Emit LLVM Code from ASTs for a Module --------===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This provides an abstract class for Objective-C code generation. Concrete
|
|
|
|
// subclasses of this implement code generation for specific Objective-C
|
|
|
|
// runtime libraries.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef CLANG_CODEGEN_OBCJRUNTIME_H
|
|
|
|
#define CLANG_CODEGEN_OBCJRUNTIME_H
|
2008-06-01 22:13:53 +08:00
|
|
|
#include "llvm/ADT/SmallVector.h"
|
2008-06-02 05:23:24 +08:00
|
|
|
#include <string>
|
2008-03-01 16:50:34 +08:00
|
|
|
|
|
|
|
namespace llvm {
|
2008-04-13 15:32:11 +08:00
|
|
|
class IRBuilder;
|
2008-03-01 16:50:34 +08:00
|
|
|
class Constant;
|
|
|
|
class Type;
|
|
|
|
class Value;
|
|
|
|
class Module;
|
2008-03-31 07:03:07 +08:00
|
|
|
class Function;
|
2008-03-01 16:50:34 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
namespace clang {
|
2008-06-26 12:37:12 +08:00
|
|
|
class Selector;
|
|
|
|
|
2008-03-01 16:50:34 +08:00
|
|
|
namespace CodeGen {
|
2008-06-26 12:19:03 +08:00
|
|
|
class CodeGenModule;
|
2008-03-01 16:50:34 +08:00
|
|
|
|
2008-06-01 22:13:53 +08:00
|
|
|
//FIXME Several methods should be pure virtual but aren't to avoid the
|
|
|
|
//partially-implemented subclass breaking.
|
|
|
|
|
|
|
|
/// Implements runtime-specific code generation functions.
|
2008-03-01 16:50:34 +08:00
|
|
|
class CGObjCRuntime {
|
|
|
|
public:
|
|
|
|
virtual ~CGObjCRuntime();
|
|
|
|
|
2008-03-31 07:03:07 +08:00
|
|
|
/// Generate an Objective-C message send operation
|
2008-06-01 22:13:53 +08:00
|
|
|
virtual llvm::Value *GenerateMessageSend(llvm::IRBuilder &Builder,
|
2008-03-01 16:50:34 +08:00
|
|
|
const llvm::Type *ReturnTy,
|
2008-03-31 07:03:07 +08:00
|
|
|
llvm::Value *Sender,
|
2008-03-01 16:50:34 +08:00
|
|
|
llvm::Value *Receiver,
|
2008-06-26 12:42:20 +08:00
|
|
|
Selector Sel,
|
2008-03-01 16:50:34 +08:00
|
|
|
llvm::Value** ArgV,
|
2008-06-01 22:13:53 +08:00
|
|
|
unsigned ArgC) =0;
|
2008-03-31 07:03:07 +08:00
|
|
|
/// Generate the function required to register all Objective-C components in
|
|
|
|
/// this compilation unit with the runtime library.
|
2008-06-01 22:13:53 +08:00
|
|
|
virtual llvm::Function *ModuleInitFunction() =0;
|
|
|
|
/// Get a selector for the specified name and type values
|
2008-06-26 12:38:58 +08:00
|
|
|
virtual llvm::Value *GetSelector(llvm::IRBuilder &Builder, Selector Sel) = 0;
|
2008-06-01 22:13:53 +08:00
|
|
|
/// Generate a constant string object
|
2008-06-26 12:38:58 +08:00
|
|
|
virtual llvm::Constant *GenerateConstantString(const char *String,
|
|
|
|
const size_t Length) = 0;
|
2008-06-01 22:13:53 +08:00
|
|
|
/// Generate a category. A category contains a list of methods (and
|
|
|
|
/// accompanying metadata) and a list of protocols.
|
|
|
|
virtual void GenerateCategory(const char *ClassName, const char *CategoryName,
|
2008-06-26 13:08:00 +08:00
|
|
|
const llvm::SmallVectorImpl<Selector> &InstanceMethodSels,
|
2008-06-01 22:13:53 +08:00
|
|
|
const llvm::SmallVectorImpl<llvm::Constant *> &InstanceMethodTypes,
|
2008-06-26 13:08:00 +08:00
|
|
|
const llvm::SmallVectorImpl<Selector> &ClassMethodSels,
|
2008-06-01 22:13:53 +08:00
|
|
|
const llvm::SmallVectorImpl<llvm::Constant *> &ClassMethodTypes,
|
|
|
|
const llvm::SmallVectorImpl<std::string> &Protocols) =0;
|
|
|
|
/// Generate a class stucture for this class.
|
|
|
|
virtual void GenerateClass(
|
|
|
|
const char *ClassName,
|
|
|
|
const char *SuperClassName,
|
|
|
|
const int instanceSize,
|
|
|
|
const llvm::SmallVectorImpl<llvm::Constant *> &IvarNames,
|
|
|
|
const llvm::SmallVectorImpl<llvm::Constant *> &IvarTypes,
|
|
|
|
const llvm::SmallVectorImpl<llvm::Constant *> &IvarOffsets,
|
2008-06-26 13:08:00 +08:00
|
|
|
const llvm::SmallVectorImpl<Selector> &InstanceMethodSels,
|
2008-06-01 22:13:53 +08:00
|
|
|
const llvm::SmallVectorImpl<llvm::Constant *> &InstanceMethodTypes,
|
2008-06-26 13:08:00 +08:00
|
|
|
const llvm::SmallVectorImpl<Selector> &ClassMethodSels,
|
2008-06-01 22:13:53 +08:00
|
|
|
const llvm::SmallVectorImpl<llvm::Constant *> &ClassMethodTypes,
|
|
|
|
const llvm::SmallVectorImpl<std::string> &Protocols) =0;
|
|
|
|
/// Generate a reference to the named protocol.
|
|
|
|
virtual llvm::Value *GenerateProtocolRef(llvm::IRBuilder &Builder, const char
|
|
|
|
*ProtocolName) =0;
|
|
|
|
virtual llvm::Value *GenerateMessageSendSuper(llvm::IRBuilder &Builder,
|
2008-06-26 12:37:12 +08:00
|
|
|
const llvm::Type *ReturnTy,
|
|
|
|
llvm::Value *Sender,
|
|
|
|
const char *SuperClassName,
|
|
|
|
llvm::Value *Receiver,
|
|
|
|
Selector Sel,
|
|
|
|
llvm::Value** ArgV,
|
|
|
|
unsigned ArgC) = 0;
|
2008-06-01 22:13:53 +08:00
|
|
|
/// Generate the named protocol. Protocols contain method metadata but no
|
|
|
|
/// implementations.
|
|
|
|
virtual void GenerateProtocol(const char *ProtocolName,
|
|
|
|
const llvm::SmallVectorImpl<std::string> &Protocols,
|
|
|
|
const llvm::SmallVectorImpl<llvm::Constant *> &InstanceMethodNames,
|
|
|
|
const llvm::SmallVectorImpl<llvm::Constant *> &InstanceMethodTypes,
|
|
|
|
const llvm::SmallVectorImpl<llvm::Constant *> &ClassMethodNames,
|
|
|
|
const llvm::SmallVectorImpl<llvm::Constant *> &ClassMethodTypes) =0;
|
2008-03-31 07:03:07 +08:00
|
|
|
/// Generate a function preamble for a method with the specified types
|
2008-06-01 22:13:53 +08:00
|
|
|
virtual llvm::Function *MethodPreamble(
|
|
|
|
const std::string &ClassName,
|
|
|
|
const std::string &CategoryName,
|
|
|
|
const std::string &MethodName,
|
|
|
|
const llvm::Type *ReturnTy,
|
2008-03-31 07:03:07 +08:00
|
|
|
const llvm::Type *SelfTy,
|
|
|
|
const llvm::Type **ArgTy,
|
|
|
|
unsigned ArgC,
|
2008-06-01 22:13:53 +08:00
|
|
|
bool isClassMethod,
|
2008-03-31 07:03:07 +08:00
|
|
|
bool isVarArg) = 0;
|
2008-06-01 22:13:53 +08:00
|
|
|
/// Look up the class for the specified name
|
|
|
|
virtual llvm::Value *LookupClass(llvm::IRBuilder &Builder, llvm::Value
|
|
|
|
*ClassName) =0;
|
2008-03-31 07:03:07 +08:00
|
|
|
/// If instance variable addresses are determined at runtime then this should
|
|
|
|
/// return true, otherwise instance variables will be accessed directly from
|
|
|
|
/// the structure. If this returns true then @defs is invalid for this
|
|
|
|
/// runtime and a warning should be generated.
|
|
|
|
virtual bool LateBoundIVars() { return false; }
|
2008-03-01 16:50:34 +08:00
|
|
|
};
|
|
|
|
|
2008-03-31 07:03:07 +08:00
|
|
|
/// Creates an instance of an Objective-C runtime class.
|
|
|
|
//TODO: This should include some way of selecting which runtime to target.
|
2008-06-26 12:19:03 +08:00
|
|
|
CGObjCRuntime *CreateObjCRuntime(CodeGenModule &CGM);
|
2008-03-01 16:50:34 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|