Changeset 51587aa


Ignore:
Timestamp:
May 18, 2015, 11:45:33 PM (8 years ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
aaron-thesis, arm-eh, 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

Location:
translator
Files:
86 edited

Legend:

Unmodified
Added
Removed
  • translator/ArgTweak/FunctionFixer.cc

    r0dd3a2f r51587aa  
    1010// Created On       : Sat May 16 08:12:38 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sat May 16 08:17:07 2015
    13 // Update Count     : 5
     12// Last Modified On : Mon May 18 23:30:39 2015
     13// Update Count     : 6
    1414//
    1515
  • translator/ArgTweak/FunctionFixer.h

    r0dd3a2f r51587aa  
    1 #ifndef _DEFS_FUNCTION_FIXER_H_
    2 #define _DEFS_FUNCTION_FIXER_H_
     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// FunctionFixer.h --
     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 23:31:58 2015
     13// Update Count     : 3
     14//
     15
     16#ifndef _FUNCTION_FIXER_H_
     17#define _FUNCTION_FIXER_H_
    318
    419#include "SynTree/Mutator.h"
     
    823
    924namespace ArgTweak {
    10   class FunctionFixer : public Mutator
    11   {
    12     typedef Mutator Parent;
     25        class FunctionFixer : public Mutator {
     26                typedef Mutator Parent;
     27          public:
     28                FunctionFixer(SymTab::Indexer *ind = 0);
     29                ~FunctionFixer();
    1330
    14   public:
    15     FunctionFixer(SymTab::Indexer *ind = 0);
    16     ~FunctionFixer();
     31                virtual DeclarationWithType *mutate( FunctionDecl *functionDecl );
     32                virtual Expression *mutate( UntypedExpr *untypedExpr ) throw ( SemanticError );
     33          private:
     34                class Matcher {
     35                        typedef std::string key;
     36                        typedef DeclarationWithType * pattern_type;
     37                        typedef Expression * permutation_type;
     38                  public:
     39                        static key null_key;
     40                        static permutation_type null_value;
    1741
    18     virtual DeclarationWithType *mutate( FunctionDecl *functionDecl );
    19     virtual Expression *mutate( UntypedExpr *untypedExpr ) throw ( SemanticError );
     42                        std::string extract_key( DeclarationWithType * );
     43                        std::string extract_key( Expression * );
    2044
    21   private:
    22     class Matcher {
    23       typedef std::string key;
    24       typedef DeclarationWithType * pattern_type;
    25       typedef Expression * permutation_type;
    26     public:
    27       static key null_key;
    28       static permutation_type null_value;
     45                        bool operator()( DeclarationWithType *, Expression * ) { return true; }
     46                };
    2947
    30       std::string extract_key( DeclarationWithType * );
    31       std::string extract_key( Expression * );
     48                SymTab::Indexer *index;
     49        };
    3250
    33       bool operator()( DeclarationWithType *, Expression * ) { return true; }
    34     };
    35 
    36     SymTab::Indexer *index;
    37   };
    38 
    39   template < class L1, class L2, class Predicate > bool align( L1 &pattern, L2 &possible_permutation, Predicate pred );
    40 
     51        template < class L1, class L2, class Predicate > bool align( L1 &pattern, L2 &possible_permutation, Predicate pred );
    4152} // namespace ArgTweak
    4253
     54#endif // _FUNCTION_FIXER_H_
    4355
    44 #endif // #ifndef _DEFS_FUNCTION_FIXER_H_
    45 
    46 /*
    47   Local Variables:
    48   mode: c++
    49   End:
    50 */
     56// Local Variables: //
     57// tab-width: 4 //
     58// mode: c++ //
     59// compile-command: "make install" //
     60// End: //
  • translator/ArgTweak/Mutate.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// Mutate.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 23:32:23 2015
     13// Update Count     : 1
     14//
     15
    116#include "SynTree/Mutator.h"
    217
     
    520
    621namespace ArgTweak {
     22        void mutate( std::list< Declaration * > translationUnit ) {
     23                FunctionFixer ff;
    724
    8   void mutate( std::list< Declaration * > translationUnit )
    9   {
    10     FunctionFixer ff;
    11 
    12     mutateAll( translationUnit, ff );
    13   }
    14 
     25                mutateAll( translationUnit, ff );
     26        }
    1527} // namespace ArgTweak
    1628
    17 
     29// Local Variables: //
     30// tab-width: 4 //
     31// mode: c++ //
     32// compile-command: "make install" //
     33// End: //
  • translator/ArgTweak/Mutate.h

    r0dd3a2f r51587aa  
    1 #ifndef ARGTWEAK_MUTATE_H
    2 #define ARGTWEAK_MUTATE_H
     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// Mutate.h --
     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 23:33:04 2015
     13// Update Count     : 2
     14//
     15
     16#ifndef _MUTATE_H
     17#define _MUTATE_H
    318
    419#include <list>
     
    823
    924namespace ArgTweak {
    10 
    11   void mutate( std::list< Declaration* > translationUnit );
    12 
     25        void mutate( std::list< Declaration* > translationUnit );
    1326} // namespace ArgTweak
    1427
    15 #endif // #ifndef ARGTWEAK_MUTATE_H
     28#endif // _MUTATE_H
    1629
    17 /*
    18   Local Variables:
    19   mode: c++
    20   End:
    21 */
     30// Local Variables: //
     31// tab-width: 4 //
     32// mode: c++ //
     33// compile-command: "make install" //
     34// End: //
  • translator/CodeGen/CodeGenerator2.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// CodeGenerator2.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 23:34:27 2015
     13// Update Count     : 1
     14//
     15
    116#include <algorithm>
    217#include <iostream>
     
    2035
    2136namespace CodeGen {
    22     int CodeGenerator2::tabsize = 4;
    23 
    24     CodeGenerator2::CodeGenerator2( std::ostream &os ) : cur_indent( 0 ), insideFunction( false ), before( os ), after() { }
    25 
    26     CodeGenerator2::CodeGenerator2( std::ostream &os, std::string init, int indent, bool infunp )
    27         : cur_indent( indent ), insideFunction( infunp ), before( os )
    28     {
    29         //before << std::string( init );
    30     }
    31 
    32     CodeGenerator2::CodeGenerator2( std::ostream &os, char *init, int indent, bool infunp )
    33         : cur_indent( indent ), insideFunction( infunp ), before( os )
    34     {
    35         //before << std::string( init );
    36     }
    37 
    38     string mangleName( DeclarationWithType *decl ) {
    39         if ( decl->get_mangleName() != "" ) {
    40             return decl->get_mangleName();
    41         } else {
    42             return decl->get_name();
    43         } // if
    44     }
    45  
    46     //*** Declarations
    47     void CodeGenerator2::visit( FunctionDecl *functionDecl ) {
    48         handleStorageClass( functionDecl );
    49         before << genType( functionDecl->get_functionType(), mangleName( functionDecl ) );
    50 
    51         // how to get this to the Functype?
    52         std::list< Declaration * > olds = functionDecl->get_oldDecls();
    53         if ( ! olds.empty() ) {
    54             before << " /* function has old declaration */";
    55         } // if
    56 
    57         // acceptAll( functionDecl->get_oldDecls(), *this );
    58         if ( functionDecl->get_statements() ) {
    59             functionDecl->get_statements()->accept(*this );
    60         } // if
    61     }
    62 
    63     void CodeGenerator2::visit( ObjectDecl *objectDecl ) {
    64         handleStorageClass( objectDecl );
    65         before << genType( objectDecl->get_type(), mangleName( objectDecl ) );
    66    
    67         if ( objectDecl->get_init() ) {
    68             before << " = ";
    69             objectDecl->get_init()->accept( *this );
    70         } // if
    71         if ( objectDecl->get_bitfieldWidth() ) {
    72             before << ":";
    73             objectDecl->get_bitfieldWidth()->accept( *this );
    74         } // if
    75     }
    76 
    77     void CodeGenerator2::handleAggregate( AggregateDecl *aggDecl ) {
    78         if ( aggDecl->get_name() != "" )
    79             before << aggDecl->get_name();
    80    
    81         std::list< Declaration * > &memb = aggDecl->get_members();
    82 
    83         if ( ! memb.empty() ) {
    84             before << endl << string( cur_indent, ' ' ) << "{" << endl;
    85 
    86             cur_indent += CodeGenerator2::tabsize;
    87             for ( std::list< Declaration* >::iterator i = memb.begin(); i != memb.end();  i++) {
    88                 before << string( cur_indent, ' ' );
    89                 (*i)->accept(*this );
    90                 before << ";" << endl;
    91             }
    92 
    93             cur_indent -= CodeGenerator2::tabsize;
    94 
    95             before << string( cur_indent, ' ' ) << "}";
    96         } // if
    97     }
    98 
    99     void CodeGenerator2::visit( StructDecl *structDecl ) {
    100         before << "struct ";
    101         handleAggregate( structDecl );
    102     }
    103 
    104     void CodeGenerator2::visit( UnionDecl *aggregateDecl ) {
    105         before << "union ";
    106         handleAggregate( aggregateDecl );
    107     }
    108  
    109     void CodeGenerator2::visit( EnumDecl *aggDecl ) {
    110         before << "enum ";
    111 
    112         if ( aggDecl->get_name() != "" )
    113             before << aggDecl->get_name();
    114    
    115         std::list< Declaration* > &memb = aggDecl->get_members();
    116 
    117         if ( ! memb.empty() ) {
    118             before << endl << "{" << endl;
    119 
    120             cur_indent += CodeGenerator2::tabsize;
    121             for ( std::list< Declaration* >::iterator i = memb.begin(); i != memb.end();  i++) {
    122                 ObjectDecl *obj = dynamic_cast< ObjectDecl* >( *i );
    123                 assert( obj );
    124                 before << string( cur_indent, ' ' ) << mangleName( obj );
    125                 if ( obj->get_init() ) {
    126                     before << " = ";
    127                     obj->get_init()->accept(*this );
    128                 } // if
    129                 before << "," << endl;
    130             }
    131 
    132             cur_indent -= CodeGenerator2::tabsize;
    133 
    134             before << "}" << endl;
    135         } // if
    136     }
    137  
    138     void CodeGenerator2::visit( ContextDecl *aggregateDecl ) {}
    139  
    140     void CodeGenerator2::visit( TypedefDecl *typeDecl ) {
    141         before << "typedef ";
    142         before << genType( typeDecl->get_base(), typeDecl->get_name() );
    143     }
    144  
    145     void CodeGenerator2::visit( TypeDecl *typeDecl ) {
    146         // really, we should mutate this into something that isn't a TypeDecl but that requires large-scale changes,
    147         // still to be done
    148         before << "extern unsigned long " << typeDecl->get_name();
    149         if ( typeDecl->get_base() ) {
    150             before << " = sizeof( " << genType( typeDecl->get_base(), "" ) << " )";
    151         } // if
    152     }
    153 
    154     void CodeGenerator2::visit( SingleInit *init ) {
    155         init->get_value()->accept( *this );
    156     }
    157 
    158     void CodeGenerator2::visit( ListInit *init ) {
    159         before << "{ ";
    160         genCommaList( init->begin_initializers(), init->end_initializers() );
    161         before << " }";
    162     }
    163 
    164     void CodeGenerator2::visit( Constant *constant ) {
    165         before << constant->get_value() ;
    166     }
    167 
    168     //*** Expressions
    169     void CodeGenerator2::visit( ApplicationExpr *applicationExpr ) {
    170         if ( VariableExpr *varExpr = dynamic_cast< VariableExpr* >( applicationExpr->get_function() ) ) {
    171             OperatorInfo opInfo;
    172             if ( varExpr->get_var()->get_linkage() == LinkageSpec::Intrinsic && operatorLookup( varExpr->get_var()->get_name(), opInfo ) ) {
    173                 std::list< Expression* >::iterator arg = applicationExpr->get_args().begin();
    174                 switch ( opInfo.type ) {
    175                   case OT_PREFIXASSIGN:
    176                   case OT_POSTFIXASSIGN:
    177                   case OT_INFIXASSIGN:
    178                     {
    179                         assert( arg != applicationExpr->get_args().end() );
    180                         if ( AddressExpr *addrExpr = dynamic_cast< AddressExpr * >( *arg ) ) {
    181            
    182                             *arg = addrExpr->get_arg();
     37        int CodeGenerator2::tabsize = 4;
     38
     39        CodeGenerator2::CodeGenerator2( std::ostream &os ) : cur_indent( 0 ), insideFunction( false ), before( os ), after() { }
     40
     41        CodeGenerator2::CodeGenerator2( std::ostream &os, std::string init, int indent, bool infunp )
     42                : cur_indent( indent ), insideFunction( infunp ), before( os ) {
     43                //before << std::string( init );
     44        }
     45
     46        CodeGenerator2::CodeGenerator2( std::ostream &os, char *init, int indent, bool infunp )
     47                : cur_indent( indent ), insideFunction( infunp ), before( os ) {
     48                //before << std::string( init );
     49        }
     50
     51        string mangleName( DeclarationWithType *decl ) {
     52                if ( decl->get_mangleName() != "" ) {
     53                        return decl->get_mangleName();
     54                } else {
     55                        return decl->get_name();
     56                } // if
     57        }
     58 
     59        //*** Declarations
     60        void CodeGenerator2::visit( FunctionDecl *functionDecl ) {
     61                handleStorageClass( functionDecl );
     62                before << genType( functionDecl->get_functionType(), mangleName( functionDecl ) );
     63
     64                // how to get this to the Functype?
     65                std::list< Declaration * > olds = functionDecl->get_oldDecls();
     66                if ( ! olds.empty() ) {
     67                        before << " /* function has old declaration */";
     68                } // if
     69
     70                // acceptAll( functionDecl->get_oldDecls(), *this );
     71                if ( functionDecl->get_statements() ) {
     72                        functionDecl->get_statements()->accept(*this );
     73                } // if
     74        }
     75
     76        void CodeGenerator2::visit( ObjectDecl *objectDecl ) {
     77                handleStorageClass( objectDecl );
     78                before << genType( objectDecl->get_type(), mangleName( objectDecl ) );
     79       
     80                if ( objectDecl->get_init() ) {
     81                        before << " = ";
     82                        objectDecl->get_init()->accept( *this );
     83                } // if
     84                if ( objectDecl->get_bitfieldWidth() ) {
     85                        before << ":";
     86                        objectDecl->get_bitfieldWidth()->accept( *this );
     87                } // if
     88        }
     89
     90        void CodeGenerator2::handleAggregate( AggregateDecl *aggDecl ) {
     91                if ( aggDecl->get_name() != "" )
     92                        before << aggDecl->get_name();
     93       
     94                std::list< Declaration * > &memb = aggDecl->get_members();
     95
     96                if ( ! memb.empty() ) {
     97                        before << endl << string( cur_indent, ' ' ) << "{" << endl;
     98
     99                        cur_indent += CodeGenerator2::tabsize;
     100                        for ( std::list< Declaration* >::iterator i = memb.begin(); i != memb.end();  i++) {
     101                                before << string( cur_indent, ' ' );
     102                                (*i)->accept(*this );
     103                                before << ";" << endl;
     104                        }
     105
     106                        cur_indent -= CodeGenerator2::tabsize;
     107
     108                        before << string( cur_indent, ' ' ) << "}";
     109                } // if
     110        }
     111
     112        void CodeGenerator2::visit( StructDecl *structDecl ) {
     113                before << "struct ";
     114                handleAggregate( structDecl );
     115        }
     116
     117        void CodeGenerator2::visit( UnionDecl *aggregateDecl ) {
     118                before << "union ";
     119                handleAggregate( aggregateDecl );
     120        }
     121 
     122        void CodeGenerator2::visit( EnumDecl *aggDecl ) {
     123                before << "enum ";
     124
     125                if ( aggDecl->get_name() != "" )
     126                        before << aggDecl->get_name();
     127       
     128                std::list< Declaration* > &memb = aggDecl->get_members();
     129
     130                if ( ! memb.empty() ) {
     131                        before << endl << "{" << endl;
     132
     133                        cur_indent += CodeGenerator2::tabsize;
     134                        for ( std::list< Declaration* >::iterator i = memb.begin(); i != memb.end();  i++) {
     135                                ObjectDecl *obj = dynamic_cast< ObjectDecl* >( *i );
     136                                assert( obj );
     137                                before << string( cur_indent, ' ' ) << mangleName( obj );
     138                                if ( obj->get_init() ) {
     139                                        before << " = ";
     140                                        obj->get_init()->accept(*this );
     141                                } // if
     142                                before << "," << endl;
     143                        } // for
     144
     145                        cur_indent -= CodeGenerator2::tabsize;
     146
     147                        before << "}" << endl;
     148                } // if
     149        }
     150 
     151        void CodeGenerator2::visit( ContextDecl *aggregateDecl ) {}
     152 
     153        void CodeGenerator2::visit( TypedefDecl *typeDecl ) {
     154                before << "typedef ";
     155                before << genType( typeDecl->get_base(), typeDecl->get_name() );
     156        }
     157 
     158        void CodeGenerator2::visit( TypeDecl *typeDecl ) {
     159                // really, we should mutate this into something that isn't a TypeDecl but that requires large-scale changes,
     160                // still to be done
     161                before << "extern unsigned long " << typeDecl->get_name();
     162                if ( typeDecl->get_base() ) {
     163                        before << " = sizeof( " << genType( typeDecl->get_base(), "" ) << " )";
     164                } // if
     165        }
     166
     167        void CodeGenerator2::visit( SingleInit *init ) {
     168                init->get_value()->accept( *this );
     169        }
     170
     171        void CodeGenerator2::visit( ListInit *init ) {
     172                before << "{ ";
     173                genCommaList( init->begin_initializers(), init->end_initializers() );
     174                before << " }";
     175        }
     176
     177        void CodeGenerator2::visit( Constant *constant ) {
     178                before << constant->get_value() ;
     179        }
     180
     181        //*** Expressions
     182        void CodeGenerator2::visit( ApplicationExpr *applicationExpr ) {
     183                if ( VariableExpr *varExpr = dynamic_cast< VariableExpr* >( applicationExpr->get_function() ) ) {
     184                        OperatorInfo opInfo;
     185                        if ( varExpr->get_var()->get_linkage() == LinkageSpec::Intrinsic && operatorLookup( varExpr->get_var()->get_name(), opInfo ) ) {
     186                                std::list< Expression* >::iterator arg = applicationExpr->get_args().begin();
     187                                switch ( opInfo.type ) {
     188                                  case OT_PREFIXASSIGN:
     189                                  case OT_POSTFIXASSIGN:
     190                                  case OT_INFIXASSIGN:
     191                                        {
     192                                                assert( arg != applicationExpr->get_args().end() );
     193                                                if ( AddressExpr *addrExpr = dynamic_cast< AddressExpr * >( *arg ) ) {
     194               
     195                                                        *arg = addrExpr->get_arg();
     196                                                } else {
     197                                                        UntypedExpr *newExpr = new UntypedExpr( new NameExpr( "*?" ) );
     198                                                        newExpr->get_args().push_back( *arg );
     199                                                        *arg = newExpr;
     200                                                } // if
     201                                                break;
     202                                        }
     203             
     204                                  default:
     205                                        // do nothing
     206                                        ;
     207                                }
     208           
     209                                switch ( opInfo.type ) {
     210                                  case OT_INDEX:
     211                                        assert( applicationExpr->get_args().size() == 2 );
     212                                        (*arg++)->accept( *this );
     213                                        before << "[";
     214                                        (*arg)->accept( *this );
     215                                        before << "]";
     216                                        break;
     217             
     218                                  case OT_CALL:
     219                                        // there are no intrinsic definitions of the function call operator
     220                                        assert( false );
     221                                        break;
     222             
     223                                  case OT_PREFIX:
     224                                  case OT_PREFIXASSIGN:
     225                                        assert( applicationExpr->get_args().size() == 1 );
     226                                        before << "(";
     227                                        before << opInfo.symbol;
     228                                        (*arg)->accept( *this );
     229                                        before << ")";
     230                                        break;
     231             
     232                                  case OT_POSTFIX:
     233                                  case OT_POSTFIXASSIGN:
     234                                        assert( applicationExpr->get_args().size() == 1 );
     235                                        (*arg)->accept( *this );
     236                                        before << opInfo.symbol;
     237                                        break;
     238
     239                                  case OT_INFIX:
     240                                  case OT_INFIXASSIGN:
     241                                        assert( applicationExpr->get_args().size() == 2 );
     242                                        before << "(";
     243                                        (*arg++)->accept( *this );
     244                                        before << opInfo.symbol;
     245                                        (*arg)->accept( *this );
     246                                        before << ")";
     247                                        break;
     248             
     249                                  case OT_CONSTANT:
     250                                        // there are no intrinsic definitions of 0 or 1 as functions
     251                                        assert( false );
     252                                }
    183253                        } else {
    184                             UntypedExpr *newExpr = new UntypedExpr( new NameExpr( "*?" ) );
    185                             newExpr->get_args().push_back( *arg );
    186                             *arg = newExpr;
     254                                varExpr->accept( *this );
     255                                before << "(";
     256                                genCommaList( applicationExpr->get_args().begin(), applicationExpr->get_args().end() );
     257                                before << ")";
    187258                        } // if
    188                         break;
    189                     }
    190          
    191                   default:
    192                     // do nothing
    193                     ;
     259                } else {
     260                        applicationExpr->get_function()->accept( *this );
     261                        before << "(";
     262                        genCommaList( applicationExpr->get_args().begin(), applicationExpr->get_args().end() );
     263                        before << ")";
     264                } // if
     265        }
     266 
     267        void CodeGenerator2::visit( UntypedExpr *untypedExpr ) {
     268                if ( NameExpr *nameExpr = dynamic_cast< NameExpr* >( untypedExpr->get_function() ) ) {
     269                        OperatorInfo opInfo;
     270                        if ( operatorLookup( nameExpr->get_name(), opInfo ) ) {
     271                                std::list< Expression* >::iterator arg = untypedExpr->get_args().begin();
     272                                switch ( opInfo.type ) {
     273                                  case OT_INDEX:
     274                                        assert( untypedExpr->get_args().size() == 2 );
     275                                        (*arg++)->accept( *this );
     276                                        before << "[";
     277                                        (*arg)->accept( *this );
     278                                        before << "]";
     279                                        break;
     280             
     281                                  case OT_CALL:
     282                                        assert( false );
     283                                        break;
     284             
     285                                  case OT_PREFIX:
     286                                  case OT_PREFIXASSIGN:
     287                                        assert( untypedExpr->get_args().size() == 1 );
     288                                        before << "(";
     289                                        before << opInfo.symbol;
     290                                        (*arg)->accept( *this );
     291                                        before << ")";
     292                                        break;
     293             
     294                                  case OT_POSTFIX:
     295                                  case OT_POSTFIXASSIGN:
     296                                        assert( untypedExpr->get_args().size() == 1 );
     297                                        (*arg)->accept( *this );
     298                                        before << opInfo.symbol;
     299                                        break;
     300 
     301                                  case OT_INFIX:
     302                                  case OT_INFIXASSIGN:
     303                                        assert( untypedExpr->get_args().size() == 2 );
     304                                        before << "(";
     305                                        (*arg++)->accept( *this );
     306                                        before << opInfo.symbol;
     307                                        (*arg)->accept( *this );
     308                                        before << ")";
     309                                        break;
     310             
     311                                  case OT_CONSTANT:
     312                                        // there are no intrinsic definitions of 0 or 1 as functions
     313                                        assert( false );
     314                                }
     315                        } else {
     316                                nameExpr->accept( *this );
     317                                before << "(";
     318                                genCommaList( untypedExpr->get_args().begin(), untypedExpr->get_args().end() );
     319                                before << ")";
     320                        } // if
     321                } else {
     322                        untypedExpr->get_function()->accept( *this );
     323                        before << "(";
     324                        genCommaList( untypedExpr->get_args().begin(), untypedExpr->get_args().end() );
     325                        before << ")";
     326                } // if
     327        }
     328 
     329        void CodeGenerator2::visit( NameExpr *nameExpr ) {
     330                OperatorInfo opInfo;
     331                if ( operatorLookup( nameExpr->get_name(), opInfo ) ) {
     332                        assert( opInfo.type == OT_CONSTANT );
     333                        before << opInfo.symbol;
     334                } else {
     335                        before << nameExpr->get_name();
     336                } // if
     337        }
     338 
     339        void CodeGenerator2::visit( AddressExpr *addressExpr ) {
     340                before << "(&";
     341                // this hack makes sure that we don't convert "constant_zero" to "0" if we're taking its address
     342                if ( VariableExpr *variableExpr = dynamic_cast< VariableExpr* >( addressExpr->get_arg() ) ) {
     343                        before << mangleName( variableExpr->get_var() );
     344                } else {
     345                        addressExpr->get_arg()->accept( *this );
     346                } // if
     347                before << ")";
     348        }
     349
     350        void CodeGenerator2::visit( CastExpr *castExpr ) {
     351                before << "((";
     352                if ( castExpr->get_results().empty() ) {
     353                        before << "void" ;
     354                } else {
     355                        before << genType( castExpr->get_results().front(), "" );
     356                } // if
     357                before << ")";
     358                castExpr->get_arg()->accept( *this );
     359                before << ")";
     360        }
     361 
     362        void CodeGenerator2::visit( UntypedMemberExpr *memberExpr ) {
     363                assert( false );
     364        }
     365 
     366        void CodeGenerator2::visit( MemberExpr *memberExpr ) {
     367                memberExpr->get_aggregate()->accept( *this );
     368                before << "." << mangleName( memberExpr->get_member() );
     369        }
     370 
     371        void CodeGenerator2::visit( VariableExpr *variableExpr ) {
     372                OperatorInfo opInfo;
     373                if ( variableExpr->get_var()->get_linkage() == LinkageSpec::Intrinsic && operatorLookup( variableExpr->get_var()->get_name(), opInfo ) && opInfo.type == OT_CONSTANT ) {
     374                        before << opInfo.symbol;
     375                } else {
     376                        before << mangleName( variableExpr->get_var() );
     377                } // if
     378        }
     379 
     380        void CodeGenerator2::visit( ConstantExpr *constantExpr ) {
     381                assert( constantExpr->get_constant() );
     382                constantExpr->get_constant()->accept( *this );
     383        }
     384 
     385        void CodeGenerator2::visit( SizeofExpr *sizeofExpr ) {
     386                before << "sizeof(";
     387                if ( sizeofExpr->get_isType() ) {
     388                        before << genType( sizeofExpr->get_type(), "" );
     389                } else {
     390                        sizeofExpr->get_expr()->accept( *this );
     391                } // if
     392                before << ")";
     393        }
     394 
     395        void CodeGenerator2::visit( LogicalExpr *logicalExpr ) {
     396                before << "(";
     397                logicalExpr->get_arg1()->accept( *this );
     398                if ( logicalExpr->get_isAnd() ) {
     399                        before << " && ";
     400                } else {
     401                        before << " || ";
     402                } // if
     403                logicalExpr->get_arg2()->accept( *this );
     404                before << ")";
     405        }
     406 
     407        void CodeGenerator2::visit( ConditionalExpr *conditionalExpr ) {
     408                before << "(";
     409                conditionalExpr->get_arg1()->accept( *this );
     410                before << " ? ";
     411                conditionalExpr->get_arg2()->accept( *this );
     412                before << " : ";
     413                conditionalExpr->get_arg3()->accept( *this );
     414                before << ")";
     415        }
     416 
     417        void CodeGenerator2::visit( CommaExpr *commaExpr ) {
     418                before << "(";
     419                commaExpr->get_arg1()->accept( *this );
     420                before << " , ";
     421                commaExpr->get_arg2()->accept( *this );
     422                before << ")";
     423        }
     424 
     425        void CodeGenerator2::visit( TupleExpr *tupleExpr ) {}
     426 
     427        void CodeGenerator2::visit( TypeExpr *typeExpr ) {}
     428 
     429 
     430        //*** Statements
     431        void CodeGenerator2::visit( CompoundStmt *compoundStmt ) {
     432                std::list<Statement*> ks = compoundStmt->get_kids();
     433
     434                before << endl << string( cur_indent, ' ' ) << "{" << endl;
     435
     436                cur_indent += CodeGenerator2::tabsize;
     437
     438                for ( std::list<Statement *>::iterator i = ks.begin(); i != ks.end();  i++) {
     439                        before << string( cur_indent, ' ' ) << printLabels( (*i)->get_labels() )  ;
     440                        (*i)->accept(*this );
     441                        shift_left();
     442                        before << endl;
    194443                }
    195        
    196                 switch ( opInfo.type ) {
    197                   case OT_INDEX:
    198                     assert( applicationExpr->get_args().size() == 2 );
    199                     (*arg++)->accept( *this );
    200                     before << "[";
    201                     (*arg)->accept( *this );
    202                     before << "]";
    203                     break;
    204          
    205                   case OT_CALL:
    206                     // there are no intrinsic definitions of the function call operator
    207                     assert( false );
    208                     break;
    209          
    210                   case OT_PREFIX:
    211                   case OT_PREFIXASSIGN:
    212                     assert( applicationExpr->get_args().size() == 1 );
    213                     before << "(";
    214                     before << opInfo.symbol;
    215                     (*arg)->accept( *this );
    216                     before << ")";
    217                     break;
    218          
    219                   case OT_POSTFIX:
    220                   case OT_POSTFIXASSIGN:
    221                     assert( applicationExpr->get_args().size() == 1 );
    222                     (*arg)->accept( *this );
    223                     before << opInfo.symbol;
    224                     break;
    225 
    226                   case OT_INFIX:
    227                   case OT_INFIXASSIGN:
    228                     assert( applicationExpr->get_args().size() == 2 );
    229                     before << "(";
    230                     (*arg++)->accept( *this );
    231                     before << opInfo.symbol;
    232                     (*arg)->accept( *this );
    233                     before << ")";
    234                     break;
    235          
    236                   case OT_CONSTANT:
    237                     // there are no intrinsic definitions of 0 or 1 as functions
    238                     assert( false );
     444                cur_indent -= CodeGenerator2::tabsize;
     445
     446                before << string( cur_indent, ' ' ) << "}" << endl;
     447        }
     448
     449        void CodeGenerator2::visit( ExprStmt *exprStmt ) {
     450                if ( exprStmt != 0 ) {
     451                        exprStmt->get_expr()->accept( *this );
     452                        shift_left();
     453                        before << ";" ;
     454                } // if
     455        }
     456
     457        void CodeGenerator2::visit( IfStmt *ifStmt ) {
     458                before << "if (";
     459                ifStmt->get_condition()->accept(*this );
     460                after += ")\n";
     461                shift_left();
     462
     463                cur_indent += CodeGenerator2::tabsize;
     464                before << string( cur_indent, ' ' );
     465                ifStmt->get_thenPart()->accept(*this );
     466                cur_indent -= CodeGenerator2::tabsize;
     467                shift_left(); before << endl;
     468
     469                if ( ifStmt->get_elsePart() != 0) {
     470                        before << string( cur_indent, ' ' ) << " else " << endl ;
     471
     472                        cur_indent += CodeGenerator2::tabsize;
     473                        ifStmt->get_elsePart()->accept(*this );
     474                        cur_indent -= CodeGenerator2::tabsize;
     475                } // if
     476        }
     477
     478        void CodeGenerator2::visit( SwitchStmt *switchStmt ) {
     479                //before << /* "\r" << */ string( cur_indent, ' ' ) << CodeGenerator2::printLabels( switchStmt->get_labels() )
     480                before << "switch (" ;
     481                switchStmt->get_condition()->accept(*this );
     482                after += ")\n";
     483                shift_left();
     484
     485                before << string( cur_indent, ' ' ) << "{" << std::endl;
     486                cur_indent += CodeGenerator2::tabsize;
     487
     488                std::list< Statement * > stmts = switchStmt->get_branches();
     489                bool lastBreak = false;
     490
     491                // horrible, horrible hack
     492                if ( dynamic_cast<BranchStmt *>( stmts.back() ) != 0 ) {
     493                        lastBreak = true;
     494                        stmts.pop_back();
     495                } // if
     496                acceptAll( stmts, *this );
     497                if ( lastBreak ) {
     498                        Statement *st = switchStmt->get_branches().back();
     499                        before << CodeGenerator2::printLabels( st->get_labels());
     500                        st->accept( *this );
     501                } // if
     502         
     503                cur_indent -= CodeGenerator2::tabsize;
     504
     505                before << /* "\r" << */ string( cur_indent, ' ' ) << "}" << endl ;
     506        }
     507
     508        void CodeGenerator2::visit( CaseStmt *caseStmt ) {
     509                before << string( cur_indent, ' ' );
     510                if ( caseStmt->isDefault())
     511                        before << "default "  ;
     512                else {
     513                        before << "case "  ;
     514                        caseStmt->get_condition()->accept(*this );
     515                } // if
     516                after += ":\n";
     517                shift_left();
     518
     519                std::list<Statement *> sts = caseStmt->get_statements();
     520
     521                cur_indent += CodeGenerator2::tabsize;
     522                for ( std::list<Statement *>::iterator i = sts.begin(); i != sts.end();  i++) {
     523                        before << /* "\r" << */ string( cur_indent, ' ' ) << printLabels( (*i)->get_labels() )  ;
     524                        (*i)->accept(*this );
     525                        shift_left();
     526                        before << ";" << endl;
    239527                }
    240             } else {
    241                 varExpr->accept( *this );
    242                 before << "(";
    243                 genCommaList( applicationExpr->get_args().begin(), applicationExpr->get_args().end() );
    244                 before << ")";
    245             } // if
    246         } else {
    247             applicationExpr->get_function()->accept( *this );
    248             before << "(";
    249             genCommaList( applicationExpr->get_args().begin(), applicationExpr->get_args().end() );
    250             before << ")";
    251         } // if
    252     }
    253  
    254     void CodeGenerator2::visit( UntypedExpr *untypedExpr ) {
    255         if ( NameExpr *nameExpr = dynamic_cast< NameExpr* >( untypedExpr->get_function() ) ) {
    256             OperatorInfo opInfo;
    257             if ( operatorLookup( nameExpr->get_name(), opInfo ) ) {
    258                 std::list< Expression* >::iterator arg = untypedExpr->get_args().begin();
    259                 switch ( opInfo.type ) {
    260                   case OT_INDEX:
    261                     assert( untypedExpr->get_args().size() == 2 );
    262                     (*arg++)->accept( *this );
    263                     before << "[";
    264                     (*arg)->accept( *this );
    265                     before << "]";
    266                     break;
    267          
    268                   case OT_CALL:
    269                     assert( false );
    270                     break;
    271          
    272                   case OT_PREFIX:
    273                   case OT_PREFIXASSIGN:
    274                     assert( untypedExpr->get_args().size() == 1 );
    275                     before << "(";
    276                     before << opInfo.symbol;
    277                     (*arg)->accept( *this );
    278                     before << ")";
    279                     break;
    280          
    281                   case OT_POSTFIX:
    282                   case OT_POSTFIXASSIGN:
    283                     assert( untypedExpr->get_args().size() == 1 );
    284                     (*arg)->accept( *this );
    285                     before << opInfo.symbol;
    286                     break;
    287  
    288                   case OT_INFIX:
    289                   case OT_INFIXASSIGN:
    290                     assert( untypedExpr->get_args().size() == 2 );
    291                     before << "(";
    292                     (*arg++)->accept( *this );
    293                     before << opInfo.symbol;
    294                     (*arg)->accept( *this );
    295                     before << ")";
    296                     break;
    297          
    298                   case OT_CONSTANT:
    299                     // there are no intrinsic definitions of 0 or 1 as functions
    300                     assert( false );
     528                cur_indent -= CodeGenerator2::tabsize;
     529        }
     530
     531        void CodeGenerator2::visit( BranchStmt *branchStmt ) {
     532                switch ( branchStmt->get_type()) {
     533                  case BranchStmt::Goto:
     534                        if ( ! branchStmt->get_target().empty() )
     535                                before << "goto " << branchStmt->get_target();
     536                        else {
     537                                if ( branchStmt->get_computedTarget() != 0 ) {
     538                                        before << "goto *";
     539                                        branchStmt->get_computedTarget()->accept( *this );
     540                                } // if
     541                        } // if
     542                        break;
     543                  case BranchStmt::Break:
     544                        before << "break";
     545                        break;
     546                  case BranchStmt::Continue:
     547                        before << "continue";
     548                        break;
    301549                }
    302             } else {
    303                 nameExpr->accept( *this );
    304                 before << "(";
    305                 genCommaList( untypedExpr->get_args().begin(), untypedExpr->get_args().end() );
    306                 before << ")";
    307             } // if
    308         } else {
    309             untypedExpr->get_function()->accept( *this );
    310             before << "(";
    311             genCommaList( untypedExpr->get_args().begin(), untypedExpr->get_args().end() );
    312             before << ")";
    313         } // if
    314     }
    315  
    316     void CodeGenerator2::visit( NameExpr *nameExpr ) {
    317         OperatorInfo opInfo;
    318         if ( operatorLookup( nameExpr->get_name(), opInfo ) ) {
    319             assert( opInfo.type == OT_CONSTANT );
    320             before << opInfo.symbol;
    321         } else {
    322             before << nameExpr->get_name();
    323         } // if
    324     }
    325  
    326     void CodeGenerator2::visit( AddressExpr *addressExpr ) {
    327         before << "(&";
    328         // this hack makes sure that we don't convert "constant_zero" to "0" if we're taking its address
    329         if ( VariableExpr *variableExpr = dynamic_cast< VariableExpr* >( addressExpr->get_arg() ) ) {
    330             before << mangleName( variableExpr->get_var() );
    331         } else {
    332             addressExpr->get_arg()->accept( *this );
    333         } // if
    334         before << ")";
    335     }
    336 
    337     void CodeGenerator2::visit( CastExpr *castExpr ) {
    338         before << "((";
    339         if ( castExpr->get_results().empty() ) {
    340             before << "void" ;
    341         } else {
    342             before << genType( castExpr->get_results().front(), "" );
    343         } // if
    344         before << ")";
    345         castExpr->get_arg()->accept( *this );
    346         before << ")";
    347     }
    348  
    349     void CodeGenerator2::visit( UntypedMemberExpr *memberExpr ) {
    350         assert( false );
    351     }
    352  
    353     void CodeGenerator2::visit( MemberExpr *memberExpr ) {
    354         memberExpr->get_aggregate()->accept( *this );
    355         before << "." << mangleName( memberExpr->get_member() );
    356     }
    357  
    358     void CodeGenerator2::visit( VariableExpr *variableExpr ) {
    359         OperatorInfo opInfo;
    360         if ( variableExpr->get_var()->get_linkage() == LinkageSpec::Intrinsic && operatorLookup( variableExpr->get_var()->get_name(), opInfo ) && opInfo.type == OT_CONSTANT ) {
    361             before << opInfo.symbol;
    362         } else {
    363             before << mangleName( variableExpr->get_var() );
    364         } // if
    365     }
    366  
    367     void CodeGenerator2::visit( ConstantExpr *constantExpr ) {
    368         assert( constantExpr->get_constant() );
    369         constantExpr->get_constant()->accept( *this );
    370     }
    371  
    372     void CodeGenerator2::visit( SizeofExpr *sizeofExpr ) {
    373         before << "sizeof(";
    374         if ( sizeofExpr->get_isType() ) {
    375             before << genType( sizeofExpr->get_type(), "" );
    376         } else {
    377             sizeofExpr->get_expr()->accept( *this );
    378         } // if
    379         before << ")";
    380     }
    381  
    382     void CodeGenerator2::visit( LogicalExpr *logicalExpr ) {
    383         before << "(";
    384         logicalExpr->get_arg1()->accept( *this );
    385         if ( logicalExpr->get_isAnd() ) {
    386             before << " && ";
    387         } else {
    388             before << " || ";
    389         } // if
    390         logicalExpr->get_arg2()->accept( *this );
    391         before << ")";
    392     }
    393  
    394     void CodeGenerator2::visit( ConditionalExpr *conditionalExpr ) {
    395         before << "(";
    396         conditionalExpr->get_arg1()->accept( *this );
    397         before << " ? ";
    398         conditionalExpr->get_arg2()->accept( *this );
    399         before << " : ";
    400         conditionalExpr->get_arg3()->accept( *this );
    401         before << ")";
    402     }
    403  
    404     void CodeGenerator2::visit( CommaExpr *commaExpr ) {
    405         before << "(";
    406         commaExpr->get_arg1()->accept( *this );
    407         before << " , ";
    408         commaExpr->get_arg2()->accept( *this );
    409         before << ")";
    410     }
    411  
    412     void CodeGenerator2::visit( TupleExpr *tupleExpr ) {}
    413  
    414     void CodeGenerator2::visit( TypeExpr *typeExpr ) {}
    415  
    416  
    417     //*** Statements
    418     void CodeGenerator2::visit( CompoundStmt *compoundStmt ) {
    419         std::list<Statement*> ks = compoundStmt->get_kids();
    420 
    421         before << endl << string( cur_indent, ' ' ) << "{" << endl;
    422 
    423         cur_indent += CodeGenerator2::tabsize;
    424 
    425         for ( std::list<Statement *>::iterator i = ks.begin(); i != ks.end();  i++) {
    426             before << string( cur_indent, ' ' ) << printLabels( (*i)->get_labels() )  ;
    427             (*i)->accept(*this );
    428             shift_left();
    429             before << endl;
    430         }
    431         cur_indent -= CodeGenerator2::tabsize;
    432 
    433         before << string( cur_indent, ' ' ) << "}" << endl;
    434     }
    435 
    436     void CodeGenerator2::visit( ExprStmt *exprStmt ) {
    437         if ( exprStmt != 0 ) {
    438             exprStmt->get_expr()->accept( *this );
    439             shift_left();
    440             before << ";" ;
    441         } // if
    442     }
    443 
    444     void CodeGenerator2::visit( IfStmt *ifStmt ) {
    445         before << "if (";
    446         ifStmt->get_condition()->accept(*this );
    447         after += ")\n";
    448         shift_left();
    449 
    450         cur_indent += CodeGenerator2::tabsize;
    451         before << string( cur_indent, ' ' );
    452         ifStmt->get_thenPart()->accept(*this );
    453         cur_indent -= CodeGenerator2::tabsize;
    454         shift_left(); before << endl;
    455 
    456         if ( ifStmt->get_elsePart() != 0) {
    457             before << string( cur_indent, ' ' ) << " else " << endl ;
    458 
    459             cur_indent += CodeGenerator2::tabsize;
    460             ifStmt->get_elsePart()->accept(*this );
    461             cur_indent -= CodeGenerator2::tabsize;
    462         } // if
    463     }
    464 
    465     void CodeGenerator2::visit( SwitchStmt *switchStmt ) {
    466         //before << /* "\r" << */ string( cur_indent, ' ' ) << CodeGenerator2::printLabels( switchStmt->get_labels() )
    467         before << "switch (" ;
    468         switchStmt->get_condition()->accept(*this );
    469         after += ")\n";
    470         shift_left();
    471 
    472         before << string( cur_indent, ' ' ) << "{" << std::endl;
    473         cur_indent += CodeGenerator2::tabsize;
    474 
    475         std::list< Statement * > stmts = switchStmt->get_branches();
    476         bool lastBreak = false;
    477 
    478         // horrible, horrible hack
    479         if ( dynamic_cast<BranchStmt *>( stmts.back() ) != 0 ) {
    480             lastBreak = true;
    481             stmts.pop_back();
    482         } // if
    483         acceptAll( stmts, *this );
    484         if ( lastBreak ) {
    485             Statement *st = switchStmt->get_branches().back();
    486             before << CodeGenerator2::printLabels( st->get_labels());
    487             st->accept( *this );
    488         } // if
    489      
    490         cur_indent -= CodeGenerator2::tabsize;
    491 
    492         before << /* "\r" << */ string( cur_indent, ' ' ) << "}" << endl ;
    493     }
    494 
    495     void CodeGenerator2::visit( CaseStmt *caseStmt ) {
    496         before << string( cur_indent, ' ' );
    497         if ( caseStmt->isDefault())
    498             before << "default "  ;
    499         else {
    500             before << "case "  ;
    501             caseStmt->get_condition()->accept(*this );
    502         } // if
    503         after += ":\n";
    504         shift_left();
    505 
    506         std::list<Statement *> sts = caseStmt->get_statements();
    507 
    508         cur_indent += CodeGenerator2::tabsize;
    509         for ( std::list<Statement *>::iterator i = sts.begin(); i != sts.end();  i++) {
    510             before << /* "\r" << */ string( cur_indent, ' ' ) << printLabels( (*i)->get_labels() )  ;
    511             (*i)->accept(*this );
    512             shift_left();
    513             before << ";" << endl;
    514         }
    515         cur_indent -= CodeGenerator2::tabsize;
    516     }
    517 
    518     void CodeGenerator2::visit( BranchStmt *branchStmt ) {
    519         switch ( branchStmt->get_type()) {
    520           case BranchStmt::Goto:
    521             if ( ! branchStmt->get_target().empty() )
    522                 before << "goto " << branchStmt->get_target();
    523             else {
    524                 if ( branchStmt->get_computedTarget() != 0 ) {
    525                     before << "goto *";
    526                     branchStmt->get_computedTarget()->accept( *this );
    527                 } // if
    528             } // if
    529             break;
    530           case BranchStmt::Break:
    531             before << "break";
    532             break;
    533           case BranchStmt::Continue:
    534             before << "continue";
    535             break;
    536         }
    537         before << ";";
    538     }
    539 
    540 
    541     void CodeGenerator2::visit( ReturnStmt *returnStmt ) {
    542         before << "return ";
    543 
    544         // xxx -- check for null expression;
    545         if ( returnStmt->get_expr() ) {
    546             returnStmt->get_expr()->accept( *this );
    547         } // if
    548         after += ";";
    549     }
    550 
    551     void CodeGenerator2::visit( WhileStmt *whileStmt ) {
    552         if ( whileStmt->get_isDoWhile() )
    553             before << "do" ;
    554         else {
    555             before << "while (" ;
    556             whileStmt->get_condition()->accept(*this );
    557             after += ")";
    558         } // if
    559         after += "{\n";
    560         shift_left();
    561 
    562         whileStmt->get_body()->accept( *this );
    563 
    564         before << /* "\r" << */ string( cur_indent, ' ' ) << "}" ;
    565 
    566         if ( whileStmt->get_isDoWhile() ) {
    567             before << " while (" ;
    568             whileStmt->get_condition()->accept(*this );
    569             after += ");";
    570         } // if
    571 
    572         after += "\n";
    573     }
    574 
    575     void CodeGenerator2::visit( ForStmt *forStmt ) {
    576         before << "for (";
    577 
    578         if ( forStmt->get_initialization() != 0 )
    579             forStmt->get_initialization()->accept( *this );
    580         else
    581             before << ";";
    582         shift_left();
    583 
    584         if ( forStmt->get_condition() != 0 )
    585             forStmt->get_condition()->accept( *this );
    586         shift_left(); before << ";";
    587 
    588         if ( forStmt->get_increment() != 0 )
    589             forStmt->get_increment()->accept( *this );
    590         shift_left(); before << ")" << endl;
    591 
    592         if ( forStmt->get_body() != 0 ) {
    593             cur_indent += CodeGenerator2::tabsize;
    594             before << string( cur_indent, ' ' ) << CodeGenerator2::printLabels( forStmt->get_body()->get_labels() );
    595             forStmt->get_body()->accept( *this );
    596             cur_indent -= CodeGenerator2::tabsize;
    597         } // if
    598     }
    599 
    600     void CodeGenerator2::visit( NullStmt *nullStmt ) {
    601         //before << /* "\r" << */ string( cur_indent, ' ' ) << CodeGenerator2::printLabels( nullStmt->get_labels() );
    602         before << "/* null statement */ ;";
    603     }
    604 
    605     void CodeGenerator2::visit( DeclStmt *declStmt ) {
    606         declStmt->get_decl()->accept( *this );
    607    
    608         if ( doSemicolon( declStmt->get_decl() ) ) {
    609             after += ";";
    610         } // if
    611         shift_left();
    612     }
    613 
    614     std::string CodeGenerator2::printLabels( std::list< Label > &l ) {
    615         std::string str( "" );
    616         l.unique();
    617 
    618         for ( std::list< Label >::iterator i = l.begin(); i != l.end(); i++ )
    619             str += *i + ": ";
    620 
    621         return str;
    622     }
    623 
    624     void CodeGenerator2::shift_left() {
    625         before << after;
    626         after = "";
    627     }
    628 
    629     void CodeGenerator2::handleStorageClass( Declaration *decl ) {
    630         switch ( decl->get_storageClass() ) {
    631           case Declaration::NoStorageClass:
    632             break;
    633           case Declaration::Extern:
    634             before << "extern ";
    635             break;
    636           case Declaration::Static:
    637             before << "static ";
    638             break;
    639           case Declaration::Auto:
    640             // silently drop storage class
    641             break;
    642           case Declaration::Register:
    643             before << "register ";
    644             break;
    645           case Declaration::Inline:
    646             before << "inline ";
    647             break;
    648           case Declaration::Fortran:
    649             before << "fortran ";
    650             break;
    651         }
    652     }
     550                before << ";";
     551        }
     552
     553
     554        void CodeGenerator2::visit( ReturnStmt *returnStmt ) {
     555                before << "return ";
     556
     557                // xxx -- check for null expression;
     558                if ( returnStmt->get_expr() ) {
     559                        returnStmt->get_expr()->accept( *this );
     560                } // if
     561                after += ";";
     562        }
     563
     564        void CodeGenerator2::visit( WhileStmt *whileStmt ) {
     565                if ( whileStmt->get_isDoWhile() )
     566                        before << "do" ;
     567                else {
     568                        before << "while (" ;
     569                        whileStmt->get_condition()->accept(*this );
     570                        after += ")";
     571                } // if
     572                after += "{\n";
     573                shift_left();
     574
     575                whileStmt->get_body()->accept( *this );
     576
     577                before << /* "\r" << */ string( cur_indent, ' ' ) << "}" ;
     578
     579                if ( whileStmt->get_isDoWhile() ) {
     580                        before << " while (" ;
     581                        whileStmt->get_condition()->accept(*this );
     582                        after += ");";
     583                } // if
     584
     585                after += "\n";
     586        }
     587
     588        void CodeGenerator2::visit( ForStmt *forStmt ) {
     589                before << "for (";
     590
     591                if ( forStmt->get_initialization() != 0 )
     592                        forStmt->get_initialization()->accept( *this );
     593                else
     594                        before << ";";
     595                shift_left();
     596
     597                if ( forStmt->get_condition() != 0 )
     598                        forStmt->get_condition()->accept( *this );
     599                shift_left(); before << ";";
     600
     601                if ( forStmt->get_increment() != 0 )
     602                        forStmt->get_increment()->accept( *this );
     603                shift_left(); before << ")" << endl;
     604
     605                if ( forStmt->get_body() != 0 ) {
     606                        cur_indent += CodeGenerator2::tabsize;
     607                        before << string( cur_indent, ' ' ) << CodeGenerator2::printLabels( forStmt->get_body()->get_labels() );
     608                        forStmt->get_body()->accept( *this );
     609                        cur_indent -= CodeGenerator2::tabsize;
     610                } // if
     611        }
     612
     613        void CodeGenerator2::visit( NullStmt *nullStmt ) {
     614                //before << /* "\r" << */ string( cur_indent, ' ' ) << CodeGenerator2::printLabels( nullStmt->get_labels() );
     615                before << "/* null statement */ ;";
     616        }
     617
     618        void CodeGenerator2::visit( DeclStmt *declStmt ) {
     619                declStmt->get_decl()->accept( *this );
     620       
     621                if ( doSemicolon( declStmt->get_decl() ) ) {
     622                        after += ";";
     623                } // if
     624                shift_left();
     625        }
     626
     627        std::string CodeGenerator2::printLabels( std::list< Label > &l ) {
     628                std::string str( "" );
     629                l.unique();
     630
     631                for ( std::list< Label >::iterator i = l.begin(); i != l.end(); i++ )
     632                        str += *i + ": ";
     633
     634                return str;
     635        }
     636
     637        void CodeGenerator2::shift_left() {
     638                before << after;
     639                after = "";
     640        }
     641
     642        void CodeGenerator2::handleStorageClass( Declaration *decl ) {
     643                switch ( decl->get_storageClass() ) {
     644                  case Declaration::NoStorageClass:
     645                        break;
     646                  case Declaration::Extern:
     647                        before << "extern ";
     648                        break;
     649                  case Declaration::Static:
     650                        before << "static ";
     651                        break;
     652                  case Declaration::Auto:
     653                        // silently drop storage class
     654                        break;
     655                  case Declaration::Register:
     656                        before << "register ";
     657                        break;
     658                  case Declaration::Inline:
     659                        before << "inline ";
     660                        break;
     661                  case Declaration::Fortran:
     662                        before << "fortran ";
     663                        break;
     664                }
     665        }
    653666} // namespace CodeGen
     667
     668// Local Variables: //
     669// tab-width: 4 //
     670// mode: c++ //
     671// compile-command: "make install" //
     672// End: //
  • translator/CodeGen/CodeGenerator2.h

    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// CodeGenerator2.h --
     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 23:35:37 2015
     13// Update Count     : 2
     14//
     15
    116#ifndef CODEGENV_H
    217#define CODEGENV_H
     
    1025
    1126namespace CodeGen {
    12     class CodeGenerator2 : public Visitor {
    13       public:
    14         static int tabsize;
     27        class CodeGenerator2 : public Visitor {
     28          public:
     29                static int tabsize;
    1530
    16         CodeGenerator2( std::ostream &os );
    17         CodeGenerator2( std::ostream &os, std::string, int indent = 0, bool infun = false );
    18         CodeGenerator2( std::ostream &os, char *, int indent = 0, bool infun = false );
     31                CodeGenerator2( std::ostream &os );
     32                CodeGenerator2( std::ostream &os, std::string, int indent = 0, bool infun = false );
     33                CodeGenerator2( std::ostream &os, char *, int indent = 0, bool infun = false );
    1934
    20         CodeGenerator2( CodeGenerator2 & );
     35                CodeGenerator2( CodeGenerator2 & );
    2136
    22         //*** Declaration
    23         virtual void visit( StructDecl * );
    24         virtual void visit( FunctionDecl * );
    25         virtual void visit( ObjectDecl * );
    26         virtual void visit( UnionDecl *aggregateDecl );
    27         virtual void visit( EnumDecl *aggregateDecl );
    28         virtual void visit( ContextDecl *aggregateDecl );
    29         virtual void visit( TypedefDecl *typeDecl );
    30         virtual void visit( TypeDecl *typeDecl );
     37                //*** Declaration
     38                virtual void visit( StructDecl * );
     39                virtual void visit( FunctionDecl * );
     40                virtual void visit( ObjectDecl * );
     41                virtual void visit( UnionDecl *aggregateDecl );
     42                virtual void visit( EnumDecl *aggregateDecl );
     43                virtual void visit( ContextDecl *aggregateDecl );
     44                virtual void visit( TypedefDecl *typeDecl );
     45                virtual void visit( TypeDecl *typeDecl );
    3146
    32         //*** Initializer
    33         virtual void visit( SingleInit * );
    34         virtual void visit( ListInit * );
     47                //*** Initializer
     48                virtual void visit( SingleInit * );
     49                virtual void visit( ListInit * );
    3550
    36         //*** Constant
    37         virtual void visit( Constant * );
     51                //*** Constant
     52                virtual void visit( Constant * );
    3853
    39         //*** Expression
    40         virtual void visit( ApplicationExpr *applicationExpr );
    41         virtual void visit( UntypedExpr *untypedExpr );
    42         virtual void visit( NameExpr *nameExpr );
    43         virtual void visit( AddressExpr *addressExpr );
    44         virtual void visit( CastExpr *castExpr );
    45         virtual void visit( UntypedMemberExpr *memberExpr );
    46         virtual void visit( MemberExpr *memberExpr );
    47         virtual void visit( VariableExpr *variableExpr );
    48         virtual void visit( ConstantExpr *constantExpr );
    49         virtual void visit( SizeofExpr *sizeofExpr );
    50         virtual void visit( LogicalExpr *logicalExpr );
    51         virtual void visit( ConditionalExpr *conditionalExpr );
    52         virtual void visit( CommaExpr *commaExpr );
    53         virtual void visit( TupleExpr *tupleExpr );
    54         virtual void visit( TypeExpr *typeExpr );
     54                //*** Expression
     55                virtual void visit( ApplicationExpr *applicationExpr );
     56                virtual void visit( UntypedExpr *untypedExpr );
     57                virtual void visit( NameExpr *nameExpr );
     58                virtual void visit( AddressExpr *addressExpr );
     59                virtual void visit( CastExpr *castExpr );
     60                virtual void visit( UntypedMemberExpr *memberExpr );
     61                virtual void visit( MemberExpr *memberExpr );
     62                virtual void visit( VariableExpr *variableExpr );
     63                virtual void visit( ConstantExpr *constantExpr );
     64                virtual void visit( SizeofExpr *sizeofExpr );
     65                virtual void visit( LogicalExpr *logicalExpr );
     66                virtual void visit( ConditionalExpr *conditionalExpr );
     67                virtual void visit( CommaExpr *commaExpr );
     68                virtual void visit( TupleExpr *tupleExpr );
     69                virtual void visit( TypeExpr *typeExpr );
    5570
    56         //*** Statements
    57         virtual void visit( CompoundStmt * );
    58         virtual void visit( ExprStmt * );
    59         virtual void visit( IfStmt * );
    60         virtual void visit( SwitchStmt * );
    61         virtual void visit( CaseStmt * );
    62         virtual void visit( BranchStmt * );
    63         virtual void visit( ReturnStmt * );
    64         virtual void visit( WhileStmt * );
    65         virtual void visit( ForStmt * );
    66         virtual void visit( NullStmt * );
    67         virtual void visit( DeclStmt * );
     71                //*** Statements
     72                virtual void visit( CompoundStmt * );
     73                virtual void visit( ExprStmt * );
     74                virtual void visit( IfStmt * );
     75                virtual void visit( SwitchStmt * );
     76                virtual void visit( CaseStmt * );
     77                virtual void visit( BranchStmt * );
     78                virtual void visit( ReturnStmt * );
     79                virtual void visit( WhileStmt * );
     80                virtual void visit( ForStmt * );
     81                virtual void visit( NullStmt * );
     82                virtual void visit( DeclStmt * );
    6883
    69         std::string get_string( void );
    70         void add_string_left( std::string s ) { before << s; }
    71         void shift_left();
    72         template< class Iterator > void genCommaList( Iterator begin, Iterator end );
    73       private:
    74         int cur_indent;
    75         bool insideFunction;
    76         std::ostream &before;
    77         std::string after;
     84                std::string get_string( void );
     85                void add_string_left( std::string s ) { before << s; }
     86                void shift_left();
     87                template< class Iterator > void genCommaList( Iterator begin, Iterator end );
     88          private:
     89                int cur_indent;
     90                bool insideFunction;
     91                std::ostream &before;
     92                std::string after;
    7893
    79         static std::string printLabels ( std::list < Label > & );
    80         void handleStorageClass( Declaration *decl );
    81         void handleAggregate( AggregateDecl *aggDecl );
    82         void handleTypedef( NamedTypeDecl *namedType );
     94                static std::string printLabels ( std::list < Label > & );
     95                void handleStorageClass( Declaration *decl );
     96                void handleAggregate( AggregateDecl *aggDecl );
     97                void handleTypedef( NamedTypeDecl *namedType );
    8398
    84     };
    85    
    86     template< class Iterator >
    87     void CodeGenerator2::genCommaList( Iterator begin, Iterator end ) {
    88         if ( begin == end ) return;
     99        };
     100       
     101        template< class Iterator >
     102        void CodeGenerator2::genCommaList( Iterator begin, Iterator end ) {
     103                if ( begin == end ) return;
    89104
    90         for ( ;; ) {
    91             (*begin++)->accept( *this );
    92             if ( begin == end ) return;
    93             before << ", ";
     105                for ( ;; ) {
     106                        (*begin++)->accept( *this );
     107                        if ( begin == end ) return;
     108                        before << ", ";
     109                } // for
    94110        }
    95     }
    96111 
    97     inline bool doSemicolon( Declaration* decl ) {
    98         if ( FunctionDecl* func = dynamic_cast< FunctionDecl* >( decl ) ) {
    99             return ! func->get_statements();
     112        inline bool doSemicolon( Declaration* decl ) {
     113                if ( FunctionDecl* func = dynamic_cast< FunctionDecl* >( decl ) ) {
     114                        return ! func->get_statements();
     115                } // if
     116                return true;
    100117        }
    101         return true;
    102     }
    103118} // namespace CodeGen
    104119
    105 #endif /* #ifndef CODEGENV_H */
     120#endif // CODEGENV_H
    106121
    107 /*
    108   Local Variables:
    109   mode: "c++"
    110   End:
    111 */
     122// Local Variables: //
     123// tab-width: 4 //
     124// mode: c++ //
     125// compile-command: "make install" //
     126// End: //
  • translator/CodeGen/FixNames.cc

    r0dd3a2f r51587aa  
    1 /*
    2  * This file is part of the Cforall project
    3  *
    4  * $Id: FixNames.cc,v 1.8 2005/08/29 20:14:12 rcbilson Exp $
    5  *
    6  */
     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// FixNames.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 23:36:42 2015
     13// Update Count     : 1
     14//
    715
    816#include "FixNames.h"
     
    1422
    1523namespace CodeGen {
     24        class FixNames : public Visitor {
     25          public:
     26                virtual void visit( ObjectDecl *objectDecl );
     27                virtual void visit( FunctionDecl *functionDecl );
     28        };
    1629
    17 class FixNames : public Visitor
    18 {
    19 public:
    20   virtual void visit( ObjectDecl *objectDecl );
    21   virtual void visit( FunctionDecl *functionDecl );
    22 };
     30        void fixNames( std::list< Declaration* > translationUnit ) {
     31                FixNames fixer;
     32                acceptAll( translationUnit, fixer );
     33        }
    2334
    24 void
    25 fixNames( std::list< Declaration* > translationUnit )
    26 {
    27   FixNames fixer;
    28   acceptAll( translationUnit, fixer );
    29 }
     35        void fixDWT( DeclarationWithType *dwt ) {
     36                if ( dwt->get_name() != "" ) {
     37                        if ( LinkageSpec::isDecoratable( dwt->get_linkage() ) ) {
     38                                dwt->set_mangleName( SymTab::Mangler::mangle( dwt ) );
     39                        } // if
     40                } // if
     41        }
    3042
    31 void
    32 fixDWT( DeclarationWithType *dwt )
    33 {
    34   if ( dwt->get_name() != "" ) {
    35     if ( LinkageSpec::isDecoratable( dwt->get_linkage() ) ) {
    36       dwt->set_mangleName( SymTab::Mangler::mangle( dwt ) );
    37     }
    38   }
    39 }
     43        void FixNames::visit( ObjectDecl *objectDecl ) {
     44                Visitor::visit( objectDecl );
     45                fixDWT( objectDecl );
     46        }
    4047
    41 void
    42 FixNames::visit( ObjectDecl *objectDecl )
    43 {
    44   Visitor::visit( objectDecl );
    45   fixDWT( objectDecl );
    46 }
     48        void FixNames::visit( FunctionDecl *functionDecl ) {
     49                Visitor::visit( functionDecl );
     50                fixDWT( functionDecl );
     51        }
     52} // namespace CodeGen
    4753
    48 void
    49 FixNames::visit( FunctionDecl *functionDecl )
    50 {
    51   Visitor::visit( functionDecl );
    52   fixDWT( functionDecl );
    53 }
    54 
    55 } // namespace CodeGen
     54// Local Variables: //
     55// tab-width: 4 //
     56// mode: c++ //
     57// compile-command: "make install" //
     58// End: //
  • translator/CodeGen/FixNames.h

    r0dd3a2f r51587aa  
    1 /*
    2  * This file is part of the Cforall project
    3  *
    4  * $Id: FixNames.h,v 1.2 2005/08/29 20:14:12 rcbilson Exp $
    5  *
    6  */
     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// FixNames.h --
     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 23:37:32 2015
     13// Update Count     : 2
     14//
    715
    816#ifndef FIXNAMES_H
     
    1220
    1321namespace CodeGen {
    14 
    15 void fixNames( std::list< Declaration* > translationUnit );
    16 
     22        void fixNames( std::list< Declaration* > translationUnit );
    1723} // namespace CodeGen
    1824
    19 #endif /* #ifndef FIXNAMES_H */
     25#endif // FIXNAMES_H
     26
     27// Local Variables: //
     28// tab-width: 4 //
     29// mode: c++ //
     30// compile-command: "make install" //
     31// End: //
  • translator/CodeGen/GenType.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// GenType.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 23:38:22 2015
     13// Update Count     : 2
     14//
     15
    116#include <strstream>
    217#include <cassert>
     
    924
    1025namespace CodeGen {
    11     class GenType : public Visitor {
    12       public:
    13         GenType( const std::string &typeString );
    14         std::string get_typeString() const { return typeString; }
    15         void set_typeString( const std::string &newValue ) { typeString = newValue; }
    16  
    17         virtual void visit( FunctionType *funcType );
    18         virtual void visit( VoidType *voidType );
    19         virtual void visit( BasicType *basicType );
    20         virtual void visit( PointerType *pointerType );
    21         virtual void visit( ArrayType *arrayType );
    22         virtual void visit( StructInstType *structInst );
    23         virtual void visit( UnionInstType *unionInst );
    24         virtual void visit( EnumInstType *enumInst );
    25         virtual void visit( TypeInstType *typeInst );
    26  
    27       private:
    28         void handleQualifiers( Type *type );
    29         void genArray( const Type::Qualifiers &qualifiers, Type *base, Expression *dimension, bool isVarLen, bool isStatic );
    30  
    31         std::string typeString;
    32     };
    33 
    34     std::string genType( Type *type, const std::string &baseString ) {
    35         GenType gt( baseString );
    36         type->accept( gt );
    37         return gt.get_typeString();
    38     }
    39 
    40     GenType::GenType( const std::string &typeString ) : typeString( typeString ) {}
    41 
    42     void GenType::visit( VoidType *voidType ) {
    43         typeString = "void " + typeString;
    44         handleQualifiers( voidType );
    45     }
    46 
    47     void GenType::visit( BasicType *basicType ) {
    48         BasicType::Kind kind = basicType->get_kind();
    49         assert( 0 <= kind && kind < BasicType::NUMBER_OF_BASIC_TYPES );
    50         typeString = std::string( BasicType::typeNames[kind] ) + " " + typeString;
    51         handleQualifiers( basicType );
    52     }
    53 
    54     void GenType::genArray( const Type::Qualifiers &qualifiers, Type *base, Expression *dimension, bool isVarLen, bool isStatic ) {
    55         std::ostrstream os;
    56         if ( typeString != "" ) {
    57             if ( typeString[ 0 ] == '*' ) {
    58                 os << "(" << typeString << ")";
    59             } else {
    60                 os << typeString;
    61             } // if
    62         } // if
    63         os << "[";
    64 
    65         if ( isStatic ) {
    66             os << "static ";
    67         } // if
    68         if ( qualifiers.isConst ) {
    69             os << "const ";
    70         } // if
    71         if ( qualifiers.isVolatile ) {
    72             os << "volatile ";
    73         } // if
    74         if ( qualifiers.isRestrict ) {
    75             os << "__restrict ";
    76         } // if
    77         if ( qualifiers.isAtomic ) {
    78             os << "_Atomic ";
    79         } // if
    80         if ( isVarLen ) {
    81             os << "*";
    82         } // if
    83         if ( dimension != 0 ) {
    84             CodeGenerator2 cg( os );
    85             dimension->accept( cg );
    86         } // if
    87         os << "]";
    88 
    89         typeString = std::string( os.str(), os.pcount() );
    90  
    91         base->accept( *this );
    92     }
    93 
    94     void GenType::visit( PointerType *pointerType ) {
    95         assert( pointerType->get_base() != 0);
    96         if ( pointerType->get_isStatic() || pointerType->get_isVarLen() || pointerType->get_dimension() ) {
    97             genArray( pointerType->get_qualifiers(), pointerType->get_base(), pointerType->get_dimension(), pointerType->get_isVarLen(), pointerType->get_isStatic() );
    98         } else {
    99             handleQualifiers( pointerType );
    100             if ( typeString[ 0 ] == '?' ) {
    101                 typeString = "* " + typeString;
    102             } else {
    103                 typeString = "*" + typeString;
    104             } // if
    105             pointerType->get_base()->accept( *this );
    106         } // if
    107     }
    108 
    109     void GenType::visit( ArrayType *arrayType ){
    110         genArray( arrayType->get_qualifiers(), arrayType->get_base(), arrayType->get_dimension(), arrayType->get_isVarLen(), arrayType->get_isStatic() );
    111     }
    112 
    113     void GenType::visit( FunctionType *funcType ) {
    114         std::ostrstream os;
    115 
    116         if ( typeString != "" ) {
    117             if ( typeString[ 0 ] == '*' ) {
    118                 os << "(" << typeString << ")";
    119             } else {
    120                 os << typeString;
    121             } // if
    122         } // if
    123  
    124         /************* parameters ***************/
    125 
    126         const std::list<DeclarationWithType *> &pars = funcType->get_parameters();
    127 
    128         if ( pars.empty() ) {
    129             if ( funcType->get_isVarArgs() ) {
    130                 os << "()";
    131             } else {
    132                 os << "(void)";
    133             } // if
    134         } else {
    135             CodeGenerator2 cg( os );
    136             os << "(" ;
    137 
    138             cg.genCommaList( pars.begin(), pars.end() );
    139 
    140             if ( funcType->get_isVarArgs() ){
    141                 os << ", ...";
    142             } // if
    143             os << ")";
    144         } // if
    145  
    146         typeString = std::string( os.str(), os.pcount() );
    147 
    148         if ( funcType->get_returnVals().size() == 0 ) {
    149             typeString = "void " + typeString;
    150         } else {
    151             funcType->get_returnVals().front()->get_type()->accept( *this );
    152         } // if
    153     }
    154 
    155     void GenType::visit( StructInstType *structInst )  {
    156         typeString = "struct " + structInst->get_name() + " " + typeString;
    157         handleQualifiers( structInst );
    158     }
    159 
    160     void GenType::visit( UnionInstType *unionInst ) {
    161         typeString = "union " + unionInst->get_name() + " " + typeString;
    162         handleQualifiers( unionInst );
    163     }
    164 
    165     void GenType::visit( EnumInstType *enumInst ) {
    166         typeString = "enum " + enumInst->get_name() + " " + typeString;
    167         handleQualifiers( enumInst );
    168     }
    169 
    170     void GenType::visit( TypeInstType *typeInst ) {
    171         typeString = typeInst->get_name() + " " + typeString;
    172         handleQualifiers( typeInst );
    173     }
    174 
    175     void GenType::handleQualifiers( Type *type ) {
    176         if ( type->get_isConst() ) {
    177             typeString = "const " + typeString;
    178         } // if
    179         if ( type->get_isVolatile() ) {
    180             typeString = "volatile " + typeString;
    181         } // if
    182         if ( type->get_isRestrict() ) {
    183             typeString = "__restrict " + typeString;
    184         } // if
    185         if ( type->get_isAtomic() ) {
    186             typeString = "_Atomic " + typeString;
    187         } // if
    188     }
     26        class GenType : public Visitor {
     27          public:
     28                GenType( const std::string &typeString );
     29                std::string get_typeString() const { return typeString; }
     30                void set_typeString( const std::string &newValue ) { typeString = newValue; }
     31 
     32                virtual void visit( FunctionType *funcType );
     33                virtual void visit( VoidType *voidType );
     34                virtual void visit( BasicType *basicType );
     35                virtual void visit( PointerType *pointerType );
     36                virtual void visit( ArrayType *arrayType );
     37                virtual void visit( StructInstType *structInst );
     38                virtual void visit( UnionInstType *unionInst );
     39                virtual void visit( EnumInstType *enumInst );
     40                virtual void visit( TypeInstType *typeInst );
     41 
     42          private:
     43                void handleQualifiers( Type *type );
     44                void genArray( const Type::Qualifiers &qualifiers, Type *base, Expression *dimension, bool isVarLen, bool isStatic );
     45 
     46                std::string typeString;
     47        };
     48
     49        std::string genType( Type *type, const std::string &baseString ) {
     50                GenType gt( baseString );
     51                type->accept( gt );
     52                return gt.get_typeString();
     53        }
     54
     55        GenType::GenType( const std::string &typeString ) : typeString( typeString ) {}
     56
     57        void GenType::visit( VoidType *voidType ) {
     58                typeString = "void " + typeString;
     59                handleQualifiers( voidType );
     60        }
     61
     62        void GenType::visit( BasicType *basicType ) {
     63                BasicType::Kind kind = basicType->get_kind();
     64                assert( 0 <= kind && kind < BasicType::NUMBER_OF_BASIC_TYPES );
     65                typeString = std::string( BasicType::typeNames[kind] ) + " " + typeString;
     66                handleQualifiers( basicType );
     67        }
     68
     69        void GenType::genArray( const Type::Qualifiers &qualifiers, Type *base, Expression *dimension, bool isVarLen, bool isStatic ) {
     70                std::ostrstream os;
     71                if ( typeString != "" ) {
     72                        if ( typeString[ 0 ] == '*' ) {
     73                                os << "(" << typeString << ")";
     74                        } else {
     75                                os << typeString;
     76                        } // if
     77                } // if
     78                os << "[";
     79
     80                if ( isStatic ) {
     81                        os << "static ";
     82                } // if
     83                if ( qualifiers.isConst ) {
     84                        os << "const ";
     85                } // if
     86                if ( qualifiers.isVolatile ) {
     87                        os << "volatile ";
     88                } // if
     89                if ( qualifiers.isRestrict ) {
     90                        os << "__restrict ";
     91                } // if
     92                if ( qualifiers.isAtomic ) {
     93                        os << "_Atomic ";
     94                } // if
     95                if ( isVarLen ) {
     96                        os << "*";
     97                } // if
     98                if ( dimension != 0 ) {
     99                        CodeGenerator2 cg( os );
     100                        dimension->accept( cg );
     101                } // if
     102                os << "]";
     103
     104                typeString = std::string( os.str(), os.pcount() );
     105 
     106                base->accept( *this );
     107        }
     108
     109        void GenType::visit( PointerType *pointerType ) {
     110                assert( pointerType->get_base() != 0);
     111                if ( pointerType->get_isStatic() || pointerType->get_isVarLen() || pointerType->get_dimension() ) {
     112                        genArray( pointerType->get_qualifiers(), pointerType->get_base(), pointerType->get_dimension(), pointerType->get_isVarLen(), pointerType->get_isStatic() );
     113                } else {
     114                        handleQualifiers( pointerType );
     115                        if ( typeString[ 0 ] == '?' ) {
     116                                typeString = "* " + typeString;
     117                        } else {
     118                                typeString = "*" + typeString;
     119                        } // if
     120                        pointerType->get_base()->accept( *this );
     121                } // if
     122        }
     123
     124        void GenType::visit( ArrayType *arrayType ){
     125                genArray( arrayType->get_qualifiers(), arrayType->get_base(), arrayType->get_dimension(), arrayType->get_isVarLen(), arrayType->get_isStatic() );
     126        }
     127
     128        void GenType::visit( FunctionType *funcType ) {
     129                std::ostrstream os;
     130
     131                if ( typeString != "" ) {
     132                        if ( typeString[ 0 ] == '*' ) {
     133                                os << "(" << typeString << ")";
     134                        } else {
     135                                os << typeString;
     136                        } // if
     137                } // if
     138 
     139                /************* parameters ***************/
     140
     141                const std::list<DeclarationWithType *> &pars = funcType->get_parameters();
     142
     143                if ( pars.empty() ) {
     144                        if ( funcType->get_isVarArgs() ) {
     145                                os << "()";
     146                        } else {
     147                                os << "(void)";
     148                        } // if
     149                } else {
     150                        CodeGenerator2 cg( os );
     151                        os << "(" ;
     152
     153                        cg.genCommaList( pars.begin(), pars.end() );
     154
     155                        if ( funcType->get_isVarArgs() ){
     156                                os << ", ...";
     157                        } // if
     158                        os << ")";
     159                } // if
     160 
     161                typeString = std::string( os.str(), os.pcount() );
     162
     163                if ( funcType->get_returnVals().size() == 0 ) {
     164                        typeString = "void " + typeString;
     165                } else {
     166                        funcType->get_returnVals().front()->get_type()->accept( *this );
     167                } // if
     168        }
     169
     170        void GenType::visit( StructInstType *structInst )  {
     171                typeString = "struct " + structInst->get_name() + " " + typeString;
     172                handleQualifiers( structInst );
     173        }
     174
     175        void GenType::visit( UnionInstType *unionInst ) {
     176                typeString = "union " + unionInst->get_name() + " " + typeString;
     177                handleQualifiers( unionInst );
     178        }
     179
     180        void GenType::visit( EnumInstType *enumInst ) {
     181                typeString = "enum " + enumInst->get_name() + " " + typeString;
     182                handleQualifiers( enumInst );
     183        }
     184
     185        void GenType::visit( TypeInstType *typeInst ) {
     186                typeString = typeInst->get_name() + " " + typeString;
     187                handleQualifiers( typeInst );
     188        }
     189
     190        void GenType::handleQualifiers( Type *type ) {
     191                if ( type->get_isConst() ) {
     192                        typeString = "const " + typeString;
     193                } // if
     194                if ( type->get_isVolatile() ) {
     195                        typeString = "volatile " + typeString;
     196                } // if
     197                if ( type->get_isRestrict() ) {
     198                        typeString = "__restrict " + typeString;
     199                } // if
     200                if ( type->get_isAtomic() ) {
     201                        typeString = "_Atomic " + typeString;
     202                } // if
     203        }
    189204} // namespace CodeGen
     205
     206// Local Variables: //
     207// tab-width: 4 //
     208// mode: c++ //
     209// compile-command: "make install" //
     210// End: //
  • translator/CodeGen/GenType.h

    r0dd3a2f r51587aa  
    1 #ifndef CODEGEN_GENTYPE_H
    2 #define CODEGEN_GENTYPE_H
     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// GenType.h --
     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 23:38:53 2015
     13// Update Count     : 1
     14//
     15
     16#ifndef _GENTYPE_H
     17#define _GENTYPE_H
    318
    419#include <string>
     
    621
    722namespace CodeGen {
    8     std::string genType( Type *type, const std::string &baseString );
     23        std::string genType( Type *type, const std::string &baseString );
    924} // namespace CodeGen
    1025
    11 #endif // CODEGEN_GENTYPE_H
     26#endif // _GENTYPE_H
     27
     28// Local Variables: //
     29// tab-width: 4 //
     30// mode: c++ //
     31// compile-command: "make install" //
     32// End: //
  • translator/CodeGen/Generate.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// Generate.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 23:39:24 2015
     13// Update Count     : 1
     14//
     15
    116#include <algorithm>
    217#include <iostream>
     
    1227
    1328namespace CodeGen {
    14     void generate( std::list< Declaration* > translationUnit, std::ostream &os, bool doIntrinsics ) {
    15         CodeGen::CodeGenerator2 cgv( os );
     29        void generate( std::list< Declaration* > translationUnit, std::ostream &os, bool doIntrinsics ) {
     30                CodeGen::CodeGenerator2 cgv( os );
    1631
    17         for ( std::list<Declaration *>::iterator i = translationUnit.begin(); i != translationUnit.end();  i++ ) {
    18             if ( LinkageSpec::isGeneratable( (*i)->get_linkage() ) && (doIntrinsics || ! LinkageSpec::isBuiltin( (*i)->get_linkage() ) ) ) {
    19                 (*i)->accept(cgv);
    20                 cgv.shift_left();
    21                 if ( doSemicolon( *i ) ) {
    22                     os << ";";
    23                 } // if
    24                 os << std::endl;
    25             } // if
    26         } // for
    27     }
     32                for ( std::list<Declaration *>::iterator i = translationUnit.begin(); i != translationUnit.end();  i++ ) {
     33                        if ( LinkageSpec::isGeneratable( (*i)->get_linkage() ) && (doIntrinsics || ! LinkageSpec::isBuiltin( (*i)->get_linkage() ) ) ) {
     34                                (*i)->accept(cgv);
     35                                cgv.shift_left();
     36                                if ( doSemicolon( *i ) ) {
     37                                        os << ";";
     38                                } // if
     39                                os << std::endl;
     40                        } // if
     41                } // for
     42        }
    2843} // namespace CodeGen
     44
     45// Local Variables: //
     46// tab-width: 4 //
     47// mode: c++ //
     48// compile-command: "make install" //
     49// End: //
  • translator/CodeGen/Generate.h

    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// Generate.h --
     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 23:39:51 2015
     13// Update Count     : 1
     14//
     15
    116#ifndef GENERATE_H
    217#define GENERATE_H
     
    823
    924namespace CodeGen {
    10 
    11   void generate( std::list< Declaration* > translationUnit, std::ostream &os, bool doIntrinsics );
    12 
     25        void generate( std::list< Declaration* > translationUnit, std::ostream &os, bool doIntrinsics );
    1326} // namespace CodeGen
    1427
    15 #endif /* #ifndef GENERATE_H */
     28#endif // GENERATE_H
     29
     30// Local Variables: //
     31// tab-width: 4 //
     32// mode: c++ //
     33// compile-command: "make install" //
     34// End: //
  • translator/CodeGen/OperatorTable.cc

    r0dd3a2f r51587aa  
    1 /*
    2  * This file is part of the Cforall project
    3  *
    4  * $Id: OperatorTable.cc,v 1.6 2003/01/19 04:19:31 rcbilson Exp $
    5  *
    6  */
     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// OperatorTable.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 23:42:07 2015
     13// Update Count     : 2
     14//
    715
    816#include <map>
    9 
    1017#include "OperatorTable.h"
    1118
    1219namespace CodeGen {
     20        namespace {
     21                const OperatorInfo tableValues[] = {
     22                        {       "?[?]",         "",             "_operator_index",                      OT_INDEX                },
     23                        {       "?()",          "",             "_operator_call",                       OT_CALL                 },
     24                        {       "?++",          "++",   "_operator_postincr",           OT_POSTFIXASSIGN        },
     25                        {       "?--",          "--",   "_operator_postdecr",           OT_POSTFIXASSIGN        },
     26                        {       "*?",           "*",    "_operator_deref",                      OT_PREFIX               },
     27                        {       "+?",           "+",    "_operator_unaryplus",          OT_PREFIX               },
     28                        {       "-?",           "-",    "_operator_unaryminus",         OT_PREFIX               },
     29                        {       "~?",           "~",    "_operator_bitnot",                     OT_PREFIX               },
     30                        {       "!?",           "!",    "_operator_lognot",                     OT_PREFIX               },
     31                        {       "++?",          "++",   "_operator_preincr",            OT_PREFIXASSIGN         },
     32                        {       "--?",          "--",   "_operator_predecr",            OT_PREFIXASSIGN         },
     33                        {       "?*?",          "*",    "_operator_multiply",           OT_INFIX                },
     34                        {       "?/?",          "/",    "_operator_divide",                     OT_INFIX                },
     35                        {       "?%?",          "%",    "_operator_modulus",            OT_INFIX                },
     36                        {       "?+?",          "+",    "_operator_add",                        OT_INFIX                },
     37                        {       "?-?",          "-",    "_operator_subtract",           OT_INFIX                },
     38                        {       "?<<?",         "<<",   "_operator_shiftleft",          OT_INFIX                },
     39                        {       "?>>?",         ">>",   "_operator_shiftright",         OT_INFIX                },
     40                        {       "?<?",          "<",    "_operator_less",                       OT_INFIX                },
     41                        {       "?>?",          ">",    "_operator_greater",            OT_INFIX                },
     42                        {       "?<=?",         "<=",   "_operator_lessequal",          OT_INFIX                },
     43                        {       "?>=?",         ">=",   "_operator_greaterequal",       OT_INFIX                },
     44                        {       "?==?",         "==",   "_operator_equal",                      OT_INFIX                },
     45                        {       "?!=?",         "!=",   "_operator_notequal",           OT_INFIX                },
     46                        {       "?&?",          "&",    "_operator_bitand",                     OT_INFIX                },
     47                        {       "?^?",          "^",    "_operator_bitxor",                     OT_INFIX                },
     48                        {       "?|?",          "|",    "_operator_bitor",                      OT_INFIX                },
     49                        {       "?=?",          "=",    "_operator_assign",                     OT_INFIXASSIGN          },
     50                        {       "?*=?",         "*=",   "_operator_multassign",         OT_INFIXASSIGN          },
     51                        {       "?/=?",         "/=",   "_operator_divassign",          OT_INFIXASSIGN          },
     52                        {       "?%=?",         "%=",   "_operator_modassign",          OT_INFIXASSIGN          },
     53                        {       "?+=?",         "+=",   "_operator_addassign",          OT_INFIXASSIGN          },
     54                        {       "?-=?",         "-=",   "_operator_subassign",          OT_INFIXASSIGN          },
     55                        {       "?<<=?",        "<<=",  "_operator_shiftleftassign",    OT_INFIXASSIGN          },
     56                        {       "?>>=?",        ">>=",  "_operator_shiftrightassign",   OT_INFIXASSIGN          },
     57                        {       "?&=?",         "&=",   "_operator_bitandassign",       OT_INFIXASSIGN          },
     58                        {       "?^=?",         "^=",   "_operator_bitxorassign",       OT_INFIXASSIGN          },
     59                        {       "?|=?",         "|=",   "_operator_bitorassign",        OT_INFIXASSIGN          },
     60                        {       "0",            "0",    "_constant_zero",                       OT_CONSTANT             },
     61                        {       "1",            "1",    "_constant_one",                        OT_CONSTANT             }
     62                };
    1363
    14 namespace {
     64                const int numOps = sizeof( tableValues ) / sizeof( OperatorInfo );
    1565
    16 const OperatorInfo tableValues[] = {
    17 {       "?[?]",         "",             "_operator_index",              OT_INDEX                },
    18 {       "?()",          "",             "_operator_call",               OT_CALL                 },
    19 {       "?++",          "++",           "_operator_postincr",           OT_POSTFIXASSIGN        },
    20 {       "?--",          "--",           "_operator_postdecr",           OT_POSTFIXASSIGN        },
    21 {       "*?",           "*",            "_operator_deref",              OT_PREFIX               },
    22 {       "+?",           "+",            "_operator_unaryplus",          OT_PREFIX               },
    23 {       "-?",           "-",            "_operator_unaryminus",         OT_PREFIX               },
    24 {       "~?",           "~",            "_operator_bitnot",             OT_PREFIX               },
    25 {       "!?",           "!",            "_operator_lognot",             OT_PREFIX               },
    26 {       "++?",          "++",           "_operator_preincr",            OT_PREFIXASSIGN         },
    27 {       "--?",          "--",           "_operator_predecr",            OT_PREFIXASSIGN         },
    28 {       "?*?",          "*",            "_operator_multiply",           OT_INFIX                },
    29 {       "?/?",          "/",            "_operator_divide",             OT_INFIX                },
    30 {       "?%?",          "%",            "_operator_modulus",            OT_INFIX                },
    31 {       "?+?",          "+",            "_operator_add",                OT_INFIX                },
    32 {       "?-?",          "-",            "_operator_subtract",           OT_INFIX                },
    33 {       "?<<?",         "<<",           "_operator_shiftleft",          OT_INFIX                },
    34 {       "?>>?",         ">>",           "_operator_shiftright",         OT_INFIX                },
    35 {       "?<?",          "<",            "_operator_less",               OT_INFIX                },
    36 {       "?>?",          ">",            "_operator_greater",            OT_INFIX                },
    37 {       "?<=?",         "<=",           "_operator_lessequal",          OT_INFIX                },
    38 {       "?>=?",         ">=",           "_operator_greaterequal",       OT_INFIX                },
    39 {       "?==?",         "==",           "_operator_equal",              OT_INFIX                },
    40 {       "?!=?",         "!=",           "_operator_notequal",           OT_INFIX                },
    41 {       "?&?",          "&",            "_operator_bitand",             OT_INFIX                },
    42 {       "?^?",          "^",            "_operator_bitxor",             OT_INFIX                },
    43 {       "?|?",          "|",            "_operator_bitor",              OT_INFIX                },
    44 {       "?=?",          "=",            "_operator_assign",             OT_INFIXASSIGN          },
    45 {       "?*=?",         "*=",           "_operator_multassign",         OT_INFIXASSIGN          },
    46 {       "?/=?",         "/=",           "_operator_divassign",          OT_INFIXASSIGN          },
    47 {       "?%=?",         "%=",           "_operator_modassign",          OT_INFIXASSIGN          },
    48 {       "?+=?",         "+=",           "_operator_addassign",          OT_INFIXASSIGN          },
    49 {       "?-=?",         "-=",           "_operator_subassign",          OT_INFIXASSIGN          },
    50 {       "?<<=?",        "<<=",          "_operator_shiftleftassign",    OT_INFIXASSIGN          },
    51 {       "?>>=?",        ">>=",          "_operator_shiftrightassign",   OT_INFIXASSIGN          },
    52 {       "?&=?",         "&=",           "_operator_bitandassign",       OT_INFIXASSIGN          },
    53 {       "?^=?",         "^=",           "_operator_bitxorassign",       OT_INFIXASSIGN          },
    54 {       "?|=?",         "|=",           "_operator_bitorassign",        OT_INFIXASSIGN          },
    55 {       "0",            "0",            "_constant_zero",               OT_CONSTANT             },
    56 {       "1",            "1",            "_constant_one",                        OT_CONSTANT             }
    57 };
     66                std::map< std::string, OperatorInfo > table;
    5867
    59 const int numOps = sizeof( tableValues ) / sizeof( OperatorInfo );
     68                void initialize() {
     69                        for ( int i = 0; i < numOps; ++i ) {
     70                                table[ tableValues[i].inputName ] = tableValues[i];
     71                        } // for
     72                }
     73        } // namespace
    6074
    61 std::map< std::string, OperatorInfo > table;
     75        bool operatorLookup( std::string funcName, OperatorInfo &info ) {
     76                static bool init = false;
     77                if ( ! init ) {
     78                        initialize();
     79                } // if
     80                std::map< std::string, OperatorInfo >::const_iterator i = table.find( funcName );
     81                if ( i == table.end() ) {
     82                        return false;
     83                } else {
     84                        info = i->second;
     85                        return true;
     86                } // if
     87        }
     88} // namespace CodeGen
    6289
    63 void
    64 initialize()
    65 {
    66   for ( int i = 0; i < numOps; ++i ) {
    67     table[ tableValues[i].inputName ] = tableValues[i];
    68   }
    69 }
    70 
    71 } // namespace
    72 
    73 bool
    74 operatorLookup( std::string funcName, OperatorInfo &info )
    75 {
    76   static bool init = false;
    77   if ( ! init ) {
    78     initialize();
    79   }
    80   std::map< std::string, OperatorInfo >::const_iterator i = table.find( funcName );
    81   if ( i == table.end() ) {
    82     return false;
    83   } else {
    84     info = i->second;
    85     return true;
    86   }
    87 }
    88 
    89 } // namespace CodeGen
     90// Local Variables: //
     91// tab-width: 4 //
     92// mode: c++ //
     93// compile-command: "make install" //
     94// End: //
  • translator/CodeGen/OperatorTable.h

    r0dd3a2f r51587aa  
    1 /*
    2  * This file is part of the Cforall project
    3  *
    4  * $Id: OperatorTable.h,v 1.4 2003/01/19 04:19:31 rcbilson Exp $
    5  *
    6  */
     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// OperatorTable.h --
     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 23:43:07 2015
     13// Update Count     : 2
     14//
    715
    8 #ifndef CODEGEN_OPERATORTABLE_H
    9 #define CODEGEN_OPERATORTABLE_H
     16#ifndef _OPERATORTABLE_H
     17#define _OPERATORTABLE_H
    1018
    1119#include <string>
    1220
    1321namespace CodeGen {
     22        enum OperatorType {
     23                OT_INDEX,
     24                OT_CALL,
     25                OT_PREFIX,
     26                OT_POSTFIX,
     27                OT_INFIX,
     28                OT_PREFIXASSIGN,
     29                OT_POSTFIXASSIGN,
     30                OT_INFIXASSIGN,
     31                OT_CONSTANT
     32        };
    1433
    15 enum OperatorType
    16 {
    17   OT_INDEX,
    18   OT_CALL,
    19   OT_PREFIX,
    20   OT_POSTFIX,
    21   OT_INFIX,
    22   OT_PREFIXASSIGN,
    23   OT_POSTFIXASSIGN,
    24   OT_INFIXASSIGN,
    25   OT_CONSTANT
    26 };
     34        struct OperatorInfo {
     35                std::string inputName;
     36                std::string symbol;
     37                std::string outputName;
     38                OperatorType type;
     39        };
    2740
    28 struct OperatorInfo
    29 {
    30   std::string inputName;
    31   std::string symbol;
    32   std::string outputName;
    33   OperatorType type;
    34 };
    35 
    36 bool operatorLookup( std::string funcName, OperatorInfo &info );
    37 
     41        bool operatorLookup( std::string funcName, OperatorInfo &info );
    3842} // namespace CodeGen
    3943
    40 #endif /* #ifndef CODEGEN_OPERATORTABLE_H */
     44#endif // _OPERATORTABLE_H
     45
     46// Local Variables: //
     47// tab-width: 4 //
     48// mode: c++ //
     49// compile-command: "make install" //
     50// End: //
  • translator/Common/CompilerError.h

    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// XXX.cc --
     8//
     9// Author           : Richard C. Bilson
     10// Created On       : Mon May 18 07:44:20 2015
     11// Last Modified By :
     12// Last Modified On :
     13// Update Count     : 0
     14//
    115#ifndef COMPILER_ERROR_H
    216#define COMPILER_ERROR_H
     
    2640  End:
    2741*/
     42// Local Variables: //
     43// tab-width: 4 //
     44// mode: c++ //
     45// compile-command: "make install" //
     46// End: //
  • translator/Common/SemanticError.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// XXX.cc --
     8//
     9// Author           : Richard C. Bilson
     10// Created On       : Mon May 18 07:44:20 2015
     11// Last Modified By :
     12// Last Modified On :
     13// Update Count     : 0
     14//
    115/*
    216 * This file is part of the Cforall project
     
    4054  std::copy( errors.begin(), errors.end(), std::ostream_iterator< std::string >( os, "\n" ) );
    4155}
     56// Local Variables: //
     57// tab-width: 4 //
     58// mode: c++ //
     59// compile-command: "make install" //
     60// End: //
  • translator/Common/SemanticError.h

    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// XXX.cc --
     8//
     9// Author           : Richard C. Bilson
     10// Created On       : Mon May 18 07:44:20 2015
     11// Last Modified By :
     12// Last Modified On :
     13// Update Count     : 0
     14//
    115/*
    216 * This file is part of the Cforall project
     
    4458
    4559#endif /* SEMANTICERROR_H */
     60// Local Variables: //
     61// tab-width: 4 //
     62// mode: c++ //
     63// compile-command: "make install" //
     64// End: //
  • translator/Common/UnimplementedError.h

    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// XXX.cc --
     8//
     9// Author           : Richard C. Bilson
     10// Created On       : Mon May 18 07:44:20 2015
     11// Last Modified By :
     12// Last Modified On :
     13// Update Count     : 0
     14//
    115/*
    216 * This file is part of the Cforall project
     
    2640
    2741#endif /* #ifndef COMMON_UNIMPLEMENTEDERROR_H */
     42// Local Variables: //
     43// tab-width: 4 //
     44// mode: c++ //
     45// compile-command: "make install" //
     46// End: //
  • translator/Common/UniqueName.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// XXX.cc --
     8//
     9// Author           : Richard C. Bilson
     10// Created On       : Mon May 18 07:44:20 2015
     11// Last Modified By :
     12// Last Modified On :
     13// Update Count     : 0
     14//
    115/*
    216 * This file is part of the Cforall project
     
    2438}
    2539
     40// Local Variables: //
     41// tab-width: 4 //
     42// mode: c++ //
     43// compile-command: "make install" //
     44// End: //
  • translator/Common/UniqueName.h

    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// XXX.cc --
     8//
     9// Author           : Richard C. Bilson
     10// Created On       : Mon May 18 07:44:20 2015
     11// Last Modified By :
     12// Last Modified On :
     13// Update Count     : 0
     14//
    115/*
    216 * This file is part of the Cforall project
     
    2438
    2539#endif /* #ifndef UNIQUENAME_H */
     40// Local Variables: //
     41// tab-width: 4 //
     42// mode: c++ //
     43// compile-command: "make install" //
     44// End: //
  • translator/Common/utility.h

    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// XXX.cc --
     8//
     9// Author           : Richard C. Bilson
     10// Created On       : Mon May 18 07:44:20 2015
     11// Last Modified By :
     12// Last Modified On :
     13// Update Count     : 0
     14//
    115/*
    216 * This file is part of the Cforall project
     
    217231  End:
    218232*/
     233// Local Variables: //
     234// tab-width: 4 //
     235// mode: c++ //
     236// compile-command: "make install" //
     237// End: //
  • translator/ControlStruct/CaseRangeMutator.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// XXX.cc --
     8//
     9// Author           : Richard C. Bilson
     10// Created On       : Mon May 18 07:44:20 2015
     11// Last Modified By :
     12// Last Modified On :
     13// Update Count     : 0
     14//
    115#include <list>
    216#include <cassert>
     
    180194    }
    181195} // namespace ControlStruct
     196// Local Variables: //
     197// tab-width: 4 //
     198// mode: c++ //
     199// compile-command: "make install" //
     200// End: //
  • translator/ControlStruct/CaseRangeMutator.h

    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// XXX.cc --
     8//
     9// Author           : Richard C. Bilson
     10// Created On       : Mon May 18 07:44:20 2015
     11// Last Modified By :
     12// Last Modified On :
     13// Update Count     : 0
     14//
    115#ifndef CASERNG_MUTATOR_H
    216#define CASERNG_MUTATOR_H
     
    3145  End:
    3246*/
     47// Local Variables: //
     48// tab-width: 4 //
     49// mode: c++ //
     50// compile-command: "make install" //
     51// End: //
  • translator/ControlStruct/ChooseMutator.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// XXX.cc --
     8//
     9// Author           : Richard C. Bilson
     10// Created On       : Mon May 18 07:44:20 2015
     11// Last Modified By :
     12// Last Modified On :
     13// Update Count     : 0
     14//
    115#include <list>
    216
     
    4458    }
    4559} // namespace ControlStruct
     60// Local Variables: //
     61// tab-width: 4 //
     62// mode: c++ //
     63// compile-command: "make install" //
     64// End: //
  • translator/ControlStruct/ChooseMutator.h

    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// XXX.cc --
     8//
     9// Author           : Richard C. Bilson
     10// Created On       : Mon May 18 07:44:20 2015
     11// Last Modified By :
     12// Last Modified On :
     13// Update Count     : 0
     14//
    115#ifndef CHOOSE_MUTATOR_H
    216#define CHOOSE_MUTATOR_H
     
    2842  End:
    2943*/
     44// Local Variables: //
     45// tab-width: 4 //
     46// mode: c++ //
     47// compile-command: "make install" //
     48// End: //
  • translator/ControlStruct/ForExprMutator.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// XXX.cc --
     8//
     9// Author           : Richard C. Bilson
     10// Created On       : Mon May 18 07:44:20 2015
     11// Last Modified By :
     12// Last Modified On :
     13// Update Count     : 0
     14//
    115#include "SynTree/Mutator.h"
    216#include "SynTree/Statement.h"
     
    2236    }
    2337} // namespace ControlStruct
     38// Local Variables: //
     39// tab-width: 4 //
     40// mode: c++ //
     41// compile-command: "make install" //
     42// End: //
  • translator/ControlStruct/ForExprMutator.h

    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// XXX.cc --
     8//
     9// Author           : Richard C. Bilson
     10// Created On       : Mon May 18 07:44:20 2015
     11// Last Modified By :
     12// Last Modified On :
     13// Update Count     : 0
     14//
    115#ifndef FOR_MUTATOR_H
    216#define FOR_MUTATOR_H
     
    2034  End:
    2135*/
     36// Local Variables: //
     37// tab-width: 4 //
     38// mode: c++ //
     39// compile-command: "make install" //
     40// End: //
  • translator/ControlStruct/LabelFixer.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// XXX.cc --
     8//
     9// Author           : Richard C. Bilson
     10// Created On       : Mon May 18 07:44:20 2015
     11// Last Modified By :
     12// Last Modified On :
     13// Update Count     : 0
     14//
    115#include <list>
    216#include <cassert>
     
    127141    }
    128142}  // namespace ControlStruct
     143// Local Variables: //
     144// tab-width: 4 //
     145// mode: c++ //
     146// compile-command: "make install" //
     147// End: //
  • translator/ControlStruct/LabelFixer.h

    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// XXX.cc --
     8//
     9// Author           : Richard C. Bilson
     10// Created On       : Mon May 18 07:44:20 2015
     11// Last Modified By :
     12// Last Modified On :
     13// Update Count     : 0
     14//
    115#ifndef LABEL_FIXER_H
    216#define LABEL_FIXER_H
     
    8094  End:
    8195*/
     96// Local Variables: //
     97// tab-width: 4 //
     98// mode: c++ //
     99// compile-command: "make install" //
     100// End: //
  • translator/ControlStruct/LabelGenerator.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// XXX.cc --
     8//
     9// Author           : Richard C. Bilson
     10// Created On       : Mon May 18 07:44:20 2015
     11// Last Modified By :
     12// Last Modified On :
     13// Update Count     : 0
     14//
    115#include <iostream>
    216#include <strstream>
     
    2236    }
    2337} // namespace ControlStruct
     38// Local Variables: //
     39// tab-width: 4 //
     40// mode: c++ //
     41// compile-command: "make install" //
     42// End: //
  • translator/ControlStruct/LabelGenerator.h

    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// XXX.cc --
     8//
     9// Author           : Richard C. Bilson
     10// Created On       : Mon May 18 07:44:20 2015
     11// Last Modified By :
     12// Last Modified On :
     13// Update Count     : 0
     14//
    115#ifndef LABEL_GENERATOR_H
    216#define LABEL_GENERATOR_H
     
    2640  End:
    2741*/
     42// Local Variables: //
     43// tab-width: 4 //
     44// mode: c++ //
     45// compile-command: "make install" //
     46// End: //
  • translator/ControlStruct/LabelTypeChecker.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// XXX.cc --
     8//
     9// Author           : Richard C. Bilson
     10// Created On       : Mon May 18 07:44:20 2015
     11// Last Modified By :
     12// Last Modified On :
     13// Update Count     : 0
     14//
    115#include <list>
    216#include <cassert>
     
    6579    }
    6680} // namespace ControlStruct
     81// Local Variables: //
     82// tab-width: 4 //
     83// mode: c++ //
     84// compile-command: "make install" //
     85// End: //
  • translator/ControlStruct/LabelTypeChecker.h

    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// XXX.cc --
     8//
     9// Author           : Richard C. Bilson
     10// Created On       : Mon May 18 07:44:20 2015
     11// Last Modified By :
     12// Last Modified On :
     13// Update Count     : 0
     14//
    115#ifndef LABEL_TYPE_H
    216#define LABEL_TYPE_H
     
    3246
    3347
     48// Local Variables: //
     49// tab-width: 4 //
     50// mode: c++ //
     51// compile-command: "make install" //
     52// End: //
  • translator/ControlStruct/MLEMutator.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// XXX.cc --
     8//
     9// Author           : Richard C. Bilson
     10// Created On       : Mon May 18 07:44:20 2015
     11// Last Modified By :
     12// Last Modified On :
     13// Update Count     : 0
     14//
    115#include <cassert>
    216#include <algorithm>
     
    192206    }
    193207} // namespace ControlStruct
     208// Local Variables: //
     209// tab-width: 4 //
     210// mode: c++ //
     211// compile-command: "make install" //
     212// End: //
  • translator/ControlStruct/MLEMutator.h

    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// XXX.cc --
     8//
     9// Author           : Richard C. Bilson
     10// Created On       : Mon May 18 07:44:20 2015
     11// Last Modified By :
     12// Last Modified On :
     13// Update Count     : 0
     14//
    115#ifndef MLE_MUTATOR_H
    216#define MLE_MUTATOR_H
     
    7185  End:
    7286*/
     87// Local Variables: //
     88// tab-width: 4 //
     89// mode: c++ //
     90// compile-command: "make install" //
     91// End: //
  • translator/ControlStruct/Mutate.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// XXX.cc --
     8//
     9// Author           : Richard C. Bilson
     10// Created On       : Mon May 18 07:44:20 2015
     11// Last Modified By :
     12// Last Modified On :
     13// Update Count     : 0
     14//
    115#include <algorithm>
    216#include <iostream>
     
    3650    }
    3751} // namespace CodeGen
     52// Local Variables: //
     53// tab-width: 4 //
     54// mode: c++ //
     55// compile-command: "make install" //
     56// End: //
  • translator/ControlStruct/Mutate.h

    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// XXX.cc --
     8//
     9// Author           : Richard C. Bilson
     10// Created On       : Mon May 18 07:44:20 2015
     11// Last Modified By :
     12// Last Modified On :
     13// Update Count     : 0
     14//
    115#ifndef CTRLS_MUTATE_H
    216#define CTRLS_MUTATE_H
     
    1832  End:
    1933*/
     34// Local Variables: //
     35// tab-width: 4 //
     36// mode: c++ //
     37// compile-command: "make install" //
     38// End: //
  • translator/Designators/Processor.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// XXX.cc --
     8//
     9// Author           : Richard C. Bilson
     10// Created On       : Mon May 18 07:44:20 2015
     11// Last Modified By :
     12// Last Modified On :
     13// Update Count     : 0
     14//
    115#include <vector>
    216#include <algorithm>
     
    146160#endif // 0
    147161} // namespaces Designators
     162// Local Variables: //
     163// tab-width: 4 //
     164// mode: c++ //
     165// compile-command: "make install" //
     166// End: //
  • translator/Designators/Processor.h

    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// XXX.cc --
     8//
     9// Author           : Richard C. Bilson
     10// Created On       : Mon May 18 07:44:20 2015
     11// Last Modified By :
     12// Last Modified On :
     13// Update Count     : 0
     14//
    115#include "SynTree/Declaration.h"
    216#include "SynTree/Expression.h"
     
    6377  End:
    6478*/
     79// Local Variables: //
     80// tab-width: 4 //
     81// mode: c++ //
     82// compile-command: "make install" //
     83// End: //
  • translator/GenPoly/Box.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// XXX.cc --
     8//
     9// Author           : Richard C. Bilson
     10// Created On       : Mon May 18 07:44:20 2015
     11// Last Modified By :
     12// Last Modified On :
     13// Update Count     : 0
     14//
    115/*
    216 * This file is part of the Cforall project
     
    10731087
    10741088} // namespace GenPoly
     1089// Local Variables: //
     1090// tab-width: 4 //
     1091// mode: c++ //
     1092// compile-command: "make install" //
     1093// End: //
  • translator/GenPoly/Box.h

    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// XXX.cc --
     8//
     9// Author           : Richard C. Bilson
     10// Created On       : Mon May 18 07:44:20 2015
     11// Last Modified By :
     12// Last Modified On :
     13// Update Count     : 0
     14//
    115/*
    216 * This file is part of the Cforall project
     
    2034
    2135#endif /* #ifndef GENPOLY_BOX_H */
     36// Local Variables: //
     37// tab-width: 4 //
     38// mode: c++ //
     39// compile-command: "make install" //
     40// End: //
  • translator/GenPoly/CopyParams.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// XXX.cc --
     8//
     9// Author           : Richard C. Bilson
     10// Created On       : Mon May 18 07:44:20 2015
     11// Last Modified By :
     12// Last Modified On :
     13// Update Count     : 0
     14//
    115#include <set>
    216#include <map>
     
    8397    }
    8498} // namespace GenPoly
     99// Local Variables: //
     100// tab-width: 4 //
     101// mode: c++ //
     102// compile-command: "make install" //
     103// End: //
  • translator/GenPoly/CopyParams.h

    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// XXX.cc --
     8//
     9// Author           : Richard C. Bilson
     10// Created On       : Mon May 18 07:44:20 2015
     11// Last Modified By :
     12// Last Modified On :
     13// Update Count     : 0
     14//
    115/*
    216 * This file is part of the Cforall project
     
    1832
    1933#endif /* #ifndef GENPOLY_COPYPARAMS_H */
     34// Local Variables: //
     35// tab-width: 4 //
     36// mode: c++ //
     37// compile-command: "make install" //
     38// End: //
  • translator/GenPoly/FindFunction.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// XXX.cc --
     8//
     9// Author           : Richard C. Bilson
     10// Created On       : Mon May 18 07:44:20 2015
     11// Last Modified By :
     12// Last Modified On :
     13// Update Count     : 0
     14//
    115/*
    216 * This file is part of the Cforall project
     
    88102
    89103} // namespace GenPoly
     104// Local Variables: //
     105// tab-width: 4 //
     106// mode: c++ //
     107// compile-command: "make install" //
     108// End: //
  • translator/GenPoly/FindFunction.h

    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// XXX.cc --
     8//
     9// Author           : Richard C. Bilson
     10// Created On       : Mon May 18 07:44:20 2015
     11// Last Modified By :
     12// Last Modified On :
     13// Update Count     : 0
     14//
    115/*
    216 * This file is part of the Cforall project
     
    2236
    2337#endif /* #ifndef FINDFUNCTION_H */
     38// Local Variables: //
     39// tab-width: 4 //
     40// mode: c++ //
     41// compile-command: "make install" //
     42// End: //
  • translator/GenPoly/GenPoly.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// XXX.cc --
     8//
     9// Author           : Richard C. Bilson
     10// Created On       : Mon May 18 07:44:20 2015
     11// Last Modified By :
     12// Last Modified On :
     13// Update Count     : 0
     14//
    115/*
    216 * This file is part of the Cforall project
     
    6377
    6478} // namespace GenPoly
     79// Local Variables: //
     80// tab-width: 4 //
     81// mode: c++ //
     82// compile-command: "make install" //
     83// End: //
  • translator/GenPoly/GenPoly.h

    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// XXX.cc --
     8//
     9// Author           : Richard C. Bilson
     10// Created On       : Mon May 18 07:44:20 2015
     11// Last Modified By :
     12// Last Modified On :
     13// Update Count     : 0
     14//
    115/*
    216 * This file is part of the Cforall project
     
    3145
    3246#endif
     47// Local Variables: //
     48// tab-width: 4 //
     49// mode: c++ //
     50// compile-command: "make install" //
     51// End: //
  • translator/GenPoly/Lvalue.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// XXX.cc --
     8//
     9// Author           : Richard C. Bilson
     10// Created On       : Mon May 18 07:44:20 2015
     11// Last Modified By :
     12// Last Modified On :
     13// Update Count     : 0
     14//
    115/*
    216 * This file is part of the Cforall project
     
    167181
    168182} // namespace GenPoly
     183// Local Variables: //
     184// tab-width: 4 //
     185// mode: c++ //
     186// compile-command: "make install" //
     187// End: //
  • translator/GenPoly/Lvalue.h

    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// XXX.cc --
     8//
     9// Author           : Richard C. Bilson
     10// Created On       : Mon May 18 07:44:20 2015
     11// Last Modified By :
     12// Last Modified On :
     13// Update Count     : 0
     14//
    115/*
    216 * This file is part of the Cforall project
     
    2034
    2135#endif /* #ifndef GENPOLY_LVALUE_H */
     36// Local Variables: //
     37// tab-width: 4 //
     38// mode: c++ //
     39// compile-command: "make install" //
     40// End: //
  • translator/GenPoly/PolyMutator.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// XXX.cc --
     8//
     9// Author           : Richard C. Bilson
     10// Created On       : Mon May 18 07:44:20 2015
     11// Last Modified By :
     12// Last Modified On :
     13// Update Count     : 0
     14//
    115/*
    216 * This file is part of the Cforall project
     
    188202/* static class method */
    189203} // namespace GenPoly
     204// Local Variables: //
     205// tab-width: 4 //
     206// mode: c++ //
     207// compile-command: "make install" //
     208// End: //
  • translator/GenPoly/PolyMutator.h

    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// XXX.cc --
     8//
     9// Author           : Richard C. Bilson
     10// Created On       : Mon May 18 07:44:20 2015
     11// Last Modified By :
     12// Last Modified On :
     13// Update Count     : 0
     14//
    115/*
    216 * This file is part of the Cforall project
     
    5973
    6074#endif /* #ifndef GENPOLY_POLYMUTATOR_H */
     75// Local Variables: //
     76// tab-width: 4 //
     77// mode: c++ //
     78// compile-command: "make install" //
     79// End: //
  • translator/GenPoly/ScrubTyVars.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// XXX.cc --
     8//
     9// Author           : Richard C. Bilson
     10// Created On       : Mon May 18 07:44:20 2015
     11// Last Modified By :
     12// Last Modified On :
     13// Update Count     : 0
     14//
    115#include "GenPoly.h"
    216#include "ScrubTyVars.h"
     
    5064    }
    5165} // namespace GenPoly
     66// Local Variables: //
     67// tab-width: 4 //
     68// mode: c++ //
     69// compile-command: "make install" //
     70// End: //
  • translator/GenPoly/ScrubTyVars.h

    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// XXX.cc --
     8//
     9// Author           : Richard C. Bilson
     10// Created On       : Mon May 18 07:44:20 2015
     11// Last Modified By :
     12// Last Modified On :
     13// Update Count     : 0
     14//
    115#ifndef GENPOLY_SCRUBTYVARS_H
    216#define GENPOLY_SCRUBTYVARS_H
     
    4256
    4357#endif // GENPOLY_SCRUBTYVARS_H
     58// Local Variables: //
     59// tab-width: 4 //
     60// mode: c++ //
     61// compile-command: "make install" //
     62// End: //
  • translator/GenPoly/Specialize.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// XXX.cc --
     8//
     9// Author           : Richard C. Bilson
     10// Created On       : Mon May 18 07:44:20 2015
     11// Last Modified By :
     12// Last Modified On :
     13// Update Count     : 0
     14//
    115/*
    216 * This file is part of the Cforall project
     
    205219
    206220} // namespace GenPoly
     221// Local Variables: //
     222// tab-width: 4 //
     223// mode: c++ //
     224// compile-command: "make install" //
     225// End: //
  • translator/GenPoly/Specialize.h

    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// XXX.cc --
     8//
     9// Author           : Richard C. Bilson
     10// Created On       : Mon May 18 07:44:20 2015
     11// Last Modified By :
     12// Last Modified On :
     13// Update Count     : 0
     14//
    115/*
    216 * This file is part of the Cforall project
     
    2034
    2135#endif /* #ifndef GENPOLY_SPECIALIZE_H */
     36// Local Variables: //
     37// tab-width: 4 //
     38// mode: c++ //
     39// compile-command: "make install" //
     40// End: //
  • translator/InitTweak/Association.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// XXX.cc --
     8//
     9// Author           : Richard C. Bilson
     10// Created On       : Mon May 18 07:44:20 2015
     11// Last Modified By :
     12// Last Modified On :
     13// Update Count     : 0
     14//
    115#include "Association.h"
    216
     
    822const int RangeAssociation::RangeAssociation::UNDEF = -1;
    923RangeAssociation::~RangeAssociation() {}
     24// Local Variables: //
     25// tab-width: 4 //
     26// mode: c++ //
     27// compile-command: "make install" //
     28// End: //
  • translator/InitTweak/Association.h

    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// XXX.cc --
     8//
     9// Author           : Richard C. Bilson
     10// Created On       : Mon May 18 07:44:20 2015
     11// Last Modified By :
     12// Last Modified On :
     13// Update Count     : 0
     14//
    115#ifndef _ASSOCIATE_H_
    216#define _ASSOCIATE_H_
     
    276290  End:
    277291*/
     292// Local Variables: //
     293// tab-width: 4 //
     294// mode: c++ //
     295// compile-command: "make install" //
     296// End: //
  • translator/InitTweak/BasicInit.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// XXX.cc --
     8//
     9// Author           : Richard C. Bilson
     10// Created On       : Mon May 18 07:44:20 2015
     11// Last Modified By :
     12// Last Modified On :
     13// Update Count     : 0
     14//
    115#include <list>
    216#include <cassert>
     
    262276} // namespace InitTweak
    263277
     278// Local Variables: //
     279// tab-width: 4 //
     280// mode: c++ //
     281// compile-command: "make install" //
     282// End: //
  • translator/InitTweak/BasicInit.h

    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// XXX.cc --
     8//
     9// Author           : Richard C. Bilson
     10// Created On       : Mon May 18 07:44:20 2015
     11// Last Modified By :
     12// Last Modified On :
     13// Update Count     : 0
     14//
    115#ifndef _BASINIT_H_
    216#define _BASINIT_H_
     
    215229  End:
    216230*/
     231// Local Variables: //
     232// tab-width: 4 //
     233// mode: c++ //
     234// compile-command: "make install" //
     235// End: //
  • translator/InitTweak/DeclarationHoister.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// XXX.cc --
     8//
     9// Author           : Richard C. Bilson
     10// Created On       : Mon May 18 07:44:20 2015
     11// Last Modified By :
     12// Last Modified On :
     13// Update Count     : 0
     14//
    115#include <list>
    216#include <cassert>
     
    4862
    4963
     64// Local Variables: //
     65// tab-width: 4 //
     66// mode: c++ //
     67// compile-command: "make install" //
     68// End: //
  • translator/InitTweak/DeclarationHoister.h

    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// XXX.cc --
     8//
     9// Author           : Richard C. Bilson
     10// Created On       : Mon May 18 07:44:20 2015
     11// Last Modified By :
     12// Last Modified On :
     13// Update Count     : 0
     14//
    115#include "SynTree/Visitor.h"
    216#include "SymTab/Indexer.h"
     
    1832  End:
    1933*/
     34// Local Variables: //
     35// tab-width: 4 //
     36// mode: c++ //
     37// compile-command: "make install" //
     38// End: //
  • translator/InitTweak/InitExpander.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// XXX.cc --
     8//
     9// Author           : Richard C. Bilson
     10// Created On       : Mon May 18 07:44:20 2015
     11// Last Modified By :
     12// Last Modified On :
     13// Update Count     : 0
     14//
    115#include <list>
    216#include <stack>
     
    3448} // namespace InitTweak
    3549
     50// Local Variables: //
     51// tab-width: 4 //
     52// mode: c++ //
     53// compile-command: "make install" //
     54// End: //
  • translator/InitTweak/InitExpander.h

    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// XXX.cc --
     8//
     9// Author           : Richard C. Bilson
     10// Created On       : Mon May 18 07:44:20 2015
     11// Last Modified By :
     12// Last Modified On :
     13// Update Count     : 0
     14//
    115#ifndef _INIT_EXPANDER_H_
    216#define _INIT_EXPANDER_H_
     
    6579  End:
    6680*/
     81// Local Variables: //
     82// tab-width: 4 //
     83// mode: c++ //
     84// compile-command: "make install" //
     85// End: //
  • translator/InitTweak/InitModel.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// XXX.cc --
     8//
     9// Author           : Richard C. Bilson
     10// Created On       : Mon May 18 07:44:20 2015
     11// Last Modified By :
     12// Last Modified On :
     13// Update Count     : 0
     14//
    115#include "SynTree/Constant.h"
    216#include "InitModel.h"
     
    208222
    209223} // namespace InitTweak
     224// Local Variables: //
     225// tab-width: 4 //
     226// mode: c++ //
     227// compile-command: "make install" //
     228// End: //
  • translator/InitTweak/InitModel.h

    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// XXX.cc --
     8//
     9// Author           : Richard C. Bilson
     10// Created On       : Mon May 18 07:44:20 2015
     11// Last Modified By :
     12// Last Modified On :
     13// Update Count     : 0
     14//
    115#ifndef _INITTWEAK_MODEL_H_
    216#define _INITTWEAK_MODEL_H_
     
    113127  End:
    114128*/
     129// Local Variables: //
     130// tab-width: 4 //
     131// mode: c++ //
     132// compile-command: "make install" //
     133// End: //
  • translator/InitTweak/Mutate.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// XXX.cc --
     8//
     9// Author           : Richard C. Bilson
     10// Created On       : Mon May 18 07:44:20 2015
     11// Last Modified By :
     12// Last Modified On :
     13// Update Count     : 0
     14//
    115#include "SynTree/Mutator.h"
    216
     
    2337
    2438
     39// Local Variables: //
     40// tab-width: 4 //
     41// mode: c++ //
     42// compile-command: "make install" //
     43// End: //
  • translator/InitTweak/Mutate.h

    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// XXX.cc --
     8//
     9// Author           : Richard C. Bilson
     10// Created On       : Mon May 18 07:44:20 2015
     11// Last Modified By :
     12// Last Modified On :
     13// Update Count     : 0
     14//
    115#ifndef INIT_MUTATE_H
    216#define INIT_MUTATE_H
     
    1933  End:
    2034*/
     35// Local Variables: //
     36// tab-width: 4 //
     37// mode: c++ //
     38// compile-command: "make install" //
     39// End: //
  • translator/InitTweak/RemoveInit.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// XXX.cc --
     8//
     9// Author           : Richard C. Bilson
     10// Created On       : Mon May 18 07:44:20 2015
     11// Last Modified By :
     12// Last Modified On :
     13// Update Count     : 0
     14//
    115#include "RemoveInit.h"
    216#include "SynTree/Declaration.h"
     
    5165} // namespace InitTweak
    5266
     67// Local Variables: //
     68// tab-width: 4 //
     69// mode: c++ //
     70// compile-command: "make install" //
     71// End: //
  • translator/InitTweak/RemoveInit.h

    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// XXX.cc --
     8//
     9// Author           : Richard C. Bilson
     10// Created On       : Mon May 18 07:44:20 2015
     11// Last Modified By :
     12// Last Modified On :
     13// Update Count     : 0
     14//
    115/*
    216 * This file is part of the Cforall project
     
    3347
    3448#endif /* #ifndef GENPOLY_POLYMUTATOR_H */
     49// Local Variables: //
     50// tab-width: 4 //
     51// mode: c++ //
     52// compile-command: "make install" //
     53// End: //
  • translator/InitTweak/diet_map.h

    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// XXX.cc --
     8//
     9// Author           : Richard C. Bilson
     10// Created On       : Mon May 18 07:44:20 2015
     11// Last Modified By :
     12// Last Modified On :
     13// Update Count     : 0
     14//
    115#include <cassert>
    216#include <string>
     
    206220  End:
    207221*/
     222// Local Variables: //
     223// tab-width: 4 //
     224// mode: c++ //
     225// compile-command: "make install" //
     226// End: //
  • 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: //
  • translator/Tuples/AssignExpand.h

    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.h --
     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:25:53 2015
     13// Update Count     : 3
     14//
     15
    116#ifndef _ASSIGN_EXPAND_H_
    217#define _ASSIGN_EXPAND_H_
     
    1126
    1227namespace Tuples {
    13   class AssignExpander : public Mutator
    14   {
    15     typedef Mutator Parent;
    16 
    17   public:
    18     AssignExpander();
    19     virtual Statement *mutate( ExprStmt *expr );
    20     virtual Expression *mutate( SolvedTupleExpr *tupleExpr );
    21 
    22   private:
    23     std::list<Statement *> extra, extra2;
    24     std::list<Expression *> replace;
    25     UniqueName temporaryNamer;
    26   };
    27 
     28        class AssignExpander : public Mutator {
     29                typedef Mutator Parent;
     30          public:
     31                AssignExpander();
     32                virtual Statement *mutate( ExprStmt *expr );
     33                virtual Expression *mutate( SolvedTupleExpr *tupleExpr );
     34          private:
     35                std::list<Statement *> extra, extra2;
     36                std::list<Expression *> replace;
     37                UniqueName temporaryNamer;
     38        };
    2839} // namespace Tuples
    2940
    3041
    31 #endif // #ifndef _ASSIGN_EXPAND_H_
     42#endif // _ASSIGN_EXPAND_H_
    3243
    33 /*
    34   Local Variables:
    35   mode: c++
    36   End:
    37 */
     44// Local Variables: //
     45// tab-width: 4 //
     46// mode: c++ //
     47// compile-command: "make install" //
     48// End: //
  • translator/Tuples/FlattenTuple.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// FlattenTuple.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:26:56 2015
     13// Update Count     : 1
     14//
     15
    116#include <list>
    217#include <vector>
     
    621#include "FlattenTuple.h"
    722
     23namespace Tuples {
     24        FlattenTuple::FlattenTuple() {
     25        }
    826
    9 namespace Tuples {
     27        FlattenTuple::~FlattenTuple() {
     28        }
    1029
    11   FlattenTuple::FlattenTuple()
    12   {
    13   }
     30        Expression *FlattenTuple::mutate( TupleExpr *tupleExpr ) {
     31                CollectArgs c;
    1432
    15   FlattenTuple::~FlattenTuple()
    16   {
    17   }
     33                acceptAll( tupleExpr->get_exprs(), c );
     34                tupleExpr->set_exprs( c.get_args() );
    1835
    19   Expression *FlattenTuple::mutate( TupleExpr *tupleExpr )
    20   {
    21     CollectArgs c;
     36                return tupleExpr;
     37        }
    2238
    23     acceptAll( tupleExpr->get_exprs(), c );
    24     tupleExpr->set_exprs( c.get_args() );
     39        void FlattenTuple::CollectArgs::visit( UntypedExpr       *expr )  {  currentArgs.insert( currentArgs.end(), expr );  }
     40        void FlattenTuple::CollectArgs::visit( NameExpr          *expr )  {  currentArgs.insert( currentArgs.end(), expr );  }
     41        void FlattenTuple::CollectArgs::visit( CastExpr          *expr )  {  currentArgs.insert( currentArgs.end(), expr );  }
     42        void FlattenTuple::CollectArgs::visit( AddressExpr       *expr )  {  currentArgs.insert( currentArgs.end(), expr );  }
     43        void FlattenTuple::CollectArgs::visit( UntypedMemberExpr *expr )  {  currentArgs.insert( currentArgs.end(), expr );  }
     44        void FlattenTuple::CollectArgs::visit( MemberExpr        *expr )  {  currentArgs.insert( currentArgs.end(), expr );  }
     45        void FlattenTuple::CollectArgs::visit( VariableExpr      *expr )  {  currentArgs.insert( currentArgs.end(), expr );  }
     46        void FlattenTuple::CollectArgs::visit( ConstantExpr      *expr )  {  currentArgs.insert( currentArgs.end(), expr );  }
     47        void FlattenTuple::CollectArgs::visit( SizeofExpr        *expr )  {  currentArgs.insert( currentArgs.end(), expr );  }
     48        void FlattenTuple::CollectArgs::visit( AttrExpr          *expr )  {  currentArgs.insert( currentArgs.end(), expr );  }
     49        void FlattenTuple::CollectArgs::visit( LogicalExpr       *expr )  {  currentArgs.insert( currentArgs.end(), expr );  }
     50        void FlattenTuple::CollectArgs::visit( ConditionalExpr   *expr )  {  currentArgs.insert( currentArgs.end(), expr );  }
     51        void FlattenTuple::CollectArgs::visit( CommaExpr         *expr )  {  currentArgs.insert( currentArgs.end(), expr );  }
     52        void FlattenTuple::CollectArgs::visit( TypeExpr          *expr )  {  currentArgs.insert( currentArgs.end(), expr );  }
     53        void FlattenTuple::CollectArgs::visit( UntypedValofExpr  *expr )  {  currentArgs.insert( currentArgs.end(), expr );  }
    2554
    26     return tupleExpr;
    27   }
     55        void FlattenTuple::CollectArgs::visit( TupleExpr *tupleExpr) {
     56                acceptAll( tupleExpr->get_exprs(), *this );
     57                //currentArgs.splice( currentArgs.end(), c.get_args() );
     58        }
     59} // namespace Tuples
    2860
    29   void FlattenTuple::CollectArgs::visit( UntypedExpr       *expr )  {  currentArgs.insert( currentArgs.end(), expr );  }
    30   void FlattenTuple::CollectArgs::visit( NameExpr          *expr )  {  currentArgs.insert( currentArgs.end(), expr );  }
    31   void FlattenTuple::CollectArgs::visit( CastExpr          *expr )  {  currentArgs.insert( currentArgs.end(), expr );  }
    32   void FlattenTuple::CollectArgs::visit( AddressExpr       *expr )  {  currentArgs.insert( currentArgs.end(), expr );  }
    33   void FlattenTuple::CollectArgs::visit( UntypedMemberExpr *expr )  {  currentArgs.insert( currentArgs.end(), expr );  }
    34   void FlattenTuple::CollectArgs::visit( MemberExpr        *expr )  {  currentArgs.insert( currentArgs.end(), expr );  }
    35   void FlattenTuple::CollectArgs::visit( VariableExpr      *expr )  {  currentArgs.insert( currentArgs.end(), expr );  }
    36   void FlattenTuple::CollectArgs::visit( ConstantExpr      *expr )  {  currentArgs.insert( currentArgs.end(), expr );  }
    37   void FlattenTuple::CollectArgs::visit( SizeofExpr        *expr )  {  currentArgs.insert( currentArgs.end(), expr );  }
    38   void FlattenTuple::CollectArgs::visit( AttrExpr          *expr )  {  currentArgs.insert( currentArgs.end(), expr );  }
    39   void FlattenTuple::CollectArgs::visit( LogicalExpr       *expr )  {  currentArgs.insert( currentArgs.end(), expr );  }
    40   void FlattenTuple::CollectArgs::visit( ConditionalExpr   *expr )  {  currentArgs.insert( currentArgs.end(), expr );  }
    41   void FlattenTuple::CollectArgs::visit( CommaExpr         *expr )  {  currentArgs.insert( currentArgs.end(), expr );  }
    42   void FlattenTuple::CollectArgs::visit( TypeExpr          *expr )  {  currentArgs.insert( currentArgs.end(), expr );  }
    43   void FlattenTuple::CollectArgs::visit( UntypedValofExpr  *expr )  {  currentArgs.insert( currentArgs.end(), expr );  }
    44 
    45   void FlattenTuple::CollectArgs::visit( TupleExpr *tupleExpr)
    46   {
    47     acceptAll( tupleExpr->get_exprs(), *this );
    48 
    49     //currentArgs.splice( currentArgs.end(), c.get_args() );
    50   }
    51 } // namespace Tuples
     61// Local Variables: //
     62// tab-width: 4 //
     63// mode: c++ //
     64// compile-command: "make install" //
     65// End: //
  • translator/Tuples/FlattenTuple.h

    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// FlattenTuple.h --
     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:28:15 2015
     13// Update Count     : 3
     14//
     15
    116#ifndef _FLATTEN_TUPLE_H_
    217#define _FLATTEN_TUPLE_H_
     
    823
    924namespace Tuples {
    10   class FlattenTuple : public Mutator
    11   {
    12     typedef Mutator Parent;
     25        class FlattenTuple : public Mutator {
     26                typedef Mutator Parent;
     27          public:
     28                FlattenTuple();
     29                ~FlattenTuple();
    1330
    14   public:
    15     FlattenTuple();
    16     ~FlattenTuple();
     31                virtual Expression *mutate( TupleExpr *tupleExpr );
     32          private:
     33                class CollectArgs : public Visitor {
     34                  public:
     35                        virtual void visit( UntypedExpr * );
     36                        virtual void visit( NameExpr * );
     37                        virtual void visit( CastExpr *);
     38                        virtual void visit( AddressExpr * );
     39                        virtual void visit( UntypedMemberExpr * );
     40                        virtual void visit( MemberExpr * );
     41                        virtual void visit( VariableExpr * );
     42                        virtual void visit( ConstantExpr * );
     43                        virtual void visit( SizeofExpr * );
     44                        virtual void visit( AttrExpr * );
     45                        virtual void visit( LogicalExpr * );
     46                        virtual void visit( ConditionalExpr * );
     47                        virtual void visit( CommaExpr * );
     48                        virtual void visit( TypeExpr * );
     49                        virtual void visit( UntypedValofExpr * );
    1750
    18     virtual Expression *mutate( TupleExpr *tupleExpr );
     51                        virtual void visit( TupleExpr *tupleExpr );
    1952
    20   private:
    21     class CollectArgs : public Visitor
    22     {
    23     public:
    24       virtual void visit( UntypedExpr * );
    25       virtual void visit( NameExpr * );
    26       virtual void visit( CastExpr *);
    27       virtual void visit( AddressExpr * );
    28       virtual void visit( UntypedMemberExpr * );
    29       virtual void visit( MemberExpr * );
    30       virtual void visit( VariableExpr * );
    31       virtual void visit( ConstantExpr * );
    32       virtual void visit( SizeofExpr * );
    33       virtual void visit( AttrExpr * );
    34       virtual void visit( LogicalExpr * );
    35       virtual void visit( ConditionalExpr * );
    36       virtual void visit( CommaExpr * );
    37       virtual void visit( TypeExpr * );
    38       virtual void visit( UntypedValofExpr * );
     53                        std::list< Expression *> &get_args() { return currentArgs; }
     54                  private:
     55                        std::list< Expression * > currentArgs;
     56                };
    3957
    40       virtual void visit( TupleExpr *tupleExpr );
    41 
    42       std::list< Expression *> &get_args() { return currentArgs; }
    43     private:
    44       std::list< Expression * > currentArgs;
    45     };
    46 
    47   };
    48 
     58        };
    4959} // namespace Tuples
    5060
     61#endif // _FLATTEN_TUPLE_H_
    5162
    52 #endif // #ifndef _FLATTEN_TUPLE_H_
    53 
    54 /*
    55   Local Variables:
    56   mode: c++
    57   End:
    58 */
     63// Local Variables: //
     64// tab-width: 4 //
     65// mode: c++ //
     66// compile-command: "make install" //
     67// End: //
  • translator/Tuples/FunctionChecker.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// FunctionChecker.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:59:55 2015
     13// Update Count     : 3
     14//
     15
    116#include "FunctionChecker.h"
    217#include "FunctionFixer.h"
     
    823
    924namespace Tuples {
    10   using namespace std;
     25        using namespace std;
    1126
    12   void checkFunctions( std::list< Declaration * > translationUnit )
    13   {
    14     FunctionChecker fchk(true);
    15     TupleDistrib td;
    16     FunctionFixer ff;
     27        void checkFunctions( std::list< Declaration * > translationUnit ) {
     28                FunctionChecker fchk( true );
     29                TupleDistrib td;
     30                FunctionFixer ff;
    1731
    18     mutateAll( translationUnit , fchk );
    19     mutateAll( translationUnit , ff );
    20     mutateAll( translationUnit , td );
    21     return;
    22   }
    23 
    24   FunctionChecker::FunctionChecker( bool _topLevel, UniqueName *_nameGen ) : topLevel( _topLevel ), nameGen( _nameGen ) {
    25     if ( topLevel) {
    26       assert( ! nameGen );
    27       nameGen = new UniqueName("_MVR_");
    28     } else
    29       assert( nameGen );
    30   }
    31 
    32   FunctionChecker::~FunctionChecker() {
    33     if ( topLevel) {
    34       delete nameGen;
    35       nameGen = 0;
    36     }
    37   }
    38 
    39   Statement* FunctionChecker::mutate(ExprStmt *exprStmt) {
    40     exprStmt->set_expr( maybeMutate( exprStmt->get_expr(), *this ) );
    41     if ( ! tempExpr.empty() ) {
    42       assert ( ! temporaries.empty() );
    43       CompoundStmt *newBlock = new CompoundStmt( std::list< Label >() );
    44       // declarations
    45       for ( std::list< ObjectDecl *>::iterator d = temporaries.begin(); d != temporaries.end(); ++d )
    46         newBlock->get_kids().push_back( new DeclStmt( std::list<Label>(), *d ) );
    47       // new expression statements
    48       for ( std::list< Expression *>::iterator e = tempExpr.begin(); e != tempExpr.end(); ++e )
    49         newBlock->get_kids().push_back( new ExprStmt( std::list<Label>(), *e ) );
    50 
    51       newBlock->get_kids().push_back( exprStmt );
    52       return newBlock;
    53     } else
    54       return exprStmt;
    55   }
    56 
    57   Expression* FunctionChecker::mutate(ApplicationExpr *applicationExpr) {
    58     if ( topLevel )
    59       ; // In top level of Functionchecker
    60 
    61     if ( applicationExpr->get_results().size() > 1 ) {
    62       for ( std::list< Type *>::iterator res = applicationExpr->get_results().begin(); res != applicationExpr->get_results().end(); res++ )
    63         temporaries.push_back( new ObjectDecl(nameGen->newName(),Declaration::Auto,LinkageSpec::AutoGen, 0, (*res)->clone(), 0 ) );
    64 
    65       assert( ! temporaries.empty() );
    66     }
    67 
    68     applicationExpr->set_function(  maybeMutate( applicationExpr->get_function(), *this ) );
    69 
    70     std::list< Expression * > newArgs;
    71     for ( std::list< Expression *>::iterator e = applicationExpr->get_args().begin(); e != applicationExpr->get_args().end(); ++e ) {
    72       FunctionChecker rec( false, nameGen );
    73       (*e)->acceptMutator( rec );
    74 
    75       if ( ! rec.temporaries.empty() ) {
    76         TupleExpr *lhs = new TupleExpr;
    77         std::list< Expression * > &tmem = lhs->get_exprs();
    78         for ( std::list<ObjectDecl *>::iterator d = rec.temporaries.begin();  d != rec.temporaries.end(); ++d ) {
    79           tmem.push_back( new VariableExpr( *d ) );
    80           newArgs.push_back( new VariableExpr( *d ) );
     32                mutateAll( translationUnit , fchk );
     33                mutateAll( translationUnit , ff );
     34                mutateAll( translationUnit , td );
     35                return;
    8136        }
    8237
    83         // construct tuple assignment
    84         std::list<Expression *> args;
    85         args.push_back( new AddressExpr(lhs) );
    86         args.push_back( *e );
    87         tempExpr.push_back( new UntypedExpr( new NameExpr("?=?"), args ) );
     38        FunctionChecker::FunctionChecker( bool _topLevel, UniqueName *_nameGen ) : topLevel( _topLevel ), nameGen( _nameGen ) {
     39                if ( topLevel ) {
     40                        assert( ! nameGen );
     41                        nameGen = new UniqueName("_MVR_");
     42                } else
     43                        assert( nameGen );
     44        }
    8845
    89         temporaries.splice( temporaries.end(), rec.temporaries );
    90       } else
    91         newArgs.push_back( *e );
    92       // percolate to recursive calls
    93     }
     46        FunctionChecker::~FunctionChecker() {
     47                if ( topLevel ) {
     48                        delete nameGen;
     49                        nameGen = 0;
     50                }
     51        }
    9452
    95     applicationExpr->get_args().clear();
    96     std::copy( newArgs.begin(), newArgs.end(), back_inserter(applicationExpr->get_args()) );
     53        Statement* FunctionChecker::mutate( ExprStmt *exprStmt ) {
     54                exprStmt->set_expr( maybeMutate( exprStmt->get_expr(), *this ) );
     55                if ( ! tempExpr.empty() ) {
     56                        assert ( ! temporaries.empty() );
     57                        CompoundStmt *newBlock = new CompoundStmt( std::list< Label >() );
     58                        // declarations
     59                        for ( std::list< ObjectDecl *>::iterator d = temporaries.begin(); d != temporaries.end(); ++d )
     60                                newBlock->get_kids().push_back( new DeclStmt( std::list<Label>(), *d ) );
     61                        // new expression statements
     62                        for ( std::list< Expression *>::iterator e = tempExpr.begin(); e != tempExpr.end(); ++e )
     63                                newBlock->get_kids().push_back( new ExprStmt( std::list<Label>(), *e ) );
    9764
    98     return applicationExpr;
    99   }
     65                        newBlock->get_kids().push_back( exprStmt );
     66                        return newBlock;
     67                } else
     68                        return exprStmt;
     69        }
    10070
    101   Expression* TupleDistrib::mutate(UntypedExpr *expr) {
    102     if (  NameExpr *assgnop = dynamic_cast< NameExpr * >(expr->get_function()) ) {
    103       if ( assgnop->get_name() == std::string("?=?") ) {
    104         std::list<Expression *> &args = expr->get_args();
    105         assert(args.size() == 2);
    106         //if args.front() points to a tuple and if args.back() is already resolved
    107         if ( AddressExpr *addr = dynamic_cast<AddressExpr *>(args.front()) )
    108           if ( TupleExpr *lhs = dynamic_cast<TupleExpr *>(addr->get_arg()) )
    109             if ( ApplicationExpr *rhs = dynamic_cast<ApplicationExpr *>( args.back() ) ) {
    110               for ( std::list<Expression *>::iterator tc = lhs->get_exprs().begin(); tc != lhs->get_exprs().end(); ++tc )
    111                 rhs->get_args().push_back( new AddressExpr( *tc ) );
    112               return rhs; // XXX
    113             }
    114       } else
    115         assert(false); // It's not an assignment, shouldn't be here
    116     }
    117     return expr;
    118   }
     71        Expression* FunctionChecker::mutate( ApplicationExpr *applicationExpr ) {
     72                if ( topLevel )
     73                        ; // In top level of Functionchecker
    11974
    120 } // namespace Tuples
     75                if ( applicationExpr->get_results().size() > 1 ) {
     76                        for ( std::list< Type *>::iterator res = applicationExpr->get_results().begin(); res != applicationExpr->get_results().end(); res++ )
     77                                temporaries.push_back( new ObjectDecl( nameGen->newName(),Declaration::Auto,LinkageSpec::AutoGen, 0, (*res )->clone(), 0 ) );
     78
     79                        assert( ! temporaries.empty() );
     80                }
     81
     82                applicationExpr->set_function(  maybeMutate( applicationExpr->get_function(), *this ) );
     83
     84                std::list< Expression * > newArgs;
     85                for ( std::list< Expression *>::iterator e = applicationExpr->get_args().begin(); e != applicationExpr->get_args().end(); ++e ) {
     86                        FunctionChecker rec( false, nameGen );
     87                        (*e )->acceptMutator( rec );
     88
     89                        if ( ! rec.temporaries.empty() ) {
     90                                TupleExpr *lhs = new TupleExpr;
     91                                std::list< Expression * > &tmem = lhs->get_exprs();
     92                                for ( std::list<ObjectDecl *>::iterator d = rec.temporaries.begin();  d != rec.temporaries.end(); ++d ) {
     93                                        tmem.push_back( new VariableExpr( *d ) );
     94                                        newArgs.push_back( new VariableExpr( *d ) );
     95                                }
     96
     97                                // construct tuple assignment
     98                                std::list<Expression *> args;
     99                                args.push_back( new AddressExpr( lhs ) );
     100                                args.push_back( *e );
     101                                tempExpr.push_back( new UntypedExpr( new NameExpr("?=?"), args ) );
     102
     103                                temporaries.splice( temporaries.end(), rec.temporaries );
     104                        } else
     105                                newArgs.push_back( *e );
     106                        // percolate to recursive calls
     107                }
     108
     109                applicationExpr->get_args().clear();
     110                std::copy( newArgs.begin(), newArgs.end(), back_inserter( applicationExpr->get_args()) );
     111
     112                return applicationExpr;
     113        }
     114
     115        Expression* TupleDistrib::mutate( UntypedExpr *expr ) {
     116                if (  NameExpr *assgnop = dynamic_cast< NameExpr * >( expr->get_function()) ) {
     117                        if ( assgnop->get_name() == std::string("?=?") ) {
     118                                std::list<Expression *> &args = expr->get_args();
     119                                assert( args.size() == 2 );
     120                                //if args.front() points to a tuple and if args.back() is already resolved
     121                                if ( AddressExpr *addr = dynamic_cast<AddressExpr *>( args.front()) )
     122                                        if ( TupleExpr *lhs = dynamic_cast<TupleExpr *>( addr->get_arg()) )
     123                                                if ( ApplicationExpr *rhs = dynamic_cast<ApplicationExpr *>( args.back() ) ) {
     124                                                        for ( std::list<Expression *>::iterator tc = lhs->get_exprs().begin(); tc != lhs->get_exprs().end(); ++tc )
     125                                                                rhs->get_args().push_back( new AddressExpr( *tc ) );
     126                                                        return rhs; // XXX
     127                                                } // if
     128                        } else
     129                                assert( false ); // It's not an assignment, shouldn't be here
     130                } // if
     131                return expr;
     132        }
     133
     134}
     135
     136// namespace Tuples
     137// Local Variables: //
     138// tab-width: 4 //
     139// mode: c++ //
     140// compile-command: "make install" //
     141// End: //
  • translator/Tuples/FunctionChecker.h

    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// FunctionChecker.h --
     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 12:00:57 2015
     13// Update Count     : 2
     14//
     15
    116#ifndef _TUPLE_FUNCHK_H_
    217#define _TUPLE_FUNCHK_H_
     
    1631#include "SynTree/Statement.h"
    1732
     33namespace Tuples {
     34        class FunctionChecker : public Mutator {
     35                typedef Mutator Parent;
     36          public:
     37                FunctionChecker( bool _topLevel = false, UniqueName *_nameGen = 0 );
     38                ~FunctionChecker();
    1839
    19 namespace Tuples {
    20   class FunctionChecker : public Mutator
    21   {
    22     typedef Mutator Parent;
     40                virtual Expression* mutate(ApplicationExpr *applicationExpr);
     41                virtual Statement* mutate(ExprStmt *exprStmt);
     42          private:
     43                bool topLevel;
     44                UniqueName *nameGen;
     45                std::list< ObjectDecl * > temporaries;
     46                std::list< Expression * > tempExpr;
     47        };
    2348
    24   public:
    25     FunctionChecker( bool _topLevel = false, UniqueName *_nameGen = 0 );
    26     ~FunctionChecker();
     49        class TupleDistrib : public Mutator {
     50          public:
     51                virtual Expression* mutate(UntypedExpr *utExpr);
     52          private:
     53        };
    2754
    28     virtual Expression* mutate(ApplicationExpr *applicationExpr);
    29     virtual Statement* mutate(ExprStmt *exprStmt);
    30 
    31   private:
    32     bool topLevel;
    33     UniqueName *nameGen;
    34     std::list< ObjectDecl * > temporaries;
    35     std::list< Expression * > tempExpr;
    36   };
    37 
    38   class TupleDistrib : public Mutator {
    39   public:
    40     virtual Expression* mutate(UntypedExpr *utExpr);
    41 
    42   private:
    43   };
    44 
    45   void checkFunctions( std::list< Declaration * > translationUnit );
    46 
     55        void checkFunctions( std::list< Declaration * > translationUnit );
    4756} // namespace Tuples
    4857
    49 #endif // #ifndef _TUPLE_FUNCHK_H_
     58#endif // _TUPLE_FUNCHK_H_
    5059
    51 /*
    52   Local Variables:
    53   mode: c++
    54   End:
    55 */
     60// Local Variables: //
     61// tab-width: 4 //
     62// mode: c++ //
     63// compile-command: "make install" //
     64// End: //
  • translator/Tuples/FunctionFixer.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// FunctionFixer.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 12:02:22 2015
     13// Update Count     : 1
     14//
     15
    116#include <list>
    217#include <vector>
     
    722
    823namespace Tuples {
    9   DeclarationWithType *FunctionFixer::mutate( FunctionDecl *functionDecl ) {
    10     functionDecl->set_functionType( maybeMutate( functionDecl->get_functionType(), *this ) );
    11     mutateAll( functionDecl->get_oldDecls(), *this );
    12     functionDecl->set_statements( maybeMutate( functionDecl->get_statements(), *this ) );
    13     index.visit( functionDecl );
    14     rets.clear();
    15     return functionDecl;
    16   }
     24        DeclarationWithType *FunctionFixer::mutate( FunctionDecl *functionDecl ) {
     25                functionDecl->set_functionType( maybeMutate( functionDecl->get_functionType(), *this ) );
     26                mutateAll( functionDecl->get_oldDecls(), *this );
     27                functionDecl->set_statements( maybeMutate( functionDecl->get_statements(), *this ) );
     28                index.visit( functionDecl );
     29                rets.clear();
     30                return functionDecl;
     31        }
    1732
    18   Type *FunctionFixer::mutate( FunctionType *functionType )
    19   {
    20     typedef std::list< DeclarationWithType * >  Decls;
     33        Type *FunctionFixer::mutate( FunctionType *functionType ) {
     34                typedef std::list< DeclarationWithType * >  Decls;
    2135
    22     if ( functionType->get_returnVals().size() <= 1 )  return functionType;
    23     std::copy( functionType->get_returnVals().begin(), functionType->get_returnVals().end(), back_inserter(rets) );
     36                if ( functionType->get_returnVals().size() <= 1 )  return functionType;
     37                std::copy( functionType->get_returnVals().begin(), functionType->get_returnVals().end(), back_inserter(rets) );
    2438
    25     Type::Qualifiers qual;
    26     for ( Decls::iterator i = rets.begin(); i != rets.end(); i++ ) {
    27       (*i)->set_type( new PointerType( qual, (*i)->get_type() ) );
    28       functionType->get_parameters().push_back( *i );
    29     }
     39                Type::Qualifiers qual;
     40                for ( Decls::iterator i = rets.begin(); i != rets.end(); i++ ) {
     41                        (*i)->set_type( new PointerType( qual, (*i)->get_type() ) );
     42                        functionType->get_parameters().push_back( *i );
     43                } // for
    3044
    31     functionType->get_returnVals() = *(new std::list< DeclarationWithType * >());
     45                functionType->get_returnVals() = *(new std::list< DeclarationWithType * >());
    3246
    33     functionType->set_isVarArgs( false );
    34     return functionType;
    35   }
     47                functionType->set_isVarArgs( false );
     48                return functionType;
     49        }
    3650
    37   Statement *FunctionFixer::mutate( ReturnStmt *retStmt )
    38   {
    39     bool tupleReturn = false;
    40     Expression *rhs = 0;
    41     // also check if returning multiple values
    42     if ( CastExpr *cst = dynamic_cast<CastExpr *>( retStmt->get_expr() ) ) {
    43       if ( ApplicationExpr *app = dynamic_cast<ApplicationExpr *>( cst->get_arg() ) ) {
    44         if ( app->get_results().size() > 1 ) { // doesn't need to be ApplicationExpr
    45           tupleReturn = true;
    46           rhs = app;
     51        Statement *FunctionFixer::mutate( ReturnStmt *retStmt ) {
     52                bool tupleReturn = false;
     53                Expression *rhs = 0;
     54                // also check if returning multiple values
     55                if ( CastExpr *cst = dynamic_cast<CastExpr *>( retStmt->get_expr() ) ) {
     56                        if ( ApplicationExpr *app = dynamic_cast<ApplicationExpr *>( cst->get_arg() ) ) {
     57                                if ( app->get_results().size() > 1 ) { // doesn't need to be ApplicationExpr
     58                                        tupleReturn = true;
     59                                        rhs = app;
     60                                }
     61                        } else if ( TupleExpr *t = dynamic_cast<TupleExpr *>( cst->get_arg() ) ) {
     62                                tupleReturn = true;
     63                                assert( rets.size() == t->get_exprs().size() ); // stupid check, resolve expression
     64                                rhs = t;
     65                        } // if
     66
     67                        if ( tupleReturn ) {
     68                                assert ( rhs != 0 );
     69                                std::list< Expression * > lhs;
     70                                for ( std::list< DeclarationWithType * >::iterator d = rets.begin(); d != rets.end(); ++d ) {
     71                                        std::list<Expression *> largs;
     72                                        largs.push_back(new VariableExpr( *d ));
     73                                        Expression *exp = ResolvExpr::resolveInVoidContext( new CastExpr( new UntypedExpr(new NameExpr("*?"), largs), (*d)->get_type()),
     74                                                                                                                                                index );
     75                                        lhs.push_back(exp);
     76                                } // for
     77                                std::list< Expression * > args;
     78                                TupleExpr *tlhs = new TupleExpr; tlhs->set_exprs( lhs );
     79                                args.push_back( new AddressExpr(tlhs) );
     80                                args.push_back(rhs);
     81
     82                                return new ExprStmt( std::list< Label>(), new UntypedExpr( new NameExpr("?=?"), args ) );
     83                        } // if
     84                } // if
     85                /*
     86                  else
     87                  std::cerr << "Empty return statement" << std::endl;
     88                */
     89
     90                return retStmt;
    4791        }
    48       } else if ( TupleExpr *t = dynamic_cast<TupleExpr *>( cst->get_arg() ) ) {
    49         tupleReturn = true;
    50         assert( rets.size() == t->get_exprs().size() ); // stupid check, resolve expression
    51         rhs = t;
    52       }
    5392
    54       if ( tupleReturn ) {
    55         assert ( rhs != 0 );
    56         std::list< Expression * > lhs;
    57         for ( std::list< DeclarationWithType * >::iterator d = rets.begin(); d != rets.end(); ++d ) {
    58           std::list<Expression *> largs;
    59           largs.push_back(new VariableExpr( *d ));
    60           Expression *exp = ResolvExpr::resolveInVoidContext( new CastExpr( new UntypedExpr(new NameExpr("*?"), largs), (*d)->get_type()),
    61                                                                        index );
    62           lhs.push_back(exp);
     93        Expression* FunctionFixer::mutate( VariableExpr *variableExpr ) {
     94                if ( rets.empty() ) return variableExpr;
     95                mutateAll( variableExpr->get_results(), *this );
     96                if ( std::find( rets.begin(), rets.end(), variableExpr->get_var() ) != rets.end() )
     97//      if ( PointerType *ptr = dynamic_cast<PointerType *>(variableExpr->get_var()->get_type()) ) {
     98                        if ( dynamic_cast<PointerType *>(variableExpr->get_var()->get_type()) != 0 ) {
     99                                std::list<Expression *> largs;
     100                                largs.push_back( new AddressExpr(variableExpr) );
     101                                Expression *expr = ResolvExpr::resolveInVoidContext( /*new CastExpr(*/new UntypedExpr( new NameExpr( "*?" ), largs )/*,
     102                                                                                                                                                                                                                                                                          ptr->get_base()),*/, index);
     103                                if ( ApplicationExpr *app = dynamic_cast< ApplicationExpr * >( expr ) ) {
     104                                        assert( app->get_args().size() == 1 );
     105                                        app->get_args().pop_front();
     106                                        app->get_args().push_back( variableExpr );
     107                                        return app;
     108                                }
     109                        }
     110                return variableExpr;
    63111        }
    64         std::list< Expression * > args;
    65         TupleExpr *tlhs = new TupleExpr; tlhs->set_exprs( lhs );
    66         args.push_back( new AddressExpr(tlhs) );
    67         args.push_back(rhs);
    68112
    69         return new ExprStmt( std::list< Label>(), new UntypedExpr( new NameExpr("?=?"), args ) );
    70       }
    71     }
    72     /*
    73     else
    74       std::cerr << "Empty return statement" << std::endl;
    75     */
    76 
    77     return retStmt;
    78   }
    79 
    80   Expression* FunctionFixer::mutate( VariableExpr *variableExpr ) {
    81     if ( rets.empty() ) return variableExpr;
    82     mutateAll( variableExpr->get_results(), *this );
    83     if ( std::find( rets.begin(), rets.end(), variableExpr->get_var() ) != rets.end() )
    84 //      if ( PointerType *ptr = dynamic_cast<PointerType *>(variableExpr->get_var()->get_type()) ) {
    85       if ( dynamic_cast<PointerType *>(variableExpr->get_var()->get_type()) != 0 ) {
    86         std::list<Expression *> largs;
    87         largs.push_back( new AddressExpr(variableExpr) );
    88           Expression *expr = ResolvExpr::resolveInVoidContext( /*new CastExpr(*/new UntypedExpr( new NameExpr( "*?" ), largs )/*,
    89                                                                                                                                  ptr->get_base()),*/, index);
    90           if ( ApplicationExpr *app = dynamic_cast< ApplicationExpr * >( expr ) ) {
    91             assert( app->get_args().size() == 1 );
    92             app->get_args().pop_front();
    93             app->get_args().push_back( variableExpr );
    94             return app;
     113        /*
     114          Expression* FunctionFixer::mutate(ApplicationExpr *applicationExpr) {
     115          std::cerr << "In Application Expression" << std::endl;
     116          mutateAll( applicationExpr->get_results(), *this );
     117          applicationExpr->set_function(  maybeMutate( applicationExpr->get_function(), *this ) );
     118          mutateAll( applicationExpr->get_args(), *this );
     119          return applicationExpr;
    95120          }
    96       }
    97     return variableExpr;
    98   }
    99 
    100   /*
    101   Expression* FunctionFixer::mutate(ApplicationExpr *applicationExpr) {
    102     std::cerr << "In Application Expression" << std::endl;
    103     mutateAll( applicationExpr->get_results(), *this );
    104     applicationExpr->set_function(  maybeMutate( applicationExpr->get_function(), *this ) );
    105     mutateAll( applicationExpr->get_args(), *this );
    106     return applicationExpr;
    107   }
    108   */
     121        */
    109122} // namespace Tuples
     123// Local Variables: //
     124// tab-width: 4 //
     125// mode: c++ //
     126// compile-command: "make install" //
     127// End: //
  • translator/Tuples/FunctionFixer.h

    r0dd3a2f r51587aa  
    1 #ifndef _FUNFIX_H_
    2 #define _FUNFIX_H_
     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// FunctionFixer.h --
     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 14:58:45 2015
     13