- Timestamp:
 - Jun 16, 2017, 3:34:55 PM (8 years ago)
 - Branches:
 - ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
 - Children:
 - 9d85038
 - Parents:
 - a724ac1 (diff), d33bc7c (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 added
 - 4 edited
 
- 
          
  Common/PassVisitor.h (modified) (3 diffs)
 - 
          
  Common/PassVisitor.impl.h (modified) (3 diffs)
 - 
          
  Common/PassVisitor.proto.h (modified) (3 diffs)
 - 
          
  InitTweak/GenInit.cc (modified) (5 diffs)
 - 
          
  tests/preempt_longrun/Makefile.am (added)
 - 
          
  tests/preempt_longrun/Makefile.in (added)
 - 
          
  tests/preempt_longrun/create.c (added)
 - 
          
  tests/preempt_longrun/processor.c (added)
 - 
          
  tests/preempt_longrun/stack.c (added)
 - 
          
  tests/preempt_longrun/yield.c (added)
 
 
Legend:
- Unmodified
 - Added
 - Removed
 
- 
      
src/Common/PassVisitor.h
ra724ac1 r1bc9dcb 54 54 virtual void visit( BranchStmt *branchStmt ) override final; 55 55 virtual void visit( ReturnStmt *returnStmt ) override final; 56 virtual void visit( ThrowStmt *throwStmt ) override final; 56 57 virtual void visit( TryStmt *tryStmt ) override final; 57 58 virtual void visit( CatchStmt *catchStmt ) override final; … … 139 140 virtual Statement* mutate( BranchStmt *branchStmt ) override final; 140 141 virtual Statement* mutate( ReturnStmt *returnStmt ) override final; 142 virtual Statement* mutate( ThrowStmt *throwStmt ) override final; 141 143 virtual Statement* mutate( TryStmt *returnStmt ) override final; 142 144 virtual Statement* mutate( CatchStmt *catchStmt ) override final; … … 230 232 std::list< Statement* > * get_afterStmts () { return stmtsToAddAfter_impl ( pass, 0); } 231 233 bool visit_children() { bool* skip = skip_children_impl(pass, 0); return ! (skip && *skip); } 232 }; 234 void reset_visit() { bool* skip = skip_children_impl(pass, 0); if(skip) *skip = false; } 235 236 guard_value_impl init_guard() { 237 guard_value_impl guard; 238 auto at_cleanup = at_cleanup_impl(pass, 0); 239 if( at_cleanup ) { 240 *at_cleanup = [&guard]( cleanup_func_t && func, void* val ) { 241 guard.push( std::move( func ), val ); 242 }; 243 } 244 return guard; 245 } 246 }; 247 248 template<typename pass_type, typename T> 249 void GuardValue( pass_type * pass, T& val ) { 250 pass->at_cleanup( [ val ]( void * newVal ) { 251 * static_cast< T * >( newVal ) = val; 252 }, static_cast< void * >( & val ) ); 253 } 254 255 class WithTypeSubstitution { 256 protected: 257 WithTypeSubstitution() = default; 258 ~WithTypeSubstitution() = default; 259 260 public: 261 TypeSubstitution * env; 262 }; 263 264 class WithStmtsToAdd { 265 protected: 266 WithStmtsToAdd() = default; 267 ~WithStmtsToAdd() = default; 268 269 public: 270 std::list< Statement* > stmtsToAddBefore; 271 std::list< Statement* > stmtsToAddAfter; 272 }; 273 274 class WithShortCircuiting { 275 protected: 276 WithShortCircuiting() = default; 277 ~WithShortCircuiting() = default; 278 279 public: 280 bool skip_children; 281 }; 282 283 class WithScopes { 284 protected: 285 WithScopes() = default; 286 ~WithScopes() = default; 287 288 public: 289 at_cleanup_t at_cleanup; 290 291 template< typename T > 292 void GuardValue( T& val ) { 293 at_cleanup( [ val ]( void * newVal ) { 294 * static_cast< T * >( newVal ) = val; 295 }, static_cast< void * >( & val ) ); 296 } 297 }; 298 233 299 234 300 #include "PassVisitor.impl.h"  - 
      
