Changeset 90152a4 for src/main.cc
- Timestamp:
- Aug 27, 2018, 4:40:34 PM (7 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:
- b7c89aa
- Parents:
- f9feab8 (diff), 305581d (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
-
src/main.cc (modified) (28 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/main.cc
rf9feab8 r90152a4 1 2 1 // 3 2 // Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo … … 11 10 // Created On : Fri May 15 23:12:02 2015 12 11 // Last Modified By : Peter A. Buhr 13 // Last Modified On : Tue Oct 31 12:22:40 201714 // Update Count : 4 4512 // Last Modified On : Wed Jun 6 15:51:47 2018 13 // Update Count : 498 15 14 // 16 15 … … 29 28 #include <string> // for char_traits, operator<< 30 29 30 #include "CompilationState.h" 31 31 #include "../config.h" // for CFA_LIBDIR 32 32 #include "CodeGen/FixMain.h" // for FixMain … … 35 35 #include "CodeTools/DeclStats.h" // for printDeclStats 36 36 #include "CodeTools/TrackLoc.h" // for fillLocations 37 #include "Common/CompilerError.h" // for CompilerError 38 #include "Common/Heap.h" 37 39 #include "Common/PassVisitor.h" 38 #include "Common/CompilerError.h" // for CompilerError39 40 #include "Common/SemanticError.h" // for SemanticError 40 41 #include "Common/UnimplementedError.h" // for UnimplementedError … … 63 64 using namespace std; 64 65 65 #define OPTPRINT(x) if ( errorp ) cerr << x << endl; 66 66 #define PASS(name, pass) \ 67 if ( errorp ) { cerr << name << endl; } \ 68 HeapStats::newPass(name); \ 69 pass; 67 70 68 71 LinkageSpec::Spec linkage = LinkageSpec::Cforall; … … 70 73 DeclarationNode * parseTree = nullptr; // program parse tree 71 74 72 extern int yydebug; // set for -g flag (Grammar) 73 bool 74 astp = false, 75 bresolvep = false, 76 bboxp = false, 77 bcodegenp = false, 78 ctorinitp = false, 79 declstatsp = false, 80 exprp = false, 81 expraltp = false, 82 libcfap = false, 83 nopreludep = false, 84 noprotop = false, 85 nomainp = false, 86 parsep = false, 87 resolvep = false, // used in AlternativeFinder 88 symtabp = false, 89 treep = false, 90 tuplep = false, 91 validp = false, 92 errorp = false, 93 codegenp = false, 94 prettycodegenp = false, 95 linemarks = false; 75 std::string PreludeDirector = ""; 96 76 97 77 static void parse_cmdline( int argc, char *argv[], const char *& filename ); … … 154 134 << "." << endl; 155 135 backtrace( 2 ); // skip first 2 stack frames 156 exit( EXIT_FAILURE ); 136 //_exit( EXIT_FAILURE ); 137 abort(); 157 138 } // sigSegvBusHandler 158 139 … … 173 154 signal( SIGBUS, sigSegvBusHandler ); 174 155 signal( SIGABRT, sigAbortHandler ); 156 157 // std::cout << "main" << std::endl; 158 // for ( int i = 0; i < argc; i += 1 ) { 159 // std::cout << '\t' << argv[i] << std::endl; 160 // } // for 175 161 176 162 parse_cmdline( argc, argv, filename ); // process command-line arguments … … 198 184 // -l is for initial build ONLY and builtins.cf is not in the lib directory so access it here. 199 185 186 assertf( !PreludeDirector.empty(), "Can't find prelude without option --prelude-dir must be used." ); 187 200 188 // Read to gcc builtins, if not generating the cfa library 201 FILE * gcc_builtins = fopen( libcfap | treep ? "../prelude/gcc-builtins.cf" : CFA_LIBDIR "/gcc-builtins.cf", "r" );189 FILE * gcc_builtins = fopen( (PreludeDirector + "/gcc-builtins.cf").c_str(), "r" ); 202 190 assertf( gcc_builtins, "cannot open gcc-builtins.cf\n" ); 203 191 parse( gcc_builtins, LinkageSpec::Compiler ); 204 192 205 193 // read the extra prelude in, if not generating the cfa library 206 FILE * extras = fopen( libcfap | treep ? "../prelude/extras.cf" : CFA_LIBDIR "/extras.cf", "r" );194 FILE * extras = fopen( (PreludeDirector + "/extras.cf").c_str(), "r" ); 207 195 assertf( extras, "cannot open extras.cf\n" ); 208 196 parse( extras, LinkageSpec::BuiltinC ); … … 210 198 if ( ! libcfap ) { 211 199 // read the prelude in, if not generating the cfa library 212 FILE * prelude = fopen( treep ? "../prelude/prelude.cf" : CFA_LIBDIR "/prelude.cf", "r" );200 FILE * prelude = fopen( (PreludeDirector + "/prelude.cf").c_str(), "r" ); 213 201 assertf( prelude, "cannot open prelude.cf\n" ); 214 202 parse( prelude, LinkageSpec::Intrinsic ); 215 203 216 204 // Read to cfa builtins, if not generating the cfa library 217 FILE * builtins = fopen( libcfap | treep ? "../prelude/builtins.cf" : CFA_LIBDIR "/builtins.cf", "r" );205 FILE * builtins = fopen( (PreludeDirector + "/builtins.cf").c_str(), "r" ); 218 206 assertf( builtins, "cannot open builtins.cf\n" ); 219 207 parse( builtins, LinkageSpec::BuiltinCFA ); … … 238 226 } // if 239 227 228 // Temporary: fill locations after parsing so that every node has a location, for early error messages. 229 // Eventually we should pass the locations from the parser to every node, but this quick and dirty solution 230 // works okay for now. 231 CodeTools::fillLocations( translationUnit ); 232 240 233 // add the assignment statement after the initialization of a type parameter 241 OPTPRINT( "validate" ) 242 SymTab::validate( translationUnit, symtabp ); 234 PASS( "validate", SymTab::validate( translationUnit, symtabp ) ); 243 235 if ( symtabp ) { 244 236 deleteAll( translationUnit ); … … 257 249 } // if 258 250 259 OPTPRINT( "mutate" ) 260 ControlStruct::mutate( translationUnit ); 261 OPTPRINT( "fixNames" ) 262 CodeGen::fixNames( translationUnit ); 263 OPTPRINT( "genInit" ) 264 InitTweak::genInit( translationUnit ); 265 OPTPRINT( "expandMemberTuples" ); 266 Tuples::expandMemberTuples( translationUnit ); 251 PASS( "fixLabels", ControlStruct::fixLabels( translationUnit ) ); 252 PASS( "fixNames", CodeGen::fixNames( translationUnit ) ); 253 PASS( "genInit", InitTweak::genInit( translationUnit ) ); 254 PASS( "expandMemberTuples" , Tuples::expandMemberTuples( translationUnit ) ); 267 255 if ( libcfap ) { 268 256 // generate the bodies of cfa library functions … … 281 269 } // if 282 270 283 OPTPRINT( "resolve" ) 284 ResolvExpr::resolve( translationUnit ); 271 CodeTools::fillLocations( translationUnit ); 272 273 PASS( "resolve", ResolvExpr::resolve( translationUnit ) ); 285 274 if ( exprp ) { 286 275 dump( translationUnit ); … … 289 278 290 279 // fix ObjectDecl - replaces ConstructorInit nodes 291 OPTPRINT( "fixInit" ) 292 InitTweak::fix( translationUnit, filename, libcfap || treep ); 280 PASS( "fixInit", InitTweak::fix( translationUnit, buildingLibrary() ) ); 293 281 if ( ctorinitp ) { 294 282 dump ( translationUnit ); … … 296 284 } // if 297 285 298 OPTPRINT( "expandUniqueExpr" ); // xxx - is this the right place for this? want to expand ASAP so that subsequent 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 299 Tuples::expandUniqueExpr( translationUnit ); 300 301 OPTPRINT( "translateEHM" ); 302 ControlStruct::translateEHM( translationUnit ); 303 304 OPTPRINT( "generateWaitfor" ); 305 Concurrency::generateWaitFor( translationUnit ); 306 307 OPTPRINT( "convertSpecializations" ) // needs to happen before tuple types are expanded 308 GenPoly::convertSpecializations( translationUnit ); 309 310 OPTPRINT( "expandTuples" ); // xxx - is this the right place for this? 311 Tuples::expandTuples( translationUnit ); 286 PASS( "expandUniqueExpr", 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 287 288 PASS( "translateEHM" , ControlStruct::translateEHM( translationUnit ) ); 289 290 PASS( "generateWaitfor" , Concurrency::generateWaitFor( translationUnit ) ); 291 292 PASS( "convertSpecializations", GenPoly::convertSpecializations( translationUnit ) ); // needs to happen before tuple types are expanded 293 294 PASS( "expandTuples", Tuples::expandTuples( translationUnit ) ); // xxx - is this the right place for this? 295 312 296 if ( tuplep ) { 313 297 dump( translationUnit ); … … 315 299 } 316 300 317 OPTPRINT( "virtual expandCasts" ) // Must come after translateEHM 318 Virtual::expandCasts( translationUnit ); 319 320 OPTPRINT("instantiateGenerics") 321 GenPoly::instantiateGeneric( translationUnit ); 322 OPTPRINT( "convertLvalue" ) 323 GenPoly::convertLvalue( translationUnit ); 301 PASS( "virtual expandCasts", Virtual::expandCasts( translationUnit ) ); // Must come after translateEHM 302 303 PASS( "instantiateGenerics", GenPoly::instantiateGeneric( translationUnit ) ); 304 if ( genericsp ) { 305 dump( translationUnit ); 306 return 0; 307 } 308 PASS( "convertLvalue", GenPoly::convertLvalue( translationUnit ) ); 309 324 310 325 311 if ( bboxp ) { … … 327 313 return 0; 328 314 } // if 329 OPTPRINT( "box" ) 330 GenPoly::box( translationUnit ); 315 PASS( "box", GenPoly::box( translationUnit ) ); 331 316 332 317 if ( bcodegenp ) { … … 340 325 341 326 CodeTools::fillLocations( translationUnit ); 342 CodeGen::generate( translationUnit, *output, ! noprotop, prettycodegenp, true, linemarks ); 343 344 CodeGen::FixMain::fix( *output, treep ? "../prelude/bootloader.c" : CFA_LIBDIR "/bootloader.c" ); 345 327 PASS( "codegen", CodeGen::generate( translationUnit, *output, ! noprotop, prettycodegenp, true, linemarks ) ); 328 329 CodeGen::FixMain::fix( *output, (PreludeDirector + "/bootloader.c").c_str() ); 346 330 if ( output != &cout ) { 347 331 delete output; 348 332 } // if 349 } catch ( SemanticError &e ) {333 } catch ( SemanticErrorException &e ) { 350 334 if ( errorp ) { 351 335 cerr << "---AST at error:---" << endl; … … 353 337 cerr << endl << "---End of AST, begin error message:---\n" << endl; 354 338 } // if 355 e.print( cerr);339 e.print(); 356 340 if ( output != &cout ) { 357 341 delete output; … … 371 355 } // if 372 356 return 1; 373 } // try 357 } catch(...) { 358 std::exception_ptr eptr = std::current_exception(); 359 try { 360 if (eptr) { 361 std::rethrow_exception(eptr); 362 } 363 else { 364 std::cerr << "Exception Uncaught and Unkown" << std::endl; 365 } 366 } catch(const std::exception& e) { 367 std::cerr << "Unaught Exception \"" << e.what() << "\"\n"; 368 } 369 return 1; 370 }// try 374 371 375 372 deleteAll( translationUnit ); 373 if(!libcfap && !treep) HeapStats::printStats(); 376 374 return 0; 377 375 } // main 378 376 379 377 void parse_cmdline( int argc, char * argv[], const char *& filename ) { 380 enum { Ast, Bbox, Bresolver, CtorInitFix, DeclStats, Expr, ExprAlt, Grammar, LibCFA, Linemarks, Nolinemarks, Nopreamble, Parse, Pr ototypes, Resolver, Symbol, Tree, TupleExpansion, Validate, };378 enum { Ast, Bbox, Bresolver, CtorInitFix, DeclStats, Expr, ExprAlt, Grammar, LibCFA, Linemarks, Nolinemarks, Nopreamble, Parse, PreludeDir, Prototypes, Resolver, Symbol, Tree, TupleExpansion, Validate, }; 381 379 382 380 static struct option long_opts[] = { … … 394 392 { "no-preamble", no_argument, 0, Nopreamble }, 395 393 { "parse", no_argument, 0, Parse }, 394 { "prelude-dir", required_argument, 0, PreludeDir }, 396 395 { "no-prototypes", no_argument, 0, Prototypes }, 397 396 { "resolver", no_argument, 0, Resolver }, … … 406 405 opterr = 0; // (global) prevent getopt from printing error messages 407 406 407 bool Wsuppress = false, Werror = false; 408 408 int c; 409 while ( (c = getopt_long( argc, argv, "abBcCdefg lLmnNpqrstTvyzZD:F:", long_opts, &long_index )) != -1 ) {409 while ( (c = getopt_long( argc, argv, "abBcCdefgGlLmnNpqrstTvwW:yzZD:F:", long_opts, &long_index )) != -1 ) { 410 410 switch ( c ) { 411 411 case Ast: … … 443 443 yydebug = true; 444 444 break; 445 case 'G': // dump AST after instantiate generics 446 genericsp = true; 447 break; 445 448 case LibCFA: 446 449 case 'l': // generate libcfa.c … … 463 466 noprotop = true; 464 467 break; 468 case PreludeDir: 469 PreludeDirector = optarg; 470 break; 465 471 case 'm': // don't replace the main 466 472 nomainp = true; … … 488 494 case 'v': // dump AST after decl validation pass 489 495 validp = true; 496 break; 497 case 'w': 498 Wsuppress = true; 499 break; 500 case 'W': 501 if ( strcmp( optarg, "all" ) == 0 ) { 502 SemanticWarning_EnableAll(); 503 } else if ( strcmp( optarg, "error" ) == 0 ) { 504 Werror = true; 505 } else { 506 char * warning = optarg; 507 Severity s; 508 if ( strncmp( optarg, "no-", 3 ) == 0 ) { 509 warning += 3; 510 s = Severity::Suppress; 511 } else { 512 s = Severity::Warn; 513 } // if 514 SemanticWarning_Set( warning, s ); 515 } // if 490 516 break; 491 517 case 'y': // dump AST on error … … 509 535 assertf( false, "Unknown option: %s\n", argv[optind - 1] ); 510 536 } // if 511 #if __GNUC__ < 7 512 #else 537 #if defined(__GNUC__) && __GNUC__ >= 7 513 538 __attribute__((fallthrough)); 514 539 #endif … … 517 542 } // switch 518 543 } // while 544 545 if ( Werror ) { 546 SemanticWarning_WarningAsError(); 547 } // if 548 if ( Wsuppress ) { 549 SemanticWarning_SuppressAll(); 550 } // if 551 // for ( const auto w : WarningFormats ) { 552 // cout << w.name << ' ' << (int)w.severity << endl; 553 // } // for 519 554 } // parse_cmdline 520 555 … … 527 562 yyin = input; 528 563 yylineno = 1; 529 typedefTable.enterScope();530 564 int parseStatus = yyparse(); 531 565
Note:
See TracChangeset
for help on using the changeset viewer.