Changeset 9243cc91 for src/Concurrency


Ignore:
Timestamp:
Mar 15, 2017, 3:16:04 PM (7 years ago)
Author:
Thierry Delisle <tdelisle@…>
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:
0ea1b65
Parents:
f841241
Message:

Updated the plan and made some code review changes in the keywords implementation

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Concurrency/Keywords.cc

    rf841241 r9243cc91  
    8888        //Handles mutex routines definitions :
    8989        // void foo( A * mutex a, B * mutex b,  int i ) {                  void foo( A * a, B * b,  int i ) {
    90         //                                                                       monitor_desc * __monitors[] = { a, b };
     90        //                                                                       monitor_desc * __monitors[] = { get_monitor(a), get_monitor(b) };
    9191        //                                                                       monitor_guard_t __guard = { __monitors, 2 };
    9292        //    /*Some code*/                                       =>           /*Some code*/
     
    9898                using Visitor::visit;
    9999                virtual void visit( FunctionDecl *functionDecl ) override final;
     100                virtual void visit(   StructDecl *functionDecl ) override final;
    100101
    101102                std::list<DeclarationWithType*> findMutexArgs( FunctionDecl* );
     
    107108                        acceptAll( translationUnit, impl );
    108109                }
     110
     111          private:
     112                StructDecl* monitor_decl = nullptr;
    109113        };
    110114
     
    133137                if( ! body ) return;
    134138
     139                assert(monitor_decl);
    135140                addStatments( body, mutexArgs );
     141        }
     142
     143        void MutexKeyword::visit(StructDecl* decl) {
     144                if( decl->get_name() == "monitor_desc" ) {
     145                        assert( !monitor_decl );
     146                        monitor_decl = decl;
     147                }
    136148        }
    137149
     
    167179
    168180        void MutexKeyword::addStatments( CompoundStmt * body, const std::list<DeclarationWithType * > & args ) {
     181
     182                ObjectDecl * monitors = new ObjectDecl(
     183                        "__monitors",
     184                        noStorage,
     185                        LinkageSpec::Cforall,
     186                        nullptr,
     187                        new ArrayType(
     188                                noQualifiers,
     189                                new PointerType(
     190                                        noQualifiers,
     191                                        new StructInstType(
     192                                                noQualifiers,
     193                                                monitor_decl
     194                                        )
     195                                ),
     196                                new ConstantExpr( Constant::from_ulong( args.size() ) ),
     197                                false,
     198                                false
     199                        ),
     200                        new ListInit(
     201                                map_range < std::list<Initializer*> > ( args, [](DeclarationWithType * var ){
     202                                        return new SingleInit( new UntypedExpr(
     203                                                new NameExpr( "get_monitor" ),
     204                                                {  new VariableExpr( var ) }
     205                                        ) );
     206                                })
     207                        )
     208                );
     209
    169210                //in reverse order :
    170211                // monitor_guard_t __guard = { __monitors, # };
     
    181222                                new ListInit(
    182223                                        {
    183                                                 new SingleInit( new NameExpr( "__monitors" ) ),
     224                                                new SingleInit( new VariableExpr( monitors ) ),
    184225                                                new SingleInit( new ConstantExpr( Constant::from_ulong( args.size() ) ) )
    185226                                        }
     
    189230
    190231                //monitor_desc * __monitors[] = { a, b };
    191                 body->push_front(
    192                         new DeclStmt( noLabels, new ObjectDecl(
    193                                 "__monitors",
    194                                 noStorage,
    195                                 LinkageSpec::Cforall,
    196                                 nullptr,
    197                                 new ArrayType(
    198                                         noQualifiers,
    199                                         new PointerType(
    200                                                 noQualifiers,
    201                                                 new StructInstType(
    202                                                         noQualifiers,
    203                                                         "monitor_desc"
    204                                                 )
    205                                         ),
    206                                         new ConstantExpr( Constant::from_ulong( args.size() ) ),
    207                                         false,
    208                                         false
    209                                 ),
    210                                 new ListInit(
    211                                         map_range < std::list<Initializer*> > ( args, [](DeclarationWithType * var ){
    212                                                 return new SingleInit( new VariableExpr( var ) );
    213                                         })
    214                                 )
    215                         ))
    216                 );
     232                body->push_front( new DeclStmt( noLabels, monitors) );
    217233        }
    218234};
Note: See TracChangeset for help on using the changeset viewer.