Changes in / [0ca9dea:94ad12f]
- Location:
- src
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
src/CodeGen/Generate.cc
r0ca9dea r94ad12f 22 22 #include "SynTree/Declaration.h" 23 23 #include "CodeGenerator.h" 24 #include "Tuples/Tuples.h"25 24 26 25 using namespace std; … … 29 28 void generate( std::list< Declaration* > translationUnit, std::ostream &os, bool doIntrinsics, bool pretty ) { 30 29 CodeGen::CodeGenerator cgv( os, pretty ); 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 ) ) { 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 ) ) { 35 35 os << ";"; 36 36 } // if -
src/InitTweak/FixInit.cc
r0ca9dea r94ad12f 1116 1116 // xxx - is the size check necessary? 1117 1117 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.1120 1118 ObjectDecl * tmp = new ObjectDecl( tempNamer.newName(), DeclarationNode::NoStorageClass, LinkageSpec::C, nullptr, ctorExpr->get_result()->clone(), nullptr ); 1121 1119 addDeclaration( tmp ); -
src/InitTweak/InitTweak.cc
r0ca9dea r94ad12f 332 332 return nullptr; 333 333 } 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() );343 334 } 344 335 -
src/InitTweak/InitTweak.h
r0ca9dea r94ad12f 51 51 bool checkInitDepth( ObjectDecl * objDecl ); 52 52 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 ); 53 /// Non-Null if expr is a call expression whose target function is intrinsic 54 ApplicationExpr * isIntrinsicCallExpr( Expression * expr ); 58 55 59 56 /// True if stmt is a call statement where the function called is intrinsic and takes one parameter. -
src/ResolvExpr/AlternativeFinder.cc
r0ca9dea r94ad12f 1044 1044 1045 1045 void AlternativeFinder::visit( ConditionalExpr *conditionalExpr ) { 1046 // find alternatives for condition1047 1046 AlternativeFinder firstFinder( indexer, env ); 1048 1047 firstFinder.findWithAdjustment( conditionalExpr->get_arg1() ); 1049 1048 for ( AltList::const_iterator first = firstFinder.alternatives.begin(); first != firstFinder.alternatives.end(); ++first ) { 1050 // find alternatives for true expression1051 1049 AlternativeFinder secondFinder( indexer, first->env ); 1052 1050 secondFinder.findWithAdjustment( conditionalExpr->get_arg2() ); 1053 1051 for ( AltList::const_iterator second = secondFinder.alternatives.begin(); second != secondFinder.alternatives.end(); ++second ) { 1054 // find alterantives for false expression1055 1052 AlternativeFinder thirdFinder( indexer, second->env ); 1056 1053 thirdFinder.findWithAdjustment( conditionalExpr->get_arg3() ); 1057 1054 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 alternatives1059 1055 OpenVarSet openVars; 1060 1056 AssertionSet needAssertions, haveAssertions; … … 1083 1079 } 1084 1080 1085 void AlternativeFinder::visit( RangeExpr * rangeExpr ) {1086 // resolve low and high, accept alternatives whose low and high types unify1087 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 } // if1103 } // for1104 } // for1105 }1106 1107 1081 void AlternativeFinder::visit( UntypedTupleExpr *tupleExpr ) { 1108 1082 std::list< AlternativeFinder > subExprAlternatives; -
src/ResolvExpr/AlternativeFinder.h
r0ca9dea r94ad12f 66 66 virtual void visit( ImplicitCopyCtorExpr * impCpCtorExpr ); 67 67 virtual void visit( ConstructorExpr * ctorExpr ); 68 virtual void visit( RangeExpr * rangeExpr );69 68 virtual void visit( UntypedTupleExpr *tupleExpr ); 70 69 virtual void visit( TupleExpr *tupleExpr ); -
src/ResolvExpr/Resolver.cc
r0ca9dea r94ad12f 302 302 } 303 303 304 void Resolver::visit( SwitchStmt *switchStmt ) {305 ValueGuard< Type * > oldInitContext( initContext );304 template< typename SwitchClass > 305 void handleSwitchStmt( SwitchClass *switchStmt, SymTab::Indexer &visitor ) { 306 306 Expression *newExpr; 307 newExpr = findIntegralExpression( switchStmt->get_condition(), *this);307 newExpr = findIntegralExpression( switchStmt->get_condition(), visitor ); 308 308 delete switchStmt->get_condition(); 309 309 switchStmt->set_condition( newExpr ); 310 310 311 initContext = newExpr->get_result(); 312 Parent::visit( switchStmt ); 311 visitor.Visitor::visit( switchStmt ); 312 } 313 314 void Resolver::visit( SwitchStmt *switchStmt ) { 315 handleSwitchStmt( switchStmt, *this ); 313 316 } 314 317 315 318 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 }325 319 Parent::visit( caseStmt ); 326 320 } -
src/Tuples/TupleExpansion.cc
r0ca9dea r94ad12f 29 29 #include "ResolvExpr/typeops.h" 30 30 #include "InitTweak/GenInit.h" 31 #include "InitTweak/InitTweak.h"32 31 33 32 namespace Tuples { … … 79 78 } 80 79 private: 81 ScopedMap< int, StructDecl * > typeMap;80 ScopedMap< std::string, StructDecl * > typeMap; 82 81 }; 83 82 … … 214 213 215 214 Type * TupleTypeReplacer::mutate( TupleType * tupleType ) { 215 std::string mangleName = SymTab::Mangler::mangleType( tupleType ); 216 216 tupleType = safe_dynamic_cast< TupleType * > ( Parent::mutate( tupleType ) ); 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 tuple220 StructDecl * decl = new StructDecl( toString( "_tuple_type_", tupleSize ));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 ); 221 221 decl->set_body( true ); 222 for ( size_t i = 0; i < tuple Size; ++i ) {222 for ( size_t i = 0; i < tupleType->size(); ++i ) { 223 223 TypeDecl * tyParam = new TypeDecl( toString("tuple_param_", i), DeclarationNode::NoStorageClass, nullptr, TypeDecl::Any ); 224 224 decl->get_members().push_back( new ObjectDecl( toString("field_", i), DeclarationNode::NoStorageClass, LinkageSpec::C, nullptr, new TypeInstType( Type::Qualifiers(), tyParam->get_name(), tyParam ), nullptr ) ); 225 225 decl->get_parameters().push_back( tyParam ); 226 226 } 227 if ( tuple Size== 0 ) {227 if ( tupleType->size() == 0 ) { 228 228 // empty structs are not standard C. Add a dummy field to empty tuples to silence warnings when a compound literal Tuple0 is created. 229 229 decl->get_members().push_back( new ObjectDecl( "dummy", DeclarationNode::NoStorageClass, LinkageSpec::C, nullptr, new BasicType( Type::Qualifiers(), BasicType::SignedInt ), nullptr ) ); 230 230 } 231 typeMap[ tupleSize] = decl;231 typeMap[mangleName] = decl; 232 232 addDeclaration( decl ); 233 233 } 234 234 Type::Qualifiers qualifiers = tupleType->get_qualifiers(); 235 235 236 StructDecl * decl = typeMap[ tupleSize];236 StructDecl * decl = typeMap[mangleName]; 237 237 StructInstType * newType = new StructInstType( qualifiers, decl ); 238 238 for ( Type * t : *tupleType ) { … … 337 337 public: 338 338 typedef Visitor Parent; 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 } 339 virtual void visit( ApplicationExpr * appExpr ) { maybeImpure = true; } 351 340 virtual void visit( UntypedExpr * untypedExpr ) { maybeImpure = true; } 352 341 bool maybeImpure = false; -
src/tests/dtor-early-exit.c
r0ca9dea r94ad12f 1 // 1 // 2 2 // Cforall Version 1.0.0 Copyright (C) 2016 University of Waterloo 3 3 // 4 4 // The contents of this file are covered under the licence agreement in the 5 5 // file "LICENCE" distributed with Cforall. 6 // 7 // dtor-early-exit.c -- 8 // 6 // 7 // dtor-early-exit.c -- 8 // 9 9 // Author : Rob Schluntz 10 10 // Created On : Wed Aug 17 08:26:25 2016 … … 12 12 // Last Modified On : Wed Aug 17 08:29:37 2016 13 13 // Update Count : 2 14 // 14 // 15 15 16 16 #include <fstream> … … 213 213 // S_G-S_L = {} 214 214 } 215 // S_G = {} 215 216 #ifdef ERR2 216 // S_G = {}217 217 if (i == 5) goto L2; // this is an error in g++ because it skips initialization of y, x 218 218 // S_L-S_G = { y, x } => non-empty, so error
Note: See TracChangeset
for help on using the changeset viewer.