Changes in src/main.cc [61efa42:cf3da24]
- File:
-
- 1 edited
-
src/main.cc (modified) (17 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/main.cc
r61efa42 rcf3da24 10 10 // Created On : Fri May 15 23:12:02 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Wed Nov 1 21:12:58202313 // Update Count : 6 9012 // Last Modified On : Thu Sep 28 22:28:45 2023 13 // Update Count : 687 14 14 // 15 15 … … 29 29 #include <string> // for char_traits, operator<< 30 30 31 #include "AST/Convert.hpp" 31 32 #include "AST/Pass.hpp" // for pass_visitor_stats 32 #include "AST/Print.hpp" // for printAll33 33 #include "AST/TranslationUnit.hpp" // for TranslationUnit 34 34 #include "AST/Util.hpp" // for checkInvariants … … 39 39 #include "CodeGen/Generate.h" // for generate 40 40 #include "CodeGen/LinkOnce.h" // for translateLinkOnce 41 #include "CodeTools/TrackLoc.h" // for fillLocations 41 42 #include "Common/CodeLocationTools.hpp" // for forceFillCodeLocations 42 43 #include "Common/DeclStats.hpp" // for printDeclStats … … 64 65 #include "ResolvExpr/EraseWith.hpp" // for eraseWith 65 66 #include "ResolvExpr/Resolver.h" // for resolve 67 #include "SynTree/LinkageSpec.h" // for Spec, Cforall, Intrinsic 68 #include "SynTree/Declaration.h" // for Declaration 66 69 #include "Tuples/Tuples.h" // for expandMemberTuples, expan... 67 70 #include "Validate/Autogen.hpp" // for autogenerateRoutines … … 91 94 using namespace Stats::Counters; 92 95 { 93 static auto group = build<CounterGroup>( "Pass Visitor Template" );96 static auto group = build<CounterGroup>( "Pass Visitor" ); 94 97 auto pass = build<CounterGroup>( name, group ); 95 ast::pass_visitor_stats.depth = 0; 96 ast::pass_visitor_stats.avg = build<AverageCounter<double>>( "Average Depth", pass ); 97 ast::pass_visitor_stats.max = build<MaxCounter<double>>( "Max Depth", pass ); 98 pass_visitor_stats.depth = 0; 99 pass_visitor_stats.avg = build<AverageCounter<double>>( "Average Depth", pass ); 100 pass_visitor_stats.max = build<MaxCounter<double>>( "Max Depth", pass ); 101 } 102 { 103 static auto group = build<CounterGroup>( "Syntax Node" ); 104 auto pass = build<CounterGroup>( name, group ); 105 BaseSyntaxNode::new_nodes = build<SimpleCounter>( "Allocs", pass ); 98 106 } 99 107 } … … 124 132 125 133 static void parse_cmdline( int argc, char * argv[] ); 134 static void dump( list< Declaration * > & translationUnit, ostream & out = cout ); 126 135 static void dump( ast::TranslationUnit && transUnit, ostream & out = cout ); 127 136 … … 237 246 FILE * input; // use FILE rather than istream because yyin is FILE 238 247 ostream * output = & cout; 248 list< Declaration * > translationUnit; 239 249 ast::TranslationUnit transUnit; 240 250 … … 250 260 251 261 parse_cmdline( argc, argv ); // process command-line arguments 262 CodeGen::FixMain::setReplaceMain( !nomainp ); 252 263 253 264 if ( waiting_for_gdb ) { … … 279 290 280 291 // Read to gcc builtins, if not generating the cfa library 281 FILE * gcc_builtins = fopen( (PreludeDirector + "/gcc-builtins.cf a").c_str(), "r" );292 FILE * gcc_builtins = fopen( (PreludeDirector + "/gcc-builtins.cf").c_str(), "r" ); 282 293 assertf( gcc_builtins, "cannot open gcc-builtins.cf\n" ); 283 294 parse( gcc_builtins, ast::Linkage::Compiler ); 284 295 285 296 // read the extra prelude in, if not generating the cfa library 286 FILE * extras = fopen( (PreludeDirector + "/extras.cf a").c_str(), "r" );297 FILE * extras = fopen( (PreludeDirector + "/extras.cf").c_str(), "r" ); 287 298 assertf( extras, "cannot open extras.cf\n" ); 288 299 parse( extras, ast::Linkage::BuiltinC ); … … 295 306 296 307 // Read to cfa builtins, if not generating the cfa library 297 FILE * builtins = fopen( (PreludeDirector + "/builtins.cf a").c_str(), "r" );308 FILE * builtins = fopen( (PreludeDirector + "/builtins.cf").c_str(), "r" ); 298 309 assertf( builtins, "cannot open builtins.cf\n" ); 299 310 parse( builtins, ast::Linkage::BuiltinCFA ); … … 308 319 309 320 Stats::Time::StopBlock(); 321 322 if (Stats::Counters::enabled) { 323 ast::pass_visitor_stats.avg = Stats::Counters::build<Stats::Counters::AverageCounter<double>>("Average Depth - New"); 324 ast::pass_visitor_stats.max = Stats::Counters::build<Stats::Counters::MaxCounter<double>>("Max depth - New"); 325 } 310 326 311 327 PASS( "Hoist Type Decls", Validate::hoistTypeDecls, transUnit ); … … 393 409 PASS( "Translate Tries", ControlStruct::translateTries, transUnit ); 394 410 PASS( "Gen Waitfor", Concurrency::generateWaitFor, transUnit ); 395 PASS( "Fix Main Linkage", CodeGen::fixMainLinkage, transUnit, !nomainp );396 411 397 412 // Needs to happen before tuple types are expanded. … … 412 427 PASS( "Link-Once", CodeGen::translateLinkOnce, transUnit ); 413 428 429 translationUnit = convert( std::move( transUnit ) ); 430 414 431 // Code has been lowered to C, now we can start generation. 415 432 416 DUMP( bcodegenp, std::move( transUnit ));433 DUMP( bcodegenp, translationUnit ); 417 434 418 435 if ( optind < argc ) { // any commands after the flags and input file ? => output file name … … 420 437 } // if 421 438 422 PASS( "Code Gen", CodeGen::generate, transUnit, *output, !genproto, prettycodegenp, true, linemarks, false ); 423 CodeGen::fixMainInvoke( transUnit, *output, (PreludeDirector + "/bootloader.c").c_str() ); 424 439 CodeTools::fillLocations( translationUnit ); 440 PASS( "Code Gen", CodeGen::generate, translationUnit, *output, ! genproto, prettycodegenp, true, linemarks ); 441 442 CodeGen::FixMain::fix( translationUnit, *output, 443 (PreludeDirector + "/bootloader.c").c_str() ); 425 444 if ( output != &cout ) { 426 445 delete output; … … 429 448 if ( errorp ) { 430 449 cerr << "---AST at error:---" << endl; 431 dump( std::move( transUnit ), cerr ); 450 // We check which section the errors came from without looking at 451 // transUnit because std::move means it could look like anything. 452 if ( !translationUnit.empty() ) { 453 dump( translationUnit, cerr ); 454 } else { 455 dump( std::move( transUnit ), cerr ); 456 } 432 457 cerr << endl << "---End of AST, begin error message:---\n" << endl; 433 458 } // if … … 455 480 } // try 456 481 482 deleteAll( translationUnit ); 457 483 Stats::print(); 458 484 return EXIT_SUCCESS; … … 684 710 } // parse_cmdline 685 711 686 static bool notPrelude( ast::ptr<ast::Decl> & decl ) { 687 return !decl->linkage.is_builtin; 688 } 689 690 static void dump( ast::TranslationUnit && unit, std::ostream & out ) { 691 // May filter out all prelude declarations. 712 static bool notPrelude( Declaration * decl ) { 713 return ! LinkageSpec::isBuiltin( decl->get_linkage() ); 714 } // notPrelude 715 716 static void dump( list< Declaration * > & translationUnit, ostream & out ) { 717 list< Declaration * > decls; 718 692 719 if ( genproto ) { 693 std::list<ast::ptr<ast::Decl>> decls; 694 std::copy_if( unit.decls.begin(), unit.decls.end(), 695 std::back_inserter( decls ), notPrelude ); 696 decls.swap( unit.decls ); 697 } 698 699 // May print as full dump or as code generation. 720 filter( translationUnit.begin(), translationUnit.end(), back_inserter( decls ), notPrelude ); 721 } else { 722 decls = translationUnit; 723 } // if 724 725 // depending on commandline options, either generate code or dump the AST 700 726 if ( codegenp ) { 701 CodeGen::generate( unit, out, !genproto, prettycodegenp, false, false, false);727 CodeGen::generate( decls, out, ! genproto, prettycodegenp ); 702 728 } else { 703 ast::printAll( out, unit.decls ); 704 } 729 printAll( decls, out ); 730 } // if 731 deleteAll( translationUnit ); 732 } // dump 733 734 static void dump( ast::TranslationUnit && transUnit, ostream & out ) { 735 std::list< Declaration * > translationUnit = convert( std::move( transUnit ) ); 736 dump( translationUnit, out ); 705 737 } 706 738
Note:
See TracChangeset
for help on using the changeset viewer.