Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/main.cc

    rdee1f89 re0bd0f9  
    1010// Created On       : Fri May 15 23:12:02 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Wed Jun  5 20:35:13 2019
    13 // Update Count     : 601
     12// Last Modified On : Thu Aug 22 13:06:18 2019
     13// Update Count     : 605
    1414//
    1515
     
    1717#include <execinfo.h>                       // for backtrace, backtrace_symbols
    1818#include <getopt.h>                         // for no_argument, optind, geto...
     19#include <signal.h>                         // for signal, SIGABRT, SIGSEGV
    1920#include <cassert>                          // for assertf
    2021#include <cstdio>                           // for fopen, FILE, fclose, stdin
    2122#include <cstdlib>                          // for exit, free, abort, EXIT_F...
    22 #include <csignal>                         // for signal, SIGABRT, SIGSEGV
    2323#include <cstring>                          // for index
    2424#include <fstream>                          // for ofstream
     
    9696DeclarationNode * parseTree = nullptr;                                  // program parse tree
    9797
    98 static bool waiting_for_gdb = false; // flag to set cfa-cpp to wait for gdb on start
    99 
    10098static std::string PreludeDirector = "";
    10199
    102 static void parse_cmdline( int argc, char *argv[], const char *& filename );
     100static void parse_cmdline( int argc, char *argv[] );
    103101static void parse( FILE * input, LinkageSpec::Spec linkage, bool shouldExit = false );
    104102static void dump( list< Declaration * > & translationUnit, ostream & out = cout );
     
    169167} // sigAbortHandler
    170168
     169
    171170int main( int argc, char * argv[] ) {
    172171        FILE * input;                                                                           // use FILE rather than istream because yyin is FILE
    173172        ostream * output = & cout;
    174         const char * filename = nullptr;
    175173        list< Declaration * > translationUnit;
    176174
     
    184182        // } // for
    185183
    186         parse_cmdline( argc, argv, filename );                          // process command-line arguments
     184        parse_cmdline( argc, argv );                                            // process command-line arguments
    187185        CodeGen::FixMain::setReplaceMain( !nomainp );
    188 
    189         if(waiting_for_gdb) {
    190                 std::cerr << "Waiting for gdb" << std::endl;
    191                 std::cerr << "run :" << std::endl;
    192                 std::cerr << "  gdb attach " << getpid() << std::endl;
    193                 raise(SIGSTOP);
    194         }
    195186
    196187        try {
     
    198189                if ( optind < argc ) {                                                  // any commands after the flags ? => input file name
    199190                        input = fopen( argv[ optind ], "r" );
    200                         assertf( input, "cannot open %s\n", argv[ optind ] );
    201                         // if running cfa-cpp directly, might forget to pass -F option (and really shouldn't have to)
    202                         if ( filename == nullptr ) filename = argv[ optind ];
    203                         // prelude filename comes in differently
    204                         if ( libcfap ) filename = "prelude.cfa";
     191                        assertf( input, "cannot open %s because %s\n", argv[ optind ], strerror( errno ) );
    205192                        optind += 1;
    206193                } else {                                                                                // no input file name
    207194                        input = stdin;
    208                         std::cerr << "Input from stdin" << std::endl;
    209                         // if running cfa-cpp directly, might forget to pass -F option. Since this takes from stdin, pass
    210                         // a fake name along
    211                         if ( filename == nullptr ) filename = "stdin";
    212195                } // if
    213196
     
    447430
    448431
    449 static const char optstring[] = ":hlLmNnpP:S:tgwW:D:F:";
     432static const char optstring[] = ":hlLmNnpP:S:twW:D:";
    450433
    451434enum { PreludeDir = 128 };
     
    462445        { "statistics", required_argument, nullptr, 'S' },
    463446        { "tree", no_argument, nullptr, 't' },
    464         { "gdb", no_argument, nullptr, 'g' },
    465447        { "", no_argument, nullptr, 0 },                                        // -w
    466448        { "", no_argument, nullptr, 0 },                                        // -W
    467449        { "", no_argument, nullptr, 0 },                                        // -D
    468         { "", no_argument, nullptr, 0 },                                        // -F
    469450        { nullptr, 0, nullptr, 0 }
    470451}; // long_opts
     
    481462        "<directory> prelude directory for debug/nodebug",      // no flag
    482463        "<option-list> enable profiling information:\n          counters,heap,time,all,none", // -S
    483         "building cfa standard lib",                                                                    // -t
    484         "wait for gdb to attach",                                                                       // -g
     464        "build in tree",                                                                        // -t
    485465        "",                                                                                                     // -w
    486466        "",                                                                                                     // -W
    487467        "",                                                                                                     // -D
    488         "",                                                                                                     // -F
    489468}; // description
    490469
     
    521500
    522501static void usage( char *argv[] ) {
    523     cout << "Usage: " << argv[0] << " options are:" << endl;
     502    cout << "Usage: " << argv[0] << " [options] [input-file (default stdin)] [output-file (default stdout)], where options are:" << endl;
    524503        int i = 0, j = 1;                                                                       // j skips starting colon
    525504        for ( ; long_opts[i].name != 0 && optstring[j] != '\0'; i += 1, j += 1 ) {
     
    547526} // usage
    548527
    549 static void parse_cmdline( int argc, char * argv[], const char *& filename ) {
     528static void parse_cmdline( int argc, char * argv[] ) {
    550529        opterr = 0;                                                                                     // (global) prevent getopt from printing error messages
    551530
     
    593572                        Stats::parse_params( optarg );
    594573                        break;
    595                   case 't':                                                                             // building cfa stdlib
     574                  case 't':                                                                             // build in tree
    596575                        treep = true;
    597                         break;
    598                   case 'g':                                                                             // wait for gdb
    599                         waiting_for_gdb = true;
    600576                        break;
    601577                  case 'w':                                                                             // suppress all warnings, hidden
     
    621597                  case 'D':                                                                             // ignore -Dxxx, forwarded by cpp, hidden
    622598                        break;
    623                   case 'F':                                                                             // source file-name without suffix, hidden
    624                         filename = optarg;
    625                         break;
    626599                  case '?':                                                                             // unknown option
    627600                        if ( optopt ) {                                                         // short option ?
Note: See TracChangeset for help on using the changeset viewer.