Changeset 330d933 for src/main.cc
- Timestamp:
- Aug 25, 2019, 8:48:51 AM (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:
- 2aab69b, 5a43ab8
- Parents:
- f9bf142 (diff), bbb1b35 (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. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/main.cc
rf9bf142 r330d933 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 : Fri Aug 23 06:50:08 2019 13 // Update Count : 607 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 … … 59 59 #include "ResolvExpr/Resolver.h" // for resolve 60 60 #include "SymTab/Validate.h" // for validate 61 #include "SynTree/TopLvalue.h" // for assertTopLvalue, clearInn... 61 62 #include "SynTree/Declaration.h" // for Declaration 62 63 #include "SynTree/Visitor.h" // for acceptAll 63 64 #include "Tuples/Tuples.h" // for expandMemberTuples, expan... 64 65 #include "Virtual/ExpandCasts.h" // for expandCasts 66 65 67 66 68 using namespace std; … … 94 96 DeclarationNode * parseTree = nullptr; // program parse tree 95 97 98 static bool waiting_for_gdb = false; // flag to set cfa-cpp to wait for gdb on start 99 96 100 static std::string PreludeDirector = ""; 97 101 98 static void parse_cmdline( int argc, char *argv[] , const char *& filename);102 static void parse_cmdline( int argc, char *argv[] ); 99 103 static void parse( FILE * input, LinkageSpec::Spec linkage, bool shouldExit = false ); 100 104 static void dump( list< Declaration * > & translationUnit, ostream & out = cout ); … … 165 169 } // sigAbortHandler 166 170 167 168 171 int main( int argc, char * argv[] ) { 169 172 FILE * input; // use FILE rather than istream because yyin is FILE 170 173 ostream * output = & cout; 171 const char * filename = nullptr;172 174 list< Declaration * > translationUnit; 173 175 … … 181 183 // } // for 182 184 183 parse_cmdline( argc, argv , filename );// process command-line arguments185 parse_cmdline( argc, argv ); // process command-line arguments 184 186 CodeGen::FixMain::setReplaceMain( !nomainp ); 187 188 if ( waiting_for_gdb ) { 189 std::cerr << "Waiting for gdb" << std::endl; 190 std::cerr << "run :" << std::endl; 191 std::cerr << " gdb attach " << getpid() << std::endl; 192 raise(SIGSTOP); 193 } // if 185 194 186 195 try { … … 188 197 if ( optind < argc ) { // any commands after the flags ? => input file name 189 198 input = fopen( argv[ optind ], "r" ); 190 assertf( input, "cannot open %s\n", argv[ optind ] ); 191 // if running cfa-cpp directly, might forget to pass -F option (and really shouldn't have to) 192 if ( filename == nullptr ) filename = argv[ optind ]; 193 // prelude filename comes in differently 194 if ( libcfap ) filename = "prelude.cfa"; 199 assertf( input, "cannot open %s because %s\n", argv[ optind ], strerror( errno ) ); 195 200 optind += 1; 196 201 } else { // no input file name 197 202 input = stdin; 198 // if running cfa-cpp directly, might forget to pass -F option. Since this takes from stdin, pass199 // a fake name along200 if ( filename == nullptr ) filename = "stdin";201 203 } // if 202 204 … … 257 259 Stats::Time::StopBlock(); 258 260 261 //std::cerr << "Post-Parse Check" << std::endl; 262 clearInnerLvalue( translationUnit ); 263 assertTopLvalue( translationUnit ); 264 259 265 // add the assignment statement after the initialization of a type parameter 260 266 PASS( "Validate", SymTab::validate( translationUnit, symtabp ) ); … … 275 281 } // if 276 282 283 assertTopLvalue( translationUnit ); 277 284 PASS( "Fix Labels", ControlStruct::fixLabels( translationUnit ) ); 285 assertTopLvalue( translationUnit ); 278 286 PASS( "Fix Names", CodeGen::fixNames( translationUnit ) ); 287 assertTopLvalue( translationUnit ); 279 288 PASS( "Gen Init", InitTweak::genInit( translationUnit ) ); 289 assertTopLvalue( translationUnit ); 280 290 PASS( "Expand Member Tuples" , Tuples::expandMemberTuples( translationUnit ) ); 291 assertTopLvalue( translationUnit ); 281 292 if ( libcfap ) { 282 293 // generate the bodies of cfa library functions … … 302 313 } // if 303 314 315 assertTopLvalue( translationUnit ); 316 304 317 PASS( "Resolve", ResolvExpr::resolve( translationUnit ) ); 305 318 if ( exprp ) { … … 308 321 } // if 309 322 323 clearInnerLvalue( translationUnit ); 324 assertTopLvalue( translationUnit ); 325 310 326 // fix ObjectDecl - replaces ConstructorInit nodes 311 327 PASS( "Fix Init", InitTweak::fix( translationUnit, buildingLibrary() ) ); 328 clearInnerLvalue( translationUnit ); 329 assertTopLvalue( translationUnit ); 312 330 if ( ctorinitp ) { 313 331 dump ( translationUnit ); … … 316 334 317 335 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 336 assertTopLvalue( translationUnit ); 318 337 319 338 PASS( "Translate EHM" , ControlStruct::translateEHM( translationUnit ) ); 339 assertTopLvalue( translationUnit ); 320 340 321 341 PASS( "Gen Waitfor" , Concurrency::generateWaitFor( translationUnit ) ); 342 clearInnerLvalue( translationUnit ); 343 assertTopLvalue( translationUnit ); 322 344 323 345 PASS( "Convert Specializations", GenPoly::convertSpecializations( translationUnit ) ); // needs to happen before tuple types are expanded 346 clearInnerLvalue( translationUnit ); 347 assertTopLvalue( translationUnit ); 324 348 325 349 PASS( "Expand Tuples", Tuples::expandTuples( translationUnit ) ); // xxx - is this the right place for this? 350 assertTopLvalue( translationUnit ); 326 351 327 352 if ( tuplep ) { … … 331 356 332 357 PASS( "Virtual Expand Casts", Virtual::expandCasts( translationUnit ) ); // Must come after translateEHM 358 assertTopLvalue( translationUnit ); 333 359 334 360 PASS( "Instantiate Generics", GenPoly::instantiateGeneric( translationUnit ) ); … … 337 363 return EXIT_SUCCESS; 338 364 } // if 365 clearInnerLvalue( translationUnit ); 366 assertTopLvalue( translationUnit ); 339 367 PASS( "Convert L-Value", GenPoly::convertLvalue( translationUnit ) ); 340 368 clearInnerLvalue( translationUnit ); 369 assertTopLvalue( translationUnit ); 341 370 342 371 if ( bboxp ) { … … 345 374 } // if 346 375 PASS( "Box", GenPoly::box( translationUnit ) ); 376 clearInnerLvalue( translationUnit ); 377 assertTopLvalue( translationUnit ); 347 378 348 379 if ( bcodegenp ) { … … 356 387 357 388 CodeTools::fillLocations( translationUnit ); 389 assertTopLvalue( translationUnit ); 358 390 PASS( "Code Gen", CodeGen::generate( translationUnit, *output, ! genproto, prettycodegenp, true, linemarks ) ); 359 391 … … 406 438 407 439 408 static const char optstring[] = ":hlLmNnpP:S:twW:D: F:";440 static const char optstring[] = ":hlLmNnpP:S:twW:D:"; 409 441 410 442 enum { PreludeDir = 128 }; … … 421 453 { "statistics", required_argument, nullptr, 'S' }, 422 454 { "tree", no_argument, nullptr, 't' }, 455 { "gdb", no_argument, nullptr, 'g' }, 423 456 { "", no_argument, nullptr, 0 }, // -w 424 457 { "", no_argument, nullptr, 0 }, // -W 425 458 { "", no_argument, nullptr, 0 }, // -D 426 { "", no_argument, nullptr, 0 }, // -F427 459 { nullptr, 0, nullptr, 0 } 428 460 }; // long_opts … … 439 471 "<directory> prelude directory for debug/nodebug", // no flag 440 472 "<option-list> enable profiling information:\n counters,heap,time,all,none", // -S 441 "build in tree", // -t 473 "building cfa standard lib", // -t 474 "wait for gdb to attach", // -g 442 475 "", // -w 443 476 "", // -W 444 477 "", // -D 445 "", // -F446 478 }; // description 447 479 … … 478 510 479 511 static void usage( char *argv[] ) { 480 cout << "Usage: " << argv[0] << " options are:" << endl;512 cout << "Usage: " << argv[0] << " [options] [input-file (default stdin)] [output-file (default stdout)], where options are:" << endl; 481 513 int i = 0, j = 1; // j skips starting colon 482 514 for ( ; long_opts[i].name != 0 && optstring[j] != '\0'; i += 1, j += 1 ) { … … 504 536 } // usage 505 537 506 static void parse_cmdline( int argc, char * argv[] , const char *& filename) {538 static void parse_cmdline( int argc, char * argv[] ) { 507 539 opterr = 0; // (global) prevent getopt from printing error messages 508 540 … … 550 582 Stats::parse_params( optarg ); 551 583 break; 552 case 't': // build in tree584 case 't': // building cfa stdlib 553 585 treep = true; 586 break; 587 case 'g': // wait for gdb 588 waiting_for_gdb = true; 554 589 break; 555 590 case 'w': // suppress all warnings, hidden … … 575 610 case 'D': // ignore -Dxxx, forwarded by cpp, hidden 576 611 break; 577 case 'F': // source file-name without suffix, hidden578 filename = optarg;579 break;580 612 case '?': // unknown option 581 613 if ( optopt ) { // short option ?
Note: See TracChangeset
for help on using the changeset viewer.