Changes in src/main.cc [52f9804:3dd8f42]
- File:
-
- 1 edited
-
src/main.cc (modified) (17 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/main.cc
r52f9804 r3dd8f42 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/Util.hpp" // for checkInvariants35 34 #include "CompilationState.h" 36 35 #include "../config.h" // for CFA_LIBDIR … … 41 40 #include "CodeTools/TrackLoc.h" // for fillLocations 42 41 #include "Common/CodeLocationTools.hpp" // for forceFillCodeLocations 42 #include "Common/CompilerError.h" // for CompilerError 43 43 #include "Common/DeclStats.hpp" // for printDeclStats 44 44 #include "Common/ResolvProtoDump.hpp" // for dumpAsResolverProto 45 45 #include "Common/Stats.h" // for Stats 46 #include "Common/UnimplementedError.h" // for UnimplementedError 46 47 #include "Common/utility.h" // for deleteAll, filter, printAll 47 48 #include "Concurrency/Actors.hpp" // for implementActors … … 83 84 #include "Validate/VerifyCtorDtorAssign.hpp" // for verifyCtorDtorAssign 84 85 #include "Virtual/ExpandCasts.h" // for expandCasts 85 #include "Virtual/VirtualDtor.hpp" // for implementVirtDtors86 86 87 87 static void NewPass( const char * const name ) { … … 102 102 } 103 103 104 // Helpers for checkInvariant: 105 void checkInvariants( std::list< Declaration * > & ) {} 106 using ast::checkInvariants; 107 108 #define PASS( name, pass, unit, ... ) \ 104 #define PASS( name, pass ) \ 109 105 if ( errorp ) { cerr << name << endl; } \ 110 106 NewPass(name); \ 111 107 Stats::Time::StartBlock(name); \ 112 pass(unit,##__VA_ARGS__); \ 113 Stats::Time::StopBlock(); \ 114 if ( invariant ) { \ 115 checkInvariants(unit); \ 116 } 117 118 #define DUMP( cond, unit ) \ 119 if ( cond ) { \ 120 dump(unit); \ 121 return EXIT_SUCCESS; \ 122 } 108 pass; \ 109 Stats::Time::StopBlock(); 123 110 124 111 static bool waiting_for_gdb = false; // flag to set cfa-cpp to wait for gdb on start … … 287 274 FILE * gcc_builtins = fopen( (PreludeDirector + "/gcc-builtins.cf").c_str(), "r" ); 288 275 assertf( gcc_builtins, "cannot open gcc-builtins.cf\n" ); 289 parse( gcc_builtins, ast::Linkage::Compiler );276 parse( gcc_builtins, LinkageSpec::Compiler ); 290 277 291 278 // read the extra prelude in, if not generating the cfa library 292 279 FILE * extras = fopen( (PreludeDirector + "/extras.cf").c_str(), "r" ); 293 280 assertf( extras, "cannot open extras.cf\n" ); 294 parse( extras, ast::Linkage::BuiltinC );281 parse( extras, LinkageSpec::BuiltinC ); 295 282 296 283 if ( ! libcfap ) { … … 298 285 FILE * prelude = fopen( (PreludeDirector + "/prelude.cfa").c_str(), "r" ); 299 286 assertf( prelude, "cannot open prelude.cfa\n" ); 300 parse( prelude, ast::Linkage::Intrinsic );287 parse( prelude, LinkageSpec::Intrinsic ); 301 288 302 289 // Read to cfa builtins, if not generating the cfa library 303 290 FILE * builtins = fopen( (PreludeDirector + "/builtins.cf").c_str(), "r" ); 304 291 assertf( builtins, "cannot open builtins.cf\n" ); 305 parse( builtins, ast::Linkage::BuiltinCFA );306 } // if 307 } // if 308 309 parse( input, libcfap ? ast::Linkage::Intrinsic : ast::Linkage::Cforall, yydebug );292 parse( builtins, LinkageSpec::BuiltinCFA ); 293 } // if 294 } // if 295 296 parse( input, libcfap ? LinkageSpec::Intrinsic : LinkageSpec::Cforall, yydebug ); 310 297 311 298 transUnit = buildUnit(); 312 299 313 DUMP( astp, std::move( transUnit ) ); 300 if ( astp ) { 301 dump( std::move( transUnit ) ); 302 return EXIT_SUCCESS; 303 } // if 314 304 315 305 Stats::Time::StopBlock(); … … 320 310 } 321 311 322 PASS( "Hoist Type Decls", Validate::hoistTypeDecls, transUnit ); 323 324 PASS( "Translate Exception Declarations", ControlStruct::translateExcept, transUnit ); 325 DUMP( exdeclp, std::move( transUnit ) ); 326 PASS( "Verify Ctor, Dtor & Assign", Validate::verifyCtorDtorAssign, transUnit ); 327 PASS( "Replace Typedefs", Validate::replaceTypedef, transUnit ); 328 PASS( "Fix Return Types", Validate::fixReturnTypes, transUnit ); 329 PASS( "Enum and Pointer Decay", Validate::decayEnumsAndPointers, transUnit ); 330 331 PASS( "Link Reference To Types", Validate::linkReferenceToTypes, transUnit ); 332 333 PASS( "Fix Qualified Types", Validate::fixQualifiedTypes, transUnit ); 334 PASS( "Hoist Struct", Validate::hoistStruct, transUnit ); 335 PASS( "Eliminate Typedef", Validate::eliminateTypedef, transUnit ); 336 PASS( "Validate Generic Parameters", Validate::fillGenericParameters, transUnit ); 337 PASS( "Translate Dimensions", Validate::translateDimensionParameters, transUnit ); 338 PASS( "Check Function Returns", Validate::checkReturnStatements, transUnit ); 339 PASS( "Fix Return Statements", InitTweak::fixReturnStatements, transUnit ); 340 PASS( "Implement Concurrent Keywords", Concurrency::implementKeywords, transUnit ); 341 PASS( "Forall Pointer Decay", Validate::decayForallPointers, transUnit ); 342 PASS( "Hoist Control Declarations", ControlStruct::hoistControlDecls, transUnit ); 343 344 PASS( "Generate Autogen Routines", Validate::autogenerateRoutines, transUnit ); 345 346 PASS( "Implement Actors", Concurrency::implementActors, transUnit ); 347 PASS( "Implement Virtual Destructors", Virtual::implementVirtDtors, transUnit ); 348 PASS( "Implement Mutex", Concurrency::implementMutex, transUnit ); 349 PASS( "Implement Thread Start", Concurrency::implementThreadStarter, transUnit ); 350 PASS( "Compound Literal", Validate::handleCompoundLiterals, transUnit ); 351 PASS( "Set Length From Initializer", Validate::setLengthFromInitializer, transUnit ); 352 PASS( "Find Global Decls", Validate::findGlobalDecls, transUnit ); 353 PASS( "Fix Label Address", Validate::fixLabelAddresses, transUnit ); 312 PASS( "Hoist Type Decls", Validate::hoistTypeDecls( transUnit ) ); 313 // Hoist Type Decls pulls some declarations out of contexts where 314 // locations are not tracked. Perhaps they should be, but for now 315 // the full fill solves it. 316 forceFillCodeLocations( transUnit ); 317 318 PASS( "Translate Exception Declarations", ControlStruct::translateExcept( transUnit ) ); 319 if ( exdeclp ) { 320 dump( std::move( transUnit ) ); 321 return EXIT_SUCCESS; 322 } 323 324 PASS( "Verify Ctor, Dtor & Assign", Validate::verifyCtorDtorAssign( transUnit ) ); 325 PASS( "Replace Typedefs", Validate::replaceTypedef( transUnit ) ); 326 PASS( "Fix Return Types", Validate::fixReturnTypes( transUnit ) ); 327 PASS( "Enum and Pointer Decay", Validate::decayEnumsAndPointers( transUnit ) ); 328 329 PASS( "Link Reference To Types", Validate::linkReferenceToTypes( transUnit ) ); 330 331 PASS( "Fix Qualified Types", Validate::fixQualifiedTypes( transUnit ) ); 332 PASS( "Hoist Struct", Validate::hoistStruct( transUnit ) ); 333 PASS( "Eliminate Typedef", Validate::eliminateTypedef( transUnit ) ); 334 PASS( "Validate Generic Parameters", Validate::fillGenericParameters( transUnit ) ); 335 PASS( "Translate Dimensions", Validate::translateDimensionParameters( transUnit ) ); 336 PASS( "Check Function Returns", Validate::checkReturnStatements( transUnit ) ); 337 PASS( "Fix Return Statements", InitTweak::fixReturnStatements( transUnit ) ); 338 PASS( "Implement Concurrent Keywords", Concurrency::implementKeywords( transUnit ) ); 339 PASS( "Forall Pointer Decay", Validate::decayForallPointers( transUnit ) ); 340 PASS( "Hoist Control Declarations", ControlStruct::hoistControlDecls( transUnit ) ); 341 342 PASS( "Generate Autogen Routines", Validate::autogenerateRoutines( transUnit ) ); 343 344 PASS( "Implement Actors", Concurrency::implementActors( transUnit ) ); 345 346 PASS( "Implement Mutex", Concurrency::implementMutex( transUnit ) ); 347 PASS( "Implement Thread Start", Concurrency::implementThreadStarter( transUnit ) ); 348 PASS( "Compound Literal", Validate::handleCompoundLiterals( transUnit ) ); 349 PASS( "Set Length From Initializer", Validate::setLengthFromInitializer( transUnit ) ); 350 PASS( "Find Global Decls", Validate::findGlobalDecls( transUnit ) ); 351 PASS( "Fix Label Address", Validate::fixLabelAddresses( transUnit ) ); 354 352 355 353 if ( symtabp ) { … … 362 360 } // if 363 361 364 DUMP( validp, std::move( transUnit ) ); 365 366 PASS( "Translate Throws", ControlStruct::translateThrows, transUnit ); 367 PASS( "Fix Labels", ControlStruct::fixLabels, transUnit ); 368 PASS( "Fix Names", CodeGen::fixNames, transUnit ); 369 PASS( "Gen Init", InitTweak::genInit, transUnit ); 370 PASS( "Expand Member Tuples" , Tuples::expandMemberTuples, transUnit ); 362 if ( validp ) { 363 dump( std::move( transUnit ) ); 364 return EXIT_SUCCESS; 365 } // if 366 367 PASS( "Translate Throws", ControlStruct::translateThrows( transUnit ) ); 368 PASS( "Fix Labels", ControlStruct::fixLabels( transUnit ) ); 369 PASS( "Fix Names", CodeGen::fixNames( transUnit ) ); 370 PASS( "Gen Init", InitTweak::genInit( transUnit ) ); 371 PASS( "Expand Member Tuples" , Tuples::expandMemberTuples( transUnit ) ); 371 372 372 373 if ( libcfap ) { … … 380 381 } // if 381 382 382 DUMP( bresolvep, std::move( transUnit ) ); 383 if ( bresolvep ) { 384 dump( std::move( transUnit ) ); 385 return EXIT_SUCCESS; 386 } // if 383 387 384 388 if ( resolvprotop ) { … … 387 391 } // if 388 392 389 PASS( "Resolve", ResolvExpr::resolve, transUnit ); 390 DUMP( exprp, std::move( transUnit ) ); 391 392 PASS( "Fix Init", InitTweak::fix, transUnit, buildingLibrary() ); 393 PASS( "Resolve", ResolvExpr::resolve( transUnit ) ); 394 if ( exprp ) { 395 dump( std::move( transUnit ) ); 396 return EXIT_SUCCESS; 397 } // if 398 399 forceFillCodeLocations( transUnit ); 400 401 PASS( "Fix Init", InitTweak::fix(transUnit, buildingLibrary())); 393 402 394 403 // fix ObjectDecl - replaces ConstructorInit nodes 395 DUMP( ctorinitp, std::move( transUnit ) ); 404 if ( ctorinitp ) { 405 dump( std::move( transUnit ) ); 406 return EXIT_SUCCESS; 407 } // if 396 408 397 409 // Currently not working due to unresolved issues with UniqueExpr 398 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 reused399 400 PASS( "Translate Tries", ControlStruct::translateTries , transUnit);401 PASS( "Gen Waitfor", Concurrency::generateWaitFor , transUnit);410 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 411 412 PASS( "Translate Tries", ControlStruct::translateTries( transUnit ) ); 413 PASS( "Gen Waitfor", Concurrency::generateWaitFor( transUnit ) ); 402 414 403 415 // Needs to happen before tuple types are expanded. 404 PASS( "Convert Specializations", GenPoly::convertSpecializations, transUnit ); 405 406 PASS( "Expand Tuples", Tuples::expandTuples, transUnit ); 407 DUMP( tuplep, std::move( transUnit ) ); 416 PASS( "Convert Specializations", GenPoly::convertSpecializations( transUnit ) ); 417 418 PASS( "Expand Tuples", Tuples::expandTuples( transUnit ) ); 419 420 if ( tuplep ) { 421 dump( std::move( transUnit ) ); 422 return EXIT_SUCCESS; 423 } // if 408 424 409 425 // Must come after Translate Tries. 410 PASS( "Virtual Expand Casts", Virtual::expandCasts, transUnit ); 411 412 PASS( "Instantiate Generics", GenPoly::instantiateGeneric, transUnit ); 413 DUMP( genericsp, std::move( transUnit ) ); 414 415 PASS( "Convert L-Value", GenPoly::convertLvalue, transUnit ); 426 PASS( "Virtual Expand Casts", Virtual::expandCasts( transUnit ) ); 427 428 PASS( "Instantiate Generics", GenPoly::instantiateGeneric( transUnit ) ); 429 if ( genericsp ) { 430 dump( std::move( transUnit ) ); 431 return EXIT_SUCCESS; 432 } // if 433 434 PASS( "Convert L-Value", GenPoly::convertLvalue( transUnit ) ); 416 435 417 436 translationUnit = convert( std::move( transUnit ) ); 418 437 419 DUMP( bboxp, translationUnit ); 420 PASS( "Box", GenPoly::box, translationUnit ); 421 422 PASS( "Link-Once", CodeGen::translateLinkOnce, translationUnit ); 438 if ( bboxp ) { 439 dump( translationUnit ); 440 return EXIT_SUCCESS; 441 } // if 442 PASS( "Box", GenPoly::box( translationUnit ) ); 443 444 PASS( "Link-Once", CodeGen::translateLinkOnce( translationUnit ) ); 423 445 424 446 // Code has been lowered to C, now we can start generation. 425 447 426 DUMP( bcodegenp, translationUnit ); 448 if ( bcodegenp ) { 449 dump( translationUnit ); 450 return EXIT_SUCCESS; 451 } // if 427 452 428 453 if ( optind < argc ) { // any commands after the flags and input file ? => output file name … … 431 456 432 457 CodeTools::fillLocations( translationUnit ); 433 PASS( "Code Gen", CodeGen::generate , translationUnit, *output, ! genproto, prettycodegenp, true, linemarks);458 PASS( "Code Gen", CodeGen::generate( translationUnit, *output, ! genproto, prettycodegenp, true, linemarks ) ); 434 459 435 460 CodeGen::FixMain::fix( translationUnit, *output, … … 451 476 } // if 452 477 e.print(); 478 if ( output != &cout ) { 479 delete output; 480 } // if 481 return EXIT_FAILURE; 482 } catch ( UnimplementedError & e ) { 483 cout << "Sorry, " << e.get_what() << " is not currently implemented" << endl; 484 if ( output != &cout ) { 485 delete output; 486 } // if 487 return EXIT_FAILURE; 488 } catch ( CompilerError & e ) { 489 cerr << "Compiler Error: " << e.get_what() << endl; 490 cerr << "(please report bugs to [REDACTED])" << endl; 453 491 if ( output != &cout ) { 454 492 delete output; … … 479 517 480 518 481 static const char optstring[] = ":c:gh ilLmNnpdP:S:twW:D:";519 static const char optstring[] = ":c:ghlLmNnpdP:S:twW:D:"; 482 520 483 521 enum { PreludeDir = 128 }; … … 486 524 { "gdb", no_argument, nullptr, 'g' }, 487 525 { "help", no_argument, nullptr, 'h' }, 488 { "invariant", no_argument, nullptr, 'i' },489 526 { "libcfa", no_argument, nullptr, 'l' }, 490 527 { "linemarks", no_argument, nullptr, 'L' }, 491 { "no-main", no_argument, nullptr, 'm' },528 { "no-main", no_argument, 0, 'm' }, 492 529 { "no-linemarks", no_argument, nullptr, 'N' }, 493 530 { "no-prelude", no_argument, nullptr, 'n' }, … … 508 545 "wait for gdb to attach", // -g 509 546 "print translator help message", // -h 510 "invariant checking during AST passes", // -i511 547 "generate libcfa.c", // -l 512 548 "generate line marks", // -L … … 602 638 usage( argv ); // no return 603 639 break; 604 case 'i': // invariant checking605 invariant = true;606 break;607 640 case 'l': // generate libcfa.c 608 641 libcfap = true;
Note:
See TracChangeset
for help on using the changeset viewer.