Changeset d150ea2


Ignore:
Timestamp:
Feb 19, 2017, 10:23:23 AM (7 years ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
Children:
a98b2cc, bd9bcc8
Parents:
e7cc8cb (diff), 0ca9dea (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'master' of plg2:software/cfa/cfa-cc

Location:
src
Files:
1 added
9 edited
1 moved

Legend:

Unmodified
Added
Removed
  • src/CodeGen/Generate.cc

    re7cc8cb rd150ea2  
    2222#include "SynTree/Declaration.h"
    2323#include "CodeGenerator.h"
     24#include "Tuples/Tuples.h"
    2425
    2526using namespace std;
     
    2829        void generate( std::list< Declaration* > translationUnit, std::ostream &os, bool doIntrinsics, bool pretty ) {
    2930                CodeGen::CodeGenerator cgv( os, pretty );
    30 
    31                 for ( std::list<Declaration *>::iterator i = translationUnit.begin(); i != translationUnit.end();  i++ ) {
    32                         if ( LinkageSpec::isGeneratable( (*i)->get_linkage() ) && (doIntrinsics || ! LinkageSpec::isBuiltin( (*i)->get_linkage() ) ) ) {
    33                                 (*i)->accept(cgv);
    34                                 if ( doSemicolon( *i ) ) {
     31                for ( auto & dcl : translationUnit ) {
     32                        if ( LinkageSpec::isGeneratable( dcl->get_linkage() ) && (doIntrinsics || ! LinkageSpec::isBuiltin( dcl->get_linkage() ) ) ) {
     33                                dcl->accept(cgv);
     34                                if ( doSemicolon( dcl ) ) {
    3535                                        os << ";";
    3636                                } // if
  • src/InitTweak/FixInit.cc

    re7cc8cb rd150ea2  
    11161116                        // xxx - is the size check necessary?
    11171117                        assert( ctorExpr->has_result() && ctorExpr->get_result()->size() == 1 );
     1118
     1119                        // xxx - ideally we would reuse the temporary generated from the copy constructor passes from within firstArg if it exists and not generate a temporary if it's unnecessary.
    11181120                        ObjectDecl * tmp = new ObjectDecl( tempNamer.newName(), DeclarationNode::NoStorageClass, LinkageSpec::C, nullptr, ctorExpr->get_result()->clone(), nullptr );
    11191121                        addDeclaration( tmp );
  • src/InitTweak/InitTweak.cc

    re7cc8cb rd150ea2  
    332332                        return nullptr;
    333333                }
     334        }
     335
     336        DeclarationWithType * getFunction( Expression * expr ) {
     337                if ( ApplicationExpr * appExpr = dynamic_cast< ApplicationExpr * >( expr ) ) {
     338                        return getCalledFunction( appExpr->get_function() );
     339                } else if ( UntypedExpr * untyped = dynamic_cast< UntypedExpr * > ( expr ) ) {
     340                        return getCalledFunction( untyped->get_function() );
     341                }
     342                assertf( false, "getFunction received unknown expression: %s", toString( expr ).c_str() );
    334343        }
    335344
  • src/InitTweak/InitTweak.h

    re7cc8cb rd150ea2  
    5151        bool checkInitDepth( ObjectDecl * objDecl );
    5252
    53   /// Non-Null if expr is a call expression whose target function is intrinsic
    54   ApplicationExpr * isIntrinsicCallExpr( Expression * expr );
     53        /// returns the declaration of the function called by the expr (must be ApplicationExpr or UntypedExpr)
     54        DeclarationWithType * getFunction( Expression * expr );
     55
     56        /// Non-Null if expr is a call expression whose target function is intrinsic
     57        ApplicationExpr * isIntrinsicCallExpr( Expression * expr );
    5558
    5659        /// True if stmt is a call statement where the function called is intrinsic and takes one parameter.
  • src/ResolvExpr/AlternativeFinder.cc

    re7cc8cb rd150ea2  
    10441044
    10451045        void AlternativeFinder::visit( ConditionalExpr *conditionalExpr ) {
     1046                // find alternatives for condition
    10461047                AlternativeFinder firstFinder( indexer, env );
    10471048                firstFinder.findWithAdjustment( conditionalExpr->get_arg1() );
    10481049                for ( AltList::const_iterator first = firstFinder.alternatives.begin(); first != firstFinder.alternatives.end(); ++first ) {
     1050                        // find alternatives for true expression
    10491051                        AlternativeFinder secondFinder( indexer, first->env );
    10501052                        secondFinder.findWithAdjustment( conditionalExpr->get_arg2() );
    10511053                        for ( AltList::const_iterator second = secondFinder.alternatives.begin(); second != secondFinder.alternatives.end(); ++second ) {
     1054                                // find alterantives for false expression
    10521055                                AlternativeFinder thirdFinder( indexer, second->env );
    10531056                                thirdFinder.findWithAdjustment( conditionalExpr->get_arg3() );
    10541057                                for ( AltList::const_iterator third = thirdFinder.alternatives.begin(); third != thirdFinder.alternatives.end(); ++third ) {
     1058                                        // unify true and false types, then infer parameters to produce new alternatives
    10551059                                        OpenVarSet openVars;
    10561060                                        AssertionSet needAssertions, haveAssertions;
     
    10791083        }
    10801084
     1085        void AlternativeFinder::visit( RangeExpr * rangeExpr ) {
     1086                // resolve low and high, accept alternatives whose low and high types unify
     1087                AlternativeFinder firstFinder( indexer, env );
     1088                firstFinder.findWithAdjustment( rangeExpr->get_low() );
     1089                for ( AltList::const_iterator first = firstFinder.alternatives.begin(); first != firstFinder.alternatives.end(); ++first ) {
     1090                        AlternativeFinder secondFinder( indexer, first->env );
     1091                        secondFinder.findWithAdjustment( rangeExpr->get_high() );
     1092                        for ( AltList::const_iterator second = secondFinder.alternatives.begin(); second != secondFinder.alternatives.end(); ++second ) {
     1093                                OpenVarSet openVars;
     1094                                AssertionSet needAssertions, haveAssertions;
     1095                                Alternative newAlt( 0, second->env, first->cost + second->cost );
     1096                                Type* commonType = nullptr;
     1097                                if ( unify( first->expr->get_result(), second->expr->get_result(), newAlt.env, needAssertions, haveAssertions, openVars, indexer, commonType ) ) {
     1098                                        RangeExpr *newExpr = new RangeExpr( first->expr->clone(), second->expr->clone() );
     1099                                        newExpr->set_result( commonType ? commonType : first->expr->get_result()->clone() );
     1100                                        newAlt.expr = newExpr;
     1101                                        inferParameters( needAssertions, haveAssertions, newAlt, openVars, back_inserter( alternatives ) );
     1102                                } // if
     1103                        } // for
     1104                } // for
     1105        }
     1106
    10811107        void AlternativeFinder::visit( UntypedTupleExpr *tupleExpr ) {
    10821108                std::list< AlternativeFinder > subExprAlternatives;
  • src/ResolvExpr/AlternativeFinder.h

    re7cc8cb rd150ea2  
    6666                virtual void visit( ImplicitCopyCtorExpr * impCpCtorExpr );
    6767                virtual void visit( ConstructorExpr * ctorExpr );
     68                virtual void visit( RangeExpr * rangeExpr );
    6869                virtual void visit( UntypedTupleExpr *tupleExpr );
    6970                virtual void visit( TupleExpr *tupleExpr );
  • src/ResolvExpr/Resolver.cc

    re7cc8cb rd150ea2  
    302302        }
    303303
    304         template< typename SwitchClass >
    305         void handleSwitchStmt( SwitchClass *switchStmt, SymTab::Indexer &visitor ) {
     304        void Resolver::visit( SwitchStmt *switchStmt ) {
     305                ValueGuard< Type * > oldInitContext( initContext );
    306306                Expression *newExpr;
    307                 newExpr = findIntegralExpression( switchStmt->get_condition(), visitor );
     307                newExpr = findIntegralExpression( switchStmt->get_condition(), *this );
    308308                delete switchStmt->get_condition();
    309309                switchStmt->set_condition( newExpr );
    310310
    311                 visitor.Visitor::visit( switchStmt );
    312         }
    313 
    314         void Resolver::visit( SwitchStmt *switchStmt ) {
    315                 handleSwitchStmt( switchStmt, *this );
     311                initContext = newExpr->get_result();
     312                Parent::visit( switchStmt );
    316313        }
    317314
    318315        void Resolver::visit( CaseStmt *caseStmt ) {
     316                if ( caseStmt->get_condition() ) {
     317                        assert( initContext );
     318                        CastExpr * castExpr = new CastExpr( caseStmt->get_condition(), initContext->clone() );
     319                        Expression * newExpr = findSingleExpression( castExpr, *this );
     320                        castExpr = safe_dynamic_cast< CastExpr * >( newExpr );
     321                        caseStmt->set_condition( castExpr->get_arg() );
     322                        castExpr->set_arg( nullptr );
     323                        delete castExpr;
     324                }
    319325                Parent::visit( caseStmt );
    320326        }
  • src/Tuples/TupleExpansion.cc

    re7cc8cb rd150ea2  
    2929#include "ResolvExpr/typeops.h"
    3030#include "InitTweak/GenInit.h"
     31#include "InitTweak/InitTweak.h"
    3132
    3233namespace Tuples {
     
    7879                        }
    7980                  private:
    80                         ScopedMap< std::string, StructDecl * > typeMap;
     81                        ScopedMap< int, StructDecl * > typeMap;
    8182                };
    8283
     
    213214
    214215        Type * TupleTypeReplacer::mutate( TupleType * tupleType ) {
    215                 std::string mangleName = SymTab::Mangler::mangleType( tupleType );
    216216                tupleType = safe_dynamic_cast< TupleType * > ( Parent::mutate( tupleType ) );
    217                 if ( ! typeMap.count( mangleName ) ) {
    218                         // generate struct type to replace tuple type
    219                         // xxx - should fix this to only generate one tuple struct for each number of type parameters
    220                         StructDecl * decl = new StructDecl( "_tuple_type_" + mangleName );
     217                unsigned tupleSize = tupleType->size();
     218                if ( ! typeMap.count( tupleSize ) ) {
     219                        // generate struct type to replace tuple type based on the number of components in the tuple
     220                        StructDecl * decl = new StructDecl( toString( "_tuple_type_", tupleSize  ) );
    221221                        decl->set_body( true );
    222                         for ( size_t i = 0; i < tupleType->size(); ++i ) {
     222                        for ( size_t i = 0; i < tupleSize; ++i ) {
    223223                                TypeDecl * tyParam = new TypeDecl( toString("tuple_param_", i), DeclarationNode::NoStorageClass, nullptr, TypeDecl::Any );
    224224                                decl->get_members().push_back( new ObjectDecl( toString("field_", i), DeclarationNode::NoStorageClass, LinkageSpec::C, nullptr, new TypeInstType( Type::Qualifiers(), tyParam->get_name(), tyParam ), nullptr ) );
    225225                                decl->get_parameters().push_back( tyParam );
    226226                        }
    227                         if ( tupleType->size() == 0 ) {
     227                        if ( tupleSize == 0 ) {
    228228                                // empty structs are not standard C. Add a dummy field to empty tuples to silence warnings when a compound literal Tuple0 is created.
    229229                                decl->get_members().push_back( new ObjectDecl( "dummy", DeclarationNode::NoStorageClass, LinkageSpec::C, nullptr, new BasicType( Type::Qualifiers(), BasicType::SignedInt ), nullptr ) );
    230230                        }
    231                         typeMap[mangleName] = decl;
     231                        typeMap[tupleSize] = decl;
    232232                        addDeclaration( decl );
    233233                }
    234234                Type::Qualifiers qualifiers = tupleType->get_qualifiers();
    235235
    236                 StructDecl * decl = typeMap[mangleName];
     236                StructDecl * decl = typeMap[tupleSize];
    237237                StructInstType * newType = new StructInstType( qualifiers, decl );
    238238                for ( Type * t : *tupleType ) {
     
    337337                public:
    338338                        typedef Visitor Parent;
    339                         virtual void visit( ApplicationExpr * appExpr ) { maybeImpure = true;   }
     339                        virtual void visit( ApplicationExpr * appExpr ) {
     340                                if ( DeclarationWithType * function = InitTweak::getFunction( appExpr ) ) {
     341                                        if ( function->get_linkage() == LinkageSpec::Intrinsic ) {
     342                                                if ( function->get_name() == "*?" || function->get_name() == "?[?]" ) {
     343                                                        // intrinsic dereference, subscript are pure, but need to recursively look for impurity
     344                                                        Parent::visit( appExpr );
     345                                                        return;
     346                                                }
     347                                        }
     348                                }
     349                                maybeImpure = true;
     350                        }
    340351                        virtual void visit( UntypedExpr * untypedExpr ) { maybeImpure = true; }
    341352                        bool maybeImpure = false;
  • src/tests/dtor-early-exit.c

    re7cc8cb rd150ea2  
    1 // 
     1//
    22// Cforall Version 1.0.0 Copyright (C) 2016 University of Waterloo
    33//
    44// The contents of this file are covered under the licence agreement in the
    55// file "LICENCE" distributed with Cforall.
    6 // 
    7 // dtor-early-exit.c -- 
    8 // 
     6//
     7// dtor-early-exit.c --
     8//
    99// Author           : Rob Schluntz
    1010// Created On       : Wed Aug 17 08:26:25 2016
     
    1212// Last Modified On : Wed Aug 17 08:29:37 2016
    1313// Update Count     : 2
    14 // 
     14//
    1515
    1616#include <fstream>
     
    213213                // S_G-S_L = {}
    214214        }
     215#ifdef ERR2
    215216        // S_G = {}
    216 #ifdef ERR2
    217217        if (i == 5) goto L2; // this is an error in g++ because it skips initialization of y, x
    218218        // S_L-S_G = { y, x } => non-empty, so error
Note: See TracChangeset for help on using the changeset viewer.