aboutsummaryrefslogtreecommitdiff
path: root/lib/CodeGen/CodeGenFunction.cpp
diff options
context:
space:
mode:
authorDaniel Dunbar <daniel@zuster.org>2008-09-09 23:14:03 +0000
committerDaniel Dunbar <daniel@zuster.org>2008-09-09 23:14:03 +0000
commit7c086516f3cc9fba2733b1919973206c6ba4b171 (patch)
treed6bf0f2be9e8b147829ae3209e81ec414c1b1304 /lib/CodeGen/CodeGenFunction.cpp
parentf99cb051665d2faab038ed855b2eff15d603796d (diff)
Factor CodeGenFunction::StartFunction out of GenerateCode and
StartObjCMethod. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@56030 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen/CodeGenFunction.cpp')
-rw-r--r--lib/CodeGen/CodeGenFunction.cpp68
1 files changed, 41 insertions, 27 deletions
diff --git a/lib/CodeGen/CodeGenFunction.cpp b/lib/CodeGen/CodeGenFunction.cpp
index d2da71270e..a934e43e48 100644
--- a/lib/CodeGen/CodeGenFunction.cpp
+++ b/lib/CodeGen/CodeGenFunction.cpp
@@ -110,11 +110,11 @@ void CodeGenFunction::FinishFunction(SourceLocation EndLoc) {
assert(!verifyFunction(*CurFn) && "Generated function is not well formed.");
}
-// FIXME: There is parallel code in StartObjCMethod.
-void CodeGenFunction::GenerateCode(const FunctionDecl *FD,
- llvm::Function *Fn) {
- CurFuncDecl = FD;
- FnRetTy = FD->getResultType();
+void CodeGenFunction::StartFunction(const Decl *D, QualType RetTy,
+ llvm::Function *Fn,
+ const FunctionArgList &Args) {
+ CurFuncDecl = D;
+ FnRetTy = RetTy;
CurFn = Fn;
assert(CurFn->isDeclaration() && "Function already has body?");
@@ -129,48 +129,62 @@ void CodeGenFunction::GenerateCode(const FunctionDecl *FD,
ReturnBlock = llvm::BasicBlock::Create("return", CurFn);
ReturnValue = 0;
- if (!FnRetTy->isVoidType())
- ReturnValue = CreateTempAlloca(ConvertType(FnRetTy), "retval");
+ if (!RetTy->isVoidType())
+ ReturnValue = CreateTempAlloca(ConvertType(RetTy), "retval");
Builder.SetInsertPoint(EntryBB);
// Emit subprogram debug descriptor.
- CGDebugInfo *DI = CGM.getDebugInfo();
- if (DI) {
- CompoundStmt* body = dyn_cast<CompoundStmt>(FD->getBody());
- if (body && body->getLBracLoc().isValid()) {
- DI->setLocation(body->getLBracLoc());
+ // FIXME: The cast here is a huge hack.
+ if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) {
+ if (CGDebugInfo *DI = CGM.getDebugInfo()) {
+ CompoundStmt* body = dyn_cast<CompoundStmt>(FD->getBody());
+ if (body && body->getLBracLoc().isValid()) {
+ DI->setLocation(body->getLBracLoc());
+ }
+ DI->EmitFunctionStart(FD, CurFn, Builder);
}
- DI->EmitFunctionStart(FD, CurFn, Builder);
}
// Emit allocs for param decls. Give the LLVM Argument nodes names.
llvm::Function::arg_iterator AI = CurFn->arg_begin();
// Name the struct return argument.
- if (hasAggregateLLVMType(FD->getResultType())) {
+ if (hasAggregateLLVMType(FnRetTy)) {
AI->setName("agg.result");
++AI;
}
+
+ for (FunctionArgList::const_iterator i = Args.begin(), e = Args.end();
+ i != e; ++i, ++AI) {
+ const VarDecl *Arg = i->first;
+ QualType T = i->second;
+ assert(AI != CurFn->arg_end() && "Argument mismatch!");
+ llvm::Value* V = AI;
+ if (!getContext().typesAreCompatible(T, Arg->getType())) {
+ // This must be a promotion, for something like
+ // "void a(x) short x; {..."
+ V = EmitScalarConversion(V, T, Arg->getType());
+ }
+ EmitParmDecl(*Arg, V);
+ }
+ assert(AI == CurFn->arg_end() && "Argument mismatch!");
+}
+void CodeGenFunction::GenerateCode(const FunctionDecl *FD,
+ llvm::Function *Fn) {
+ FunctionArgList Args;
if (FD->getNumParams()) {
const FunctionTypeProto* FProto = FD->getType()->getAsFunctionTypeProto();
assert(FProto && "Function def must have prototype!");
- for (unsigned i = 0, e = FD->getNumParams(); i != e; ++i, ++AI) {
- assert(AI != CurFn->arg_end() && "Argument mismatch!");
- const ParmVarDecl* CurParam = FD->getParamDecl(i);
- llvm::Value* V = AI;
- if (!getContext().typesAreCompatible(FProto->getArgType(i),
- CurParam->getType())) {
- // This must be a promotion, for something like
- // "void a(x) short x; {..."
- V = EmitScalarConversion(V, FProto->getArgType(i),
- CurParam->getType());
- }
- EmitParmDecl(*CurParam, V);
- }
+
+ for (unsigned i = 0, e = FD->getNumParams(); i != e; ++i)
+ Args.push_back(std::make_pair(FD->getParamDecl(i),
+ FProto->getArgType(i)));
}
+ StartFunction(FD, FD->getResultType(), Fn, Args);
+
EmitStmt(FD->getBody());
const CompoundStmt *S = dyn_cast<CompoundStmt>(FD->getBody());