Changeset f80e0218 for src/main.cc
- Timestamp:
- Jun 30, 2016, 4:32:56 PM (10 years ago)
- Branches:
- ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, ctor, deferred_resn, demangler, enum, forall-pointer-decay, gc_noraii, jacob/cs343-translation, jenkins-sandbox, master, memory, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
- Children:
- ea29e73
- Parents:
- 1b5c81ed (diff), 84d4d6f (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) (18 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/main.cc
r1b5c81ed rf80e0218 5 5 // file "LICENCE" distributed with Cforall. 6 6 // 7 // main.cc -- 7 // main.cc -- 8 8 // 9 9 // Author : Richard C. Bilson 10 10 // Created On : Fri May 15 23:12:02 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Wed Jan 27 22:20:20 201613 // Update Count : 19912 // Last Modified On : Sun Jun 5 15:57:30 2016 13 // Update Count : 205 14 14 // 15 15 … … 40 40 #include "MakeLibCfa.h" 41 41 #include "InitTweak/Mutate.h" 42 #include "InitTweak/RemoveInit.h" 42 #include "InitTweak/GenInit.h" 43 #include "InitTweak/FixInit.h" 44 #include "InitTweak/FixGlobalInit.h" 43 45 //#include "Explain/GenProlog.h" 44 46 //#include "Try/Visit.h" … … 55 57 56 58 static void parse( FILE * input, LinkageSpec::Type t, bool shouldExit = false ); 57 static void dump( std::list< Declaration * > & translationUnit );59 static void dump( std::list< Declaration * > & translationUnit, std::ostream & out = std::cout ); 58 60 59 61 bool 60 62 astp = false, 61 63 bresolvep = false, 64 bboxp = false, 65 ctorinitp = false, 62 66 exprp = false, 63 67 expraltp = false, … … 74 78 codegenp = false; 75 79 76 enum { Ast, B resolver, Expr, ExprAlt, Grammar, LibCFA, Nopreamble, Parse, Prototypes, Resolver, Symbol, Tree, Validate, };80 enum { Ast, Bbox, Bresolver, CtorInitFix, Expr, ExprAlt, Grammar, LibCFA, Nopreamble, Parse, Prototypes, Resolver, Symbol, Tree, Validate, }; 77 81 78 82 static struct option long_opts[] = { 79 83 { "ast", no_argument, 0, Ast }, 84 { "before-box", no_argument, 0, Bbox }, 80 85 { "before-resolver", no_argument, 0, Bresolver }, 86 { "ctorinitfix", no_argument, 0, CtorInitFix }, 81 87 { "expr", no_argument, 0, Expr }, 82 88 { "expralt", no_argument, 0, ExprAlt }, … … 97 103 std::ostream *output = &std::cout; 98 104 int long_index; 99 std::list< Declaration* > translationUnit; 105 std::list< Declaration * > translationUnit; 106 const char *filename = NULL; 100 107 101 108 opterr = 0; // prevent getopt from printing error messages 102 109 103 110 int c; 104 while ( (c = getopt_long( argc, argv, "ab efglnpqrstvyzD:", long_opts, &long_index )) != -1 ) {111 while ( (c = getopt_long( argc, argv, "abBcefglnpqrstvyzD:F:", long_opts, &long_index )) != -1 ) { 105 112 switch ( c ) { 106 113 case Ast: … … 112 119 bresolvep = true; 113 120 break; 121 case 'B': // print before resolver steps 122 bboxp = true; 123 break; 124 case CtorInitFix: 125 case 'c': 126 ctorinitp = true; 127 break; 114 128 case Expr: 115 129 case 'e': // dump AST after expression analysis … … 163 177 case 'D': // ignore -Dxxx 164 178 break; 179 case 'F': // source file-name without suffix 180 filename = optarg; 181 break; 165 182 case '?': 166 183 cout << "Unknown option: '" << (char)optopt << "'" << endl; 167 exit( 1);184 exit( EXIT_FAILURE ); 168 185 default: 169 186 abort(); … … 176 193 input = fopen( argv[ optind ], "r" ); 177 194 if ( ! input ) { 178 std::cout << "Error: can't open " << argv[ optind] << std::endl;179 exit( 1);195 std::cout << "Error: can't open " << argv[ optind ] << std::endl; 196 exit( EXIT_FAILURE ); 180 197 } // if 198 // if running cfa-cpp directly, might forget to pass -F option (and really shouldn't have to) 199 if ( filename == NULL ) filename = argv[ optind ]; 200 // prelude filename comes in differently 201 if ( libcfap ) filename = "prelude.cf"; 181 202 optind += 1; 182 203 } else { 183 204 input = stdin; 205 // if running cfa-cpp directly, might forget to pass -F option. Since this takes from stdin, pass 206 // a fake name along 207 if ( filename == NULL ) filename = "stdin"; 184 208 } // if 185 209 … … 187 211 output = new ofstream( argv[ optind ] ); 188 212 } // if 189 213 190 214 Parser::get_parser().set_debug( grammarp ); 191 215 … … 196 220 if ( builtins == NULL ) { 197 221 std::cerr << "Error: can't open builtins.cf" << std::endl; 198 exit( 1);222 exit( EXIT_FAILURE ); 199 223 } // if 200 224 … … 206 230 if ( prelude == NULL ) { 207 231 std::cerr << "Error: can't open prelude.cf" << std::endl; 208 exit( 1);232 exit( EXIT_FAILURE ); 209 233 } // if 210 234 211 235 parse( prelude, LinkageSpec::Intrinsic ); 212 236 } // if 213 237 } // if 214 238 215 parse( input, libcfap ? LinkageSpec::Intrinsic : LinkageSpec::Cforall, grammarp ); 216 239 parse( input, libcfap ? LinkageSpec::Intrinsic : LinkageSpec::Cforall, grammarp ); 240 217 241 if ( parsep ) { 218 242 Parser::get_parser().get_parseTree()->printList( std::cout ); … … 249 273 OPTPRINT( "mutate" ) 250 274 ControlStruct::mutate( translationUnit ); 251 OPTPRINT( "fixNames" ) 275 OPTPRINT( "fixNames" ) 252 276 CodeGen::fixNames( translationUnit ); 253 OPTPRINT( "tweak" ) 254 InitTweak::tweak( translationUnit ); 277 OPTPRINT( "fixGlobalInit" ); 278 InitTweak::fixGlobalInit( translationUnit, filename, libcfap || treep ); 279 OPTPRINT( "tweakInit" ) 280 InitTweak::genInit( translationUnit ); 255 281 256 282 if ( libcfap ) { … … 268 294 if ( exprp ) { 269 295 dump( translationUnit ); 296 return 0; 297 } 298 299 OPTPRINT( "fixInit" ) 300 // fix ObjectDecl - replaces ConstructorInit nodes 301 InitTweak::fix( translationUnit ); 302 if ( ctorinitp ) { 303 dump ( translationUnit ); 304 return 0; 270 305 } 271 306 … … 276 311 OPTPRINT( "convertLvalue" ) 277 312 GenPoly::convertLvalue( translationUnit ); 313 314 if ( bboxp ) { 315 dump( translationUnit ); 316 return 0; 317 } 278 318 OPTPRINT( "box" ) 279 319 GenPoly::box( translationUnit ); 280 320 281 321 // print tree right before code generation 282 322 if ( codegenp ) { … … 292 332 } catch ( SemanticError &e ) { 293 333 if ( errorp ) { 294 dump( translationUnit ); 334 std::cerr << "---AST at error:---" << std::endl; 335 dump( translationUnit, std::cerr ); 336 std::cerr << std::endl << "---End of AST, begin error message:---\n" << std::endl; 295 337 } 296 338 e.print( std::cerr ); … … 314 356 } // try 315 357 358 deleteAll( translationUnit ); 316 359 return 0; 317 360 } // main … … 331 374 } 332 375 333 static void dump( std::list< Declaration * > & translationUnit ) {376 static void dump( std::list< Declaration * > & translationUnit, std::ostream & out ) { 334 377 std::list< Declaration * > decls; 335 378 if ( noprotop ) { 336 filter( translationUnit.begin(), translationUnit.end(), 379 filter( translationUnit.begin(), translationUnit.end(), 337 380 std::back_inserter( decls ), notPrelude ); 338 381 } else { … … 340 383 } 341 384 342 printAll( decls, std::cout );385 printAll( decls, out ); 343 386 deleteAll( translationUnit ); 344 387 }
Note:
See TracChangeset
for help on using the changeset viewer.