2008-08-11 10:45:11 +08:00
|
|
|
//===----- CGObjCRuntime.h - Interface to ObjC Runtimes ---------*- C++ -*-===//
|
2008-03-01 16:50:34 +08:00
|
|
|
//
|
|
|
|
// 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-08-11 12:54:23 +08:00
|
|
|
#include "clang/Basic/IdentifierTable.h" // Selector
|
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
|
|
|
|
2008-11-01 09:53:16 +08:00
|
|
|
#include "CGBuilder.h"
|
2008-09-09 09:06:48 +08:00
|
|
|
#include "CGCall.h"
|
2008-11-01 09:53:16 +08:00
|
|
|
#include "CGValue.h"
|
2008-08-23 11:46:30 +08:00
|
|
|
|
2008-03-01 16:50:34 +08:00
|
|
|
namespace llvm {
|
|
|
|
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-09-09 09:06:48 +08:00
|
|
|
namespace CodeGen {
|
|
|
|
class CodeGenFunction;
|
|
|
|
}
|
2008-08-23 11:46:30 +08:00
|
|
|
|
2008-09-09 18:04:29 +08:00
|
|
|
class ObjCAtTryStmt;
|
|
|
|
class ObjCAtThrowStmt;
|
2008-11-16 05:26:17 +08:00
|
|
|
class ObjCAtSynchronizedStmt;
|
2009-01-11 05:06:09 +08:00
|
|
|
class ObjCContainerDecl;
|
2008-08-16 06:20:32 +08:00
|
|
|
class ObjCCategoryImplDecl;
|
|
|
|
class ObjCImplementationDecl;
|
2008-08-16 08:25:02 +08:00
|
|
|
class ObjCInterfaceDecl;
|
2008-08-23 11:46:30 +08:00
|
|
|
class ObjCMessageExpr;
|
2008-08-16 06:20:32 +08:00
|
|
|
class ObjCMethodDecl;
|
2008-08-13 08:59:25 +08:00
|
|
|
class ObjCProtocolDecl;
|
2008-06-26 12:37:12 +08:00
|
|
|
class Selector;
|
2009-02-03 04:02:29 +08:00
|
|
|
class ObjCIvarDecl;
|
2009-04-01 00:53:37 +08:00
|
|
|
class ObjCStringLiteral;
|
2008-08-13 08:59:25 +08:00
|
|
|
|
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 {
|
2008-08-12 00:50:21 +08:00
|
|
|
|
2008-03-01 16:50:34 +08:00
|
|
|
public:
|
|
|
|
virtual ~CGObjCRuntime();
|
2008-08-13 08:59:25 +08:00
|
|
|
|
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-08-16 06:20:32 +08:00
|
|
|
virtual llvm::Function *ModuleInitFunction() = 0;
|
2008-08-13 08:59:25 +08:00
|
|
|
|
2008-08-16 06:20:32 +08:00
|
|
|
/// Get a selector for the specified name and type values. The
|
|
|
|
/// return value should have the LLVM type for pointer-to
|
|
|
|
/// ASTContext::getObjCSelType().
|
2008-11-01 09:53:16 +08:00
|
|
|
virtual llvm::Value *GetSelector(CGBuilderTy &Builder,
|
2008-08-16 06:20:32 +08:00
|
|
|
Selector Sel) = 0;
|
2008-08-13 08:59:25 +08:00
|
|
|
|
2008-08-16 06:20:32 +08:00
|
|
|
/// Generate a constant string object.
|
2009-04-01 00:53:37 +08:00
|
|
|
virtual llvm::Constant *GenerateConstantString(const ObjCStringLiteral *) = 0;
|
2008-08-13 08:59:25 +08:00
|
|
|
|
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.
|
2008-08-16 06:20:32 +08:00
|
|
|
virtual void GenerateCategory(const ObjCCategoryImplDecl *OCD) = 0;
|
2008-08-13 08:59:25 +08:00
|
|
|
|
2008-06-01 22:13:53 +08:00
|
|
|
/// Generate a class stucture for this class.
|
2008-08-16 06:20:32 +08:00
|
|
|
virtual void GenerateClass(const ObjCImplementationDecl *OID) = 0;
|
|
|
|
|
|
|
|
/// Generate an Objective-C message send operation.
|
2008-08-23 11:46:30 +08:00
|
|
|
virtual CodeGen::RValue
|
|
|
|
GenerateMessageSend(CodeGen::CodeGenFunction &CGF,
|
2008-08-30 13:35:15 +08:00
|
|
|
QualType ResultType,
|
|
|
|
Selector Sel,
|
2008-08-25 16:19:24 +08:00
|
|
|
llvm::Value *Receiver,
|
2008-08-30 11:02:31 +08:00
|
|
|
bool IsClassMessage,
|
|
|
|
const CallArgList &CallArgs) = 0;
|
2008-08-13 08:59:25 +08:00
|
|
|
|
2008-08-16 06:20:32 +08:00
|
|
|
/// Generate an Objective-C message send operation to the super
|
2008-08-25 16:19:24 +08:00
|
|
|
/// class initiated in a method for Class and with the given Self
|
|
|
|
/// object.
|
2008-08-23 11:46:30 +08:00
|
|
|
virtual CodeGen::RValue
|
|
|
|
GenerateMessageSendSuper(CodeGen::CodeGenFunction &CGF,
|
2008-08-30 13:35:15 +08:00
|
|
|
QualType ResultType,
|
|
|
|
Selector Sel,
|
2008-08-25 16:19:24 +08:00
|
|
|
const ObjCInterfaceDecl *Class,
|
2009-03-01 04:07:56 +08:00
|
|
|
bool isCategoryImpl,
|
2008-08-25 16:19:24 +08:00
|
|
|
llvm::Value *Self,
|
2008-08-30 11:02:31 +08:00
|
|
|
bool IsClassMessage,
|
|
|
|
const CallArgList &CallArgs) = 0;
|
2008-08-12 13:08:18 +08:00
|
|
|
|
|
|
|
/// Emit the code to return the named protocol as an object, as in a
|
|
|
|
/// @protocol expression.
|
2008-11-01 09:53:16 +08:00
|
|
|
virtual llvm::Value *GenerateProtocolRef(CGBuilderTy &Builder,
|
2008-08-16 06:20:32 +08:00
|
|
|
const ObjCProtocolDecl *OPD) = 0;
|
2008-08-12 13:08:18 +08:00
|
|
|
|
2008-06-01 22:13:53 +08:00
|
|
|
/// Generate the named protocol. Protocols contain method metadata but no
|
|
|
|
/// implementations.
|
2008-08-16 06:20:32 +08:00
|
|
|
virtual void GenerateProtocol(const ObjCProtocolDecl *OPD) = 0;
|
|
|
|
|
|
|
|
/// Generate a function preamble for a method with the specified
|
|
|
|
/// types.
|
|
|
|
|
|
|
|
// FIXME: Current this just generates the Function definition, but
|
|
|
|
// really this should also be generating the loads of the
|
|
|
|
// parameters, as the runtime should have full control over how
|
|
|
|
// parameters are passed.
|
2009-01-11 05:06:09 +08:00
|
|
|
virtual llvm::Function *GenerateMethod(const ObjCMethodDecl *OMD,
|
|
|
|
const ObjCContainerDecl *CD) = 0;
|
2008-08-13 08:59:25 +08:00
|
|
|
|
2008-09-24 11:38:44 +08:00
|
|
|
/// Return the runtime function for getting properties.
|
2009-03-23 05:03:39 +08:00
|
|
|
virtual llvm::Constant *GetPropertyGetFunction() = 0;
|
2008-09-24 11:38:44 +08:00
|
|
|
|
|
|
|
/// Return the runtime function for setting properties.
|
2009-03-23 05:03:39 +08:00
|
|
|
virtual llvm::Constant *GetPropertySetFunction() = 0;
|
2008-09-24 11:38:44 +08:00
|
|
|
|
2008-08-16 08:25:02 +08:00
|
|
|
/// GetClass - Return a reference to the class for the given
|
|
|
|
/// interface decl.
|
2008-11-01 09:53:16 +08:00
|
|
|
virtual llvm::Value *GetClass(CGBuilderTy &Builder,
|
2008-08-16 08:25:02 +08:00
|
|
|
const ObjCInterfaceDecl *OID) = 0;
|
2008-08-13 08:59:25 +08:00
|
|
|
|
2008-08-31 12:05:03 +08:00
|
|
|
/// EnumerationMutationFunction - Return the function that's called by the
|
|
|
|
/// compiler when a mutation is detected during foreach iteration.
|
2009-03-23 05:03:39 +08:00
|
|
|
virtual llvm::Constant *EnumerationMutationFunction() = 0;
|
2009-04-21 08:49:20 +08:00
|
|
|
|
2008-11-21 08:49:24 +08:00
|
|
|
virtual void EmitTryOrSynchronizedStmt(CodeGen::CodeGenFunction &CGF,
|
|
|
|
const Stmt &S) = 0;
|
2008-09-09 18:04:29 +08:00
|
|
|
virtual void EmitThrowStmt(CodeGen::CodeGenFunction &CGF,
|
|
|
|
const ObjCAtThrowStmt &S) = 0;
|
2009-04-21 08:49:20 +08:00
|
|
|
virtual llvm::Value *EmitObjCWeakRead(CodeGen::CodeGenFunction &CGF,
|
|
|
|
llvm::Value *AddrWeakObj) = 0;
|
2008-11-19 06:37:34 +08:00
|
|
|
virtual void EmitObjCWeakAssign(CodeGen::CodeGenFunction &CGF,
|
|
|
|
llvm::Value *src, llvm::Value *dest) = 0;
|
2008-11-19 08:59:10 +08:00
|
|
|
virtual void EmitObjCGlobalAssign(CodeGen::CodeGenFunction &CGF,
|
|
|
|
llvm::Value *src, llvm::Value *dest) = 0;
|
2008-11-21 03:23:36 +08:00
|
|
|
virtual void EmitObjCIvarAssign(CodeGen::CodeGenFunction &CGF,
|
|
|
|
llvm::Value *src, llvm::Value *dest) = 0;
|
2008-11-19 08:59:10 +08:00
|
|
|
virtual void EmitObjCStrongCastAssign(CodeGen::CodeGenFunction &CGF,
|
|
|
|
llvm::Value *src, llvm::Value *dest) = 0;
|
2009-02-03 04:02:29 +08:00
|
|
|
|
2009-02-04 03:03:09 +08:00
|
|
|
virtual LValue EmitObjCValueForIvar(CodeGen::CodeGenFunction &CGF,
|
|
|
|
QualType ObjectTy,
|
|
|
|
llvm::Value *BaseValue,
|
|
|
|
const ObjCIvarDecl *Ivar,
|
|
|
|
unsigned CVRQualifiers) = 0;
|
2009-02-11 03:02:04 +08:00
|
|
|
virtual llvm::Value *EmitIvarOffset(CodeGen::CodeGenFunction &CGF,
|
|
|
|
ObjCInterfaceDecl *Interface,
|
|
|
|
const ObjCIvarDecl *Ivar) = 0;
|
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-08-11 10:45:11 +08:00
|
|
|
CGObjCRuntime *CreateGNUObjCRuntime(CodeGenModule &CGM);
|
|
|
|
CGObjCRuntime *CreateMacObjCRuntime(CodeGenModule &CGM);
|
2009-01-23 07:02:58 +08:00
|
|
|
CGObjCRuntime *CreateMacNonFragileABIObjCRuntime(CodeGenModule &CGM);
|
2008-03-01 16:50:34 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|