Changes in src/main.cc [bccd70a:7fffb1b]
- File:
-
- 1 edited
-
src/main.cc (modified) (22 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/main.cc
rbccd70a r7fffb1b 9 9 // Author : Peter Buhr and Rob Schluntz 10 10 // Created On : Fri May 15 23:12:02 2015 11 // Last Modified By : Peter A. Buhr12 // Last Modified On : Mon Apr 10 21:12:17 202313 // Update Count : 6 8211 // Last Modified By : Andrew Beach 12 // Last Modified On : Wed Oct 5 12:06:00 2022 13 // Update Count : 679 14 14 // 15 15 … … 32 32 33 33 #include "AST/Convert.hpp" 34 #include "AST/Pass.hpp" // for pass_visitor_stats35 #include "AST/TranslationUnit.hpp" // for TranslationUnit36 #include "AST/Util.hpp" // for checkInvariants37 34 #include "CompilationState.h" 38 35 #include "../config.h" // for CFA_LIBDIR … … 43 40 #include "CodeTools/TrackLoc.h" // for fillLocations 44 41 #include "Common/CodeLocationTools.hpp" // for forceFillCodeLocations 42 #include "Common/CompilerError.h" // for CompilerError 45 43 #include "Common/DeclStats.hpp" // for printDeclStats 46 44 #include "Common/ResolvProtoDump.hpp" // for dumpAsResolverProto 47 45 #include "Common/Stats.h" // for Stats 46 #include "Common/UnimplementedError.h" // for UnimplementedError 48 47 #include "Common/utility.h" // for deleteAll, filter, printAll 49 #include "Concurrency/Actors.hpp" // for implementActors50 48 #include "Concurrency/Keywords.h" // for implementMutex, implement... 51 49 #include "Concurrency/Waitfor.h" // for generateWaitfor 52 #include "Concurrency/Waituntil.hpp" // for generateWaitUntil53 50 #include "ControlStruct/ExceptDecl.h" // for translateExcept 54 51 #include "ControlStruct/ExceptTranslate.h" // for translateThrows, translat... … … 62 59 #include "InitTweak/GenInit.h" // for genInit 63 60 #include "MakeLibCfa.h" // for makeLibCfa 64 #include "Parser/RunParser.hpp" // for buildList, dumpParseTree,... 61 #include "Parser/ParseNode.h" // for DeclarationNode, buildList 62 #include "Parser/TypedefTable.h" // for TypedefTable 65 63 #include "ResolvExpr/CandidatePrinter.hpp" // for printCandidates 66 64 #include "ResolvExpr/Resolver.h" // for resolve … … 86 84 #include "Validate/VerifyCtorDtorAssign.hpp" // for verifyCtorDtorAssign 87 85 #include "Virtual/ExpandCasts.h" // for expandCasts 88 #include "Virtual/VirtualDtor.hpp" // for implementVirtDtors89 86 90 87 static void NewPass( const char * const name ) { … … 105 102 } 106 103 107 // Helpers for checkInvariant: 108 void checkInvariants( std::list< Declaration * > & ) {} 109 using ast::checkInvariants; 110 111 #define PASS( name, pass, unit, ... ) \ 104 #define PASS( name, pass ) \ 112 105 if ( errorp ) { cerr << name << endl; } \ 113 106 NewPass(name); \ 114 107 Stats::Time::StartBlock(name); \ 115 pass(unit,##__VA_ARGS__); \ 116 Stats::Time::StopBlock(); \ 117 if ( invariant ) { \ 118 checkInvariants(unit); \ 119 } 120 121 #define DUMP( cond, unit ) \ 122 if ( cond ) { \ 123 dump(unit); \ 124 return EXIT_SUCCESS; \ 125 } 108 pass; \ 109 Stats::Time::StopBlock(); 110 111 LinkageSpec::Spec linkage = LinkageSpec::Cforall; 112 TypedefTable typedefTable; 113 DeclarationNode * parseTree = nullptr; // program parse tree 126 114 127 115 static bool waiting_for_gdb = false; // flag to set cfa-cpp to wait for gdb on start … … 130 118 131 119 static void parse_cmdline( int argc, char * argv[] ); 120 static void parse( FILE * input, LinkageSpec::Spec linkage, bool shouldExit = false ); 132 121 static void dump( list< Declaration * > & translationUnit, ostream & out = cout ); 133 122 static void dump( ast::TranslationUnit && transUnit, ostream & out = cout ); … … 245 234 ostream * output = & cout; 246 235 list< Declaration * > translationUnit; 247 ast::TranslationUnit transUnit;248 236 249 237 Signal( SIGSEGV, sigSegvBusHandler, SA_SIGINFO ); … … 290 278 FILE * gcc_builtins = fopen( (PreludeDirector + "/gcc-builtins.cf").c_str(), "r" ); 291 279 assertf( gcc_builtins, "cannot open gcc-builtins.cf\n" ); 292 parse( gcc_builtins, ast::Linkage::Compiler );280 parse( gcc_builtins, LinkageSpec::Compiler ); 293 281 294 282 // read the extra prelude in, if not generating the cfa library 295 283 FILE * extras = fopen( (PreludeDirector + "/extras.cf").c_str(), "r" ); 296 284 assertf( extras, "cannot open extras.cf\n" ); 297 parse( extras, ast::Linkage::BuiltinC );285 parse( extras, LinkageSpec::BuiltinC ); 298 286 299 287 if ( ! libcfap ) { … … 301 289 FILE * prelude = fopen( (PreludeDirector + "/prelude.cfa").c_str(), "r" ); 302 290 assertf( prelude, "cannot open prelude.cfa\n" ); 303 parse( prelude, ast::Linkage::Intrinsic );291 parse( prelude, LinkageSpec::Intrinsic ); 304 292 305 293 // Read to cfa builtins, if not generating the cfa library 306 294 FILE * builtins = fopen( (PreludeDirector + "/builtins.cf").c_str(), "r" ); 307 295 assertf( builtins, "cannot open builtins.cf\n" ); 308 parse( builtins, ast::Linkage::BuiltinCFA ); 309 } // if 310 } // if 311 312 parse( input, libcfap ? ast::Linkage::Intrinsic : ast::Linkage::Cforall, yydebug ); 313 314 transUnit = buildUnit(); 315 316 DUMP( astp, std::move( transUnit ) ); 317 296 parse( builtins, LinkageSpec::BuiltinCFA ); 297 } // if 298 } // if 299 300 parse( input, libcfap ? LinkageSpec::Intrinsic : LinkageSpec::Cforall, yydebug ); 301 302 if ( parsep ) { 303 parseTree->printList( cout ); 304 delete parseTree; 305 return EXIT_SUCCESS; 306 } // if 307 308 buildList( parseTree, translationUnit ); 309 delete parseTree; 310 parseTree = nullptr; 311 312 if ( astp ) { 313 dump( translationUnit ); 314 return EXIT_SUCCESS; 315 } // if 316 317 // Temporary: fill locations after parsing so that every node has a location, for early error messages. 318 // Eventually we should pass the locations from the parser to every node, but this quick and dirty solution 319 // works okay for now. 320 CodeTools::fillLocations( translationUnit ); 318 321 Stats::Time::StopBlock(); 319 322 … … 322 325 ast::pass_visitor_stats.max = Stats::Counters::build<Stats::Counters::MaxCounter<double>>("Max depth - New"); 323 326 } 324 325 PASS( "Hoist Type Decls", Validate::hoistTypeDecls, transUnit ); 326 327 PASS( "Translate Exception Declarations", ControlStruct::translateExcept, transUnit ); 328 DUMP( exdeclp, std::move( transUnit ) ); 329 PASS( "Verify Ctor, Dtor & Assign", Validate::verifyCtorDtorAssign, transUnit ); 330 PASS( "Replace Typedefs", Validate::replaceTypedef, transUnit ); 331 PASS( "Fix Return Types", Validate::fixReturnTypes, transUnit ); 332 PASS( "Enum and Pointer Decay", Validate::decayEnumsAndPointers, transUnit ); 333 334 PASS( "Link Reference To Types", Validate::linkReferenceToTypes, transUnit ); 335 336 PASS( "Fix Qualified Types", Validate::fixQualifiedTypes, transUnit ); 337 PASS( "Hoist Struct", Validate::hoistStruct, transUnit ); 338 PASS( "Eliminate Typedef", Validate::eliminateTypedef, transUnit ); 339 PASS( "Validate Generic Parameters", Validate::fillGenericParameters, transUnit ); 340 PASS( "Translate Dimensions", Validate::translateDimensionParameters, transUnit ); 341 PASS( "Check Function Returns", Validate::checkReturnStatements, transUnit ); 342 PASS( "Fix Return Statements", InitTweak::fixReturnStatements, transUnit ); 343 PASS( "Implement Concurrent Keywords", Concurrency::implementKeywords, transUnit ); 344 PASS( "Forall Pointer Decay", Validate::decayForallPointers, transUnit ); 345 PASS( "Implement Waituntil", Concurrency::generateWaitUntil, transUnit ); 346 PASS( "Hoist Control Declarations", ControlStruct::hoistControlDecls, transUnit ); 347 348 PASS( "Generate Autogen Routines", Validate::autogenerateRoutines, transUnit ); 349 350 PASS( "Implement Actors", Concurrency::implementActors, transUnit ); 351 PASS( "Implement Virtual Destructors", Virtual::implementVirtDtors, transUnit ); 352 PASS( "Implement Mutex", Concurrency::implementMutex, transUnit ); 353 PASS( "Implement Thread Start", Concurrency::implementThreadStarter, transUnit ); 354 PASS( "Compound Literal", Validate::handleCompoundLiterals, transUnit ); 355 PASS( "Set Length From Initializer", Validate::setLengthFromInitializer, transUnit ); 356 PASS( "Find Global Decls", Validate::findGlobalDecls, transUnit ); 357 PASS( "Fix Label Address", Validate::fixLabelAddresses, transUnit ); 327 auto transUnit = convert( std::move( translationUnit ) ); 328 329 forceFillCodeLocations( transUnit ); 330 331 PASS( "Translate Exception Declarations", ControlStruct::translateExcept( transUnit ) ); 332 if ( exdeclp ) { 333 dump( std::move( transUnit ) ); 334 return EXIT_SUCCESS; 335 } 336 337 PASS( "Verify Ctor, Dtor & Assign", Validate::verifyCtorDtorAssign( transUnit ) ); 338 PASS( "Hoist Type Decls", Validate::hoistTypeDecls( transUnit ) ); 339 // Hoist Type Decls pulls some declarations out of contexts where 340 // locations are not tracked. Perhaps they should be, but for now 341 // the full fill solves it. 342 forceFillCodeLocations( transUnit ); 343 344 PASS( "Replace Typedefs", Validate::replaceTypedef( transUnit ) ); 345 PASS( "Fix Return Types", Validate::fixReturnTypes( transUnit ) ); 346 PASS( "Enum and Pointer Decay", Validate::decayEnumsAndPointers( transUnit ) ); 347 348 PASS( "Link Reference To Types", Validate::linkReferenceToTypes( transUnit ) ); 349 350 PASS( "Fix Qualified Types", Validate::fixQualifiedTypes( transUnit ) ); 351 PASS( "Hoist Struct", Validate::hoistStruct( transUnit ) ); 352 PASS( "Eliminate Typedef", Validate::eliminateTypedef( transUnit ) ); 353 PASS( "Validate Generic Parameters", Validate::fillGenericParameters( transUnit ) ); 354 PASS( "Translate Dimensions", Validate::translateDimensionParameters( transUnit ) ); 355 PASS( "Check Function Returns", Validate::checkReturnStatements( transUnit ) ); 356 PASS( "Fix Return Statements", InitTweak::fixReturnStatements( transUnit ) ); 357 PASS( "Implement Concurrent Keywords", Concurrency::implementKeywords( transUnit ) ); 358 PASS( "Forall Pointer Decay", Validate::decayForallPointers( transUnit ) ); 359 PASS( "Hoist Control Declarations", ControlStruct::hoistControlDecls( transUnit ) ); 360 361 PASS( "Generate Autogen Routines", Validate::autogenerateRoutines( transUnit ) ); 362 363 PASS( "Implement Mutex", Concurrency::implementMutex( transUnit ) ); 364 PASS( "Implement Thread Start", Concurrency::implementThreadStarter( transUnit ) ); 365 PASS( "Compound Literal", Validate::handleCompoundLiterals( transUnit ) ); 366 PASS( "Set Length From Initializer", Validate::setLengthFromInitializer( transUnit ) ); 367 PASS( "Find Global Decls", Validate::findGlobalDecls( transUnit ) ); 368 PASS( "Fix Label Address", Validate::fixLabelAddresses( transUnit ) ); 358 369 359 370 if ( symtabp ) { … … 366 377 } // if 367 378 368 DUMP( validp, std::move( transUnit ) ); 369 370 PASS( "Translate Throws", ControlStruct::translateThrows, transUnit ); 371 PASS( "Fix Labels", ControlStruct::fixLabels, transUnit ); 372 PASS( "Fix Names", CodeGen::fixNames, transUnit ); 373 PASS( "Gen Init", InitTweak::genInit, transUnit ); 374 PASS( "Expand Member Tuples" , Tuples::expandMemberTuples, transUnit ); 379 if ( validp ) { 380 dump( std::move( transUnit ) ); 381 return EXIT_SUCCESS; 382 } // if 383 384 PASS( "Translate Throws", ControlStruct::translateThrows( transUnit ) ); 385 PASS( "Fix Labels", ControlStruct::fixLabels( transUnit ) ); 386 PASS( "Fix Names", CodeGen::fixNames( transUnit ) ); 387 PASS( "Gen Init", InitTweak::genInit( transUnit ) ); 388 PASS( "Expand Member Tuples" , Tuples::expandMemberTuples( transUnit ) ); 375 389 376 390 if ( libcfap ) { … … 384 398 } // if 385 399 386 DUMP( bresolvep, std::move( transUnit ) ); 400 if ( bresolvep ) { 401 dump( std::move( transUnit ) ); 402 return EXIT_SUCCESS; 403 } // if 387 404 388 405 if ( resolvprotop ) { … … 391 408 } // if 392 409 393 PASS( "Resolve", ResolvExpr::resolve, transUnit ); 394 DUMP( exprp, std::move( transUnit ) ); 395 396 PASS( "Fix Init", InitTweak::fix, transUnit, buildingLibrary() ); 410 PASS( "Resolve", ResolvExpr::resolve( transUnit ) ); 411 if ( exprp ) { 412 dump( std::move( transUnit ) ); 413 return EXIT_SUCCESS; 414 } // if 415 416 forceFillCodeLocations( transUnit ); 417 418 PASS( "Fix Init", InitTweak::fix(transUnit, buildingLibrary())); 397 419 398 420 // fix ObjectDecl - replaces ConstructorInit nodes 399 DUMP( ctorinitp, std::move( transUnit ) ); 421 if ( ctorinitp ) { 422 dump( std::move( transUnit ) ); 423 return EXIT_SUCCESS; 424 } // if 400 425 401 426 // Currently not working due to unresolved issues with UniqueExpr 402 PASS( "Expand Unique Expr", Tuples::expandUniqueExpr , transUnit); // xxx - is this the right place for this? want to expand ASAP so tha, sequent passes don't need to worry about double-visiting a unique expr - needs to go after InitTweak::fix so that copy constructed return declarations are reused403 404 PASS( "Translate Tries", ControlStruct::translateTries , transUnit);405 PASS( "Gen Waitfor", Concurrency::generateWaitFor , transUnit);427 PASS( "Expand Unique Expr", Tuples::expandUniqueExpr( transUnit ) ); // xxx - is this the right place for this? want to expand ASAP so tha, sequent passes don't need to worry about double-visiting a unique expr - needs to go after InitTweak::fix so that copy constructed return declarations are reused 428 429 PASS( "Translate Tries", ControlStruct::translateTries( transUnit ) ); 430 PASS( "Gen Waitfor", Concurrency::generateWaitFor( transUnit ) ); 406 431 407 432 // Needs to happen before tuple types are expanded. 408 PASS( "Convert Specializations", GenPoly::convertSpecializations, transUnit ); 409 410 PASS( "Expand Tuples", Tuples::expandTuples, transUnit ); 411 DUMP( tuplep, std::move( transUnit ) ); 433 PASS( "Convert Specializations", GenPoly::convertSpecializations( transUnit ) ); 434 435 PASS( "Expand Tuples", Tuples::expandTuples( transUnit ) ); 436 437 if ( tuplep ) { 438 dump( std::move( transUnit ) ); 439 return EXIT_SUCCESS; 440 } // if 412 441 413 442 // Must come after Translate Tries. 414 PASS( "Virtual Expand Casts", Virtual::expandCasts, transUnit ); 415 416 PASS( "Instantiate Generics", GenPoly::instantiateGeneric, transUnit ); 417 DUMP( genericsp, std::move( transUnit ) ); 418 419 PASS( "Convert L-Value", GenPoly::convertLvalue, transUnit ); 443 PASS( "Virtual Expand Casts", Virtual::expandCasts( transUnit ) ); 444 445 PASS( "Instantiate Generics", GenPoly::instantiateGeneric( transUnit ) ); 446 if ( genericsp ) { 447 dump( std::move( transUnit ) ); 448 return EXIT_SUCCESS; 449 } // if 450 451 PASS( "Convert L-Value", GenPoly::convertLvalue( transUnit ) ); 420 452 421 453 translationUnit = convert( std::move( transUnit ) ); 422 454 423 DUMP( bboxp, translationUnit ); 424 PASS( "Box", GenPoly::box, translationUnit ); 425 426 PASS( "Link-Once", CodeGen::translateLinkOnce, translationUnit ); 455 if ( bboxp ) { 456 dump( translationUnit ); 457 return EXIT_SUCCESS; 458 } // if 459 PASS( "Box", GenPoly::box( translationUnit ) ); 460 461 PASS( "Link-Once", CodeGen::translateLinkOnce( translationUnit ) ); 427 462 428 463 // Code has been lowered to C, now we can start generation. 429 464 430 DUMP( bcodegenp, translationUnit ); 465 if ( bcodegenp ) { 466 dump( translationUnit ); 467 return EXIT_SUCCESS; 468 } // if 431 469 432 470 if ( optind < argc ) { // any commands after the flags and input file ? => output file name … … 435 473 436 474 CodeTools::fillLocations( translationUnit ); 437 PASS( "Code Gen", CodeGen::generate , translationUnit, *output, ! genproto, prettycodegenp, true, linemarks);475 PASS( "Code Gen", CodeGen::generate( translationUnit, *output, ! genproto, prettycodegenp, true, linemarks ) ); 438 476 439 477 CodeGen::FixMain::fix( translationUnit, *output, … … 445 483 if ( errorp ) { 446 484 cerr << "---AST at error:---" << endl; 447 // We check which section the errors came from without looking at 448 // transUnit because std::move means it could look like anything. 449 if ( !translationUnit.empty() ) { 450 dump( translationUnit, cerr ); 451 } else { 452 dump( std::move( transUnit ), cerr ); 453 } 485 dump( translationUnit, cerr ); 454 486 cerr << endl << "---End of AST, begin error message:---\n" << endl; 455 487 } // if 456 488 e.print(); 489 if ( output != &cout ) { 490 delete output; 491 } // if 492 return EXIT_FAILURE; 493 } catch ( UnimplementedError & e ) { 494 cout << "Sorry, " << e.get_what() << " is not currently implemented" << endl; 495 if ( output != &cout ) { 496 delete output; 497 } // if 498 return EXIT_FAILURE; 499 } catch ( CompilerError & e ) { 500 cerr << "Compiler Error: " << e.get_what() << endl; 501 cerr << "(please report bugs to [REDACTED])" << endl; 457 502 if ( output != &cout ) { 458 503 delete output; … … 483 528 484 529 485 static const char optstring[] = ":c:gh ilLmNnpdP:S:twW:D:";530 static const char optstring[] = ":c:ghlLmNnpdP:S:twW:D:"; 486 531 487 532 enum { PreludeDir = 128 }; … … 490 535 { "gdb", no_argument, nullptr, 'g' }, 491 536 { "help", no_argument, nullptr, 'h' }, 492 { "invariant", no_argument, nullptr, 'i' },493 537 { "libcfa", no_argument, nullptr, 'l' }, 494 538 { "linemarks", no_argument, nullptr, 'L' }, 495 { "no-main", no_argument, nullptr, 'm' },539 { "no-main", no_argument, 0, 'm' }, 496 540 { "no-linemarks", no_argument, nullptr, 'N' }, 497 541 { "no-prelude", no_argument, nullptr, 'n' }, … … 512 556 "wait for gdb to attach", // -g 513 557 "print translator help message", // -h 514 "invariant checking during AST passes", // -i515 558 "generate libcfa.c", // -l 516 559 "generate line marks", // -L … … 544 587 { "rproto", resolvprotop, true, "resolver-proto instance" }, 545 588 { "rsteps", resolvep, true, "print resolver steps" }, 589 { "tree", parsep, true, "print parse tree" }, 546 590 // code dumps 547 591 { "ast", astp, true, "print AST after parsing" }, … … 606 650 usage( argv ); // no return 607 651 break; 608 case 'i': // invariant checking609 invariant = true;610 break;611 652 case 'l': // generate libcfa.c 612 653 libcfap = true; … … 707 748 } // parse_cmdline 708 749 750 static void parse( FILE * input, LinkageSpec::Spec linkage, bool shouldExit ) { 751 extern int yyparse( void ); 752 extern FILE * yyin; 753 extern int yylineno; 754 755 ::linkage = linkage; // set globals 756 yyin = input; 757 yylineno = 1; 758 int parseStatus = yyparse(); 759 760 fclose( input ); 761 if ( shouldExit || parseStatus != 0 ) { 762 exit( parseStatus ); 763 } // if 764 } // parse 765 709 766 static bool notPrelude( Declaration * decl ) { 710 767 return ! LinkageSpec::isBuiltin( decl->get_linkage() );
Note:
See TracChangeset
for help on using the changeset viewer.