Changes in / [093f1a0:f678663e]


Ignore:
Location:
src
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • src/ControlStruct/LabelFixer.cc

    r093f1a0 rf678663e  
    1010// Created On       : Mon May 18 07:44:20 2015
    1111// Last Modified By : Rob Schluntz
    12 // Last Modified On : Wed Jul 08 12:36:46 2015
    13 // Update Count     : 145
     12// Last Modified On : Tue Jul 28 13:32:43 2015
     13// Update Count     : 156
    1414//
    1515
     
    2727
    2828namespace ControlStruct {
    29         LabelFixer::Entry::Entry( Statement *to, Statement *from ) : definition ( to ) {
    30                 if ( from != 0 ) {
    31                         UsageLoc loc; loc.stmt = from;
    32                         usage.push_back( loc );
    33                 }
    34         }
    35 
    36         LabelFixer::Entry::Entry( Statement *to, Expression *from ) : definition ( to ) {
    37                 if ( from != 0 ) {
    38                         UsageLoc loc; loc.expr = from;
    39                         usage.push_back( loc );
    40                 }
    41         }
    42 
    43 
    4429        bool LabelFixer::Entry::insideLoop() {
    4530                return ( dynamic_cast< ForStmt * > ( definition ) ||
    4631                        dynamic_cast< WhileStmt * > ( definition )  );
    47         }
    48 
    49         void LabelFixer::Entry::UsageLoc::accept( Visitor & visitor ) {
    50                 if ( dynamic_cast< Statement * >( stmt ) ) {
    51                         stmt->accept( visitor );
    52                 } else {
    53                         expr->accept( visitor );
    54                 }
    5532        }
    5633
     
    7754        // prune to at most one label definition for each statement
    7855        void LabelFixer::visit( Statement *stmt ) {
    79                 currentStatement = stmt;
    8056                std::list< Label > &labels = stmt->get_labels();
    8157
     
    8359                        // only remember one label for each statement
    8460                        Label current = setLabelsDef( labels, stmt );
    85                         labels.clear();
    86                         labels.push_front( current );
    8761                } // if
    8862        }
     
    130104                        }       else {
    131105                                // used previously, but undefined until now -> link with this entry
    132                                 Entry * oldEntry = labelTable[ *i ];
    133                                 e->add_uses( *oldEntry );
     106                                delete labelTable[ *i ];
    134107                                labelTable[ *i ] = e;
    135108                        } // if
     
    141114        }
    142115
    143         // Remember all uses of a label.
     116        // A label was used, add it ot the table if it isn't already there
    144117        template< typename UsageNode >
    145118        void LabelFixer::setLabelsUsg( Label orgValue, UsageNode *use ) {
    146119                assert( use != 0 );
    147120
    148                 if ( labelTable.find( orgValue ) != labelTable.end() ) {
    149                         // the label has been defined or used before
    150                         labelTable[ orgValue ]->add_use( use );
    151                 } else {
    152                         labelTable[ orgValue ] = new Entry( 0, use );
     121                // add label with an unknown origin
     122                if ( labelTable.find( orgValue ) == labelTable.end() ) {
     123                        labelTable[ orgValue ] = new Entry( 0 );
    153124                }
    154125        }
    155126
    156         class LabelGetter : public Visitor {
    157                 public:
    158                 LabelGetter( Label &label ) : label( label ) {}
    159 
    160                 virtual void visit( BranchStmt * branchStmt ) {
    161                         label = branchStmt->get_target();
    162                 }
    163 
    164                 virtual void visit( UntypedExpr * untyped ) {
    165                         NameExpr * name = dynamic_cast< NameExpr * >( untyped->get_function() );
    166                         assert( name );
    167                         assert( name->get_name() == "&&" );
    168                         NameExpr * arg = dynamic_cast< NameExpr * >( untyped->get_args().front() );
    169                         assert( arg );
    170                         label = arg->get_name();
    171                 }               
    172 
    173                 private:
    174                         Label &label;
    175         };
    176 
    177         class LabelSetter : public Visitor {
    178                 public:
    179                 LabelSetter( Label label ) : label( label ) {}
    180 
    181                 virtual void visit( BranchStmt * branchStmt ) {
    182                         branchStmt->set_target( label );
    183                 }
    184 
    185                 virtual void visit( UntypedExpr * untyped ) {
    186                         NameExpr * name = dynamic_cast< NameExpr * >( untyped->get_function() );
    187                         assert( name );
    188                         assert( name->get_name() == "&&" );
    189                         NameExpr * arg = dynamic_cast< NameExpr * >( untyped->get_args().front() );
    190                         assert( arg );
    191                         arg->set_name( label );
    192                 }
    193 
    194         private:
    195                 Label label;
    196         };
    197 
    198         // Ultimately builds a table that maps a label to its defining statement.
    199         // In the process,
     127        // Builds a table that maps a label to its defining statement.
    200128        std::map<Label, Statement * > *LabelFixer::resolveJumps() throw ( SemanticError ) {
    201                 std::map< Statement *, Entry * > def_us;
    202 
    203                 // combine the entries for all labels that target the same location
    204                 for ( std::map< Label, Entry *>::iterator i = labelTable.begin(); i != labelTable.end(); ++i ) {
    205                         Entry *e = i->second;
    206 
    207                         if ( def_us.find ( e->get_definition() ) == def_us.end() ) {
    208                                 def_us[ e->get_definition() ] = e;
    209                         } else if ( e->used() ) {
    210                                 def_us[ e->get_definition() ]->add_uses( *e );
     129                std::map< Label, Statement * > *ret = new std::map< Label, Statement * >();
     130                for ( std::map< Label, Entry * >::iterator i = labelTable.begin(); i != labelTable.end(); ++i ) {
     131                        if ( ! i->second->defined() ) {
     132                                throw SemanticError( "Use of undefined label: " + i->first );
    211133                        }
    212                 }
    213 
    214                 // create a unique label for each target location.
    215                 for ( std::map< Statement *, Entry * >::iterator i = def_us.begin(); i != def_us.end(); ++i ) {
    216                         Statement *to = (*i).first;
    217                         Entry * entry = (*i).second;
    218                         std::list< Entry::UsageLoc > &from = entry->get_uses();
    219 
    220                         // no label definition found
    221                         if ( to == 0 ) {
    222                                 Label undef;
    223                                 LabelGetter getLabel( undef );
    224                                 from.back().accept( getLabel );
    225                                 // Label undef = getLabel( from.back()->get_target() );
    226                                 throw SemanticError ( "'" + undef + "' label not defined");
    227                         } // if
    228 
    229                         // generate a new label, and attach it to its defining statement as the only label on that statement
    230                         Label finalLabel = generator->newLabel( to->get_labels().back() );
    231                         entry->set_label( finalLabel );
    232 
    233                         to->get_labels().clear();
    234                         to->get_labels().push_back( finalLabel );
    235 
    236                         // redirect each of the source branch statements to the new target label
    237                         for ( std::list< Entry::UsageLoc >::iterator j = from.begin(); j != from.end(); ++j ) {
    238                                 LabelSetter setLabel( finalLabel );
    239                                 (*j).accept( setLabel );
    240                                 // setLabel( *j, finalLabel );
    241 
    242                                 // BranchStmt *jump = *j;
    243                                 // assert( jump != 0 );
    244                                 // jump->set_target( finalLabel );
    245                         } // for
    246                 } // for
    247 
    248                 // create a table where each label maps to its defining statement
    249                 std::map< Label, Statement * > *ret = new std::map< Label, Statement * >();
    250                 for ( std::map< Statement *, Entry * >::iterator i = def_us.begin(); i != def_us.end(); ++i ) {
    251                         (*ret)[ (*i).second->get_label() ] = (*i).first;
     134                        (*ret)[ i->first ] = i->second->get_definition();
    252135                }
    253136
  • src/ControlStruct/LabelFixer.h

    r093f1a0 rf678663e  
    99// Author           : Rodolfo G. Esteves
    1010// Created On       : Mon May 18 07:44:20 2015
    11 // Last Modified By : Peter A. Buhr
    12 // Last Modified On : Mon Jun 29 17:24:39 2015
    13 // Update Count     : 29
     11// Last Modified By : Rob Schluntz
     12// Last Modified On : Tue Jul 28 13:09:02 2015
     13// Update Count     : 31
    1414//
    1515
     
    6363                class Entry {
    6464                        public:
    65                         union UsageLoc {
    66                                 Statement * stmt;
    67                                 Expression * expr;
    68 
    69                                 void accept( Visitor &visitor );
    70                         };
    71 
    7265                        Entry( Statement *to ) : definition( to ) {}
    73                         Entry( Statement *to, Statement *from );
    74                         Entry( Statement *to, Expression *from );
    75                         bool used() { return ( usage.empty() ); }
    7666                        bool defined() { return ( definition != 0 ); }
    7767                        bool insideLoop();
     
    8373                        void set_definition( Statement *def ) { definition = def; }
    8474
    85                         std::list< UsageLoc > &get_uses() { return usage; }
    86                         void add_use( Statement *use ) {
    87                                 UsageLoc loc;
    88                                 loc.stmt = use;
    89                                 usage.push_back( loc );
    90                         }
    91                         void add_use( Expression *use ) {
    92                                 UsageLoc loc;
    93                                 loc.expr = use;
    94                                 usage.push_back( loc );                                 
    95                         }
    96 
    97                         void add_uses ( Entry &other ) { usage.insert( usage.end(), other.usage.begin(), other.usage.end() ); }
    9875                  private:
    9976                        Label label; 
    10077                        Statement *definition;
    101                         std::list<UsageLoc> usage;
    10278                };
    10379                 
    10480                std::map < Label, Entry *> labelTable;
    10581                LabelGenerator *generator;
    106                 Statement * currentStatement;
    10782        };
    10883} // namespace ControlStruct
  • src/GenPoly/Box.cc

    r093f1a0 rf678663e  
    1010// Created On       : Mon May 18 07:44:20 2015
    1111// Last Modified By : Rob Schluntz
    12 // Last Modified On : Wed Jun 24 16:19:07 2015
    13 // Update Count     : 10
     12// Last Modified On : Thu Jul 30 14:35:40 2015
     13// Update Count     : 54
    1414//
    1515
     
    527527
    528528                void Pass1::passAdapters( ApplicationExpr *appExpr, FunctionType *functionType, const TyVarMap &exprTyVars ) {
     529                        // collect a list of function types passed as parameters or implicit parameters (assertions)
    529530                        std::list< DeclarationWithType *> &paramList = functionType->get_parameters();
    530531                        std::list< FunctionType *> functions;
     
    537538                                findFunction( (*arg)->get_type(), functions, exprTyVars, needsAdapter );
    538539                        } // for
     540
     541                        // parameter function types for which an appropriate adapter has been generated.
     542                        // we cannot use the types after applying substitutions, since two different
     543                        // parameter types may be unified to the same type
    539544                        std::set< std::string > adaptersDone;
     545
    540546                        for ( std::list< FunctionType *>::iterator funType = functions.begin(); funType != functions.end(); ++funType ) {
    541547                                FunctionType *realFunction = (*funType)->clone();
    542                                 assert( env );
    543                                 env->apply( realFunction );
    544 
    545548                                std::string mangleName = SymTab::Mangler::mangle( realFunction );
     549
     550                                // only attempt to create an adapter or pass one as a parameter if we haven't
     551                                // already done so for this pre-substitution parameter function type.
    546552                                if ( adaptersDone.find( mangleName ) == adaptersDone.end() ) {
     553                                        std::string mangleName = SymTab::Mangler::mangle( realFunction );
     554                                        adaptersDone.insert( adaptersDone.begin(), mangleName );
     555                                       
     556                                        // apply substitution to type variables to figure out what the
     557                                        // adapter's type should look like
     558                                        assert( env );
     559                                        env->apply( realFunction );
     560                                        mangleName = SymTab::Mangler::mangle( realFunction );
    547561                                        AdapterMap & adapters = Pass1::adapters.top();
    548562                                        AdapterMap::iterator adapter = adapters.find( mangleName );
     
    555569                                                continue;
    556570                                        } else if ( adapter == adapters.end() ) {
     571                                                // adapter has not been created yet in the current scope, so define it
    557572                                                FunctionDecl *newAdapter = makeAdapter( *funType, realFunction, mangleName, exprTyVars );
    558573                                                adapter = adapters.insert( adapters.begin(), std::pair< std::string, FunctionDecl *>( mangleName, newAdapter ) );
     
    560575                                        } // if
    561576                                        assert( adapter != adapters.end() );
     577
     578                                        // add the appropriate adapter as a parameter
    562579                                        appExpr->get_args().push_front( new VariableExpr( adapter->second ) );
    563                                         // appExpr->get_args().push_front( new NameExpr( makeAdapterName ( mangleName ) ) );
    564                                         adaptersDone.insert( adaptersDone.begin(), mangleName );
    565580                                } // if
    566581                        } // for
     
    880895
    881896                void Pass1::doBeginScope() {
     897                        // actually, maybe this could (should?) push
     898                        // a copy of the current map
    882899                        adapters.push(AdapterMap());
    883900                }
     
    10511068                        if ( ObjectDecl *objectDecl = dynamic_cast< ObjectDecl *>( declStmt->get_decl() ) ) {
    10521069                                if ( isPolyVal( objectDecl->get_type(), scopeTyVars ) ) {
     1070                                        // change initialization of a polymorphic value object
     1071                                        // to allocate storage with alloca
    10531072                                        TypeInstType *typeInst = dynamic_cast< TypeInstType *>( objectDecl->get_type() );
    10541073                                        assert( typeInst );
    10551074                                        UntypedExpr *alloc = new UntypedExpr( new NameExpr( "__builtin_alloca" ) );
    10561075                                        alloc->get_args().push_back( new NameExpr( typeInst->get_name() ) );
    1057                                         UntypedExpr *assign = new UntypedExpr( new NameExpr( "?=?" ) );
    1058                                         assign->get_args().push_back( new VariableExpr( objectDecl ) );
    1059                                         assign->get_args().push_back( alloc );
    1060                                         stmtsToAddAfter.push_back( new ExprStmt( noLabels, assign ) );
     1076
     1077                                        delete objectDecl->get_init();
     1078
     1079                                        std::list<Expression*> designators;
     1080                                        objectDecl->set_init( new SingleInit( alloc, designators ) );
    10611081                                }
    10621082                        }
  • src/ResolvExpr/Cost.h

    r093f1a0 rf678663e  
    99// Author           : Richard C. Bilson
    1010// Created On       : Sun May 17 09:39:50 2015
    11 // Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sun May 17 09:42:04 2015
    13 // Update Count     : 3
     11// Last Modified By : Rob Schluntz
     12// Last Modified On : Wed Jul 22 16:43:10 2015
     13// Update Count     : 4
    1414//
    1515
     
    5656
    5757        inline void Cost::incPoly( int inc ) {
    58                 unsafe += inc;
     58                poly += inc;
    5959        }
    6060
    6161        inline void Cost::incSafe( int inc ) {
    62                 unsafe += inc;
     62                safe += inc;
    6363        }
    6464
  • src/main.cc

    r093f1a0 rf678663e  
    99// Author           : Richard C. Bilson
    1010// Created On       : Fri May 15 23:12:02 2015
    11 // Last Modified By : Peter A. Buhr
    12 // Last Modified On : Thu Jul 30 15:36:41 2015
    13 // Update Count     : 146
     11// Last Modified By : Rob Schluntz
     12// Last Modified On : Thu Jul 30 16:08:18 2015
     13// Update Count     : 167
    1414//
    1515
     
    228228                // add the assignment statement after the
    229229                // initialization of a type parameter
    230                 OPTPRINT( "tweak" )
    231                 InitTweak::tweak( translationUnit );
    232230                OPTPRINT( "validate" )
    233231                SymTab::validate( translationUnit, symtabp );
     
    251249                OPTPRINT( "fixNames" )
    252250                CodeGen::fixNames( translationUnit );
     251                OPTPRINT( "tweak" )
     252                InitTweak::tweak( translationUnit );
    253253
    254254                if ( libcfap ) {
Note: See TracChangeset for help on using the changeset viewer.