- Timestamp:
- Aug 22, 2019, 11:21:56 PM (5 years ago)
- Branches:
- ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum
- Children:
- 2c60af75
- Parents:
- 7d01cf44
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/main.cc
r7d01cf44 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 … … 98 98 static std::string PreludeDirector = ""; 99 99 100 static void parse_cmdline( int argc, char *argv[] , const char *& filename);100 static void parse_cmdline( int argc, char *argv[] ); 101 101 static void parse( FILE * input, LinkageSpec::Spec linkage, bool shouldExit = false ); 102 102 static void dump( list< Declaration * > & translationUnit, ostream & out = cout ); … … 171 171 FILE * input; // use FILE rather than istream because yyin is FILE 172 172 ostream * output = & cout; 173 const char * filename = nullptr;174 173 list< Declaration * > translationUnit; 175 174 … … 183 182 // } // for 184 183 185 parse_cmdline( argc, argv , filename );// process command-line arguments184 parse_cmdline( argc, argv ); // process command-line arguments 186 185 CodeGen::FixMain::setReplaceMain( !nomainp ); 187 186 … … 190 189 if ( optind < argc ) { // any commands after the flags ? => input file name 191 190 input = fopen( argv[ optind ], "r" ); 192 assertf( input, "cannot open %s\n", argv[ optind ] ); 193 // if running cfa-cpp directly, might forget to pass -F option (and really shouldn't have to) 194 if ( filename == nullptr ) filename = argv[ optind ]; 195 // prelude filename comes in differently 196 if ( libcfap ) filename = "prelude.cfa"; 191 assertf( input, "cannot open %s because %s\n", argv[ optind ], strerror( errno ) ); 197 192 optind += 1; 198 193 } else { // no input file name 199 194 input = stdin; 200 // if running cfa-cpp directly, might forget to pass -F option. Since this takes from stdin, pass201 // a fake name along202 if ( filename == nullptr ) filename = "stdin";203 195 } // if 204 196 … … 438 430 439 431 440 static const char optstring[] = ":hlLmNnpP:S:twW:D: F:";432 static const char optstring[] = ":hlLmNnpP:S:twW:D:"; 441 433 442 434 enum { PreludeDir = 128 }; … … 456 448 { "", no_argument, nullptr, 0 }, // -W 457 449 { "", no_argument, nullptr, 0 }, // -D 458 { "", no_argument, nullptr, 0 }, // -F459 450 { nullptr, 0, nullptr, 0 } 460 451 }; // long_opts … … 475 466 "", // -W 476 467 "", // -D 477 "", // -F478 468 }; // description 479 469 … … 510 500 511 501 static void usage( char *argv[] ) { 512 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; 513 503 int i = 0, j = 1; // j skips starting colon 514 504 for ( ; long_opts[i].name != 0 && optstring[j] != '\0'; i += 1, j += 1 ) { … … 536 526 } // usage 537 527 538 static void parse_cmdline( int argc, char * argv[] , const char *& filename) {528 static void parse_cmdline( int argc, char * argv[] ) { 539 529 opterr = 0; // (global) prevent getopt from printing error messages 540 530 … … 607 597 case 'D': // ignore -Dxxx, forwarded by cpp, hidden 608 598 break; 609 case 'F': // source file-name without suffix, hidden610 filename = optarg;611 break;612 599 case '?': // unknown option 613 600 if ( optopt ) { // short option ?
Note: See TracChangeset
for help on using the changeset viewer.