Changeset 933f32f for src/main.cc


Ignore:
Timestamp:
May 24, 2019, 10:19:41 AM (6 years ago)
Author:
Thierry Delisle <tdelisle@…>
Branches:
ADT, arm-eh, ast-experimental, cleanup-dtors, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum
Children:
d908563
Parents:
6a9d4b4 (diff), 292642a (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' into cleanup-dtors

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/main.cc

    r6a9d4b4 r933f32f  
    77// main.cc --
    88//
    9 // Author           : Richard C. Bilson
     9// Author           : Peter Buhr and Rob Schluntz
    1010// Created On       : Fri May 15 23:12:02 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Wed Dec 26 08:11:19 2018
    13 // Update Count     : 499
     12// Last Modified On : Fri May  3 16:10:52 2019
     13// Update Count     : 599
    1414//
    1515
     
    2424#include <fstream>                          // for ofstream
    2525#include <iostream>                         // for operator<<, basic_ostream
     26#include <iomanip>
    2627#include <iterator>                         // for back_inserter
    2728#include <list>                             // for list
     
    3738#include "CodeTools/TrackLoc.h"             // for fillLocations
    3839#include "Common/CompilerError.h"           // for CompilerError
    39 #include "Common/Heap.h"
     40#include "Common/Stats.h"
    4041#include "Common/PassVisitor.h"
     42// #include "AST/Pass.hpp"
    4143#include "Common/SemanticError.h"           // for SemanticError
    4244#include "Common/UnimplementedError.h"      // for UnimplementedError
     
    6567using namespace std;
    6668
    67 #define PASS(name, pass)                   \
     69static void NewPass( const char * const name ) {
     70        Stats::Heap::newPass( name );
     71        using namespace Stats::Counters;
     72        {
     73                static auto group = build<CounterGroup>( "Pass Visitor" );
     74                auto pass = build<CounterGroup>( name, group );
     75                pass_visitor_stats.depth = 0;
     76                pass_visitor_stats.avg = build<AverageCounter<double>>( "Average Depth", pass );
     77                pass_visitor_stats.max = build<MaxCounter<double>>( "Max Depth", pass );
     78        }
     79        {
     80                static auto group = build<CounterGroup>( "Syntax Node" );
     81                auto pass = build<CounterGroup>( name, group );
     82                BaseSyntaxNode::new_nodes = build<SimpleCounter>( "Allocs", pass );
     83        }
     84}
     85
     86#define PASS( name, pass )                  \
    6887        if ( errorp ) { cerr << name << endl; } \
    69         HeapStats::newPass(name);               \
    70         pass;
     88        NewPass(name);                          \
     89        Stats::Time::StartBlock(name);          \
     90        pass;                                   \
     91        Stats::Time::StopBlock();
    7192
    7293LinkageSpec::Spec linkage = LinkageSpec::Cforall;
     
    7495DeclarationNode * parseTree = nullptr;                                  // program parse tree
    7596
    76 std::string PreludeDirector = "";
     97static std::string PreludeDirector = "";
    7798
    7899static void parse_cmdline( int argc, char *argv[], const char *& filename );
     
    130151} // backtrace
    131152
    132 void sigSegvBusHandler( int sig_num ) {
     153static void sigSegvBusHandler( int sig_num ) {
    133154        cerr << "*CFA runtime error* program cfa-cpp terminated with "
    134155                 <<     (sig_num == SIGSEGV ? "segment fault" : "bus error")
     
    136157        backtrace( 2 );                                                                         // skip first 2 stack frames
    137158        //_exit( EXIT_FAILURE );
    138         abort();
     159        abort();                                                                                        // cause core dump for debugging
    139160} // sigSegvBusHandler
    140161
    141 void sigAbortHandler( __attribute__((unused)) int sig_num ) {
     162static void sigAbortHandler( __attribute__((unused)) int sig_num ) {
    142163        backtrace( 6 );                                                                         // skip first 6 stack frames
    143164        signal( SIGABRT, SIG_DFL);                                                      // reset default signal handler
    144     raise( SIGABRT );                                                                   // reraise SIGABRT
     165                raise( SIGABRT );                                                                       // reraise SIGABRT
    145166} // sigAbortHandler
    146167
     
    148169int main( int argc, char * argv[] ) {
    149170        FILE * input;                                                                           // use FILE rather than istream because yyin is FILE
    150         ostream *output = & cout;
    151         const char *filename = nullptr;
     171        ostream * output = & cout;
     172        const char * filename = nullptr;
    152173        list< Declaration * > translationUnit;
    153174
     
    181202                } // if
    182203
     204                Stats::Time::StartGlobal();
     205                NewPass("Parse");
     206                Stats::Time::StartBlock("Parse");
     207
    183208                // read in the builtins, extras, and the prelude
    184209                if ( ! nopreludep ) {                                                   // include gcc builtins
     
    215240                        parseTree->printList( cout );
    216241                        delete parseTree;
    217                         return 0;
     242                        return EXIT_SUCCESS;
    218243                } // if
    219244
     
    224249                if ( astp ) {
    225250                        dump( translationUnit );
    226                         return 0;
     251                        return EXIT_SUCCESS;
    227252                } // if
    228253
     
    231256                // works okay for now.
    232257                CodeTools::fillLocations( translationUnit );
     258                Stats::Time::StopBlock();
    233259
    234260                // add the assignment statement after the initialization of a type parameter
    235                 PASS( "validate", SymTab::validate( translationUnit, symtabp ) );
     261                PASS( "Validate", SymTab::validate( translationUnit, symtabp ) );
    236262                if ( symtabp ) {
    237263                        deleteAll( translationUnit );
    238                         return 0;
     264                        return EXIT_SUCCESS;
    239265                } // if
    240266
     
    242268                        PassVisitor<ResolvExpr::AlternativePrinter> printer( cout );
    243269                        acceptAll( translationUnit, printer );
    244                         return 0;
     270                        return EXIT_SUCCESS;
    245271                } // if
    246272
    247273                if ( validp ) {
    248274                        dump( translationUnit );
    249                         return 0;
    250                 } // if
    251 
    252                 PASS( "fixLabels", ControlStruct::fixLabels( translationUnit ) );
    253                 PASS( "fixNames", CodeGen::fixNames( translationUnit ) );
    254                 PASS( "genInit", InitTweak::genInit( translationUnit ) );
    255                 PASS( "expandMemberTuples" , Tuples::expandMemberTuples( translationUnit ) );
     275                        return EXIT_SUCCESS;
     276                } // if
     277
     278                PASS( "Fix Labels", ControlStruct::fixLabels( translationUnit ) );
     279                PASS( "Fix Names", CodeGen::fixNames( translationUnit ) );
     280                PASS( "Gen Init", InitTweak::genInit( translationUnit ) );
     281                PASS( "Expand Member Tuples" , Tuples::expandMemberTuples( translationUnit ) );
    256282                if ( libcfap ) {
    257283                        // generate the bodies of cfa library functions
     
    262288                        CodeTools::printDeclStats( translationUnit );
    263289                        deleteAll( translationUnit );
    264                         return 0;
    265                 }
     290                        return EXIT_SUCCESS;
     291                } // if
    266292
    267293                if ( bresolvep ) {
    268294                        dump( translationUnit );
    269                         return 0;
     295                        return EXIT_SUCCESS;
    270296                } // if
    271297
     
    274300                if ( resolvprotop ) {
    275301                        CodeTools::dumpAsResolvProto( translationUnit );
    276                         return 0;
    277                 }
    278 
    279                 PASS( "resolve", ResolvExpr::resolve( translationUnit ) );
     302                        return EXIT_SUCCESS;
     303                } // if
     304
     305                PASS( "Resolve", ResolvExpr::resolve( translationUnit ) );
    280306                if ( exprp ) {
    281307                        dump( translationUnit );
    282                         return 0;
     308                        return EXIT_SUCCESS;
    283309                } // if
    284310
    285311                // fix ObjectDecl - replaces ConstructorInit nodes
    286                 PASS( "fixInit", InitTweak::fix( translationUnit, buildingLibrary() ) );
     312                PASS( "Fix Init", InitTweak::fix( translationUnit, buildingLibrary() ) );
    287313                if ( ctorinitp ) {
    288314                        dump ( translationUnit );
    289                         return 0;
    290                 } // if
    291 
    292                 PASS( "expandUniqueExpr", Tuples::expandUniqueExpr( translationUnit ) ); // 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
    293 
    294                 PASS( "translateEHM" , ControlStruct::translateEHM( translationUnit ) );
    295 
    296                 PASS( "generateWaitfor" , Concurrency::generateWaitFor( translationUnit ) );
    297 
    298                 PASS( "convertSpecializations",  GenPoly::convertSpecializations( translationUnit ) ); // needs to happen before tuple types are expanded
    299 
    300                 PASS( "expandTuples", Tuples::expandTuples( translationUnit ) ); // xxx - is this the right place for this?
     315                        return EXIT_SUCCESS;
     316                } // if
     317
     318                PASS( "Expand Unique Expr", Tuples::expandUniqueExpr( translationUnit ) ); // 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
     319
     320                PASS( "Translate EHM" , ControlStruct::translateEHM( translationUnit ) );
     321
     322                PASS( "Gen Waitfor" , Concurrency::generateWaitFor( translationUnit ) );
     323
     324                PASS( "Convert Specializations",  GenPoly::convertSpecializations( translationUnit ) ); // needs to happen before tuple types are expanded
     325
     326                PASS( "Expand Tuples", Tuples::expandTuples( translationUnit ) ); // xxx - is this the right place for this?
    301327
    302328                if ( tuplep ) {
    303329                        dump( translationUnit );
    304                         return 0;
    305                 }
    306 
    307                 PASS( "virtual expandCasts", Virtual::expandCasts( translationUnit ) ); // Must come after translateEHM
    308 
    309                 PASS( "instantiateGenerics", GenPoly::instantiateGeneric( translationUnit ) );
     330                        return EXIT_SUCCESS;
     331                } // if
     332
     333                PASS( "Virtual Expand Casts", Virtual::expandCasts( translationUnit ) ); // Must come after translateEHM
     334
     335                PASS( "Instantiate Generics", GenPoly::instantiateGeneric( translationUnit ) );
    310336                if ( genericsp ) {
    311337                        dump( translationUnit );
    312                         return 0;
    313                 }
    314                 PASS( "convertLvalue", GenPoly::convertLvalue( translationUnit ) );
     338                        return EXIT_SUCCESS;
     339                } // if
     340                PASS( "Convert L-Value", GenPoly::convertLvalue( translationUnit ) );
    315341
    316342
    317343                if ( bboxp ) {
    318344                        dump( translationUnit );
    319                         return 0;
    320                 } // if
    321                 PASS( "box", GenPoly::box( translationUnit ) );
     345                        return EXIT_SUCCESS;
     346                } // if
     347                PASS( "Box", GenPoly::box( translationUnit ) );
    322348
    323349                if ( bcodegenp ) {
    324350                        dump( translationUnit );
    325                         return 0;
    326                 }
     351                        return EXIT_SUCCESS;
     352                } // if
    327353
    328354                if ( optind < argc ) {                                                  // any commands after the flags and input file ? => output file name
     
    331357
    332358                CodeTools::fillLocations( translationUnit );
    333                 PASS( "codegen", CodeGen::generate( translationUnit, *output, ! noprotop, prettycodegenp, true, linemarks ) );
     359                PASS( "Code Gen", CodeGen::generate( translationUnit, *output, ! genproto, prettycodegenp, true, linemarks ) );
    334360
    335361                CodeGen::FixMain::fix( *output, (PreludeDirector + "/bootloader.c").c_str() );
     
    347373                        delete output;
    348374                } // if
    349                 return 1;
     375                return EXIT_FAILURE;
    350376        } catch ( UnimplementedError &e ) {
    351377                cout << "Sorry, " << e.get_what() << " is not currently implemented" << endl;
     
    353379                        delete output;
    354380                } // if
    355                 return 1;
     381                return EXIT_FAILURE;
    356382        } catch ( CompilerError &e ) {
    357383                cerr << "Compiler Error: " << e.get_what() << endl;
     
    360386                        delete output;
    361387                } // if
    362                 return 1;
    363         } catch(...) {
     388                return EXIT_FAILURE;
     389        } catch ( ... ) {
    364390                std::exception_ptr eptr = std::current_exception();
    365391                try {
    366392                        if (eptr) {
    367393                                std::rethrow_exception(eptr);
    368                         }
    369                         else {
    370                                 std::cerr << "Exception Uncaught and Unkown" << std::endl;
    371                         }
     394                        } else {
     395                                std::cerr << "Exception Uncaught and Unknown" << std::endl;
     396                        } // if
    372397                } catch(const std::exception& e) {
    373398                        std::cerr << "Uncaught Exception \"" << e.what() << "\"\n";
    374                 }
    375                 return 1;
    376         }// try
     399                } // try
     400                return EXIT_FAILURE;
     401        } // try
    377402
    378403        deleteAll( translationUnit );
    379         if(!libcfap && !treep) HeapStats::printStats();
    380         return 0;
     404        Stats::print();
     405        return EXIT_SUCCESS;
    381406} // main
    382407
    383 void parse_cmdline( int argc, char * argv[], const char *& filename ) {
    384         enum { Ast, Bbox, Bresolver, CtorInitFix, DeclStats, Expr, ExprAlt, Grammar, LibCFA, Linemarks, Nolinemarks, Nopreamble, Parse, PreludeDir, Prototypes, Resolver, ResolvProto, Symbol, Tree, TupleExpansion, Validate, };
    385 
    386         static struct option long_opts[] = {
    387                 { "ast", no_argument, 0, Ast },
    388                 { "before-box", no_argument, 0, Bbox },
    389                 { "before-resolver", no_argument, 0, Bresolver },
    390                 { "ctorinitfix", no_argument, 0, CtorInitFix },
    391                 { "decl-stats", no_argument, 0, DeclStats },
    392                 { "expr", no_argument, 0, Expr },
    393                 { "expralt", no_argument, 0, ExprAlt },
    394                 { "grammar", no_argument, 0, Grammar },
    395                 { "libcfa", no_argument, 0, LibCFA },
    396                 { "line-marks", no_argument, 0, Linemarks },
    397                 { "no-line-marks", no_argument, 0, Nolinemarks },
    398                 { "no-preamble", no_argument, 0, Nopreamble },
    399                 { "parse", no_argument, 0, Parse },
    400                 { "prelude-dir", required_argument, 0, PreludeDir },
    401                 { "no-prototypes", no_argument, 0, Prototypes },
    402                 { "resolver", no_argument, 0, Resolver },
    403                 { "resolv-proto", no_argument, 0, ResolvProto },
    404                 { "symbol", no_argument, 0, Symbol },
    405                 { "tree", no_argument, 0, Tree },
    406                 { "tuple-expansion", no_argument, 0, TupleExpansion },
    407                 { "validate", no_argument, 0, Validate },
    408                 { 0, 0, 0, 0 }
    409         }; // long_opts
    410         int long_index;
    411 
     408
     409static const char optstring[] = ":hlLmNn:pP:S:twW:D:F:";
     410
     411enum { PreludeDir = 128 };
     412static struct option long_opts[] = {
     413        { "help", no_argument, nullptr, 'h' },
     414        { "libcfa", no_argument, nullptr, 'l' },
     415        { "linemarks", no_argument, nullptr, 'L' },
     416        { "no-main", no_argument, 0, 'm' },
     417        { "no-linemarks", no_argument, nullptr, 'N' },
     418        { "no-prelude", no_argument, nullptr, 'n' },
     419        { "prototypes", no_argument, nullptr, 'p' },
     420        { "print", required_argument, nullptr, 'P' },
     421        { "prelude-dir", required_argument, nullptr, PreludeDir },
     422        { "statistics", required_argument, nullptr, 'S' },
     423        { "tree", no_argument, nullptr, 't' },
     424        { "", no_argument, nullptr, 0 },                                        // -w
     425        { "", no_argument, nullptr, 0 },                                        // -W
     426        { "", no_argument, nullptr, 0 },                                        // -D
     427        { "", no_argument, nullptr, 0 },                                        // -F
     428        { nullptr, 0, nullptr, 0 }
     429}; // long_opts
     430
     431static const char * description[] = {
     432        "print help message",                                                           // -h
     433        "generate libcfa.c",                                                            // -l
     434        "generate line marks",                                                          // -L
     435        "do not replace main",                                                          // -m
     436        "do not generate line marks",                                           // -N
     437        "do not read prelude",                                                          // -n
     438        "generate prototypes for prelude functions",            // -p
     439        "print",                                                                                        // -P
     440        "<directory> prelude directory for debug/nodebug",      // no flag
     441        "<option-list> enable profiling information:\n          counters,heap,time,all,none", // -S
     442        "build in tree",                                                                        // -t
     443        "",                                                                                                     // -w
     444        "",                                                                                                     // -W
     445        "",                                                                                                     // -D
     446        "",                                                                                                     // -F
     447}; // description
     448
     449static_assert( sizeof( long_opts ) / sizeof( long_opts[0] ) - 1 == sizeof( description ) / sizeof( description[0] ), "Long opts and description must match" );
     450
     451static struct Printopts {
     452        const char * name;
     453        int & flag;
     454        int val;
     455        const char * descript;
     456} printopts[] = {
     457        { "altexpr", expraltp, true, "alternatives for expressions" },
     458        { "ascodegen", codegenp, true, "as codegen rather than AST" },
     459        { "ast", astp, true, "AST after parsing" },
     460        { "astdecl", validp, true, "AST after declaration validation pass" },
     461        { "asterr", errorp, true, "AST on error" },
     462        { "astexpr", exprp, true, "AST after expression analysis" },
     463        { "astgen", genericsp, true, "AST after instantiate generics" },
     464        { "box", bboxp, true, "before box step" },
     465        { "ctordtor", ctorinitp, true, "after ctor/dtor are replaced" },
     466        { "codegen", bcodegenp, true, "before code generation" },
     467        { "declstats", declstatsp, true, "code property statistics" },
     468        { "parse", yydebug, true, "yacc (parsing) debug information" },
     469        { "pretty", prettycodegenp, true, "prettyprint for ascodegen flag" },
     470        { "resolver", bresolvep, true, "before resolver step" },
     471        { "rproto", resolvprotop, true, "resolver-proto instance" },
     472        { "rsteps", resolvep, true, "resolver steps" },
     473        { "symevt", symtabp, true, "symbol table events" },
     474        { "tree", parsep, true, "parse tree" },
     475        { "tuple", tuplep, true, "after tuple expansion" },
     476};
     477enum { printoptsSize = sizeof( printopts ) / sizeof( printopts[0] ) };
     478
     479static void usage( char *argv[] ) {
     480    cout << "Usage: " << argv[0] << " options are:" << endl;
     481        int i = 0, j = 1;                                                                       // j skips starting colon
     482        for ( ; long_opts[i].name != 0 && optstring[j] != '\0'; i += 1, j += 1 ) {
     483                if ( long_opts[i].name[0] != '\0' ) {                   // hidden option, internal usage only
     484                        if ( strcmp( long_opts[i].name, "prelude-dir" ) != 0 ) { // flag
     485                                cout << "  -" << optstring[j] << ",";
     486                        } else {                                                                        // no flag
     487                                j -= 1;                                                                 // compensate
     488                                cout << "     ";
     489                        } // if
     490                        cout << " --" << left << setw(12) << long_opts[i].name << "  ";
     491                        if ( strcmp( long_opts[i].name, "print" ) == 0 ) {
     492                                cout << "one of: " << endl;
     493                                for ( int i = 0; i < printoptsSize; i += 1 ) {
     494                                        cout << setw(10) << " " << left << setw(10) << printopts[i].name << "  " << printopts[i].descript << endl;
     495                                } // for
     496                        } else {
     497                                cout << description[i] << endl;
     498                        } // if
     499                } // if
     500                if ( optstring[j + 1] == ':' ) j += 1;
     501        } // for
     502        if ( long_opts[i].name != 0 || optstring[j] != '\0' ) assertf( false, "internal error, mismatch of option flags and names\n" );
     503    exit( EXIT_FAILURE );
     504} // usage
     505
     506static void parse_cmdline( int argc, char * argv[], const char *& filename ) {
    412507        opterr = 0;                                                                                     // (global) prevent getopt from printing error messages
    413508
    414509        bool Wsuppress = false, Werror = false;
    415510        int c;
    416         while ( (c = getopt_long( argc, argv, "abBcCdefgGlLmnNpqrRstTvwW:yzZD:F:", long_opts, &long_index )) != -1 ) {
     511        while ( (c = getopt_long( argc, argv, optstring, long_opts, nullptr )) != -1 ) {
    417512                switch ( c ) {
    418                   case Ast:
    419                   case 'a':                                                                             // dump AST
    420                         astp = true;
    421                         break;
    422                   case Bresolver:
    423                   case 'b':                                                                             // print before resolver steps
    424                         bresolvep = true;
    425                         break;
    426                   case 'B':                                                                             // print before box steps
    427                         bboxp = true;
    428                         break;
    429                   case CtorInitFix:
    430                   case 'c':                                                                             // print after constructors and destructors are replaced
    431                         ctorinitp = true;
    432                         break;
    433                   case 'C':                                                                             // print before code generation
    434                         bcodegenp = true;
    435                         break;
    436                   case DeclStats:
    437                   case 'd':
    438                     declstatsp = true;
    439                         break;
    440                   case Expr:
    441                   case 'e':                                                                             // dump AST after expression analysis
    442                         exprp = true;
    443                         break;
    444                   case ExprAlt:
    445                   case 'f':                                                                             // print alternatives for expressions
    446                         expraltp = true;
    447                         break;
    448                   case Grammar:
    449                   case 'g':                                                                             // bison debugging info (grammar rules)
    450                         yydebug = true;
    451                         break;
    452                   case 'G':                                                                             // dump AST after instantiate generics
    453                         genericsp = true;
    454                         break;
    455                   case LibCFA:
     513                  case 'h':                                                                             // help message
     514                        usage( argv );                                                          // no return
     515                        break;
    456516                  case 'l':                                                                             // generate libcfa.c
    457517                        libcfap = true;
    458518                        break;
    459                   case Linemarks:
    460                   case 'L':                                                                             // print lines marks
     519                  case 'L':                                                                             // generate line marks
    461520                        linemarks = true;
    462521                        break;
    463                   case Nopreamble:
    464                   case 'n':                                                                             // do not read preamble
     522                  case 'm':                                                                             // do not replace main
     523                        nomainp = true;
     524                        break;
     525                  case 'N':                                                                             // do not generate line marks
     526                        linemarks = false;
     527                        break;
     528                  case 'n':                                                                             // do not read prelude
    465529                        nopreludep = true;
    466530                        break;
    467                   case Nolinemarks:
    468                   case 'N':                                                                             // suppress line marks
    469                         linemarks = false;
    470                         break;
    471                   case Prototypes:
    472                   case 'p':                                                                             // generate prototypes for preamble functions
    473                         noprotop = true;
    474                         break;
    475                   case PreludeDir:
    476                         PreludeDirector = optarg;
    477                         break;
    478                   case 'm':                                                                             // don't replace the main
    479                         nomainp = true;
    480                         break;
    481                   case Parse:
    482                   case 'q':                                                                             // dump parse tree
    483                         parsep = true;
    484                         break;
    485                   case Resolver:
    486                   case 'r':                                                                             // print resolver steps
    487                         resolvep = true;
    488                         break;
    489                   case 'R':                                                                             // dump resolv-proto instance
    490                         resolvprotop = true;
    491                         break;
    492                   case Symbol:
    493                   case 's':                                                                             // print symbol table events
    494                         symtabp = true;
    495                         break;
    496                   case Tree:
     531                  case 'p':                                                                             // generate prototypes for prelude functions
     532                        genproto = true;
     533                        break;
     534                  case 'P':                                                                             // print options
     535                        for ( int i = 0;; i += 1 ) {
     536                                if ( i == printoptsSize ) {
     537                                        cout << "Unknown --print option " << optarg << endl;
     538                                        goto Default;
     539                                } // if
     540                                if ( strcmp( optarg, printopts[i].name ) == 0 ) {
     541                                        printopts[i].flag = printopts[i].val;
     542                                        break;
     543                                } // if
     544                        } // for
     545                        break;
     546                  case PreludeDir:                                                              // prelude directory for debug/nodebug, hidden
     547                        PreludeDirector = optarg;
     548                        break;
     549                  case 'S':                                                                             // enable profiling information, argument comma separated list of names
     550                        Stats::parse_params( optarg );
     551                        break;
    497552                  case 't':                                                                             // build in tree
    498553                        treep = true;
    499554                        break;
    500                   case TupleExpansion:
    501                   case 'T':                                                                             // print after tuple expansion
    502                         tuplep = true;
    503                         break;
    504                   case 'v':                                                                             // dump AST after decl validation pass
    505                         validp = true;
    506                         break;
    507                   case 'w':
     555                  case 'w':                                                                             // suppress all warnings, hidden
    508556                        Wsuppress = true;
    509557                        break;
    510                   case 'W':
     558                  case 'W':                                                                             // coordinate gcc -W with CFA, hidden
    511559                        if ( strcmp( optarg, "all" ) == 0 ) {
    512560                                SemanticWarning_EnableAll();
     
    525573                        } // if
    526574                        break;
    527                   case 'y':                                                                             // dump AST on error
    528                         errorp = true;
    529                         break;
    530                   case 'z':                                                                             // dump as codegen rather than AST
    531                         codegenp = true;
    532                         break;
    533                         case 'Z':                                                                       // prettyprint during codegen (i.e. print unmangled names, etc.)
    534                         prettycodegenp = true;
    535                         break;
    536                   case 'D':                                                                             // ignore -Dxxx
    537                         break;
    538                   case 'F':                                                                             // source file-name without suffix
     575                  case 'D':                                                                             // ignore -Dxxx, forwarded by cpp, hidden
     576                        break;
     577                  case 'F':                                                                             // source file-name without suffix, hidden
    539578                        filename = optarg;
    540579                        break;
    541                   case '?':
     580                  case '?':                                                                             // unknown option
    542581                        if ( optopt ) {                                                         // short option ?
    543                                 assertf( false, "Unknown option: -%c\n", (char)optopt );
     582                                cout << "Unknown option -" << (char)optopt << endl;
    544583                        } else {
    545                                 assertf( false, "Unknown option: %s\n", argv[optind - 1] );
    546                         } // if
    547                         #if defined(__GNUC__) && __GNUC__ >= 7
    548                                 __attribute__((fallthrough));
    549                         #endif
     584                                cout << "Unknown option " << argv[optind - 1] << endl;
     585                        } // if
     586                        goto Default;
     587                  case ':':                                                                             // missing option
     588                        if ( optopt ) {                                                         // short option ?
     589                                cout << "Missing option for -" << (char)optopt << endl;
     590                        } else {
     591                                cout << "Missing option for " << argv[optind - 1] << endl;
     592                        } // if
     593                        goto Default;
     594                  Default:
    550595                  default:
    551                         abort();
     596                        usage( argv );                                                          // no return
    552597                } // switch
    553598        } // while
     
    587632        list< Declaration * > decls;
    588633
    589         if ( noprotop ) {
     634        if ( genproto ) {
    590635                filter( translationUnit.begin(), translationUnit.end(), back_inserter( decls ), notPrelude );
    591636        } else {
     
    595640        // depending on commandline options, either generate code or dump the AST
    596641        if ( codegenp ) {
    597                 CodeGen::generate( decls, out, ! noprotop, prettycodegenp );
     642                CodeGen::generate( decls, out, ! genproto, prettycodegenp );
    598643        } else {
    599644                printAll( decls, out );
    600         }
     645        } // if
    601646        deleteAll( translationUnit );
    602647} // dump
Note: See TracChangeset for help on using the changeset viewer.