- Timestamp:
- May 10, 2017, 5:00:47 PM (8 years ago)
- 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:
- 8514fe19, dbfb35d
- Parents:
- 0f9bef3 (diff), 29cf9c8 (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. - Location:
- src
- Files:
-
- 15 added
- 4 deleted
- 34 edited
Legend:
- Unmodified
- Added
- Removed
-
src/CodeGen/CodeGenerator.cc
r0f9bef3 r6250a312 9 9 // Author : Richard C. Bilson 10 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : Peter A. Buhr12 // Last Modified On : T hu Mar 30 16:38:01201713 // Update Count : 48 211 // Last Modified By : Andrew Beach 12 // Last Modified On : Tus May 9 16:50:00 2017 13 // Update Count : 484 14 14 // 15 15 … … 41 41 namespace CodeGen { 42 42 int CodeGenerator::tabsize = 4; 43 44 // Pseudo Function: output << lineDirective(currentNode); 45 struct lineDirective { 46 CodeLocation const & loc; 47 lineDirective(CodeLocation const & location) : loc(location) {} 48 lineDirective(BaseSyntaxNode const * node) : loc(node->location) {} 49 }; 50 std::ostream & operator<<(std::ostream & out, lineDirective const & ld) { 51 if (ld.loc.isSet()) 52 return out << "\n# " << ld.loc.linenumber << " \"" 53 << ld.loc.filename << "\"\n"; 54 return out << "\n// Unset Location\n"; 55 } 43 56 44 57 // the kinds of statements that would ideally be followed by whitespace … … 128 141 129 142 130 // *** Declarations143 // *** Declarations 131 144 void CodeGenerator::visit( FunctionDecl * functionDecl ) { 145 output << lineDirective( functionDecl ); 146 132 147 extension( functionDecl ); 133 148 genAttributes( functionDecl->get_attributes() ); … … 153 168 } 154 169 170 output << lineDirective( objectDecl ); 171 155 172 extension( objectDecl ); 156 173 genAttributes( objectDecl->get_attributes() ); … … 192 209 cur_indent += CodeGenerator::tabsize; 193 210 for ( std::list< Declaration* >::iterator i = memb.begin(); i != memb.end(); i++ ) { 194 output << indent;211 output << lineDirective( *i ) << indent; 195 212 (*i)->accept( *this ); 196 213 output << ";" << endl; … … 204 221 205 222 void CodeGenerator::visit( StructDecl * structDecl ) { 223 output << lineDirective( structDecl ); 224 206 225 extension( structDecl ); 207 226 handleAggregate( structDecl, "struct " ); … … 209 228 210 229 void CodeGenerator::visit( UnionDecl * unionDecl ) { 230 output << lineDirective( unionDecl ); 231 211 232 extension( unionDecl ); 212 233 handleAggregate( unionDecl, "union " ); … … 215 236 void CodeGenerator::visit( EnumDecl * enumDecl ) { 216 237 extension( enumDecl ); 238 output << lineDirective ( enumDecl ); 217 239 output << "enum "; 218 240 genAttributes( enumDecl->get_attributes() ); … … 230 252 ObjectDecl * obj = dynamic_cast< ObjectDecl* >( *i ); 231 253 assert( obj ); 232 output << indent << mangleName( obj );254 output << lineDirective( obj ) << indent << mangleName( obj ); 233 255 if ( obj->get_init() ) { 234 256 output << " = "; … … 248 270 void CodeGenerator::visit( TypedefDecl * typeDecl ) { 249 271 assertf( ! genC, "Typedefs are removed and substituted in earlier passes." ); 272 output << lineDirective( typeDecl ); 250 273 output << "typedef "; 251 274 output << genType( typeDecl->get_base(), typeDecl->get_name(), pretty, genC ) << endl; … … 262 285 } // if 263 286 } else { 264 output << typeDecl->typeString() << " " << typeDecl->get_name(); 287 output << typeDecl->genTypeString() << " " << typeDecl->get_name(); 288 if ( typeDecl->get_kind() != TypeDecl::Any && typeDecl->get_sized() ) { 289 output << " | sized(" << typeDecl->get_name() << ")"; 290 } 265 291 if ( ! typeDecl->get_assertions().empty() ) { 266 292 output << " | { "; … … 316 342 } 317 343 318 // *** Expressions344 // *** Expressions 319 345 void CodeGenerator::visit( ApplicationExpr * applicationExpr ) { 320 346 extension( applicationExpr ); … … 719 745 void CodeGenerator::visit( StmtExpr * stmtExpr ) { 720 746 std::list< Statement * > & stmts = stmtExpr->get_statements()->get_kids(); 721 output << "({" << std::endl;747 output << lineDirective( stmtExpr) << "({" << std::endl; 722 748 cur_indent += CodeGenerator::tabsize; 723 749 unsigned int numStmts = stmts.size(); 724 750 unsigned int i = 0; 725 751 for ( Statement * stmt : stmts ) { 726 output << indent << printLabels( stmt->get_labels() ); 752 output << lineDirective( stmt ) << indent; 753 output << printLabels( stmt->get_labels() ); 727 754 if ( i+1 == numStmts ) { 728 755 // last statement in a statement expression needs to be handled specially - … … 746 773 } 747 774 748 // *** Statements775 // *** Statements 749 776 void CodeGenerator::visit( CompoundStmt * compoundStmt ) { 750 777 std::list<Statement*> ks = compoundStmt->get_kids(); … … 769 796 void CodeGenerator::visit( ExprStmt * exprStmt ) { 770 797 assert( exprStmt ); 771 // cast the top-level expression to void to reduce gcc warnings. 772 Expression * expr = new CastExpr( exprStmt->get_expr() ); 798 Expression * expr = exprStmt->get_expr(); 799 if ( genC ) { 800 // cast the top-level expression to void to reduce gcc warnings. 801 expr = new CastExpr( expr ); 802 } 773 803 expr->accept( *this ); 774 804 output << ";"; … … 807 837 808 838 void CodeGenerator::visit( IfStmt * ifStmt ) { 839 output << lineDirective( ifStmt ); 809 840 output << "if ( "; 810 841 ifStmt->get_condition()->accept( *this ); … … 820 851 821 852 void CodeGenerator::visit( SwitchStmt * switchStmt ) { 853 output << lineDirective( switchStmt ); 822 854 output << "switch ( " ; 823 855 switchStmt->get_condition()->accept( *this ); … … 832 864 833 865 void CodeGenerator::visit( CaseStmt * caseStmt ) { 866 output << lineDirective( caseStmt ); 834 867 output << indent; 835 868 if ( caseStmt->isDefault()) { -
src/CodeGen/Generate.cc
r0f9bef3 r6250a312 22 22 #include "SynTree/Declaration.h" 23 23 #include "CodeGenerator.h" 24 #include "Tuples/Tuples.h" 24 #include "GenType.h" 25 #include "SynTree/SynTree.h" 26 #include "SynTree/Type.h" 27 #include "SynTree/BaseSyntaxNode.h" 28 // #include "Tuples/Tuples.h" 25 29 26 30 using namespace std; … … 39 43 } // for 40 44 } 45 46 void generate( BaseSyntaxNode * node, std::ostream & os ) { 47 if ( Type * type = dynamic_cast< Type * >( node ) ) { 48 os << CodeGen::genPrettyType( type, "" ); 49 } else { 50 CodeGen::CodeGenerator cgv( os, true, false ); 51 node->accept( cgv ); 52 } 53 os << std::endl; 54 } 41 55 } // namespace CodeGen 42 56 -
src/CodeGen/Generate.h
r0f9bef3 r6250a312 25 25 /// Generates code. doIntrinsics determines if intrinsic functions are printed, pretty formats output nicely (e.g., uses unmangled names, etc.), generateC is true when the output must consist only of C code (allows some assertions, etc.) 26 26 void generate( std::list< Declaration* > translationUnit, std::ostream &os, bool doIntrinsics, bool pretty, bool generateC = false ); 27 28 /// Generate code for a single node -- helpful for debugging in gdb 29 void generate( BaseSyntaxNode * node, std::ostream & os ); 27 30 } // namespace CodeGen 28 31 -
src/CodeTools/module.mk
r0f9bef3 r6250a312 15 15 ############################################################################### 16 16 17 SRC += CodeTools/DeclStats.cc 17 SRC += CodeTools/DeclStats.cc \ 18 CodeTools/TrackLoc.cc -
src/Common/utility.h
r0f9bef3 r6250a312 9 9 // Author : Richard C. Bilson 10 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : Peter A. Buhr12 // Last Modified On : Wed Dec 14 21:25:25 201613 // Update Count : 3 111 // Last Modified By : Andrew Beach 12 // Last Modified On : Fri May 5 11:03:00 2017 13 // Update Count : 32 14 14 // 15 15 … … 322 322 std::string filename; 323 323 324 CodeLocation() 324 /// Create a new unset CodeLocation. 325 CodeLocation() 325 326 : linenumber( -1 ) 326 327 , filename("") 327 328 {} 328 329 330 /// Create a new CodeLocation with the given values. 329 331 CodeLocation( const char* filename, int lineno ) 330 332 : linenumber( lineno ) 331 333 , filename(filename ? filename : "") 332 334 {} 335 336 bool isSet () const { 337 return -1 != linenumber; 338 } 339 340 bool isUnset () const { 341 return !isSet(); 342 } 343 344 void unset () { 345 linenumber = -1; 346 filename = ""; 347 } 348 349 // Use field access for set. 333 350 }; 334 351 335 352 inline std::string to_string( const CodeLocation& location ) { 336 return location. linenumber >= 0? location.filename + ":" + std::to_string(location.linenumber) + " " : "";353 return location.isSet() ? location.filename + ":" + std::to_string(location.linenumber) + " " : ""; 337 354 } 338 355 #endif // _UTILITY_H -
src/Concurrency/Keywords.cc
r0f9bef3 r6250a312 246 246 //============================================================================================= 247 247 void ConcurrentSueKeyword::visit(StructDecl * decl) { 248 Visitor::visit(decl); 248 249 if( decl->get_name() == type_name ) { 249 250 assert( !type_decl ); … … 385 386 //============================================================================================= 386 387 void MutexKeyword::visit(FunctionDecl* decl) { 388 Visitor::visit(decl); 389 387 390 std::list<DeclarationWithType*> mutexArgs = findMutexArgs( decl ); 388 391 if( mutexArgs.empty() ) return; … … 402 405 403 406 void MutexKeyword::visit(StructDecl* decl) { 407 Visitor::visit(decl); 408 404 409 if( decl->get_name() == "monitor_desc" ) { 405 410 assert( !monitor_decl ); … … 504 509 //============================================================================================= 505 510 void ThreadStarter::visit(FunctionDecl * decl) { 511 Visitor::visit(decl); 512 506 513 if( ! InitTweak::isConstructor(decl->get_name()) ) return; 507 514 -
src/GenPoly/InstantiateGeneric.cc
r0f9bef3 r6250a312 233 233 } else { 234 234 // normalize possibly dtype-static parameter type 235 out.push_back( new TypeExpr{ 235 out.push_back( new TypeExpr{ 236 236 ScrubTyVars::scrubAll( paramType->get_type()->clone() ) } ); 237 237 gt |= genericType::concrete; … … 369 369 DeclMutator::addDeclaration( concDecl ); 370 370 insert( inst, typeSubs, concDecl ); 371 concDecl->acceptMutator( *this ); // recursively instantiate members 371 372 } 372 373 StructInstType *newInst = new StructInstType( inst->get_qualifiers(), concDecl->get_name() ); … … 423 424 DeclMutator::addDeclaration( concDecl ); 424 425 insert( inst, typeSubs, concDecl ); 426 concDecl->acceptMutator( *this ); // recursively instantiate members 425 427 } 426 428 UnionInstType *newInst = new UnionInstType( inst->get_qualifiers(), concDecl->get_name() ); -
src/GenPoly/PolyMutator.cc
r0f9bef3 r6250a312 50 50 51 51 Statement * PolyMutator::mutateStatement( Statement *stmt ) { 52 // don't want statements from outer CompoundStmts to be added to this CompoundStmt 53 ValueGuard< std::list< Statement* > > oldStmtsToAdd( stmtsToAdd ); 54 ValueGuard< std::list< Statement* > > oldStmtsToAddAfter( stmtsToAddAfter ); 55 ValueGuard< TypeSubstitution * > oldEnv( env ); 56 stmtsToAdd.clear(); 57 stmtsToAddAfter.clear(); 58 52 59 Statement *newStmt = maybeMutate( stmt, *this ); 53 60 if ( ! stmtsToAdd.empty() || ! stmtsToAddAfter.empty() ) { … … 83 90 84 91 Statement * PolyMutator::mutate(IfStmt *ifStmt) { 92 ifStmt->set_condition( mutateExpression( ifStmt->get_condition() ) ); 85 93 ifStmt->set_thenPart( mutateStatement( ifStmt->get_thenPart() ) ); 86 94 ifStmt->set_elsePart( mutateStatement( ifStmt->get_elsePart() ) ); 87 ifStmt->set_condition( mutateExpression( ifStmt->get_condition() ) );88 95 return ifStmt; 89 96 } 90 97 91 98 Statement * PolyMutator::mutate(WhileStmt *whileStmt) { 99 whileStmt->set_condition( mutateExpression( whileStmt->get_condition() ) ); 92 100 whileStmt->set_body( mutateStatement( whileStmt->get_body() ) ); 93 whileStmt->set_condition( mutateExpression( whileStmt->get_condition() ) );94 101 return whileStmt; 95 102 } 96 103 97 104 Statement * PolyMutator::mutate(ForStmt *forStmt) { 98 forStmt->set_body( mutateStatement( forStmt->get_body() ) );99 105 mutateAll( forStmt->get_initialization(), *this ); 100 106 forStmt->set_condition( mutateExpression( forStmt->get_condition() ) ); 101 107 forStmt->set_increment( mutateExpression( forStmt->get_increment() ) ); 108 forStmt->set_body( mutateStatement( forStmt->get_body() ) ); 102 109 return forStmt; 103 110 } 104 111 105 112 Statement * PolyMutator::mutate(SwitchStmt *switchStmt) { 113 switchStmt->set_condition( mutateExpression( switchStmt->get_condition() ) ); 106 114 mutateStatementList( switchStmt->get_statements() ); 107 switchStmt->set_condition( mutateExpression( switchStmt->get_condition() ) );108 115 return switchStmt; 109 116 } 110 117 111 118 Statement * PolyMutator::mutate(CaseStmt *caseStmt) { 119 caseStmt->set_condition( mutateExpression( caseStmt->get_condition() ) ); 112 120 mutateStatementList( caseStmt->get_statements() ); 113 caseStmt->set_condition( mutateExpression( caseStmt->get_condition() ) );114 121 return caseStmt; 115 122 } -
src/Makefile.in
r0f9bef3 r6250a312 108 108 CodeGen/driver_cfa_cpp-OperatorTable.$(OBJEXT) \ 109 109 CodeTools/driver_cfa_cpp-DeclStats.$(OBJEXT) \ 110 CodeTools/driver_cfa_cpp-TrackLoc.$(OBJEXT) \ 110 111 Concurrency/driver_cfa_cpp-Keywords.$(OBJEXT) \ 111 112 Common/driver_cfa_cpp-SemanticError.$(OBJEXT) \ … … 388 389 CodeGen/FixNames.cc CodeGen/FixMain.cc \ 389 390 CodeGen/OperatorTable.cc CodeTools/DeclStats.cc \ 390 Concurrency/Keywords.cc Common/SemanticError.cc \ 391 Common/UniqueName.cc Common/DebugMalloc.cc Common/Assert.cc \ 391 CodeTools/TrackLoc.cc Concurrency/Keywords.cc \ 392 Common/SemanticError.cc Common/UniqueName.cc \ 393 Common/DebugMalloc.cc Common/Assert.cc \ 392 394 ControlStruct/LabelGenerator.cc ControlStruct/LabelFixer.cc \ 393 395 ControlStruct/MLEMutator.cc ControlStruct/Mutate.cc \ … … 545 547 @: > CodeTools/$(DEPDIR)/$(am__dirstamp) 546 548 CodeTools/driver_cfa_cpp-DeclStats.$(OBJEXT): \ 549 CodeTools/$(am__dirstamp) CodeTools/$(DEPDIR)/$(am__dirstamp) 550 CodeTools/driver_cfa_cpp-TrackLoc.$(OBJEXT): \ 547 551 CodeTools/$(am__dirstamp) CodeTools/$(DEPDIR)/$(am__dirstamp) 548 552 Concurrency/$(am__dirstamp): … … 843 847 -rm -f CodeGen/driver_cfa_cpp-OperatorTable.$(OBJEXT) 844 848 -rm -f CodeTools/driver_cfa_cpp-DeclStats.$(OBJEXT) 849 -rm -f CodeTools/driver_cfa_cpp-TrackLoc.$(OBJEXT) 845 850 -rm -f Common/driver_cfa_cpp-Assert.$(OBJEXT) 846 851 -rm -f Common/driver_cfa_cpp-DebugMalloc.$(OBJEXT) … … 954 959 @AMDEP_TRUE@@am__include@ @am__quote@CodeGen/$(DEPDIR)/driver_cfa_cpp-OperatorTable.Po@am__quote@ 955 960 @AMDEP_TRUE@@am__include@ @am__quote@CodeTools/$(DEPDIR)/driver_cfa_cpp-DeclStats.Po@am__quote@ 961 @AMDEP_TRUE@@am__include@ @am__quote@CodeTools/$(DEPDIR)/driver_cfa_cpp-TrackLoc.Po@am__quote@ 956 962 @AMDEP_TRUE@@am__include@ @am__quote@Common/$(DEPDIR)/driver_cfa_cpp-Assert.Po@am__quote@ 957 963 @AMDEP_TRUE@@am__include@ @am__quote@Common/$(DEPDIR)/driver_cfa_cpp-DebugMalloc.Po@am__quote@ … … 1195 1201 @am__fastdepCXX_FALSE@ $(AM_V_CXX@am__nodep@)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(driver_cfa_cpp_CXXFLAGS) $(CXXFLAGS) -c -o CodeTools/driver_cfa_cpp-DeclStats.obj `if test -f 'CodeTools/DeclStats.cc'; then $(CYGPATH_W) 'CodeTools/DeclStats.cc'; else $(CYGPATH_W) '$(srcdir)/CodeTools/DeclStats.cc'; fi` 1196 1202 1203 CodeTools/driver_cfa_cpp-TrackLoc.o: CodeTools/TrackLoc.cc 1204 @am__fastdepCXX_TRUE@ $(AM_V_CXX)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(driver_cfa_cpp_CXXFLAGS) $(CXXFLAGS) -MT CodeTools/driver_cfa_cpp-TrackLoc.o -MD -MP -MF CodeTools/$(DEPDIR)/driver_cfa_cpp-TrackLoc.Tpo -c -o CodeTools/driver_cfa_cpp-TrackLoc.o `test -f 'CodeTools/TrackLoc.cc' || echo '$(srcdir)/'`CodeTools/TrackLoc.cc 1205 @am__fastdepCXX_TRUE@ $(AM_V_at)$(am__mv) CodeTools/$(DEPDIR)/driver_cfa_cpp-TrackLoc.Tpo CodeTools/$(DEPDIR)/driver_cfa_cpp-TrackLoc.Po 1206 @AMDEP_TRUE@@am__fastdepCXX_FALSE@ $(AM_V_CXX)source='CodeTools/TrackLoc.cc' object='CodeTools/driver_cfa_cpp-TrackLoc.o' libtool=no @AMDEPBACKSLASH@ 1207 @AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@ 1208 @am__fastdepCXX_FALSE@ $(AM_V_CXX@am__nodep@)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(driver_cfa_cpp_CXXFLAGS) $(CXXFLAGS) -c -o CodeTools/driver_cfa_cpp-TrackLoc.o `test -f 'CodeTools/TrackLoc.cc' || echo '$(srcdir)/'`CodeTools/TrackLoc.cc 1209 1210 CodeTools/driver_cfa_cpp-TrackLoc.obj: CodeTools/TrackLoc.cc 1211 @am__fastdepCXX_TRUE@ $(AM_V_CXX)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(driver_cfa_cpp_CXXFLAGS) $(CXXFLAGS) -MT CodeTools/driver_cfa_cpp-TrackLoc.obj -MD -MP -MF CodeTools/$(DEPDIR)/driver_cfa_cpp-TrackLoc.Tpo -c -o CodeTools/driver_cfa_cpp-TrackLoc.obj `if test -f 'CodeTools/TrackLoc.cc'; then $(CYGPATH_W) 'CodeTools/TrackLoc.cc'; else $(CYGPATH_W) '$(srcdir)/CodeTools/TrackLoc.cc'; fi` 1212 @am__fastdepCXX_TRUE@ $(AM_V_at)$(am__mv) CodeTools/$(DEPDIR)/driver_cfa_cpp-TrackLoc.Tpo CodeTools/$(DEPDIR)/driver_cfa_cpp-TrackLoc.Po 1213 @AMDEP_TRUE@@am__fastdepCXX_FALSE@ $(AM_V_CXX)source='CodeTools/TrackLoc.cc' object='CodeTools/driver_cfa_cpp-TrackLoc.obj' libtool=no @AMDEPBACKSLASH@ 1214 @AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@ 1215 @am__fastdepCXX_FALSE@ $(AM_V_CXX@am__nodep@)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(driver_cfa_cpp_CXXFLAGS) $(CXXFLAGS) -c -o CodeTools/driver_cfa_cpp-TrackLoc.obj `if test -f 'CodeTools/TrackLoc.cc'; then $(CYGPATH_W) 'CodeTools/TrackLoc.cc'; else $(CYGPATH_W) '$(srcdir)/CodeTools/TrackLoc.cc'; fi` 1216 1197 1217 Concurrency/driver_cfa_cpp-Keywords.o: Concurrency/Keywords.cc 1198 1218 @am__fastdepCXX_TRUE@ $(AM_V_CXX)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(driver_cfa_cpp_CXXFLAGS) $(CXXFLAGS) -MT Concurrency/driver_cfa_cpp-Keywords.o -MD -MP -MF Concurrency/$(DEPDIR)/driver_cfa_cpp-Keywords.Tpo -c -o Concurrency/driver_cfa_cpp-Keywords.o `test -f 'Concurrency/Keywords.cc' || echo '$(srcdir)/'`Concurrency/Keywords.cc -
src/Parser/parser.yy
r0f9bef3 r6250a312 393 393 | '(' compound_statement ')' // GCC, lambda expression 394 394 { $$ = new ExpressionNode( build_valexpr( $2 ) ); } 395 | primary_expression '{' argument_expression_list '}' // CFA 396 { 397 Token fn; 398 fn.str = new std::string( "?{}" ); // location undefined - use location of '{'? 399 $$ = new ExpressionNode( new ConstructorExpr( build_func( new ExpressionNode( build_varref( fn ) ), (ExpressionNode *)( $1 )->set_last( $3 ) ) ) ); 400 } 395 401 ; 396 402 … … 425 431 | '(' type_name_no_function ')' '{' initializer_list comma_opt '}' // C99, compound-literal 426 432 { $$ = new ExpressionNode( build_compoundLiteral( $2, new InitializerNode( $5, true ) ) ); } 427 | postfix_expression '{' argument_expression_list '}' // CFA433 | '^' primary_expression '{' argument_expression_list '}' // CFA 428 434 { 429 435 Token fn; 430 fn.str = new st d::string( "?{}" ); // location undefined - use location of '{'?431 $$ = new ExpressionNode( new ConstructorExpr( build_func( new ExpressionNode( build_varref( fn ) ), (ExpressionNode *)( $1 )->set_last( $3 )) ) );436 fn.str = new string( "^?{}" ); // location undefined 437 $$ = new ExpressionNode( build_func( new ExpressionNode( build_varref( fn ) ), (ExpressionNode *)( $2 )->set_last( $4 ) ) ); 432 438 } 433 439 ; … … 730 736 | exception_statement 731 737 | asm_statement 732 | '^' postfix_expression '{' argument_expression_list '}' ';' // CFA733 {734 Token fn;735 fn.str = new string( "^?{}" ); // location undefined736 $$ = new StatementNode( build_expr( new ExpressionNode( build_func( new ExpressionNode( build_varref( fn ) ), (ExpressionNode *)( $2 )->set_last( $4 ) ) ) ) );737 }738 ;739 738 740 739 labeled_statement: -
src/ResolvExpr/AlternativeFinder.cc
r0f9bef3 r6250a312 766 766 } // if 767 767 } // for 768 // function may return struct or union value, in which case we need to add alternatives for implicit conversions to each of the anonymous members 768 769 candidates.clear(); 770 candidates.splice( candidates.end(), alternatives ); 771 772 findMinCost( candidates.begin(), candidates.end(), std::back_inserter( alternatives ) ); 773 774 // function may return struct or union value, in which case we need to add alternatives for implicit 775 // conversions to each of the anonymous members, must happen after findMinCost since anon conversions 776 // are never the cheapest expression 769 777 for ( const Alternative & alt : alternatives ) { 770 778 addAnonConversions( alt ); 771 779 } 772 773 candidates.clear();774 candidates.splice( candidates.end(), alternatives );775 776 findMinCost( candidates.begin(), candidates.end(), std::back_inserter( alternatives ) );777 780 778 781 if ( alternatives.empty() && targetType && ! targetType->isVoid() ) { -
src/SymTab/Validate.cc
r0f9bef3 r6250a312 240 240 ReturnTypeFixer::fix( translationUnit ); // must happen before autogen 241 241 acceptAll( translationUnit, lrt ); // must happen before autogen, because sized flag needs to propagate to generated functions 242 acceptAll( translationUnit, epc ); // must happen before VerifyCtorDtorAssign, because void return objects should not exist 243 VerifyCtorDtorAssign::verify( translationUnit ); // must happen before autogen, because autogen examines existing ctor/dtors 242 244 Concurrency::applyKeywords( translationUnit ); 243 245 autogenerateRoutines( translationUnit ); // moved up, used to be below compoundLiteral - currently needs EnumAndPointerDecayPass 244 246 Concurrency::implementMutexFuncs( translationUnit ); 245 247 Concurrency::implementThreadStarter( translationUnit ); 246 acceptAll( translationUnit, epc );247 248 ReturnChecker::checkFunctionReturns( translationUnit ); 248 249 compoundliteral.mutateDeclarationList( translationUnit ); 249 250 acceptAll( translationUnit, pass3 ); 250 VerifyCtorDtorAssign::verify( translationUnit );251 251 ArrayLength::computeLength( translationUnit ); 252 252 } … … 817 817 throw SemanticError( "Constructors, destructors, and assignment functions require at least one parameter ", funcDecl ); 818 818 } 819 if ( ! dynamic_cast< PointerType * >( params.front()->get_type() ) ) { 819 PointerType * ptrType = dynamic_cast< PointerType * >( params.front()->get_type() ); 820 if ( ! ptrType || ptrType->is_array() ) { 820 821 throw SemanticError( "First parameter of a constructor, destructor, or assignment function must be a pointer ", funcDecl ); 821 822 } -
src/SynTree/BaseSyntaxNode.h
r0f9bef3 r6250a312 18 18 19 19 #include "Common/utility.h" 20 #include "Visitor.h" 20 21 21 22 class BaseSyntaxNode { 22 23 public: 23 24 CodeLocation location; 25 26 virtual void accept( Visitor & v ) = 0; // temporary -- needs to be here so that BaseSyntaxNode is polymorphic and can be dynamic_cast 24 27 }; 25 28 -
src/SynTree/Declaration.h
r0f9bef3 r6250a312 204 204 205 205 virtual std::string typeString() const; 206 virtual std::string genTypeString() const; 206 207 207 208 virtual TypeDecl *clone() const { return new TypeDecl( *this ); } -
src/SynTree/PointerType.cc
r0f9bef3 r6250a312 5 5 // file "LICENCE" distributed with Cforall. 6 6 // 7 // PointerType.cc -- 7 // PointerType.cc -- 8 8 // 9 9 // Author : Richard C. Bilson … … 38 38 void PointerType::print( std::ostream &os, int indent ) const { 39 39 Type::print( os, indent ); 40 os << "pointer to "; 41 if ( isStatic ) { 42 os << "static "; 43 } // if 44 if ( isVarLen ) { 45 os << "variable length array of "; 46 } else if ( dimension ) { 47 os << "array of "; 48 dimension->print( os, indent ); 49 } // if 40 if ( ! is_array() ) { 41 os << "pointer to "; 42 } else { 43 os << "decayed "; 44 if ( isStatic ) { 45 os << "static "; 46 } // if 47 if ( isVarLen ) { 48 os << "variable length array of "; 49 } else if ( dimension ) { 50 os << "array of "; 51 dimension->print( os, indent ); 52 os << " "; 53 } // if 54 } 50 55 if ( base ) { 51 56 base->print( os, indent ); -
src/SynTree/SynTree.h
r0f9bef3 r6250a312 21 21 #include <map> 22 22 #include <iostream> 23 24 class BaseSyntaxNode; 23 25 24 26 class Declaration; -
src/SynTree/Type.h
r0f9bef3 r6250a312 247 247 void set_isStatic( bool newValue ) { isStatic = newValue; } 248 248 249 bool is_array() const { return isStatic || isVarLen || dimension; } 250 249 251 virtual PointerType *clone() const { return new PointerType( *this ); } 250 252 virtual void accept( Visitor & v ) { v.visit( this ); } -
src/SynTree/TypeDecl.cc
r0f9bef3 r6250a312 29 29 } 30 30 31 std::string TypeDecl::genTypeString() const { 32 static const std::string kindNames[] = { "otype", "dtype", "ftype", "ttype" }; 33 return kindNames[ kind ]; 34 } 35 31 36 std::ostream & operator<<( std::ostream & os, const TypeDecl::Data & data ) { 32 37 return os << data.kind << ", " << data.isComplete; -
src/SynTree/Visitor.h
r0f9bef3 r6250a312 9 9 // Author : Richard C. Bilson 10 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : Peter A. Buhr12 // Last Modified On : Thu Feb 9 14:23:24201711 // Last Modified By : Andrew Beach 12 // Last Modified On : Wed May 3 08:58:00 2017 13 13 // Update Count : 10 14 14 // … … 26 26 virtual ~Visitor(); 27 27 public: 28 // visit: Default implementation of all functions visits the children 29 // of the given syntax node, but performs no other action. 30 28 31 virtual void visit( ObjectDecl *objectDecl ); 29 32 virtual void visit( FunctionDecl *functionDecl ); -
src/benchmark/CorCtxSwitch.c
r0f9bef3 r6250a312 3 3 #include <thread> 4 4 5 #include <unistd.h> // sysconf 6 #include <sys/times.h> // times 7 #include <time.h> 5 #include "bench.h" 8 6 9 inline unsigned long long int Time() { 10 timespec ts; 11 clock_gettime( 12 #if defined( __linux__ ) 13 CLOCK_THREAD_CPUTIME_ID, 14 #elif defined( __freebsd__ ) 15 CLOCK_PROF, 16 #elif defined( __solaris__ ) 17 CLOCK_HIGHRES, 18 #else 19 #error uC++ : internal error, unsupported architecture 20 #endif 21 &ts ); 22 return 1000000000LL * ts.tv_sec + ts.tv_nsec; 23 } // Time 24 25 struct GreatSuspender { 26 coroutine_desc __cor; 27 }; 28 29 DECL_COROUTINE(GreatSuspender); 7 coroutine GreatSuspender {}; 30 8 31 9 void ?{}( GreatSuspender * this ) { … … 46 24 } 47 25 48 #ifndef N49 #define N 10000000050 #endif51 52 26 int main() { 53 27 const unsigned int NoOfTimes = N; -
src/benchmark/Makefile.am
r0f9bef3 r6250a312 44 44 @rm -f ./a.out 45 45 46 sched-int: 47 ${CC} ${AM_CFLAGS} ${CFLAGS} ${ccflags} @CFA_FLAGS@ -nodebug -lrt -DN=10000000 SchedInt.c 48 @for number in 1 2 3 4 5 6 7 8 9 10; do \ 49 ./a.out ; \ 50 done 51 @rm -f ./a.out 52 53 monitor: 54 ${CC} ${AM_CFLAGS} ${CFLAGS} ${ccflags} @CFA_FLAGS@ -nodebug -lrt -DN=10000000 Monitor.c 55 @for number in 1 2 3 4 5 6 7 8 9 10; do \ 56 ./a.out ; \ 57 done 58 @rm -f ./a.out 59 46 60 csv-data: 47 61 @${CC} ${AM_CFLAGS} ${CFLAGS} ${ccflags} @CFA_FLAGS@ -nodebug -lrt -quiet -DN=10000000 csv-data.c -
src/benchmark/Makefile.in
r0f9bef3 r6250a312 492 492 @rm -f ./a.out 493 493 494 sched-int: 495 ${CC} ${AM_CFLAGS} ${CFLAGS} ${ccflags} @CFA_FLAGS@ -nodebug -lrt -DN=10000000 SchedInt.c 496 @for number in 1 2 3 4 5 6 7 8 9 10; do \ 497 ./a.out ; \ 498 done 499 @rm -f ./a.out 500 501 monitor: 502 ${CC} ${AM_CFLAGS} ${CFLAGS} ${ccflags} @CFA_FLAGS@ -nodebug -lrt -DN=10000000 Monitor.c 503 @for number in 1 2 3 4 5 6 7 8 9 10; do \ 504 ./a.out ; \ 505 done 506 @rm -f ./a.out 507 494 508 csv-data: 495 509 @${CC} ${AM_CFLAGS} ${CFLAGS} ${ccflags} @CFA_FLAGS@ -nodebug -lrt -quiet -DN=10000000 csv-data.c -
src/benchmark/ThrdCtxSwitch.c
r0f9bef3 r6250a312 3 3 #include <thread> 4 4 5 #include <unistd.h> // sysconf 6 #include <sys/times.h> // times 7 #include <time.h> 8 9 inline unsigned long long int Time() { 10 timespec ts; 11 clock_gettime( 12 #if defined( __linux__ ) 13 CLOCK_THREAD_CPUTIME_ID, 14 #elif defined( __freebsd__ ) 15 CLOCK_PROF, 16 #elif defined( __solaris__ ) 17 CLOCK_HIGHRES, 18 #else 19 #error uC++ : internal error, unsupported architecture 20 #endif 21 &ts ); 22 return 1000000000LL * ts.tv_sec + ts.tv_nsec; 23 } // Time 24 25 #ifndef N 26 #define N 100000000 27 #endif 5 #include "bench.h" 28 6 29 7 int main() { -
src/benchmark/bench.c
r0f9bef3 r6250a312 4 4 #include <thread> 5 5 6 #include <unistd.h> // sysconf 7 #include <sys/times.h> // times 8 #include <time.h> 9 10 inline unsigned long long int Time() { 11 timespec ts; 12 clock_gettime( 13 #if defined( __linux__ ) 14 CLOCK_THREAD_CPUTIME_ID, 15 #elif defined( __freebsd__ ) 16 CLOCK_PROF, 17 #elif defined( __solaris__ ) 18 CLOCK_HIGHRES, 19 #else 20 #error uC++ : internal error, unsupported architecture 21 #endif 22 &ts ); 23 return 1000000000LL * ts.tv_sec + ts.tv_nsec; 24 } // Time 6 #include "bench.h" 25 7 26 8 //======================================= … … 86 68 //======================================= 87 69 88 struct CoroutineDummy { coroutine_desc __cor; }; 89 DECL_COROUTINE(CoroutineDummy); 70 coroutine CoroutineDummy {}; 90 71 void main(CoroutineDummy * this) {} 91 72 … … 117 98 } 118 99 119 structCoroutineResume {100 coroutine CoroutineResume { 120 101 int N; 121 coroutine_desc __cor;122 102 }; 123 124 DECL_COROUTINE(CoroutineResume);125 103 126 104 void ?{}(CoroutineResume* this, int N) { … … 150 128 //======================================= 151 129 152 struct ThreadDummy { thread_desc __thrd; }; 153 DECL_THREAD(ThreadDummy); 130 thread ThreadDummy {}; 154 131 void main(ThreadDummy * this) {} 155 132 … … 177 154 } 178 155 179 structContextSwitch {156 thread ContextSwitch { 180 157 int N; 181 158 long long result; 182 thread_desc __thrd;183 159 }; 184 185 DECL_THREAD(ContextSwitch);186 160 187 161 void main(ContextSwitch * this) { … … 241 215 DynamicTaskCreateDelete( NoOfTimes ); 242 216 { 243 scoped(ContextSwitch)dummy = { (int)NoOfTimes }; // context switch217 ContextSwitch dummy = { (int)NoOfTimes }; // context switch 244 218 } 245 219 sout | "\t" | endl; -
src/benchmark/csv-data.c
r0f9bef3 r6250a312 1 1 #include <fstream> 2 #include <monitor> 2 3 #include <stdlib> 3 4 #include <thread> 4 5 5 extern "C" { 6 #include <unistd.h> // sysconf 7 #include <sys/times.h> // times 8 #include <time.h> 9 } 10 11 inline unsigned long long int Time() { 12 timespec ts; 13 clock_gettime( 14 #if defined( __linux__ ) 15 CLOCK_THREAD_CPUTIME_ID, 16 #elif defined( __freebsd__ ) 17 CLOCK_PROF, 18 #elif defined( __solaris__ ) 19 CLOCK_HIGHRES, 20 #else 21 #error uC++ : internal error, unsupported architecture 22 #endif 23 &ts ); 24 return 1000000000LL * ts.tv_sec + ts.tv_nsec; 25 } // Time 26 27 struct GreatSuspender { 28 coroutine_desc __cor; 29 }; 30 31 DECL_COROUTINE(GreatSuspender); 6 #include "bench.h" 7 8 coroutine GreatSuspender {}; 32 9 33 10 void ?{}( GreatSuspender * this ) { … … 52 29 #endif 53 30 54 55 31 //----------------------------------------------------------------------------- 32 // coroutine context switch 56 33 long long int measure_coroutine() { 57 34 const unsigned int NoOfTimes = N; … … 71 48 } 72 49 50 //----------------------------------------------------------------------------- 51 // thread context switch 73 52 long long int measure_thread() { 74 53 const unsigned int NoOfTimes = N; … … 84 63 } 85 64 65 //----------------------------------------------------------------------------- 66 // single monitor entry 67 monitor mon_t {}; 68 void dummy( mon_t * mutex m ) {} 69 70 long long int measure_1_monitor_entry() { 71 const unsigned int NoOfTimes = N; 72 long long int StartTime, EndTime; 73 mon_t mon; 74 75 StartTime = Time(); 76 for ( volatile unsigned int i = 0; i < NoOfTimes; i += 1 ) { 77 dummy( &mon ); 78 } 79 EndTime = Time(); 80 81 return ( EndTime - StartTime ) / NoOfTimes; 82 } 83 84 //----------------------------------------------------------------------------- 85 // multi monitor entry 86 void dummy( mon_t * mutex m1, mon_t * mutex m2 ) {} 87 88 long long int measure_2_monitor_entry() { 89 const unsigned int NoOfTimes = N; 90 long long int StartTime, EndTime; 91 mon_t mon1, mon2; 92 93 StartTime = Time(); 94 for ( volatile unsigned int i = 0; i < NoOfTimes; i += 1 ) { 95 dummy( &mon1, &mon2 ); 96 } 97 EndTime = Time(); 98 99 return ( EndTime - StartTime ) / NoOfTimes; 100 } 101 102 //----------------------------------------------------------------------------- 103 // single internal sched entry 104 mon_t mon1; 105 106 condition cond1a; 107 condition cond1b; 108 109 thread thrd1a { long long int * out; }; 110 thread thrd1b {}; 111 112 void ?{}( thrd1a * this, long long int * out ) { 113 this->out = out; 114 } 115 116 void side1A( mon_t * mutex a, long long int * out ) { 117 long long int StartTime, EndTime; 118 119 StartTime = Time(); 120 for( int i = 0;; i++ ) { 121 signal(&cond1a); 122 if( i > N ) break; 123 wait(&cond1b); 124 } 125 EndTime = Time(); 126 127 *out = ( EndTime - StartTime ) / N; 128 } 129 130 void side1B( mon_t * mutex a ) { 131 for( int i = 0;; i++ ) { 132 signal(&cond1b); 133 if( i > N ) break; 134 wait(&cond1a); 135 } 136 } 137 138 void main( thrd1a * this ) { side1A( &mon1, this->out ); } 139 void main( thrd1b * this ) { side1B( &mon1 ); } 140 141 long long int measure_1_sched_int() { 142 long long int t; 143 { 144 thrd1a a = { &t }; 145 thrd1b b; 146 } 147 return t; 148 } 149 150 //----------------------------------------------------------------------------- 151 // multi internal sched entry 152 mon_t mon2; 153 154 condition cond2a; 155 condition cond2b; 156 157 thread thrd2a { long long int * out; }; 158 thread thrd2b {}; 159 160 void ?{}( thrd2a * this, long long int * out ) { 161 this->out = out; 162 } 163 164 void side2A( mon_t * mutex a, mon_t * mutex b, long long int * out ) { 165 long long int StartTime, EndTime; 166 167 StartTime = Time(); 168 for( int i = 0;; i++ ) { 169 signal(&cond2a); 170 if( i > N ) break; 171 wait(&cond2b); 172 } 173 EndTime = Time(); 174 175 *out = ( EndTime - StartTime ) / N; 176 } 177 178 void side2B( mon_t * mutex a, mon_t * mutex b ) { 179 for( int i = 0;; i++ ) { 180 signal(&cond2b); 181 if( i > N ) break; 182 wait(&cond2a); 183 } 184 } 185 186 void main( thrd2a * this ) { side2A( &mon1, &mon2, this->out ); } 187 void main( thrd2b * this ) { side2B( &mon1, &mon2 ); } 188 189 long long int measure_2_sched_int() { 190 long long int t; 191 { 192 thrd2a a = { &t }; 193 thrd2b b; 194 } 195 return t; 196 } 197 198 //----------------------------------------------------------------------------- 199 // main loop 86 200 int main() 87 201 { 88 sout | time(NULL) | ',' | measure_coroutine() | ',' | measure_thread() | endl; 89 } 202 sout | time(NULL) | ','; 203 sout | measure_coroutine() | ','; 204 sout | measure_thread() | ','; 205 sout | measure_1_monitor_entry() | ','; 206 sout | measure_2_monitor_entry() | ','; 207 sout | measure_1_sched_int() | ','; 208 sout | measure_2_sched_int() | endl; 209 } -
src/libcfa/concurrency/monitor
r0f9bef3 r6250a312 81 81 } 82 82 83 static inline void ^?{}( condition * this ) { 84 free( this->monitors ); 85 } 86 83 87 void wait( condition * this ); 84 88 void signal( condition * this ); -
src/libcfa/concurrency/monitor.c
r0f9bef3 r6250a312 17 17 #include "monitor" 18 18 19 #include <stdlib> 20 19 21 #include "kernel_private.h" 20 22 #include "libhdr.h" … … 130 132 this_thread()->current_monitors = this->prev_mntrs; 131 133 this_thread()->current_monitor_count = this->prev_count; 134 } 135 136 void debug_break() __attribute__(( noinline )) 137 { 138 132 139 } 133 140 … … 171 178 172 179 //Find the next thread(s) to run 173 unsigned short thread_count = count;180 unsigned short thread_count = 0; 174 181 thread_desc * threads[ count ]; 182 for(int i = 0; i < count; i++) { 183 threads[i] = 0; 184 } 185 186 debug_break(); 175 187 176 188 for( int i = 0; i < count; i++) { 177 189 thread_desc * new_owner = next_thread( this->monitors[i] ); 178 thread_count = insert_unique( threads, i, new_owner ); 179 } 190 thread_count = insert_unique( threads, thread_count, new_owner ); 191 } 192 193 debug_break(); 180 194 181 195 LIB_DEBUG_PRINT_SAFE("Will unblock: "); … … 339 353 LIB_DEBUG_PRINT_SAFE("Branding\n"); 340 354 assertf( thrd->current_monitors != NULL, "No current monitor to brand condition", thrd->current_monitors ); 341 this->monitors = thrd->current_monitors;342 355 this->monitor_count = thrd->current_monitor_count; 356 357 this->monitors = malloc( this->monitor_count * sizeof( *this->monitors ) ); 358 for( int i = 0; i < this->monitor_count; i++ ) { 359 this->monitors[i] = thrd->current_monitors[i]; 360 } 343 361 } 344 362 } 345 363 346 364 static inline unsigned short insert_unique( thread_desc ** thrds, unsigned short end, thread_desc * val ) { 347 for(int i = 0; i < end; i++) { 365 if( !val ) return end; 366 367 for(int i = 0; i <= end; i++) { 348 368 if( thrds[i] == val ) return end; 349 369 } -
src/libcfa/concurrency/thread.c
r0f9bef3 r6250a312 40 40 this->next = NULL; 41 41 42 this->current_monitors = NULL;43 this->current_monitor_count = 0;42 this->current_monitors = &this->mon; 43 this->current_monitor_count = 1; 44 44 } 45 45 -
src/libcfa/rational
r0f9bef3 r6250a312 12 12 // Created On : Wed Apr 6 17:56:25 2016 13 13 // Last Modified By : Peter A. Buhr 14 // Last Modified On : Wed May 4 14:11:45 201615 // Update Count : 1614 // Last Modified On : Mon May 1 08:25:06 2017 15 // Update Count : 33 16 16 // 17 17 18 #ifndef RATIONAL_H 18 19 #define RATIONAL_H … … 21 22 22 23 // implementation 24 typedef long int RationalImpl; 23 25 struct Rational { 24 long intnumerator, denominator; // invariant: denominator > 026 RationalImpl numerator, denominator; // invariant: denominator > 0 25 27 }; // Rational 26 28 … … 31 33 // constructors 32 34 void ?{}( Rational * r ); 33 void ?{}( Rational * r, long intn );34 void ?{}( Rational * r, long int n, long intd );35 void ?{}( Rational * r, RationalImpl n ); 36 void ?{}( Rational * r, RationalImpl n, RationalImpl d ); 35 37 36 // getter/setter for numerator/denominator 37 long int numerator( Rational r ); 38 long int numerator( Rational r, long int n ); 39 long int denominator( Rational r ); 40 long int denominator( Rational r, long int d ); 38 // getter for numerator/denominator 39 RationalImpl numerator( Rational r ); 40 RationalImpl denominator( Rational r ); 41 [ RationalImpl, RationalImpl ] ?=?( * [ RationalImpl, RationalImpl ] dest, Rational src ); 42 // setter for numerator/denominator 43 RationalImpl numerator( Rational r, RationalImpl n ); 44 RationalImpl denominator( Rational r, RationalImpl d ); 41 45 42 46 // comparison … … 57 61 // conversion 58 62 double widen( Rational r ); 59 Rational narrow( double f, long intmd );63 Rational narrow( double f, RationalImpl md ); 60 64 61 65 // I/O -
src/libcfa/rational.c
r0f9bef3 r6250a312 10 10 // Created On : Wed Apr 6 17:54:28 2016 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Sat Jul 9 11:18:04 201613 // Update Count : 4012 // Last Modified On : Thu Apr 27 17:05:06 2017 13 // Update Count : 51 14 14 // 15 15 … … 30 30 // Calculate greatest common denominator of two numbers, the first of which may be negative. Used to reduce rationals. 31 31 // alternative: https://en.wikipedia.org/wiki/Binary_GCD_algorithm 32 static long int gcd( long int a, long intb ) {32 static RationalImpl gcd( RationalImpl a, RationalImpl b ) { 33 33 for ( ;; ) { // Euclid's algorithm 34 long intr = a % b;34 RationalImpl r = a % b; 35 35 if ( r == 0 ) break; 36 36 a = b; … … 40 40 } // gcd 41 41 42 static long int simplify( long int *n, long int*d ) {42 static RationalImpl simplify( RationalImpl *n, RationalImpl *d ) { 43 43 if ( *d == 0 ) { 44 44 serr | "Invalid rational number construction: denominator cannot be equal to 0." | endl; … … 56 56 } // rational 57 57 58 void ?{}( Rational * r, long intn ) {58 void ?{}( Rational * r, RationalImpl n ) { 59 59 r{ n, 1 }; 60 60 } // rational 61 61 62 void ?{}( Rational * r, long int n, long intd ) {63 long int t = simplify( &n, &d );// simplify62 void ?{}( Rational * r, RationalImpl n, RationalImpl d ) { 63 RationalImpl t = simplify( &n, &d ); // simplify 64 64 r->numerator = n / t; 65 65 r->denominator = d / t; … … 67 67 68 68 69 // getter /setterfor numerator/denominator70 71 long intnumerator( Rational r ) {69 // getter for numerator/denominator 70 71 RationalImpl numerator( Rational r ) { 72 72 return r.numerator; 73 73 } // numerator 74 74 75 long int numerator( Rational r, long int n ) { 76 long int prev = r.numerator; 77 long int t = gcd( abs( n ), r.denominator ); // simplify 75 RationalImpl denominator( Rational r ) { 76 return r.denominator; 77 } // denominator 78 79 [ RationalImpl, RationalImpl ] ?=?( * [ RationalImpl, RationalImpl ] dest, Rational src ) { 80 return *dest = src.[ numerator, denominator ]; 81 } 82 83 // setter for numerator/denominator 84 85 RationalImpl numerator( Rational r, RationalImpl n ) { 86 RationalImpl prev = r.numerator; 87 RationalImpl t = gcd( abs( n ), r.denominator ); // simplify 78 88 r.numerator = n / t; 79 89 r.denominator = r.denominator / t; … … 81 91 } // numerator 82 92 83 long int denominator( Rational r ) { 84 return r.denominator; 85 } // denominator 86 87 long int denominator( Rational r, long int d ) { 88 long int prev = r.denominator; 89 long int t = simplify( &r.numerator, &d ); // simplify 93 RationalImpl denominator( Rational r, RationalImpl d ) { 94 RationalImpl prev = r.denominator; 95 RationalImpl t = simplify( &r.numerator, &d ); // simplify 90 96 r.numerator = r.numerator / t; 91 97 r.denominator = d / t; … … 170 176 171 177 // http://www.ics.uci.edu/~eppstein/numth/frap.c 172 Rational narrow( double f, long intmd ) {178 Rational narrow( double f, RationalImpl md ) { 173 179 if ( md <= 1 ) { // maximum fractional digits too small? 174 180 return (Rational){ f, 1}; // truncate fraction … … 176 182 177 183 // continued fraction coefficients 178 long intm00 = 1, m11 = 1, m01 = 0, m10 = 0;179 long intai, t;184 RationalImpl m00 = 1, m11 = 1, m01 = 0, m10 = 0; 185 RationalImpl ai, t; 180 186 181 187 // find terms until denom gets too big 182 188 for ( ;; ) { 183 ai = ( long int)f;189 ai = (RationalImpl)f; 184 190 if ( ! (m10 * ai + m11 <= md) ) break; 185 191 t = m00 * ai + m01; … … 202 208 forall( dtype istype | istream( istype ) ) 203 209 istype * ?|?( istype *is, Rational *r ) { 204 long intt;210 RationalImpl t; 205 211 is | &(r->numerator) | &(r->denominator); 206 212 t = simplify( &(r->numerator), &(r->denominator) ); -
src/main.cc
r0f9bef3 r6250a312 37 37 #include "CodeGen/FixMain.h" 38 38 #include "CodeTools/DeclStats.h" 39 #include "CodeTools/TrackLoc.h" 39 40 #include "ControlStruct/Mutate.h" 40 41 #include "SymTab/Validate.h" … … 308 309 } // if 309 310 311 CodeTools::fillLocations( translationUnit ); 310 312 CodeGen::generate( translationUnit, *output, ! noprotop, prettycodegenp, true ); 311 313 -
src/tests/Makefile.am
r0f9bef3 r6250a312 22 22 concurrent=yes 23 23 quick_test+= coroutine thread monitor 24 concurrent_test=coroutine thread monitor multi-monitor sched-int sched-extpreempt24 concurrent_test=coroutine thread monitor multi-monitor sched-int-disjoint sched-int-barge sched-int-wait sched-ext sched-ext-multi preempt 25 25 else 26 26 concurrent=no -
src/tests/Makefile.in
r0f9bef3 r6250a312 230 230 @BUILD_CONCURRENCY_TRUE@concurrent = yes 231 231 @BUILD_CONCURRENCY_FALSE@concurrent_test = 232 @BUILD_CONCURRENCY_TRUE@concurrent_test = coroutine thread monitor multi-monitor sched-int sched-ext preempt 233 TEST_FLAGS = $(if $(test), 2> .err/${@}.log, ) 232 @BUILD_CONCURRENCY_TRUE@concurrent_test = coroutine thread monitor multi-monitor sched-int-disjoint sched-int-barge sched-int-wait sched-ext sched-ext-multi preempt 234 233 235 234 # applies to both programs 236 235 EXTRA_FLAGS = 237 236 BUILD_FLAGS = -g -Wall -Wno-unused-function @CFA_FLAGS@ ${EXTRA_FLAGS} 237 TEST_FLAGS = $(if $(test), 2> .err/${@}.log, ) 238 238 fstream_test_SOURCES = fstream_test.c 239 239 vector_test_SOURCES = vector/vector_int.c vector/array.c vector/vector_test.c -
src/tests/rational.c
r0f9bef3 r6250a312 10 10 // Created On : Mon Mar 28 08:43:12 2016 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Tue Jul 5 18:29:37 201613 // Update Count : 2512 // Last Modified On : Tue May 2 22:11:05 2017 13 // Update Count : 41 14 14 // 15 15 … … 36 36 b = (Rational){ -3, 2 }; 37 37 sout | a | b | endl; 38 sout | a == 1 | endl; 38 // sout | a == 1 | endl; // FIX ME 39 39 sout | a != b | endl; 40 40 sout | a < b | endl; … … 61 61 sout | narrow( 3.14159265358979, 256 ) | endl; 62 62 63 sout | "decompose" | endl; 64 RationalImpl n, d; 65 // [n, d] = a; 66 // sout | a | n | d | endl; 67 68 sout | "more tests" | endl; 63 69 Rational x = { 1, 2 }, y = { 2 }; 64 70 sout | x - y | endl;
Note:
See TracChangeset
for help on using the changeset viewer.