diff options
author | Chris Lattner <sabre@nondot.org> | 2007-08-31 22:09:40 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2007-08-31 22:09:40 +0000 |
commit | 3379320c10001d7e1ee5d7e7142c417f797cfe82 (patch) | |
tree | ab61f3194ffcd461d76407917bf40536d06671ee | |
parent | 98414c1b7d1944a57156d52e29bd41c005de09ac (diff) |
implement code generation for scalar stmt expressions.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@41656 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | CodeGen/CGExprScalar.cpp | 7 | ||||
-rw-r--r-- | CodeGen/CGStmt.cpp | 23 | ||||
-rw-r--r-- | CodeGen/CodeGenFunction.h | 2 |
3 files changed, 28 insertions, 4 deletions
diff --git a/CodeGen/CGExprScalar.cpp b/CodeGen/CGExprScalar.cpp index 1499054b6c..db0e6bf492 100644 --- a/CodeGen/CGExprScalar.cpp +++ b/CodeGen/CGExprScalar.cpp @@ -129,6 +129,8 @@ public: return CGF.EmitCallExpr(E).getVal(); } + Value *VisitStmtExpr(const StmtExpr *E); + // Unary Operators. Value *VisitPrePostIncDec(const UnaryOperator *E, bool isInc, bool isPre); Value *VisitUnaryPostDec(const UnaryOperator *E) { @@ -437,6 +439,11 @@ Value *ScalarExprEmitter::EmitCastExpr(const Expr *E, QualType DestTy) { DestTy); } +Value *ScalarExprEmitter::VisitStmtExpr(const StmtExpr *E) { + return CGF.EmitCompoundStmt(*E->getSubStmt(), true).getVal(); +} + + //===----------------------------------------------------------------------===// // Unary Operators //===----------------------------------------------------------------------===// diff --git a/CodeGen/CGStmt.cpp b/CodeGen/CGStmt.cpp index 04c9c1d3eb..85a6ca8705 100644 --- a/CodeGen/CGStmt.cpp +++ b/CodeGen/CGStmt.cpp @@ -60,12 +60,29 @@ void CodeGenFunction::EmitStmt(const Stmt *S) { } } -void CodeGenFunction::EmitCompoundStmt(const CompoundStmt &S) { +/// EmitCompoundStmt - Emit a compound statement {..} node. If GetLast is true, +/// this captures the expression result of the last sub-statement and returns it +/// (for use by the statement expression extension). +RValue CodeGenFunction::EmitCompoundStmt(const CompoundStmt &S, bool GetLast) { // FIXME: handle vla's etc. + if (S.body_empty() || !isa<Expr>(S.body_back())) GetLast = false; - for (CompoundStmt::const_body_iterator I = S.body_begin(), E = S.body_end(); - I != E; ++I) + for (CompoundStmt::const_body_iterator I = S.body_begin(), + E = S.body_end()-GetLast; I != E; ++I) EmitStmt(*I); + + + if (!GetLast) + return RValue::get(0); + + const Expr *Last = cast<Expr>(S.body_back()); + if (!hasAggregateLLVMType(Last->getType())) + return RValue::get(EmitScalarExpr(Last)); + assert(0 && "Unimp"); + //else if (Last->getType()->isComplexType()) + // EmitComplexExpr(Last); + //else + // EmitAggExpr(E, 0, false); } void CodeGenFunction::EmitBlock(llvm::BasicBlock *BB) { diff --git a/CodeGen/CodeGenFunction.h b/CodeGen/CodeGenFunction.h index af8d80bbb2..a597f43268 100644 --- a/CodeGen/CodeGenFunction.h +++ b/CodeGen/CodeGenFunction.h @@ -265,7 +265,7 @@ public: //===--------------------------------------------------------------------===// void EmitStmt(const Stmt *S); - void EmitCompoundStmt(const CompoundStmt &S); + RValue EmitCompoundStmt(const CompoundStmt &S, bool GetLast = false); void EmitLabelStmt(const LabelStmt &S); void EmitGotoStmt(const GotoStmt &S); void EmitIfStmt(const IfStmt &S); |