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