Ignore:
Timestamp:
May 18, 2015, 11:45:33 PM (9 years ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, ctor, deferred_resn, demangler, enum, forall-pointer-decay, gc_noraii, jacob/cs343-translation, jenkins-sandbox, master, memory, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, string, with_gc
Children:
01aeade
Parents:
0dd3a2f
Message:

licencing: fourth groups of files

File:
1 edited

Legend:

Unmodified
Added
Removed
  • translator/Tuples/AssignExpand.cc

    r0dd3a2f r51587aa  
     1//
     2// Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo
     3//
     4// The contents of this file are covered under the licence agreement in the
     5// file "LICENCE" distributed with Cforall.
     6//
     7// AssignExpand.cc --
     8//
     9// Author           : Richard C. Bilson
     10// Created On       : Mon May 18 07:44:20 2015
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Mon May 18 11:24:47 2015
     13// Update Count     : 2
     14//
     15
    116#include <ctime>
    217#include <cstdlib>
     
    1429
    1530namespace Tuples {
    16   AssignExpander::AssignExpander() : temporaryNamer("__tpl") {}
     31        AssignExpander::AssignExpander() : temporaryNamer("__tpl") {}
    1732
    18   Statement *AssignExpander::mutate( ExprStmt *exprStmt ) {
    19     replace.clear();
    20     extra.clear();
    21     extra2.clear();
    22     exprStmt->set_expr( maybeMutate( exprStmt->get_expr(), *this ) );
     33        Statement *AssignExpander::mutate( ExprStmt *exprStmt ) {
     34                replace.clear();
     35                extra.clear();
     36                extra2.clear();
     37                exprStmt->set_expr( maybeMutate( exprStmt->get_expr(), *this ) );
    2338
    24     CompoundStmt *newSt = 0;
    25     if (! extra.empty() ) {
    26       if ( ! newSt )
    27         newSt= new CompoundStmt(std::list<Label>());
     39                CompoundStmt *newSt = 0;
     40                if (! extra.empty() ) {
     41                        if ( ! newSt )
     42                                newSt= new CompoundStmt(std::list<Label>());
    2843
    29       newSt->get_kids().splice(newSt->get_kids().end(), extra);
    30     }
     44                        newSt->get_kids().splice(newSt->get_kids().end(), extra);
     45                } // if
    3146
    32     if (! extra2.empty() ) {
    33       if ( ! newSt )
    34         newSt= new CompoundStmt(std::list<Label>());
     47                if ( ! extra2.empty() ) {
     48                        if ( ! newSt )
     49                                newSt= new CompoundStmt(std::list<Label>());
    3550
    36       newSt->get_kids().splice(newSt->get_kids().end(), extra2);
    37     }
     51                        newSt->get_kids().splice(newSt->get_kids().end(), extra2);
     52                }
    3853
    39     if (! replace.empty() ) {
    40       if ( ! newSt )
    41         newSt= new CompoundStmt(std::list<Label>());
     54                if ( ! replace.empty() ) {
     55                        if ( ! newSt )
     56                                newSt= new CompoundStmt(std::list<Label>());
    4257
    43       for ( std::list<Expression *>::iterator r = replace.begin(); r != replace.end(); r++ )
    44         newSt->get_kids().push_back( new ExprStmt( std::list<Label>(), *r ));
    45     }
     58                        for ( std::list<Expression *>::iterator r = replace.begin(); r != replace.end(); r++ )
     59                                newSt->get_kids().push_back( new ExprStmt( std::list<Label>(), *r ));
     60                }
    4661
    47     if ( newSt ) return newSt; else return exprStmt;
    48   }
     62                if ( newSt ) return newSt; else return exprStmt;
     63        }
    4964
    50   Expression *AssignExpander::mutate( SolvedTupleExpr *tupleExpr ) {
    51     /*
    52     std::list<Expression *> &exprs = tupleExpr->get_exprs();
     65        Expression *AssignExpander::mutate( SolvedTupleExpr *tupleExpr ) {
     66                /*
     67                   std::list<Expression *> &exprs = tupleExpr->get_exprs();
    5368
    54     if ( tupleExpr->get_type() == SolvedTupleExpr::MASS ) {
    55       // extract lhs of assignments, assert that rhs is the same, create temporaries
    56       assert (! exprs.empty());
    57       ApplicationExpr *ap1 = dynamic_cast< ApplicationExpr * >( exprs.front() );
    58       std::list<Expression *> &args = ap1->get_args();
    59       assert(args.size() == 2);
    60       std::list<Type *> &temp_types = args.back()->get_results();
    61       assert(temp_types.size() == 1);
    62       extra.push_back(new DeclStmt( std::list<Label>(), new ObjectDecl(temporaryNamer.newName(), Declaration::Auto, LinkageSpec::C, 0, temp_types.front(), 0 ) ));
     69                   if ( tupleExpr->get_type() == SolvedTupleExpr::MASS ) {
     70                   // extract lhs of assignments, assert that rhs is the same, create temporaries
     71                   assert (! exprs.empty());
     72                   ApplicationExpr *ap1 = dynamic_cast< ApplicationExpr * >( exprs.front() );
     73                   std::list<Expression *> &args = ap1->get_args();
     74                   assert(args.size() == 2);
     75                   std::list<Type *> &temp_types = args.back()->get_results();
     76                   assert(temp_types.size() == 1);
     77                   extra.push_back(new DeclStmt( std::list<Label>(), new ObjectDecl(temporaryNamer.newName(), Declaration::Auto, LinkageSpec::C, 0, temp_types.front(), 0 ) ));
    6378
    64       for ( std::list<Expression *>::iterator e = exprs.begin(); e != exprs.end(); e++ ) {
    65         ApplicationExpr *ap = dynamic_cast< ApplicationExpr * >( *e );
    66         assert( ap != 0 );
    67         replace.push_back(ap);
    68       }
     79                   for ( std::list<Expression *>::iterator e = exprs.begin(); e != exprs.end(); e++ ) {
     80                   ApplicationExpr *ap = dynamic_cast< ApplicationExpr * >( *e );
     81                   assert( ap != 0 );
     82                   replace.push_back(ap);
     83                   }
    6984
    70       return tupleExpr;
    71     } else if ( tupleExpr->get_type() == SolvedTupleExpr::MULTIPLE ||
     85                   return tupleExpr;
     86                   } else if ( tupleExpr->get_type() == SolvedTupleExpr::MULTIPLE ||
    7287                   tupleExpr->get_type() == SolvedTupleExpr::MASS ) */ {
    73       std::list<Expression *> &comps = tupleExpr->get_exprs();
    74       for ( std::list<Expression *>::iterator i = comps.begin(); i != comps.end(); ++i ) {
    75         std::list<Statement *> decls;
    76         std::list<Statement *> temps;
    77         std::list<Statement *> assigns;
    78         if ( ApplicationExpr *app = dynamic_cast< ApplicationExpr * >(*i) ) {
    79           assert( app->get_args().size() == 2 );
     88                        std::list<Expression *> &comps = tupleExpr->get_exprs();
     89                        for ( std::list<Expression *>::iterator i = comps.begin(); i != comps.end(); ++i ) {
     90                                std::list<Statement *> decls;
     91                                std::list<Statement *> temps;
     92                                std::list<Statement *> assigns;
     93                                if ( ApplicationExpr *app = dynamic_cast< ApplicationExpr * >(*i) ) {
     94                                        assert( app->get_args().size() == 2 );
    8095
    81           Expression *lhsT = app->get_args().front();
    82           Expression *rhsT = app->get_args().back();
    83           // after the round of type analysis this should be true
    84           assert( lhsT->get_results().size() == 1 );
    85           assert( rhsT->get_results().size() == 1 );
    86           // declare temporaries
    87           ObjectDecl *lhs = new ObjectDecl( temporaryNamer.newName("_lhs_"), Declaration::NoStorageClass, LinkageSpec::Intrinsic, 0,
    88                                             lhsT->get_results().front(), 0 );
    89           decls.push_back( new DeclStmt( std::list< Label >(), lhs ) );
    90           ObjectDecl *rhs = new ObjectDecl( temporaryNamer.newName("_rhs_"), Declaration::NoStorageClass, LinkageSpec::Intrinsic, 0,
    91                                             rhsT->get_results().front(), 0);
    92           decls.push_back( new DeclStmt( std::list< Label >(), rhs ));
     96                                        Expression *lhsT = app->get_args().front();
     97                                        Expression *rhsT = app->get_args().back();
     98                                        // after the round of type analysis this should be true
     99                                        assert( lhsT->get_results().size() == 1 );
     100                                        assert( rhsT->get_results().size() == 1 );
     101                                        // declare temporaries
     102                                        ObjectDecl *lhs = new ObjectDecl( temporaryNamer.newName("_lhs_"), Declaration::NoStorageClass, LinkageSpec::Intrinsic, 0,
     103                                                                                                          lhsT->get_results().front(), 0 );
     104                                        decls.push_back( new DeclStmt( std::list< Label >(), lhs ) );
     105                                        ObjectDecl *rhs = new ObjectDecl( temporaryNamer.newName("_rhs_"), Declaration::NoStorageClass, LinkageSpec::Intrinsic, 0,
     106                                                                                                          rhsT->get_results().front(), 0);
     107                                        decls.push_back( new DeclStmt( std::list< Label >(), rhs ));
    93108
    94109
    95           // create temporary for lhs, assign address
    96           UntypedExpr *assgnL = new UntypedExpr( new NameExpr( "?=?" ) );
    97           assgnL->get_args().push_back( new VariableExpr( lhs ) );
    98           assgnL->get_args().push_back( lhsT );
    99           temps.push_back( new ExprStmt(std::list<Label>(), assgnL) );
     110                                        // create temporary for lhs, assign address
     111                                        UntypedExpr *assgnL = new UntypedExpr( new NameExpr( "?=?" ) );
     112                                        assgnL->get_args().push_back( new VariableExpr( lhs ) );
     113                                        assgnL->get_args().push_back( lhsT );
     114                                        temps.push_back( new ExprStmt(std::list<Label>(), assgnL) );
    100115
    101           // create temporary for rhs, assign value
    102           UntypedExpr *assgnR = new UntypedExpr( new NameExpr( "?=?" ) );
    103           assgnR->get_args().push_back( new VariableExpr( rhs ) );
    104           assgnR->get_args().push_back( rhsT );
    105           temps.push_back( new ExprStmt(std::list<Label>(), assgnR) );
     116                                        // create temporary for rhs, assign value
     117                                        UntypedExpr *assgnR = new UntypedExpr( new NameExpr( "?=?" ) );
     118                                        assgnR->get_args().push_back( new VariableExpr( rhs ) );
     119                                        assgnR->get_args().push_back( rhsT );
     120                                        temps.push_back( new ExprStmt(std::list<Label>(), assgnR) );
    106121
    107           // assign rhs to lhs
    108           UntypedExpr *assgn = new UntypedExpr( new NameExpr( "?=?" ) );
    109           UntypedExpr *deref = new UntypedExpr( new NameExpr( "*?" ) );
    110           deref->get_args().push_back( new VariableExpr( lhs ) );
    111           assgn->get_args().push_back( deref );
    112           assgn->get_args().push_back( new VariableExpr( rhs ) );
    113           assigns.push_back( new ExprStmt(std::list<Label>(), assgn) );
    114 
    115         } else
    116           throw CompilerError("Solved Tuple should contain only assignment statements");
     122                                        // assign rhs to lhs
     123                                        UntypedExpr *assgn = new UntypedExpr( new NameExpr( "?=?" ) );
     124                                        UntypedExpr *deref = new UntypedExpr( new NameExpr( "*?" ) );
     125                                        deref->get_args().push_back( new VariableExpr( lhs ) );
     126                                        assgn->get_args().push_back( deref );
     127                                        assgn->get_args().push_back( new VariableExpr( rhs ) );
     128                                        assigns.push_back( new ExprStmt(std::list<Label>(), assgn) );
     129                                } else
     130                                        throw CompilerError("Solved Tuple should contain only assignment statements");
    117131         
    118         extra.splice( extra.begin(), decls );
    119         extra.splice( extra.end(), temps );
    120         extra2.splice( extra2.end(), assigns );
    121       }
    122 
    123       return tupleExpr;
    124     }
    125 
    126     throw 0; // shouldn't be here
    127   }
    128 
    129 
     132                                extra.splice( extra.begin(), decls );
     133                                extra.splice( extra.end(), temps );
     134                                extra2.splice( extra2.end(), assigns );
     135                        } // for
     136                        return tupleExpr;
     137                }
     138                throw 0; // shouldn't be here
     139        }
    130140} // namespace Tuples
    131141
     142// Local Variables: //
     143// tab-width: 4 //
     144// mode: c++ //
     145// compile-command: "make install" //
     146// End: //
Note: See TracChangeset for help on using the changeset viewer.