src/Common/PassVisitor.impl.h
ra724ac1 r1bc9dcb 1 1 #pragma once 2 2 3 #define VISIT_START( node ) \ 4 call_previsit( node ); \ 5 if( visit_children() ) { \ 6 7 #define VISIT_END( node ) \ 8 } \ 9 return call_postvisit( node ); \ 10 11 #define MUTATE_START( node ) \ 12 call_premutate( node ); \ 13 if( visit_children() ) { \ 3 #define VISIT_START( node ) \ 4 __attribute__((unused)) \ 5 const auto & guard = init_guard(); \ 6 call_previsit( node ); \ 7 if( visit_children() ) { \ 8 reset_visit(); \ 9 10 #define VISIT_END( node ) \ 11 } \ 12 call_postvisit( node ); \ 13 14 #define MUTATE_START( node ) \ 15 __attribute__((unused)) \ 16 const auto & guard = init_guard(); \ 17 call_premutate( node ); \ 18 if( visit_children() ) { \ 19 reset_visit(); \ 14 20 15 21 #define MUTATE_END( type, node ) \ … … 18 24 19 25 20 #define VISIT_BODY( node ) \21 VISIT_START( node ); \22 Visitor::visit( node ); \23 VISIT_END( node ); \26 #define VISIT_BODY( node ) \ 27 VISIT_START( node ); \ 28 Visitor::visit( node ); \ 29 VISIT_END( node ); \ 24 30 25 31 … … 389 395 390 396 //-------------------------------------------------------------------------- 397 // ThrowStmt 398 399 template< typename pass_type > 400 void PassVisitor< pass_type >::visit( ThrowStmt * node ) { 401 VISIT_BODY( node ); 402 } 403 404 template< typename pass_type > 405 Statement * PassVisitor< pass_type >::mutate( ThrowStmt * node ) { 406 MUTATE_BODY( Statement, node ); 407 } 408 409 //-------------------------------------------------------------------------- 391 410 // TryStmt 392 411 template< typename pass_type >  - 
      
src/Common/PassVisitor.proto.h
ra724ac1 r1bc9dcb 1 1 #pragma once 2 3 typedef std::function<void( void * )> cleanup_func_t; 4 5 class guard_value_impl { 6 public: 7 guard_value_impl() = default; 8 9 ~guard_value_impl() { 10 while( !cleanups.empty() ) { 11 auto& cleanup = cleanups.top(); 12 cleanup.func( cleanup.val ); 13 cleanups.pop(); 14 } 15 } 16 17 void push( cleanup_func_t && func, void* val ) { 18 cleanups.emplace( std::move(func), val ); 19 } 20 21 private: 22 struct cleanup_t { 23 cleanup_func_t func; 24 void * val; 25 26 cleanup_t( cleanup_func_t&& func, void * val ) : func(func), val(val) {} 27 }; 28 29 std::stack< cleanup_t > cleanups; 30 }; 31 32 typedef std::function< void( cleanup_func_t, void * ) > at_cleanup_t; 2 33 3 34 //------------------------------------------------------------------------------------------------------------------------------------------------------------------------- … … 73 104 #define FIELD_PTR( type, name ) \ 74 105 template<typename pass_type> \ 75 static inline auto name##_impl( pass_type& pass, __attribute__((unused)) int unused ) -> decltype( &pass.name ) { return &pass.name; } \106 static inline auto name##_impl( pass_type& pass, __attribute__((unused)) int unused ) -> decltype( &pass.name ) { return &pass.name; } \ 76 107 \ 77 108 template<typename pass_type> \ … … 82 113 FIELD_PTR( std::list< Statement* >, stmtsToAddAfter ) 83 114 FIELD_PTR( bool, skip_children ) 115 FIELD_PTR( at_cleanup_t, at_cleanup )  - 
      
