Changeset b7fd9daf
- Timestamp:
- Nov 10, 2021, 7:47:45 PM (3 years ago)
- Branches:
- ADT, ast-experimental, enum, forall-pointer-decay, master, pthread-emulation, qualifiedEnum
- Children:
- 3249dd8b
- Parents:
- 1622af5 (diff), f95634e (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - Location:
- src
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
src/AST/Convert.cpp
r1622af5 rb7fd9daf 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 1047 1043 auto rslt = new StmtExpr( 1048 get<CompoundStmt>().accept1( stmts)1044 get<CompoundStmt>().accept1(node->stmts) 1049 1045 ); 1050 1046 1051 1047 rslt->returnDecls = get<ObjectDecl>().acceptL(node->returnDecls); 1052 1048 rslt->dtors = get<Expression>().acceptL(node->dtors); 1053 if (node->resultExpr) { 1054 // this MUST be found by children visit 1055 rslt->resultExpr = strict_dynamic_cast<ExprStmt *>(readonlyCache.at(node->resultExpr)); 1056 } 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 //} 1057 1055 1058 1056 auto expr = visitBaseExpr( node, rslt ); -
src/AST/Copy.hpp
r1622af5 rb7fd9daf 88 88 } 89 89 90 void postvisit( const StmtExpr * node ) { 91 readonlyInsert( &node->resultExpr ); 92 } 93 90 94 void postvisit( const MemberExpr * node ) { 91 95 readonlyInsert( &node->member ); … … 122 126 node_t * deepCopy( const node_t * localRoot ) { 123 127 Pass< DeepCopyCore > dc; 124 node_t const * newRoot = localRoot->accept( dc);128 node_t const * newRoot = strict_dynamic_cast<node_t const*>(localRoot->accept( dc )); 125 129 dc.core.readonlyUpdates(); 126 130 return const_cast< node_t * >( newRoot ); -
src/AST/Expr.hpp
r1622af5 rb7fd9daf 767 767 768 768 /// An expression which must only be evaluated once 769 class UniqueExpr final : public Expr { 769 class 770 UniqueExpr final : public Expr { 770 771 static unsigned long long nextId; 771 772 public: -
src/Tuples/TupleExpansionNew.cpp
r1622af5 rb7fd9daf 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 order 23 27 }; 24 28 } // namespace … … 66 70 } 67 71 } // 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 now 89 declsToAddBefore.push_back( unqExpr->object.as< ast::Decl >() ); 90 // deep copy required due to unresolved issues with UniqueExpr 91 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 } // namespace 68 113 } // namespace Tuples -
src/Tuples/Tuples.h
r1622af5 rb7fd9daf 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 ); 48 49 49 50 /// returns VoidType if any of the expressions have Voidtype, otherwise TupleType of the Expression result types -
src/main.cc
r1622af5 rb7fd9daf 381 381 PASS( "Fix Init", InitTweak::fix(transUnit, buildingLibrary())); 382 382 383 // fix ObjectDecl - replaces ConstructorInit nodes 384 if ( ctorinitp ) { 385 dump( move( transUnit ) ); 386 return EXIT_SUCCESS; 387 } // if 388 389 // Currently not working due to unresolved issues with UniqueExpr 390 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 reused 383 391 translationUnit = convert( move( transUnit ) ); 384 392 } else { … … 435 443 436 444 PASS( "Fix Init", InitTweak::fix( translationUnit, buildingLibrary() ) ); 445 446 // fix ObjectDecl - replaces ConstructorInit nodes 447 if ( ctorinitp ) { 448 dump ( translationUnit ); 449 return EXIT_SUCCESS; 450 } // if 451 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 reused 437 453 } 438 439 // fix ObjectDecl - replaces ConstructorInit nodes440 if ( ctorinitp ) {441 dump ( translationUnit );442 return EXIT_SUCCESS;443 } // if444 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 reused446 454 447 455 PASS( "Translate Tries" , ControlStruct::translateTries( translationUnit ) );
Note: See TracChangeset
for help on using the changeset viewer.