[cfe-commits] r76493 - in /cfe/trunk/lib/CodeGen: CodeGenFunction.cpp CodeGenFunction.h
Fariborz Jahanian
fjahanian at apple.com
Mon Jul 20 15:35:22 PDT 2009
Author: fjahanian
Date: Mon Jul 20 17:35:22 2009
New Revision: 76493
URL: http://llvm.org/viewvc/llvm-project?rev=76493&view=rev
Log:
Early ir-gen for constructor prologue. This is on going.
Modified:
cfe/trunk/lib/CodeGen/CodeGenFunction.cpp
cfe/trunk/lib/CodeGen/CodeGenFunction.h
Modified: cfe/trunk/lib/CodeGen/CodeGenFunction.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenFunction.cpp?rev=76493&r1=76492&r2=76493&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenFunction.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenFunction.cpp Mon Jul 20 17:35:22 2009
@@ -141,6 +141,39 @@
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 @@
// 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());
}
Modified: cfe/trunk/lib/CodeGen/CodeGenFunction.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenFunction.h?rev=76493&r1=76492&r2=76493&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenFunction.h (original)
+++ cfe/trunk/lib/CodeGen/CodeGenFunction.h Mon Jul 20 17:35:22 2009
@@ -358,6 +358,8 @@
/// legal to call this function even if there is no current insertion point.
void FinishFunction(SourceLocation EndLoc=SourceLocation());
+ void EmitCtorPrologue(const CXXConstructorDecl *CD);
+
/// EmitFunctionProlog - Emit the target specific LLVM code to load the
/// arguments for the given function. This is also responsible for naming the
/// LLVM function arguments.
More information about the cfe-commits
mailing list