diff options
author | Fariborz Jahanian <fjahanian@apple.com> | 2009-07-20 22:35:22 +0000 |
---|---|---|
committer | Fariborz Jahanian <fjahanian@apple.com> | 2009-07-20 22:35:22 +0000 |
commit | 127059c7ecc4c6102f2d7e8b65d9943a201b5582 (patch) | |
tree | da26cc2c4fd9bc31561938b78c5a84b724518839 /clang/lib/CodeGen/CodeGenFunction.cpp | |
parent | 1a7ab9473f794d4ae3f36af5d42023123bc7ddb2 (diff) | |
download | bcm5719-llvm-127059c7ecc4c6102f2d7e8b65d9943a201b5582.tar.gz bcm5719-llvm-127059c7ecc4c6102f2d7e8b65d9943a201b5582.zip |
Early ir-gen for constructor prologue. This is on going.
llvm-svn: 76493
Diffstat (limited to 'clang/lib/CodeGen/CodeGenFunction.cpp')
-rw-r--r-- | clang/lib/CodeGen/CodeGenFunction.cpp | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/clang/lib/CodeGen/CodeGenFunction.cpp b/clang/lib/CodeGen/CodeGenFunction.cpp index 3a689a43062..4bfebe5c31d 100644 --- a/clang/lib/CodeGen/CodeGenFunction.cpp +++ b/clang/lib/CodeGen/CodeGenFunction.cpp @@ -141,6 +141,39 @@ void CodeGenFunction::FinishFunction(SourceLocation EndLoc) { Ptr->eraseFromParent(); } +/// EmitCtorPrologue - This routine generates necessary code to initialize +/// base classes and non-static data members belonging to this constructor. +void CodeGenFunction::EmitCtorPrologue(const CXXConstructorDecl *CD) { + for (CXXConstructorDecl::init_const_iterator B = CD->init_begin(), + E = CD->init_end(); + B != E; ++B) { + CXXBaseOrMemberInitializer *Member = (*B); + if (Member->isBaseInitializer()) { + // FIXME. Added base initialilzers here. + ; + } + else { + // non-static data member initilaizers. + FieldDecl *Field = Member->getMember(); + QualType FieldType = getContext().getCanonicalType((Field)->getType()); + assert(!getContext().getAsArrayType(FieldType) + && "Field arrays initialization unsupported"); + assert(!FieldType->getAsRecordType() + && "Field class initialization unsupported"); + llvm::Value *LoadOfThis = LoadCXXThis(); + LValue LHS = EmitLValueForField(LoadOfThis, Field, false, 0); + + assert(Member->getNumArgs() == 1 && "Initializer count must be 1 only"); + Expr *RhsExpr = *Member->begin(); + llvm::Value *RHS = EmitScalarExpr(RhsExpr, true); + if (LHS.isBitfield()) + EmitStoreThroughBitfieldLValue(RValue::get(RHS), LHS, FieldType, 0); + else + EmitStoreThroughLValue(RValue::get(RHS), LHS, FieldType); + } + } +} + void CodeGenFunction::StartFunction(const Decl *D, QualType RetTy, llvm::Function *Fn, const FunctionArgList &Args, @@ -229,6 +262,8 @@ void CodeGenFunction::GenerateCode(const FunctionDecl *FD, // FIXME: Support CXXTryStmt here, too. if (const CompoundStmt *S = FD->getCompoundBody()) { StartFunction(FD, FD->getResultType(), Fn, Args, S->getLBracLoc()); + if (const CXXConstructorDecl *CD = dyn_cast<CXXConstructorDecl>(FD)) + EmitCtorPrologue(CD); EmitStmt(S); FinishFunction(S->getRBracLoc()); } |