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"
|
2009-05-06 05:36:57 +08:00
|
|
|
#include "clang/AST/DeclObjC.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;
|
2009-04-22 15:32:20 +08:00
|
|
|
class Function;
|
|
|
|
class Module;
|
|
|
|
class StructLayout;
|
2009-04-22 17:39:34 +08:00
|
|
|
class StructType;
|
2008-03-01 16:50:34 +08:00
|
|
|
class Type;
|
|
|
|
class Value;
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace clang {
|
2008-09-09 09:06:48 +08:00
|
|
|
namespace CodeGen {
|
|
|
|
class CodeGenFunction;
|
|
|
|
}
|
2008-08-23 11:46:30 +08:00
|
|
|
|
2009-04-22 15:32:20 +08:00
|
|
|
class FieldDecl;
|
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
|
|
|
|
2009-05-16 15:57:57 +08:00
|
|
|
// FIXME: Several methods should be pure virtual but aren't to avoid the
|
|
|
|
// partially-implemented subclass breaking.
|
2008-06-01 22:13:53 +08:00
|
|
|
|
|
|
|
/// Implements runtime-specific code generation functions.
|
2008-03-01 16:50:34 +08:00
|
|
|
class CGObjCRuntime {
|
2009-05-03 16:55:17 +08:00
|
|
|
public:
|
2009-04-22 15:32:20 +08:00
|
|
|
// Utility functions for unified ivar access. These need to
|
|
|
|
// eventually be folded into other places (the structure layout
|
|
|
|
// code).
|
|
|
|
|
2009-05-03 16:55:17 +08:00
|
|
|
protected:
|
2009-04-22 17:39:34 +08:00
|
|
|
/// Compute an offset to the given ivar, suitable for passing to
|
|
|
|
/// EmitValueForIvarAtOffset. Note that the correct handling of
|
|
|
|
/// bit-fields is carefully coordinated by these two, use caution!
|
2009-05-03 20:57:56 +08:00
|
|
|
///
|
|
|
|
/// The latter overload is suitable for computing the offset of a
|
|
|
|
/// sythesized ivar.
|
2009-04-22 15:32:20 +08:00
|
|
|
uint64_t ComputeIvarBaseOffset(CodeGen::CodeGenModule &CGM,
|
|
|
|
const ObjCInterfaceDecl *OID,
|
|
|
|
const ObjCIvarDecl *Ivar);
|
2009-05-03 20:57:56 +08:00
|
|
|
uint64_t ComputeIvarBaseOffset(CodeGen::CodeGenModule &CGM,
|
|
|
|
const ObjCImplementationDecl *OID,
|
|
|
|
const ObjCIvarDecl *Ivar);
|
2009-04-22 15:32:20 +08:00
|
|
|
|
|
|
|
LValue EmitValueForIvarAtOffset(CodeGen::CodeGenFunction &CGF,
|
|
|
|
const ObjCInterfaceDecl *OID,
|
|
|
|
llvm::Value *BaseValue,
|
|
|
|
const ObjCIvarDecl *Ivar,
|
|
|
|
unsigned CVRQualifiers,
|
2009-09-09 23:08:12 +08:00
|
|
|
llvm::Value *Offset);
|
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
|
|
|
|
Numerous changes to selector handling:
- Don't use GlobalAliases with non-0 GEPs (GNU runtime) - this was unsupported and LLVM will be generating errors if you do it soon. This also simplifies the code generated by the GNU runtime a bit.
- Make GetSelector() return a constant (GNU runtime), not a load of a store of a constant.
- Recognise @selector() expressions as valid static initialisers (as GCC does).
- Add methods to GCObjCRuntime to emit selectors as constants (needed for using @selector() expressions as constants. These need implementing for the Mac runtimes - I couldn't figure out how to do this, they seem to require a load.
- Store an ObjCMethodDecl in an ObjCSelectorExpr so that we can get at the type information for the selector. This is needed for generating typed selectors from @selector() expressions (as GCC does). Ideally, this information should be stored in the Selector, but that would be an invasive change. We should eventually add checks for common uses of @selector() expressions. Possibly adding an attribute that can be applied to method args providing the types of a selector so, for example, you'd do something like this:
- (id)performSelector: __attribute__((selector_types(id, SEL, id)))(SEL)
withObject: (id)object;
Then, any @selector() expressions passed to the method will be check to ensure that it conforms to this signature. We do this at run time on the GNU runtime already, but it would be nice to do it at compile time on all runtimes.
- Made @selector() expressions emit type info if available and the runtime supports it.
Someone more familiar with the Mac runtime needs to implement the GetConstantSelector() function in CGObjCMac. This currently just assert()s.
llvm-svn: 95189
2010-02-03 10:09:30 +08:00
|
|
|
virtual llvm::Constant *GetConstantSelector(Selector Sel) = 0;
|
|
|
|
|
|
|
|
/// Get a typed selector.
|
|
|
|
virtual llvm::Constant *GetConstantTypedSelector(
|
|
|
|
const ObjCMethodDecl *Method) = 0;
|
|
|
|
|
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
|
|
|
|
2009-09-09 23:08:12 +08:00
|
|
|
/// Get a typed selector.
|
2009-05-06 05:36:57 +08:00
|
|
|
virtual llvm::Value *GetSelector(CGBuilderTy &Builder,
|
|
|
|
const ObjCMethodDecl *Method) = 0;
|
|
|
|
|
2008-08-16 06:20:32 +08:00
|
|
|
/// Generate a constant string object.
|
2010-01-23 10:40:42 +08:00
|
|
|
virtual llvm::Constant *GenerateConstantString(const StringLiteral *) = 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;
|
2009-09-09 23:08:12 +08:00
|
|
|
|
|
|
|
/// Generate an Objective-C message send operation.
|
2009-09-17 12:01:22 +08:00
|
|
|
///
|
|
|
|
/// \param Method - The method being called, this may be null if synthesizing
|
|
|
|
/// a property setter or getter.
|
2009-09-09 23:08:12 +08:00
|
|
|
virtual CodeGen::RValue
|
2008-08-23 11:46:30 +08:00
|
|
|
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,
|
2009-05-06 05:36:57 +08:00
|
|
|
const CallArgList &CallArgs,
|
2009-09-17 12:01:22 +08:00
|
|
|
const ObjCMethodDecl *Method = 0) = 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.
|
2009-09-17 12:01:22 +08:00
|
|
|
///
|
|
|
|
/// \param Method - The method being called, this may be null if synthesizing
|
|
|
|
/// a property setter or getter.
|
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,
|
2009-09-17 12:01:22 +08:00
|
|
|
const CallArgList &CallArgs,
|
|
|
|
const ObjCMethodDecl *Method = 0) = 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
|
|
|
|
2009-09-09 23:08:12 +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
|
2009-09-09 23:08:12 +08:00
|
|
|
/// types.
|
2008-08-16 06:20:32 +08:00
|
|
|
|
2009-05-16 15:57:57 +08:00
|
|
|
// 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-09-09 23:08:12 +08:00
|
|
|
virtual llvm::Function *GenerateMethod(const ObjCMethodDecl *OMD,
|
2009-01-11 05:06:09 +08:00
|
|
|
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;
|
2009-09-09 23:08:12 +08:00
|
|
|
|
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.
|
2009-09-09 23:08:12 +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-09-09 23:08:12 +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,
|
2009-09-25 06:25:38 +08:00
|
|
|
llvm::Value *src, llvm::Value *dest,
|
|
|
|
llvm::Value *ivarOffset) = 0;
|
2008-11-19 08:59:10 +08:00
|
|
|
virtual void EmitObjCStrongCastAssign(CodeGen::CodeGenFunction &CGF,
|
|
|
|
llvm::Value *src, llvm::Value *dest) = 0;
|
2009-09-09 23:08:12 +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,
|
2009-04-22 13:08:15 +08:00
|
|
|
const ObjCInterfaceDecl *Interface,
|
2009-02-11 03:02:04 +08:00
|
|
|
const ObjCIvarDecl *Ivar) = 0;
|
2009-07-08 09:18:33 +08:00
|
|
|
virtual void EmitGCMemmoveCollectable(CodeGen::CodeGenFunction &CGF,
|
2009-09-09 23:08:12 +08:00
|
|
|
llvm::Value *DestPtr,
|
2009-07-08 09:18:33 +08:00
|
|
|
llvm::Value *SrcPtr,
|
2009-09-01 03:33:16 +08:00
|
|
|
QualType Ty) = 0;
|
2008-03-01 16:50:34 +08:00
|
|
|
};
|
|
|
|
|
2009-09-09 23:08:12 +08:00
|
|
|
/// Creates an instance of an Objective-C runtime class.
|
2008-03-31 07:03:07 +08:00
|
|
|
//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
|