Changes in src/main.cc [dee1f89:e0bd0f9]
- File:
-
- 1 edited
-
src/main.cc (modified) (13 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/main.cc
rdee1f89 re0bd0f9 10 10 // Created On : Fri May 15 23:12:02 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Wed Jun 5 20:35:13201913 // Update Count : 60 112 // Last Modified On : Thu Aug 22 13:06:18 2019 13 // Update Count : 605 14 14 // 15 15 … … 17 17 #include <execinfo.h> // for backtrace, backtrace_symbols 18 18 #include <getopt.h> // for no_argument, optind, geto... 19 #include <signal.h> // for signal, SIGABRT, SIGSEGV 19 20 #include <cassert> // for assertf 20 21 #include <cstdio> // for fopen, FILE, fclose, stdin 21 22 #include <cstdlib> // for exit, free, abort, EXIT_F... 22 #include <csignal> // for signal, SIGABRT, SIGSEGV23 23 #include <cstring> // for index 24 24 #include <fstream> // for ofstream … … 96 96 DeclarationNode * parseTree = nullptr; // program parse tree 97 97 98 static bool waiting_for_gdb = false; // flag to set cfa-cpp to wait for gdb on start99 100 98 static std::string PreludeDirector = ""; 101 99 102 static void parse_cmdline( int argc, char *argv[] , const char *& filename);100 static void parse_cmdline( int argc, char *argv[] ); 103 101 static void parse( FILE * input, LinkageSpec::Spec linkage, bool shouldExit = false ); 104 102 static void dump( list< Declaration * > & translationUnit, ostream & out = cout ); … … 169 167 } // sigAbortHandler 170 168 169 171 170 int main( int argc, char * argv[] ) { 172 171 FILE * input; // use FILE rather than istream because yyin is FILE 173 172 ostream * output = & cout; 174 const char * filename = nullptr;175 173 list< Declaration * > translationUnit; 176 174 … … 184 182 // } // for 185 183 186 parse_cmdline( argc, argv , filename );// process command-line arguments184 parse_cmdline( argc, argv ); // process command-line arguments 187 185 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 }195 186 196 187 try { … … 198 189 if ( optind < argc ) { // any commands after the flags ? => input file name 199 190 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 ) ); 205 192 optind += 1; 206 193 } else { // no input file name 207 194 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, pass210 // a fake name along211 if ( filename == nullptr ) filename = "stdin";212 195 } // if 213 196 … … 447 430 448 431 449 static const char optstring[] = ":hlLmNnpP:S:t gwW:D:F:";432 static const char optstring[] = ":hlLmNnpP:S:twW:D:"; 450 433 451 434 enum { PreludeDir = 128 }; … … 462 445 { "statistics", required_argument, nullptr, 'S' }, 463 446 { "tree", no_argument, nullptr, 't' }, 464 { "gdb", no_argument, nullptr, 'g' },465 447 { "", no_argument, nullptr, 0 }, // -w 466 448 { "", no_argument, nullptr, 0 }, // -W 467 449 { "", no_argument, nullptr, 0 }, // -D 468 { "", no_argument, nullptr, 0 }, // -F469 450 { nullptr, 0, nullptr, 0 } 470 451 }; // long_opts … … 481 462 "<directory> prelude directory for debug/nodebug", // no flag 482 463 "<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 485 465 "", // -w 486 466 "", // -W 487 467 "", // -D 488 "", // -F489 468 }; // description 490 469 … … 521 500 522 501 static 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; 524 503 int i = 0, j = 1; // j skips starting colon 525 504 for ( ; long_opts[i].name != 0 && optstring[j] != '\0'; i += 1, j += 1 ) { … … 547 526 } // usage 548 527 549 static void parse_cmdline( int argc, char * argv[] , const char *& filename) {528 static void parse_cmdline( int argc, char * argv[] ) { 550 529 opterr = 0; // (global) prevent getopt from printing error messages 551 530 … … 593 572 Stats::parse_params( optarg ); 594 573 break; 595 case 't': // build ing cfa stdlib574 case 't': // build in tree 596 575 treep = true; 597 break;598 case 'g': // wait for gdb599 waiting_for_gdb = true;600 576 break; 601 577 case 'w': // suppress all warnings, hidden … … 621 597 case 'D': // ignore -Dxxx, forwarded by cpp, hidden 622 598 break; 623 case 'F': // source file-name without suffix, hidden624 filename = optarg;625 break;626 599 case '?': // unknown option 627 600 if ( optopt ) { // short option ?
Note:
See TracChangeset
for help on using the changeset viewer.