Changeset fc12f05 for src/main.cc


Ignore:
Timestamp:
Nov 13, 2023, 3:43:43 AM (23 months ago)
Author:
JiadaL <j82liang@…>
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.
Message:

Merge branch 'master' of plg.uwaterloo.ca:software/cfa/cfa-cc

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/main.cc

    r0030b508 rfc12f05  
    1010// Created On       : Fri May 15 23:12:02 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Thu Sep 28 22:28:45 2023
    13 // Update Count     : 687
     12// Last Modified On : Wed Nov  1 21:12:58 2023
     13// Update Count     : 690
    1414//
    1515
     
    2929#include <string>                           // for char_traits, operator<<
    3030
    31 #include "AST/Convert.hpp"
    3231#include "AST/Pass.hpp"                     // for pass_visitor_stats
     32#include "AST/Print.hpp"                    // for printAll
    3333#include "AST/TranslationUnit.hpp"          // for TranslationUnit
    3434#include "AST/Util.hpp"                     // for checkInvariants
     
    3939#include "CodeGen/Generate.h"               // for generate
    4040#include "CodeGen/LinkOnce.h"               // for translateLinkOnce
    41 #include "CodeTools/TrackLoc.h"             // for fillLocations
    4241#include "Common/CodeLocationTools.hpp"     // for forceFillCodeLocations
    4342#include "Common/DeclStats.hpp"             // for printDeclStats
     
    6564#include "ResolvExpr/EraseWith.hpp"         // for eraseWith
    6665#include "ResolvExpr/Resolver.h"            // for resolve
    67 #include "SynTree/LinkageSpec.h"            // for Spec, Cforall, Intrinsic
    68 #include "SynTree/Declaration.h"            // for Declaration
    6966#include "Tuples/Tuples.h"                  // for expandMemberTuples, expan...
    7067#include "Validate/Autogen.hpp"             // for autogenerateRoutines
     
    9491        using namespace Stats::Counters;
    9592        {
    96                 static auto group = build<CounterGroup>( "Pass Visitor" );
     93                static auto group = build<CounterGroup>( "Pass Visitor Template" );
    9794                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 );
    10698        }
    10799}
     
    132124
    133125static void parse_cmdline( int argc, char * argv[] );
    134 static void dump( list< Declaration * > & translationUnit, ostream & out = cout );
    135126static void dump( ast::TranslationUnit && transUnit, ostream & out = cout );
    136127
     
    246237        FILE * input;                                                                           // use FILE rather than istream because yyin is FILE
    247238        ostream * output = & cout;
    248         list< Declaration * > translationUnit;
    249239        ast::TranslationUnit transUnit;
    250240
     
    260250
    261251        parse_cmdline( argc, argv );                                            // process command-line arguments
    262         CodeGen::FixMain::setReplaceMain( !nomainp );
    263252
    264253        if ( waiting_for_gdb ) {
     
    290279
    291280                        // 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" );
    293282                        assertf( gcc_builtins, "cannot open gcc-builtins.cf\n" );
    294283                        parse( gcc_builtins, ast::Linkage::Compiler );
    295284
    296285                        // 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" );
    298287                        assertf( extras, "cannot open extras.cf\n" );
    299288                        parse( extras, ast::Linkage::BuiltinC );
     
    306295
    307296                                // 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" );
    309298                                assertf( builtins, "cannot open builtins.cf\n" );
    310299                                parse( builtins, ast::Linkage::BuiltinCFA );
     
    319308
    320309                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                 }
    326310
    327311                PASS( "Hoist Type Decls", Validate::hoistTypeDecls, transUnit );
     
    409393                PASS( "Translate Tries", ControlStruct::translateTries, transUnit );
    410394                PASS( "Gen Waitfor", Concurrency::generateWaitFor, transUnit );
     395                PASS( "Fix Main Linkage", CodeGen::fixMainLinkage, transUnit, !nomainp );
    411396
    412397                // Needs to happen before tuple types are expanded.
     
    427412                PASS( "Link-Once", CodeGen::translateLinkOnce, transUnit );
    428413
    429                 translationUnit = convert( std::move( transUnit ) );
    430 
    431414                // Code has been lowered to C, now we can start generation.
    432415
    433                 DUMP( bcodegenp, translationUnit );
     416                DUMP( bcodegenp, std::move( transUnit ) );
    434417
    435418                if ( optind < argc ) {                                                  // any commands after the flags and input file ? => output file name
     
    437420                } // if
    438421
    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
    444425                if ( output != &cout ) {
    445426                        delete output;
     
    448429                if ( errorp ) {
    449430                        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 );
    457432                        cerr << endl << "---End of AST, begin error message:---\n" << endl;
    458433                } // if
     
    480455        } // try
    481456
    482         deleteAll( translationUnit );
    483457        Stats::print();
    484458        return EXIT_SUCCESS;
     
    710684} // parse_cmdline
    711685
    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 
     686static bool notPrelude( ast::ptr<ast::Decl> & decl ) {
     687        return !decl->linkage.is_builtin;
     688}
     689
     690static void dump( ast::TranslationUnit && unit, std::ostream & out ) {
     691        // May filter out all prelude declarations.
    719692        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 );
    721702        } 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        }
    737705}
    738706
Note: See TracChangeset for help on using the changeset viewer.