src/InitTweak/GenInit.cc
ra724ac1 r1bc9dcb 16 16 #include <stack> 17 17 #include <list> 18 19 #include "InitTweak.h" 18 20 #include "GenInit.h" 19 #include "InitTweak.h" 21 22 #include "Common/PassVisitor.h" 23 20 24 #include "SynTree/Declaration.h" 21 #include "SynTree/Type.h"22 25 #include "SynTree/Expression.h" 23 #include "SynTree/Statement.h"24 26 #include "SynTree/Initializer.h" 25 27 #include "SynTree/Mutator.h" 28 #include "SynTree/Statement.h" 29 #include "SynTree/Type.h" 30 26 31 #include "SymTab/Autogen.h" 27 32 #include "SymTab/Mangler.h" 33 34 #include "GenPoly/DeclMutator.h" 28 35 #include "GenPoly/PolyMutator.h" 29 #include "GenPoly/DeclMutator.h"30 36 #include "GenPoly/ScopedSet.h" 37 31 38 #include "ResolvExpr/typeops.h" 32 39 … … 37 44 } 38 45 39 class ReturnFixer final : public GenPoly::PolyMutator{46 class ReturnFixer : public WithStmtsToAdd, public WithScopes { 40 47 public: 41 48 /// consistently allocates a temporary variable for the return value … … 44 51 static void makeReturnTemp( std::list< Declaration * > &translationUnit ); 45 52 46 typedef GenPoly::PolyMutator Parent; 47 using Parent::mutate; 48 virtual DeclarationWithType * mutate( FunctionDecl *functionDecl ) override; 49 virtual Statement * mutate( ReturnStmt * returnStmt ) override; 53 void premutate( FunctionDecl *functionDecl ); 54 void premutate( ReturnStmt * returnStmt ); 50 55 51 56 protected: … … 129 134 130 135 void ReturnFixer::makeReturnTemp( std::list< Declaration * > & translationUnit ) { 131 ReturnFixerfixer;136 PassVisitor<ReturnFixer> fixer; 132 137 mutateAll( translationUnit, fixer ); 133 138 } 134 139 135 Statement *ReturnFixer::mutate( ReturnStmt *returnStmt ) {140 void ReturnFixer::premutate( ReturnStmt *returnStmt ) { 136 141 std::list< DeclarationWithType * > & returnVals = ftype->get_returnVals(); 137 142 assert( returnVals.size() == 0 || returnVals.size() == 1 ); … … 144 149 construct->get_args().push_back( new AddressExpr( new VariableExpr( returnVals.front() ) ) ); 145 150 construct->get_args().push_back( returnStmt->get_expr() ); 146 stmtsToAdd .push_back(new ExprStmt(noLabels, construct));151 stmtsToAddBefore.push_back(new ExprStmt(noLabels, construct)); 147 152 148 153 // return the retVal object 149 154 returnStmt->set_expr( new VariableExpr( returnVals.front() ) ); 150 155 } // if 151 return returnStmt; 152 } 153 154 DeclarationWithType* ReturnFixer::mutate( FunctionDecl *functionDecl ) { 155 ValueGuard< FunctionType * > oldFtype( ftype ); 156 ValueGuard< std::string > oldFuncName( funcName ); 156 } 157 158 void ReturnFixer::premutate( FunctionDecl *functionDecl ) { 159 GuardValue( ftype ); 160 GuardValue( funcName ); 157 161 158 162 ftype = functionDecl->get_functionType(); 159 163 funcName = functionDecl->get_name(); 160 return Parent::mutate( functionDecl );161 164 } 162 165  
  Note:
 See   TracChangeset
 for help on using the changeset viewer.