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