#include "CodeGenFunction.h"
#include "CodeGenModule.h"
+#include "clang/AST/DeclObjC.h"
#include "llvm/Module.h"
#include "llvm/Target/TargetData.h"
uint64_t subBlockSize, subBlockAlign;
llvm::SmallVector<const Expr *, 8> subBlockDeclRefDecls;
llvm::Function *Fn
- = CodeGenFunction(CGM).GenerateBlockFunction(BE, Info, LocalDeclMap,
+ = CodeGenFunction(CGM).GenerateBlockFunction(BE, Info, CurFuncDecl, LocalDeclMap,
subBlockSize,
subBlockAlign,
subBlockDeclRefDecls,
return V;
}
+void CodeGenFunction::BlockForwardSelf() {
+ const ObjCMethodDecl *OMD = cast<ObjCMethodDecl>(CurFuncDecl);
+ ImplicitParamDecl *SelfDecl = OMD->getSelfDecl();
+ llvm::Value *&DMEntry = LocalDeclMap[SelfDecl];
+ if (DMEntry)
+ return;
+ // FIXME - Eliminate BlockDeclRefExprs, clients don't need/want to care
+ BlockDeclRefExpr *BDRE = new (getContext())
+ BlockDeclRefExpr(SelfDecl,
+ SelfDecl->getType(), SourceLocation(), false);
+ DMEntry = GetAddrOfBlockDecl(BDRE);
+}
+
llvm::Constant *
BlockModule::GetAddrOfGlobalBlock(const BlockExpr *BE, const char * n) {
// Generate the block descriptor.
bool subBlockHasCopyDispose = false;
llvm::DenseMap<const Decl*, llvm::Value*> LocalDeclMap;
llvm::Function *Fn
- = CodeGenFunction(CGM).GenerateBlockFunction(BE, Info, LocalDeclMap,
+ = CodeGenFunction(CGM).GenerateBlockFunction(BE, Info, 0, LocalDeclMap,
subBlockSize,
subBlockAlign,
subBlockDeclRefDecls,
llvm::Function *
CodeGenFunction::GenerateBlockFunction(const BlockExpr *BExpr,
const BlockInfo& Info,
+ const Decl *OuterFuncDecl,
llvm::DenseMap<const Decl*, llvm::Value*> ldm,
uint64_t &Size,
uint64_t &Align,
StartFunction(BD, FTy->getResultType(), Fn, Args,
BExpr->getBody()->getLocEnd());
+ CurFuncDecl = OuterFuncDecl;
EmitStmt(BExpr->getBody());
FinishFunction(cast<CompoundStmt>(BExpr->getBody())->getRBracLoc());
typedef std::pair<llvm::Value *, llvm::Value *> ComplexPairTy;
CGBuilderTy Builder;
- // Holds the Decl for the current function or method
+ /// CurFuncDecl - Holds the Decl for the current function or method. This
+ /// excludes BlockDecls.
const Decl *CurFuncDecl;
const CGFunctionInfo *CurFnInfo;
QualType FnRetTy;
llvm::Function *GenerateBlockFunction(const BlockExpr *BExpr,
const BlockInfo& Info,
+ const Decl *OuterFuncDecl,
llvm::DenseMap<const Decl*, llvm::Value*> ldm,
uint64_t &Size, uint64_t &Align,
llvm::SmallVector<const Expr *, 8> &subBlockDeclRefDecls,
bool &subBlockHasCopyDispose);
+ void BlockForwardSelf();
llvm::Value *LoadBlockStruct();
llvm::Value *GetAddrOfBlockDecl(const BlockDeclRefExpr *E);