Changes in src/main.cc [dd51906:d3b7937]
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/main.cc
rdd51906 rd3b7937 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 : Sun Jun 5 15:57:30 201613 // Update Count : 20512 // Last Modified On : Wed Jan 27 22:20:20 2016 13 // Update Count : 199 14 14 // 15 15 … … 24 24 #include "SynTree/Declaration.h" 25 25 #include "SynTree/Visitor.h" 26 #include "GenPoly/InstantiateGeneric.h" 26 27 #include "GenPoly/Lvalue.h" 27 28 #include "GenPoly/Specialize.h" … … 40 41 #include "MakeLibCfa.h" 41 42 #include "InitTweak/Mutate.h" 42 #include "InitTweak/GenInit.h" 43 #include "InitTweak/FixInit.h" 44 #include "InitTweak/FixGlobalInit.h" 43 #include "InitTweak/RemoveInit.h" 45 44 //#include "Explain/GenProlog.h" 46 45 //#include "Try/Visit.h" … … 57 56 58 57 static void parse( FILE * input, LinkageSpec::Type t, bool shouldExit = false ); 59 static void dump( std::list< Declaration * > & translationUnit , std::ostream & out = std::cout);58 static void dump( std::list< Declaration * > & translationUnit ); 60 59 61 60 bool 62 61 astp = false, 63 62 bresolvep = false, 64 bboxp = false,65 ctorinitp = false,66 63 exprp = false, 67 64 expraltp = false, … … 78 75 codegenp = false; 79 76 80 enum { Ast, B box, Bresolver, CtorInitFix, Expr, ExprAlt, Grammar, LibCFA, Nopreamble, Parse, Prototypes, Resolver, Symbol, Tree, Validate, };77 enum { Ast, Bresolver, Expr, ExprAlt, Grammar, LibCFA, Nopreamble, Parse, Prototypes, Resolver, Symbol, Tree, Validate, }; 81 78 82 79 static struct option long_opts[] = { 83 80 { "ast", no_argument, 0, Ast }, 84 { "before-box", no_argument, 0, Bbox },85 81 { "before-resolver", no_argument, 0, Bresolver }, 86 { "ctorinitfix", no_argument, 0, CtorInitFix },87 82 { "expr", no_argument, 0, Expr }, 88 83 { "expralt", no_argument, 0, ExprAlt }, … … 103 98 std::ostream *output = &std::cout; 104 99 int long_index; 105 std::list< Declaration * > translationUnit; 106 const char *filename = NULL; 100 std::list< Declaration* > translationUnit; 107 101 108 102 opterr = 0; // prevent getopt from printing error messages 109 103 110 104 int c; 111 while ( (c = getopt_long( argc, argv, "ab BcefglnpqrstvyzD:F:", long_opts, &long_index )) != -1 ) {105 while ( (c = getopt_long( argc, argv, "abefglnpqrstvyzD:", long_opts, &long_index )) != -1 ) { 112 106 switch ( c ) { 113 107 case Ast: … … 119 113 bresolvep = true; 120 114 break; 121 case 'B': // print before resolver steps122 bboxp = true;123 break;124 case CtorInitFix:125 case 'c':126 ctorinitp = true;127 break;128 115 case Expr: 129 116 case 'e': // dump AST after expression analysis … … 177 164 case 'D': // ignore -Dxxx 178 165 break; 179 case 'F': // source file-name without suffix180 filename = optarg;181 break;182 166 case '?': 183 167 cout << "Unknown option: '" << (char)optopt << "'" << endl; 184 exit( EXIT_FAILURE);168 exit(1); 185 169 default: 186 170 abort(); … … 193 177 input = fopen( argv[ optind ], "r" ); 194 178 if ( ! input ) { 195 std::cout << "Error: can't open " << argv[ optind] << std::endl;196 exit( EXIT_FAILURE);179 std::cout << "Error: can't open " << argv[optind] << std::endl; 180 exit( 1 ); 197 181 } // 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 differently201 if ( libcfap ) filename = "prelude.cf";202 182 optind += 1; 203 183 } else { 204 184 input = stdin; 205 // if running cfa-cpp directly, might forget to pass -F option. Since this takes from stdin, pass206 // a fake name along207 if ( filename == NULL ) filename = "stdin";208 185 } // if 209 186 … … 211 188 output = new ofstream( argv[ optind ] ); 212 189 } // if 213 190 214 191 Parser::get_parser().set_debug( grammarp ); 215 192 … … 220 197 if ( builtins == NULL ) { 221 198 std::cerr << "Error: can't open builtins.cf" << std::endl; 222 exit( EXIT_FAILURE);199 exit( 1 ); 223 200 } // if 224 201 … … 230 207 if ( prelude == NULL ) { 231 208 std::cerr << "Error: can't open prelude.cf" << std::endl; 232 exit( EXIT_FAILURE);209 exit( 1 ); 233 210 } // if 234 211 235 212 parse( prelude, LinkageSpec::Intrinsic ); 236 213 } // if 237 214 } // if 238 215 239 parse( input, libcfap ? LinkageSpec::Intrinsic : LinkageSpec::Cforall, grammarp ); 240 216 parse( input, libcfap ? LinkageSpec::Intrinsic : LinkageSpec::Cforall, grammarp ); 217 241 218 if ( parsep ) { 242 219 Parser::get_parser().get_parseTree()->printList( std::cout ); … … 273 250 OPTPRINT( "mutate" ) 274 251 ControlStruct::mutate( translationUnit ); 275 OPTPRINT( "fixNames" ) 252 OPTPRINT( "fixNames" ) 276 253 CodeGen::fixNames( translationUnit ); 277 OPTPRINT( "fixGlobalInit" ); 278 InitTweak::fixGlobalInit( translationUnit, filename, libcfap || treep ); 279 OPTPRINT( "tweakInit" ) 280 InitTweak::genInit( translationUnit ); 254 OPTPRINT( "tweak" ) 255 InitTweak::tweak( translationUnit ); 281 256 282 257 if ( libcfap ) { … … 294 269 if ( exprp ) { 295 270 dump( translationUnit ); 296 return 0;297 271 } 298 272 299 OPTPRINT( "fixInit" ) 300 // fix ObjectDecl - replaces ConstructorInit nodes 301 InitTweak::fix( translationUnit ); 302 if ( ctorinitp ) { 303 dump ( translationUnit ); 304 return 0; 305 } 306 273 OPTPRINT( "instantiateGeneric" ) 274 GenPoly::instantiateGeneric( translationUnit ); 307 275 OPTPRINT( "copyParams" ); 308 276 GenPoly::copyParams( translationUnit ); … … 311 279 OPTPRINT( "convertLvalue" ) 312 280 GenPoly::convertLvalue( translationUnit ); 313 314 if ( bboxp ) {315 dump( translationUnit );316 return 0;317 }318 281 OPTPRINT( "box" ) 319 282 GenPoly::box( translationUnit ); … … 332 295 } catch ( SemanticError &e ) { 333 296 if ( errorp ) { 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; 297 dump( translationUnit ); 337 298 } 338 299 e.print( std::cerr ); … … 356 317 } // try 357 318 358 deleteAll( translationUnit );359 319 return 0; 360 320 } // main … … 374 334 } 375 335 376 static void dump( std::list< Declaration * > & translationUnit , std::ostream & out) {336 static void dump( std::list< Declaration * > & translationUnit ) { 377 337 std::list< Declaration * > decls; 378 338 if ( noprotop ) { 379 filter( translationUnit.begin(), translationUnit.end(), 339 filter( translationUnit.begin(), translationUnit.end(), 380 340 std::back_inserter( decls ), notPrelude ); 381 341 } else { … … 383 343 } 384 344 385 printAll( decls, out );345 printAll( decls, std::cout ); 386 346 deleteAll( translationUnit ); 387 347 }
Note:
See TracChangeset
for help on using the changeset viewer.