Changeset 3e96559
- Timestamp:
- May 2, 2019, 1:33:07 PM (5 years ago)
- Branches:
- ADT, arm-eh, ast-experimental, cleanup-dtors, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum
- Children:
- 76f7fc7
- Parents:
- da09ba1
- Location:
- src
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
src/CompilationState.cc
rda09ba1 r3e96559 9 9 // Author : Rob Schluntz 10 10 // Created On : Mon Ju1 30 10:47:01 2018 11 // Last Modified By : Rob Schluntz12 // Last Modified On : Mon Ju1 30 10:46:25 201813 // Update Count : 211 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Thu May 2 07:46:12 2019 13 // Update Count : 3 14 14 // 15 15 16 bool 16 int 17 17 astp = false, 18 18 bresolvep = false, -
src/CompilationState.h
rda09ba1 r3e96559 9 9 // Author : Rob Schluntz 10 10 // Created On : Mon Ju1 30 10:47:01 2018 11 // Last Modified By : Rob Schluntz12 // Last Modified On : Mon Ju1 30 10:46:25 201813 // Update Count : 211 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Thu May 2 07:46:12 2019 13 // Update Count : 3 14 14 // 15 15 16 16 extern int yydebug; // set for -g flag (Grammar) 17 extern bool17 extern int 18 18 astp, 19 19 bresolvep, -
src/main.cc
rda09ba1 r3e96559 7 7 // main.cc -- 8 8 // 9 // Author : Richard C. Bilson9 // Author : Peter Buhr and Rob Schluntz 10 10 // Created On : Fri May 15 23:12:02 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Sat Feb 16 09:14:04201913 // Update Count : 5 0012 // Last Modified On : Thu May 2 11:09:37 2019 13 // Update Count : 523 14 14 // 15 15 … … 65 65 using namespace std; 66 66 67 void NewPass(const char * const name) {68 Stats::Heap::newPass( name);67 static void NewPass( const char * const name ) { 68 Stats::Heap::newPass( name ); 69 69 using namespace Stats::Counters; 70 71 70 { 72 static auto group = build<CounterGroup>( "Pass Visitor");73 auto pass = build<CounterGroup>( name, group);71 static auto group = build<CounterGroup>( "Pass Visitor" ); 72 auto pass = build<CounterGroup>( name, group ); 74 73 pass_visitor_stats.depth = 0; 75 pass_visitor_stats.avg = build<AverageCounter<double>>( "Average Depth", pass);76 pass_visitor_stats.max = build<MaxCounter<double>>( "Max Depth", pass);74 pass_visitor_stats.avg = build<AverageCounter<double>>( "Average Depth", pass ); 75 pass_visitor_stats.max = build<MaxCounter<double>>( "Max Depth", pass ); 77 76 } 78 79 77 { 80 static auto group = build<CounterGroup>( "Syntax Node");81 auto pass = build<CounterGroup>( name, group);82 BaseSyntaxNode::new_nodes = build<SimpleCounter>( "Allocs", pass);78 static auto group = build<CounterGroup>( "Syntax Node" ); 79 auto pass = build<CounterGroup>( name, group ); 80 BaseSyntaxNode::new_nodes = build<SimpleCounter>( "Allocs", pass ); 83 81 } 84 82 } 85 83 86 #define PASS( name, pass) \84 #define PASS( name, pass ) \ 87 85 if ( errorp ) { cerr << name << endl; } \ 88 86 NewPass(name); \ … … 95 93 DeclarationNode * parseTree = nullptr; // program parse tree 96 94 97 st d::string PreludeDirector = "";95 static std::string PreludeDirector = ""; 98 96 99 97 static void parse_cmdline( int argc, char *argv[], const char *& filename ); … … 151 149 } // backtrace 152 150 153 void sigSegvBusHandler( int sig_num ) {151 static void sigSegvBusHandler( int sig_num ) { 154 152 cerr << "*CFA runtime error* program cfa-cpp terminated with " 155 153 << (sig_num == SIGSEGV ? "segment fault" : "bus error") … … 157 155 backtrace( 2 ); // skip first 2 stack frames 158 156 //_exit( EXIT_FAILURE ); 159 abort(); 157 abort(); // cause core dump for debugging 160 158 } // sigSegvBusHandler 161 159 162 void sigAbortHandler( __attribute__((unused)) int sig_num ) {160 static void sigAbortHandler( __attribute__((unused)) int sig_num ) { 163 161 backtrace( 6 ); // skip first 6 stack frames 164 162 signal( SIGABRT, SIG_DFL); // reset default signal handler … … 240 238 parseTree->printList( cout ); 241 239 delete parseTree; 242 return 0;240 return EXIT_SUCCESS; 243 241 } // if 244 242 … … 249 247 if ( astp ) { 250 248 dump( translationUnit ); 251 return 0;249 return EXIT_SUCCESS; 252 250 } // if 253 251 … … 262 260 if ( symtabp ) { 263 261 deleteAll( translationUnit ); 264 return 0;262 return EXIT_SUCCESS; 265 263 } // if 266 264 … … 268 266 PassVisitor<ResolvExpr::AlternativePrinter> printer( cout ); 269 267 acceptAll( translationUnit, printer ); 270 return 0;268 return EXIT_SUCCESS; 271 269 } // if 272 270 273 271 if ( validp ) { 274 272 dump( translationUnit ); 275 return 0;273 return EXIT_SUCCESS; 276 274 } // if 277 275 … … 288 286 CodeTools::printDeclStats( translationUnit ); 289 287 deleteAll( translationUnit ); 290 return 0;291 } 288 return EXIT_SUCCESS; 289 } // if 292 290 293 291 if ( bresolvep ) { 294 292 dump( translationUnit ); 295 return 0;293 return EXIT_SUCCESS; 296 294 } // if 297 295 … … 300 298 if ( resolvprotop ) { 301 299 CodeTools::dumpAsResolvProto( translationUnit ); 302 return 0;303 } 300 return EXIT_SUCCESS; 301 } // if 304 302 305 303 PASS( "Resolve", ResolvExpr::resolve( translationUnit ) ); 306 304 if ( exprp ) { 307 305 dump( translationUnit ); 308 return 0;306 return EXIT_SUCCESS; 309 307 } // if 310 308 … … 313 311 if ( ctorinitp ) { 314 312 dump ( translationUnit ); 315 return 0;313 return EXIT_SUCCESS; 316 314 } // if 317 315 … … 328 326 if ( tuplep ) { 329 327 dump( translationUnit ); 330 return 0;331 } 328 return EXIT_SUCCESS; 329 } // if 332 330 333 331 PASS( "Virtual Expand Casts", Virtual::expandCasts( translationUnit ) ); // Must come after translateEHM … … 336 334 if ( genericsp ) { 337 335 dump( translationUnit ); 338 return 0;339 } 336 return EXIT_SUCCESS; 337 } // if 340 338 PASS( "Convert L-Value", GenPoly::convertLvalue( translationUnit ) ); 341 339 … … 343 341 if ( bboxp ) { 344 342 dump( translationUnit ); 345 return 0;343 return EXIT_SUCCESS; 346 344 } // if 347 345 PASS( "Box", GenPoly::box( translationUnit ) ); … … 349 347 if ( bcodegenp ) { 350 348 dump( translationUnit ); 351 return 0;352 } 349 return EXIT_SUCCESS; 350 } // if 353 351 354 352 if ( optind < argc ) { // any commands after the flags and input file ? => output file name … … 373 371 delete output; 374 372 } // if 375 return 1;373 return EXIT_FAILURE; 376 374 } catch ( UnimplementedError &e ) { 377 375 cout << "Sorry, " << e.get_what() << " is not currently implemented" << endl; … … 379 377 delete output; 380 378 } // if 381 return 1;379 return EXIT_FAILURE; 382 380 } catch ( CompilerError &e ) { 383 381 cerr << "Compiler Error: " << e.get_what() << endl; … … 386 384 delete output; 387 385 } // if 388 return 1;389 } catch (...) {386 return EXIT_FAILURE; 387 } catch ( ... ) { 390 388 std::exception_ptr eptr = std::current_exception(); 391 389 try { 392 390 if (eptr) { 393 391 std::rethrow_exception(eptr); 394 } 395 else { 396 std::cerr << "Exception Uncaught and Unkown" << std::endl; 397 } 392 } else { 393 std::cerr << "Exception Uncaught and Unknown" << std::endl; 394 } // if 398 395 } catch(const std::exception& e) { 399 396 std::cerr << "Uncaught Exception \"" << e.what() << "\"\n"; 400 } 401 return 1;402 } // try397 } // try 398 return EXIT_FAILURE; 399 } // try 403 400 404 401 deleteAll( translationUnit ); 405 402 Stats::print(); 406 407 return 0; 403 return EXIT_SUCCESS; 408 404 } // main 409 405 410 void parse_cmdline( int argc, char * argv[], const char *& filename ) { 411 enum { Ast, Bbox, Bresolver, CtorInitFix, DeclStats, Expr, ExprAlt, Grammar, LibCFA, Linemarks, Nolinemarks, Nopreamble, Parse, PreludeDir, Prototypes, Resolver, ResolvProto, Stats, Symbol, Tree, TupleExpansion, Validate}; 412 413 static struct option long_opts[] = { 414 { "ast", no_argument, 0, Ast }, 415 { "before-box", no_argument, 0, Bbox }, 416 { "before-resolver", no_argument, 0, Bresolver }, 417 { "ctorinitfix", no_argument, 0, CtorInitFix }, 418 { "decl-stats", no_argument, 0, DeclStats }, 419 { "expr", no_argument, 0, Expr }, 420 { "expralt", no_argument, 0, ExprAlt }, 421 { "grammar", no_argument, 0, Grammar }, 422 { "libcfa", no_argument, 0, LibCFA }, 423 { "line-marks", no_argument, 0, Linemarks }, 424 { "no-line-marks", no_argument, 0, Nolinemarks }, 425 { "no-preamble", no_argument, 0, Nopreamble }, 426 { "parse", no_argument, 0, Parse }, 427 { "prelude-dir", required_argument, 0, PreludeDir }, 428 { "no-prototypes", no_argument, 0, Prototypes }, 429 { "resolver", no_argument, 0, Resolver }, 430 { "resolv-proto", no_argument, 0, ResolvProto }, 431 { "stats", required_argument, 0, Stats }, 432 { "symbol", no_argument, 0, Symbol }, 433 { "tree", no_argument, 0, Tree }, 434 { "tuple-expansion", no_argument, 0, TupleExpansion }, 435 { "validate", no_argument, 0, Validate }, 436 { 0, 0, 0, 0 } 437 }; // long_opts 438 int long_index; 439 406 407 static const char optstring[] = ":abBcCdeEGghlLmNnpP:qrRS:stTvwW:yzZD:F:"; 408 409 static struct option long_opts[] = { 410 { "ast", no_argument, nullptr, 'a' }, 411 { "before-resolver", no_argument, nullptr, 'b' }, 412 { "box", no_argument, nullptr, 'B' }, 413 { "ctorinitfix", no_argument, nullptr, 'c' }, 414 { "code", no_argument, nullptr, 'C' }, 415 { "decl-stmts", no_argument, nullptr, 'd' }, 416 { "expr", no_argument, nullptr, 'e' }, 417 { "expralt", no_argument, nullptr, 'E' }, 418 { "generics", no_argument, nullptr, 'G' }, 419 { "grammar", no_argument, nullptr, 'g' }, 420 { "help", no_argument, nullptr, 'h' }, 421 { "libcfa", no_argument, nullptr, 'l' }, 422 { "line-marks", no_argument, nullptr, 'L' }, 423 { "no-main", no_argument, 0, 'm' }, 424 { "no-line-marks", no_argument, nullptr, 'N' }, 425 { "no-preamble", no_argument, nullptr, 'n' }, 426 { "prototypes", no_argument, nullptr, 'p' }, 427 { "prelude-dir <directory>", required_argument, nullptr, 'P' }, 428 { "parse-tree", no_argument, nullptr, 'q' }, 429 { "resolver", no_argument, nullptr, 'r' }, 430 { "resolver-proto", no_argument, nullptr, 'R' }, 431 { "statistics <option-list>", required_argument, nullptr, 'S' }, 432 { "symbol", no_argument, nullptr, 's' }, 433 { "tree", no_argument, nullptr, 't' }, 434 { "tuple", no_argument, nullptr, 'T' }, 435 { "validate", no_argument, nullptr, 'v' }, 436 { "", no_argument, nullptr, 0 }, // -w 437 { "", no_argument, nullptr, 0 }, // -W 438 { "dump-ast-on-error", no_argument, nullptr, 'y' }, 439 { "dump-ast-code", no_argument, nullptr, 'z' }, 440 { "prettyprint-codegen", no_argument, nullptr, 'Z' }, 441 { "", no_argument, nullptr, 0 }, // -D 442 { "", no_argument, nullptr, 0 }, // -F 443 { nullptr, 0, nullptr, 0 } 444 }; // long_opts 445 446 static const char * description[] = { 447 "dump AST", // -a 448 "print before resolver step", // -b 449 "print before box step", // -B 450 "print after ctor/dtor are replaced", // -c 451 "print before code generation", // -C 452 "print declaration statements", // -d 453 "dump AST after expression analysis", // -e 454 "print alternatives for expressions", // -E 455 "dump AST after instantiate generics", // -G 456 "print bison (parsing) debugging information", // -g 457 "help message", // -h 458 "generate libcfa.c", // -l 459 "print line marks", // -L 460 "do not replace main", // -m 461 "suppress line marks", // -N 462 "do not read preamble", // -n 463 "generate prototypes for preamble functions", // -p 464 "prelude directory for debug/nodebug", // -P 465 "dump parse tree", // -q 466 "print resolver steps", // -r 467 "dump resolver-proto instance", // -R 468 "enable profiling information: counters,heap,time", // -S 469 "print symbol table events", // -s 470 "build in tree", // -t 471 "print after tuple expansion", // -T 472 "dump AST after declaration validation pass", // -v 473 "", // -w 474 "", // -W 475 "dump AST on error", // -y 476 "dump as codegen rather than AST", // -z 477 "prettyprint during codegen", // -Z 478 "", // -D 479 "", // -F 480 }; // description 481 482 static void usage( char *argv[] ) { 483 cout << "Usage: " << argv[0] << " options are:" << endl; 484 int i = 0, j = 1; // j skips starting colon 485 for ( ; long_opts[i].name != 0 && optstring[j] != '\0'; i += 1, j += 1 ) { 486 if ( long_opts[i].name[0] != '\0' ) { // hidden option, internal usage only 487 cout << " -" << optstring[j] << ", --" << long_opts[i].name << " " << description[i] << endl; 488 } // if 489 if ( optstring[j+1] == ':' ) j += 1; 490 } // for 491 if ( long_opts[i].name != 0 || optstring[j] != '\0' ) assertf( false, "internal error, mismatch of option flags and names\n" ); 492 exit( EXIT_FAILURE ); 493 } // usage 494 495 static void parse_cmdline( int argc, char * argv[], const char *& filename ) { 440 496 opterr = 0; // (global) prevent getopt from printing error messages 441 497 442 498 bool Wsuppress = false, Werror = false; 443 499 int c; 444 while ( (c = getopt_long( argc, argv, "abBcCdefgGlLmnNpqrRstTvwW:yzZD:F:", long_opts, &long_index)) != -1 ) {500 while ( (c = getopt_long( argc, argv, optstring, long_opts, nullptr )) != -1 ) { 445 501 switch ( c ) { 446 case Ast: 447 case 'a': // dump AST 502 case 'a': // dump AST 448 503 astp = true; 449 504 break; 450 case Bresolver: 451 case 'b': // print before resolver steps 505 case 'b': // print before resolver steps 452 506 bresolvep = true; 453 507 break; 454 508 case 'B': // print before box steps 455 509 bboxp = true; 456 510 break; 457 case CtorInitFix: 458 case 'c': // print after constructors and destructors are replaced 511 case 'c': // print after ctor/dtor are replaced 459 512 ctorinitp = true; 460 513 break; 461 514 case 'C': // print before code generation 462 515 bcodegenp = true; 463 516 break; 464 case DeclStats: 465 case 'd': 466 declstatsp = true; 467 break; 468 case Expr: 469 case 'e': // dump AST after expression analysis 517 case 'd': // print declaration statements 518 declstatsp = true; 519 break; 520 case 'e': // dump AST after expression analysis 470 521 exprp = true; 471 522 break; 472 case ExprAlt: 473 case 'f': // print alternatives for expressions 523 case 'E': // print alternatives for expressions 474 524 expraltp = true; 475 525 break; 476 case Grammar: 477 case 'g': // bison debugging info (grammar rules) 526 case 'G': // dump AST after instantiate generics 527 genericsp = true; 528 break; 529 case 'g': // print bison (parsing) debugging information 478 530 yydebug = true; 479 531 break; 480 case 'G': // dump AST after instantiate generics 481 genericsp = true; 482 break; 483 case LibCFA: 484 case 'l': // generate libcfa.c 532 case 'h': // help message 533 usage( argv ); // no return 534 break; 535 case 'l': // generate libcfa.c 485 536 libcfap = true; 486 537 break; 487 case Linemarks: 488 case 'L': // print lines marks 538 case 'L': // print line marks 489 539 linemarks = true; 490 540 break; 491 case Nopreamble: 492 case 'n': // do not read preamble 541 case 'm': // do not replace main 542 nomainp = true; 543 break; 544 case 'N': // suppress line marks 545 linemarks = false; 546 break; 547 case 'n': // do not read preamble 493 548 nopreludep = true; 494 549 break; 495 case Nolinemarks: 496 case 'N': // suppress line marks 497 linemarks = false; 498 break; 499 case Prototypes: 500 case 'p': // generate prototypes for preamble functions 550 case 'p': // generate prototypes for preamble functions 501 551 noprotop = true; 502 552 break; 503 case PreludeDir: 504 PreludeDirector = optarg; 505 break; 506 case 'm': // don't replace the main 507 nomainp = true; 508 break; 509 case Parse: 510 case 'q': // dump parse tree 553 case 'P': // prelude directory for debug/nodebug, hidden 554 PreludeDirector = optarg; 555 break; 556 case 'q': // dump parse tree 511 557 parsep = true; 512 558 break; 513 case Resolver: 514 case 'r': // print resolver steps 559 case 'r': // print resolver steps 515 560 resolvep = true; 516 561 break; 517 case 'R': // dump resolv-proto instance562 case 'R': // dump resolver-proto instance 518 563 resolvprotop = true; 519 564 break; 520 case Stats: 521 Stats::parse_params(optarg); 522 break; 523 case Symbol: 524 case 's': // print symbol table events 565 case 'S': // enable profiling information, argument comma separated list of names 566 Stats::parse_params( optarg ); 567 break; 568 case 's': // print symbol table events 525 569 symtabp = true; 526 570 break; 527 case Tree: 528 case 't': // build in tree 571 case 't': // build in tree 529 572 treep = true; 530 573 break; 531 case TupleExpansion: 532 case 'T': // print after tuple expansion 574 case 'T': // print after tuple expansion 533 575 tuplep = true; 534 576 break; 535 case 'v': // dump AST after declvalidation pass577 case 'v': // dump AST after declaration validation pass 536 578 validp = true; 537 579 break; 538 case 'w':580 case 'w': // suppress all warnings, hidden 539 581 Wsuppress = true; 540 582 break; 541 case 'W':583 case 'W': // coordinate gcc -W with CFA, hidden 542 584 if ( strcmp( optarg, "all" ) == 0 ) { 543 585 SemanticWarning_EnableAll(); … … 556 598 } // if 557 599 break; 558 600 case 'y': // dump AST on error 559 601 errorp = true; 560 602 break; 561 603 case 'z': // dump as codegen rather than AST 562 604 codegenp = true; 563 605 break; 564 case 'Z':// prettyprint during codegen (i.e. print unmangled names, etc.)606 case 'Z': // prettyprint during codegen (i.e. print unmangled names, etc.) 565 607 prettycodegenp = true; 566 608 break; 567 case 'D': // ignore -Dxxx568 break; 569 case 'F': // source file-name without suffix609 case 'D': // ignore -Dxxx, forwarded by cpp, hidden 610 break; 611 case 'F': // source file-name without suffix, hidden 570 612 filename = optarg; 571 613 break; 572 case '?':614 case '?': // unknown option 573 615 if ( optopt ) { // short option ? 574 assertf( false, "Unknown option: -%c\n", (char)optopt );616 cout << "Unknown option -" << (char)optopt << endl; 575 617 } else { 576 assertf( false, "Unknown option: %s\n", argv[optind - 1] );618 cout << "Unknown option " << argv[optind - 1] << endl; 577 619 } // if 578 #if defined(__GNUC__) && __GNUC__ >= 7 579 __attribute__((fallthrough)); 580 #endif 581 default: 582 abort(); 620 goto Default; 621 case ':': // missing option 622 if ( optopt ) { // short option ? 623 cout << "Missing option for -" << (char)optopt << endl; 624 } else { 625 cout << "Missing option for " << argv[optind - 1] << endl; 626 } // if 627 goto Default; 628 Default: 629 default: 630 usage( argv ); // no return 583 631 } // switch 584 632 } // while … … 629 677 } else { 630 678 printAll( decls, out ); 631 } 679 } // if 632 680 deleteAll( translationUnit ); 633 681 } // dump
Note: See TracChangeset
for help on using the changeset viewer.