Changes in / [b7fd9daf:1622af5]
- Location:
- src
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
src/AST/Convert.cpp
rb7fd9daf r1622af5 1041 1041 1042 1042 const ast::Expr * visit( const ast::StmtExpr * node ) override final { 1043 auto stmts = node->stmts; 1044 // disable sharing between multiple StmtExprs explicitly. 1045 // this should no longer be true. 1046 1043 1047 auto rslt = new StmtExpr( 1044 get<CompoundStmt>().accept1( node->stmts)1048 get<CompoundStmt>().accept1(stmts) 1045 1049 ); 1046 1050 1047 1051 rslt->returnDecls = get<ObjectDecl>().acceptL(node->returnDecls); 1048 1052 rslt->dtors = get<Expression>().acceptL(node->dtors); 1049 1050 // is this even used after convert? 1051 //if (tmp->resultExpr) { 1052 // // this MUST be found by children visit 1053 // rslt->resultExpr = strict_dynamic_cast<ExprStmt *>(readonlyCache.at(tmp->resultExpr)); 1054 //} 1053 if (node->resultExpr) { 1054 // this MUST be found by children visit 1055 rslt->resultExpr = strict_dynamic_cast<ExprStmt *>(readonlyCache.at(node->resultExpr)); 1056 } 1055 1057 1056 1058 auto expr = visitBaseExpr( node, rslt ); -
src/AST/Copy.hpp
rb7fd9daf r1622af5 88 88 } 89 89 90 void postvisit( const StmtExpr * node ) {91 readonlyInsert( &node->resultExpr );92 }93 94 90 void postvisit( const MemberExpr * node ) { 95 91 readonlyInsert( &node->member ); … … 126 122 node_t * deepCopy( const node_t * localRoot ) { 127 123 Pass< DeepCopyCore > dc; 128 node_t const * newRoot = strict_dynamic_cast<node_t const*>(localRoot->accept( dc ));124 node_t const * newRoot = localRoot->accept( dc ); 129 125 dc.core.readonlyUpdates(); 130 126 return const_cast< node_t * >( newRoot ); -
src/AST/Expr.hpp
rb7fd9daf r1622af5 767 767 768 768 /// An expression which must only be evaluated once 769 class 770 UniqueExpr final : public Expr { 769 class UniqueExpr final : public Expr { 771 770 static unsigned long long nextId; 772 771 public: -
src/Tuples/TupleExpansionNew.cpp
rb7fd9daf r1622af5 21 21 void previsit( const ast::UntypedMemberExpr * ) { visit_children = false; } 22 22 const ast::Expr * postvisit( const ast::UntypedMemberExpr * memberExpr ); 23 };24 struct UniqueExprExpander final : public ast::WithDeclsToAdd<> {25 const ast::Expr * postvisit( const ast::UniqueExpr * unqExpr );26 std::map< int, ast::ptr<ast::Expr> > decls; // not vector, because order added may not be increasing order27 23 }; 28 24 } // namespace … … 70 66 } 71 67 } // namespace 72 73 void expandUniqueExpr( ast::TranslationUnit & translationUnit ) {74 ast::Pass< UniqueExprExpander >::run( translationUnit );75 }76 77 namespace {78 const ast::Expr * UniqueExprExpander::postvisit( const ast::UniqueExpr * unqExpr ) {79 const CodeLocation loc = unqExpr->location;80 const int id = unqExpr->id;81 82 // on first time visiting a unique expr with a particular ID, generate the expression that replaces all UniqueExprs with that ID,83 // and lookup on subsequent hits. This ensures that all unique exprs with the same ID reference the same variable.84 if ( ! decls.count( id ) ) {85 ast::ptr< ast::Expr > assignUnq;86 const ast::VariableExpr * var = unqExpr->var;87 if ( unqExpr->object ) {88 // an object was generated to represent this unique expression -- it should be added to the list of declarations now89 declsToAddBefore.push_back( unqExpr->object.as< ast::Decl >() );90 // deep copy required due to unresolved issues with UniqueExpr91 assignUnq = ast::UntypedExpr::createAssign( loc, var, unqExpr->expr );92 } else {93 const auto commaExpr = unqExpr->expr.strict_as< ast::CommaExpr >();94 assignUnq = commaExpr->arg1;95 }96 auto finished = new ast::ObjectDecl( loc, toString( "_unq", id, "_finished_" ), new ast::BasicType( ast::BasicType::Kind::Bool ),97 new ast::SingleInit( loc, ast::ConstantExpr::from_int( loc, 0 ) ), {}, ast::Linkage::Cforall );98 declsToAddBefore.push_back( finished );99 // (finished ? _unq_expr_N : (_unq_expr_N = <unqExpr->get_expr()>, finished = 1, _unq_expr_N))100 // This pattern ensures that each unique expression is evaluated once, regardless of evaluation order of the generated C code.101 auto assignFinished = ast::UntypedExpr::createAssign( loc, new ast::VariableExpr( loc, finished ),102 ast::ConstantExpr::from_int( loc, 1 ) );103 auto condExpr = new ast::ConditionalExpr( loc, new ast::VariableExpr( loc, finished ), var,104 new ast::CommaExpr( loc, new ast::CommaExpr( loc, assignUnq, assignFinished ), var ) );105 condExpr->result = var->result;106 condExpr->env = unqExpr->env;107 decls[id] = condExpr;108 }109 //delete unqExpr;110 return ast::deepCopy(decls[id].get());111 }112 } // namespace113 68 } // namespace Tuples -
src/Tuples/Tuples.h
rb7fd9daf r1622af5 46 46 /// replaces UniqueExprs with a temporary variable and one call 47 47 void expandUniqueExpr( std::list< Declaration * > & translationUnit ); 48 void expandUniqueExpr( ast::TranslationUnit & translationUnit );49 48 50 49 /// returns VoidType if any of the expressions have Voidtype, otherwise TupleType of the Expression result types -
src/main.cc
rb7fd9daf r1622af5 381 381 PASS( "Fix Init", InitTweak::fix(transUnit, buildingLibrary())); 382 382 383 // fix ObjectDecl - replaces ConstructorInit nodes384 if ( ctorinitp ) {385 dump( move( transUnit ) );386 return EXIT_SUCCESS;387 } // if388 389 // Currently not working due to unresolved issues with UniqueExpr390 PASS( "Expand Unique Expr", Tuples::expandUniqueExpr( transUnit ) ); // xxx - is this the right place for this? want to expand ASAP so tha, sequent passes don't need to worry about double-visiting a unique expr - needs to go after InitTweak::fix so that copy constructed return declarations are reused391 383 translationUnit = convert( move( transUnit ) ); 392 384 } else { … … 443 435 444 436 PASS( "Fix Init", InitTweak::fix( translationUnit, buildingLibrary() ) ); 445 446 // fix ObjectDecl - replaces ConstructorInit nodes447 if ( ctorinitp ) {448 dump ( translationUnit );449 return EXIT_SUCCESS;450 } // if451 452 PASS( "Expand Unique Expr", Tuples::expandUniqueExpr( translationUnit ) ); // xxx - is this the right place for this? want to expand ASAP so tha, sequent passes don't need to worry about double-visiting a unique expr - needs to go after InitTweak::fix so that copy constructed return declarations are reused453 437 } 438 439 // fix ObjectDecl - replaces ConstructorInit nodes 440 if ( ctorinitp ) { 441 dump ( translationUnit ); 442 return EXIT_SUCCESS; 443 } // if 444 445 PASS( "Expand Unique Expr", Tuples::expandUniqueExpr( translationUnit ) ); // xxx - is this the right place for this? want to expand ASAP so tha, sequent passes don't need to worry about double-visiting a unique expr - needs to go after InitTweak::fix so that copy constructed return declarations are reused 454 446 455 447 PASS( "Translate Tries" , ControlStruct::translateTries( translationUnit ) );
Note: See TracChangeset
for help on using the changeset viewer.