[cfe-commits] r41656 - in /cfe/trunk/CodeGen: CGExprScalar.cpp CGStmt.cpp CodeGenFunction.h

Chris Lattner sabre at nondot.org
Fri Aug 31 15:09:40 PDT 2007


Author: lattner
Date: Fri Aug 31 17:09:40 2007
New Revision: 41656

URL: http://llvm.org/viewvc/llvm-project?rev=41656&view=rev
Log:
implement code generation for scalar stmt expressions.

Modified:
    cfe/trunk/CodeGen/CGExprScalar.cpp
    cfe/trunk/CodeGen/CGStmt.cpp
    cfe/trunk/CodeGen/CodeGenFunction.h

Modified: cfe/trunk/CodeGen/CGExprScalar.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/CodeGen/CGExprScalar.cpp?rev=41656&r1=41655&r2=41656&view=diff

==============================================================================
--- cfe/trunk/CodeGen/CGExprScalar.cpp (original)
+++ cfe/trunk/CodeGen/CGExprScalar.cpp Fri Aug 31 17:09:40 2007
@@ -129,6 +129,8 @@
     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 @@
                                        DestTy);
 }
 
+Value *ScalarExprEmitter::VisitStmtExpr(const StmtExpr *E) {
+  return CGF.EmitCompoundStmt(*E->getSubStmt(), true).getVal();
+}
+
+
 //===----------------------------------------------------------------------===//
 //                             Unary Operators
 //===----------------------------------------------------------------------===//

Modified: cfe/trunk/CodeGen/CGStmt.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/CodeGen/CGStmt.cpp?rev=41656&r1=41655&r2=41656&view=diff

==============================================================================
--- cfe/trunk/CodeGen/CGStmt.cpp (original)
+++ cfe/trunk/CodeGen/CGStmt.cpp Fri Aug 31 17:09:40 2007
@@ -60,12 +60,29 @@
   }
 }
 
-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) {

Modified: cfe/trunk/CodeGen/CodeGenFunction.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/CodeGen/CodeGenFunction.h?rev=41656&r1=41655&r2=41656&view=diff

==============================================================================
--- cfe/trunk/CodeGen/CodeGenFunction.h (original)
+++ cfe/trunk/CodeGen/CodeGenFunction.h Fri Aug 31 17:09:40 2007
@@ -265,7 +265,7 @@
   //===--------------------------------------------------------------------===//
 
   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);





More information about the cfe-commits mailing list