Changeset fc12f05 for src/main.cc
- Timestamp:
- Nov 13, 2023, 3:43:43 AM (23 months ago)
- Branches:
- master
- Children:
- 25f2798
- Parents:
- 0030b508 (diff), 2174191 (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. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/main.cc
r0030b508 rfc12f05 10 10 // Created On : Fri May 15 23:12:02 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Thu Sep 28 22:28:45202313 // Update Count : 6 8712 // Last Modified On : Wed Nov 1 21:12:58 2023 13 // Update Count : 690 14 14 // 15 15 … … 29 29 #include <string> // for char_traits, operator<< 30 30 31 #include "AST/Convert.hpp"32 31 #include "AST/Pass.hpp" // for pass_visitor_stats 32 #include "AST/Print.hpp" // for printAll 33 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 fillLocations42 41 #include "Common/CodeLocationTools.hpp" // for forceFillCodeLocations 43 42 #include "Common/DeclStats.hpp" // for printDeclStats … … 65 64 #include "ResolvExpr/EraseWith.hpp" // for eraseWith 66 65 #include "ResolvExpr/Resolver.h" // for resolve 67 #include "SynTree/LinkageSpec.h" // for Spec, Cforall, Intrinsic68 #include "SynTree/Declaration.h" // for Declaration69 66 #include "Tuples/Tuples.h" // for expandMemberTuples, expan... 70 67 #include "Validate/Autogen.hpp" // for autogenerateRoutines … … 94 91 using namespace Stats::Counters; 95 92 { 96 static auto group = build<CounterGroup>( "Pass Visitor " );93 static auto group = build<CounterGroup>( "Pass Visitor Template" ); 97 94 auto pass = build<CounterGroup>( name, group ); 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 ); 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 ); 106 98 } 107 99 } … … 132 124 133 125 static void parse_cmdline( int argc, char * argv[] ); 134 static void dump( list< Declaration * > & translationUnit, ostream & out = cout );135 126 static void dump( ast::TranslationUnit && transUnit, ostream & out = cout ); 136 127 … … 246 237 FILE * input; // use FILE rather than istream because yyin is FILE 247 238 ostream * output = & cout; 248 list< Declaration * > translationUnit;249 239 ast::TranslationUnit transUnit; 250 240 … … 260 250 261 251 parse_cmdline( argc, argv ); // process command-line arguments 262 CodeGen::FixMain::setReplaceMain( !nomainp );263 252 264 253 if ( waiting_for_gdb ) { … … 290 279 291 280 // Read to gcc builtins, if not generating the cfa library 292 FILE * gcc_builtins = fopen( (PreludeDirector + "/gcc-builtins.cf ").c_str(), "r" );281 FILE * gcc_builtins = fopen( (PreludeDirector + "/gcc-builtins.cfa").c_str(), "r" ); 293 282 assertf( gcc_builtins, "cannot open gcc-builtins.cf\n" ); 294 283 parse( gcc_builtins, ast::Linkage::Compiler ); 295 284 296 285 // read the extra prelude in, if not generating the cfa library 297 FILE * extras = fopen( (PreludeDirector + "/extras.cf ").c_str(), "r" );286 FILE * extras = fopen( (PreludeDirector + "/extras.cfa").c_str(), "r" ); 298 287 assertf( extras, "cannot open extras.cf\n" ); 299 288 parse( extras, ast::Linkage::BuiltinC ); … … 306 295 307 296 // Read to cfa builtins, if not generating the cfa library 308 FILE * builtins = fopen( (PreludeDirector + "/builtins.cf ").c_str(), "r" );297 FILE * builtins = fopen( (PreludeDirector + "/builtins.cfa").c_str(), "r" ); 309 298 assertf( builtins, "cannot open builtins.cf\n" ); 310 299 parse( builtins, ast::Linkage::BuiltinCFA ); … … 319 308 320 309 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 }326 310 327 311 PASS( "Hoist Type Decls", Validate::hoistTypeDecls, transUnit ); … … 409 393 PASS( "Translate Tries", ControlStruct::translateTries, transUnit ); 410 394 PASS( "Gen Waitfor", Concurrency::generateWaitFor, transUnit ); 395 PASS( "Fix Main Linkage", CodeGen::fixMainLinkage, transUnit, !nomainp ); 411 396 412 397 // Needs to happen before tuple types are expanded. … … 427 412 PASS( "Link-Once", CodeGen::translateLinkOnce, transUnit ); 428 413 429 translationUnit = convert( std::move( transUnit ) );430 431 414 // Code has been lowered to C, now we can start generation. 432 415 433 DUMP( bcodegenp, translationUnit);416 DUMP( bcodegenp, std::move( transUnit ) ); 434 417 435 418 if ( optind < argc ) { // any commands after the flags and input file ? => output file name … … 437 420 } // if 438 421 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() ); 422 PASS( "Code Gen", CodeGen::generate, transUnit, *output, !genproto, prettycodegenp, true, linemarks, false ); 423 CodeGen::fixMainInvoke( transUnit, *output, (PreludeDirector + "/bootloader.c").c_str() ); 424 444 425 if ( output != &cout ) { 445 426 delete output; … … 448 429 if ( errorp ) { 449 430 cerr << "---AST at error:---" << endl; 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 } 431 dump( std::move( transUnit ), cerr ); 457 432 cerr << endl << "---End of AST, begin error message:---\n" << endl; 458 433 } // if … … 480 455 } // try 481 456 482 deleteAll( translationUnit );483 457 Stats::print(); 484 458 return EXIT_SUCCESS; … … 710 684 } // parse_cmdline 711 685 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 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. 719 692 if ( genproto ) { 720 filter( translationUnit.begin(), translationUnit.end(), back_inserter( decls ), notPrelude ); 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. 700 if ( codegenp ) { 701 CodeGen::generate( unit, out, !genproto, prettycodegenp, false, false, false ); 721 702 } else { 722 decls = translationUnit; 723 } // if 724 725 // depending on commandline options, either generate code or dump the AST 726 if ( codegenp ) { 727 CodeGen::generate( decls, out, ! genproto, prettycodegenp ); 728 } else { 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 ); 703 ast::printAll( out, unit.decls ); 704 } 737 705 } 738 706
Note:
See TracChangeset
for help on using the changeset viewer.