/// EmitFunctionStart - Constructs the debug code for entering a function -
/// "llvm.dbg.func.start.".
-void CGDebugInfo::EmitFunctionStart(const FunctionDecl *FnDecl,
+void CGDebugInfo::EmitFunctionStart(const char *Name,
+ QualType ReturnType,
llvm::Function *Fn,
llvm::IRBuilder<> &Builder)
{
}
// Get name information.
- Subprogram->setName(FnDecl->getName());
- Subprogram->setFullName(FnDecl->getName());
+ Subprogram->setName(Name);
+ Subprogram->setFullName(Name);
// Gather location information.
llvm::CompileUnitDesc *Unit = getOrCreateCompileUnit(CurLoc);
uint64_t Loc = SM.getLogicalLineNumber(CurLoc);
// Get Function Type.
- QualType type = FnDecl->getResultType();
- llvm::TypeDesc *SPTy = getOrCreateType(type, Unit);
+ llvm::TypeDesc *SPTy = getOrCreateType(ReturnType, Unit);
Subprogram->setAnchor(SubprogramAnchor);
Subprogram->setContext(Unit);
void EmitStopPoint(llvm::Function *Fn, BuilderType &Builder);
/// EmitFunctionStart - Emit a call to llvm.dbg.function.start to indicate
- /// start of a new function
- void EmitFunctionStart(const FunctionDecl *FnDecl, llvm::Function *Fn,
- BuilderType &Builder);
+ /// start of a new function.
+ void EmitFunctionStart(const char *Name, QualType ReturnType,
+ llvm::Function *Fn, BuilderType &Builder);
/// EmitRegionStart - Emit a call to llvm.dbg.region.start to indicate start
/// of a new block.
Args.push_back(std::make_pair(IPD, IPD->getType()));
}
- StartFunction(OMD, OMD->getResultType(), Fn, Args);
+ StartFunction(OMD, OMD->getResultType(), Fn, Args, OMD->getLocEnd());
}
/// Generate an Objective-C method. An Objective-C method is a C function with
void CodeGenFunction::GenerateObjCMethod(const ObjCMethodDecl *OMD) {
StartObjCMethod(OMD);
EmitStmt(OMD->getBody());
-
- const CompoundStmt *S = dyn_cast<CompoundStmt>(OMD->getBody());
- if (S) {
- FinishFunction(S->getRBracLoc());
- } else {
- FinishFunction();
- }
+ FinishFunction(cast<CompoundStmt>(OMD->getBody())->getRBracLoc());
}
// FIXME: I wasn't sure about the synthesis approach. If we end up
void CodeGenFunction::StartFunction(const Decl *D, QualType RetTy,
llvm::Function *Fn,
- const FunctionArgList &Args) {
+ const FunctionArgList &Args,
+ SourceLocation StartLoc) {
CurFuncDecl = D;
FnRetTy = RetTy;
CurFn = Fn;
// Emit subprogram debug descriptor.
// FIXME: The cast here is a huge hack.
- if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) {
- if (CGDebugInfo *DI = CGM.getDebugInfo()) {
- if (CompoundStmt* body = dyn_cast<CompoundStmt>(FD->getBody()))
- DI->setLocation(body->getLBracLoc());
- DI->EmitFunctionStart(FD, CurFn, Builder);
+ if (CGDebugInfo *DI = CGM.getDebugInfo()) {
+ DI->setLocation(StartLoc);
+ if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) {
+ DI->EmitFunctionStart(FD->getName(), RetTy, CurFn, Builder);
+ } else {
+ // Just use LLVM function name.
+ DI->EmitFunctionStart(Fn->getName().c_str(),
+ RetTy, CurFn, Builder);
}
}
FProto->getArgType(i)));
}
- StartFunction(FD, FD->getResultType(), Fn, Args);
+ StartFunction(FD, FD->getResultType(), Fn, Args,
+ cast<CompoundStmt>(FD->getBody())->getLBracLoc());
EmitStmt(FD->getBody());
llvm::Function *Fn);
void StartFunction(const Decl *D, QualType RetTy,
llvm::Function *Fn,
- const FunctionArgList &Args);
+ const FunctionArgList &Args,
+ SourceLocation StartLoc);
void FinishFunction(SourceLocation EndLoc=SourceLocation());
/// EmitFunctionProlog - Emit the target specific LLVM code to load