Changes in src/main.cc [6cf27a07:e497c1d]
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/main.cc
r6cf27a07 re497c1d 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 // Last Modified By : Peter A. Buhr12 // Last Modified On : Tue Jul 5 15:23:11 201613 // Update Count : 20911 // Last Modified By : Rob Schluntz 12 // Last Modified On : Tue Jul 28 13:05:02 2015 13 // Update Count : 165 14 14 // 15 15 … … 40 40 #include "MakeLibCfa.h" 41 41 #include "InitTweak/Mutate.h" 42 #include "InitTweak/GenInit.h" 43 #include "InitTweak/FixInit.h" 42 #include "InitTweak/RemoveInit.h" 44 43 //#include "Explain/GenProlog.h" 45 44 //#include "Try/Visit.h" 46 45 47 #include " Common/SemanticError.h"48 #include " Common/UnimplementedError.h"46 #include "SemanticError.h" 47 #include "UnimplementedError.h" 49 48 50 49 #include "../config.h" … … 56 55 57 56 static void parse( FILE * input, LinkageSpec::Type t, bool shouldExit = false ); 58 static void dump( std::list< Declaration * > & translationUnit , std::ostream & out = std::cout);57 static void dump( std::list< Declaration * > & translationUnit ); 59 58 60 59 bool 61 60 astp = false, 62 61 bresolvep = false, 63 bboxp = false,64 ctorinitp = false,65 62 exprp = false, 66 63 expraltp = false, … … 72 69 resolvep = false, // used in AlternativeFinder 73 70 symtabp = false, 74 treep = false,75 71 validp = false, 76 72 errorp = false, 77 73 codegenp = false; 78 74 79 enum { Ast, B box, Bresolver, CtorInitFix, Expr, ExprAlt, Grammar, LibCFA, Nopreamble, Parse, Prototypes, Resolver, Symbol, Tree, Validate, };75 enum { Ast, Bresolver, Expr, ExprAlt, Grammar, LibCFA, Nopreamble, Parse, Prototypes, Resolver, Symbol, Validate, }; 80 76 81 77 static struct option long_opts[] = { 82 78 { "ast", no_argument, 0, Ast }, 83 { "before-box", no_argument, 0, Bbox },84 79 { "before-resolver", no_argument, 0, Bresolver }, 85 { "ctorinitfix", no_argument, 0, CtorInitFix },86 80 { "expr", no_argument, 0, Expr }, 87 81 { "expralt", no_argument, 0, ExprAlt }, … … 93 87 { "resolver", no_argument, 0, Resolver }, 94 88 { "symbol", no_argument, 0, Symbol }, 95 { "tree", no_argument, 0, Tree },96 89 { "validate", no_argument, 0, Validate }, 97 90 { 0, 0, 0, 0 } … … 102 95 std::ostream *output = &std::cout; 103 96 int long_index; 104 std::list< Declaration * > translationUnit; 105 const char *filename = NULL; 97 std::list< Declaration* > translationUnit; 106 98 107 99 opterr = 0; // prevent getopt from printing error messages 108 100 109 101 int c; 110 while ( (c = getopt_long( argc, argv, "ab BcefglnpqrstvyzD:F:", long_opts, &long_index )) != -1 ) {102 while ( (c = getopt_long( argc, argv, "abefglnpqrsvyzD:", long_opts, &long_index )) != -1 ) { 111 103 switch ( c ) { 112 104 case Ast: … … 118 110 bresolvep = true; 119 111 break; 120 case 'B': // print before resolver steps121 bboxp = true;122 break;123 case CtorInitFix:124 case 'c':125 ctorinitp = true;126 break;127 112 case Expr: 128 113 case 'e': // dump AST after expression analysis … … 161 146 symtabp = true; 162 147 break; 163 case Tree:164 case 't': // build in tree165 treep = true;166 break;167 148 case 'v': // dump AST after decl validation pass 168 149 validp = true; … … 176 157 case 'D': // ignore -Dxxx 177 158 break; 178 case 'F': // source file-name without suffix179 filename = optarg;180 break;181 159 case '?': 182 160 cout << "Unknown option: '" << (char)optopt << "'" << endl; 183 exit( EXIT_FAILURE);161 exit(1); 184 162 default: 185 163 abort(); … … 192 170 input = fopen( argv[ optind ], "r" ); 193 171 if ( ! input ) { 194 std::cout << "Error: can't open " << argv[ optind] << std::endl;195 exit( EXIT_FAILURE);172 std::cout << "Error: can't open " << argv[optind] << std::endl; 173 exit( 1 ); 196 174 } // if 197 // if running cfa-cpp directly, might forget to pass -F option (and really shouldn't have to)198 if ( filename == NULL ) filename = argv[ optind ];199 // prelude filename comes in differently200 if ( libcfap ) filename = "prelude.cf";201 175 optind += 1; 202 176 } else { 203 177 input = stdin; 204 // if running cfa-cpp directly, might forget to pass -F option. Since this takes from stdin, pass205 // a fake name along206 if ( filename == NULL ) filename = "stdin";207 178 } // if 208 179 … … 210 181 output = new ofstream( argv[ optind ] ); 211 182 } // if 212 183 213 184 Parser::get_parser().set_debug( grammarp ); 214 185 215 // read in the builtins , extras,and the prelude186 // read in the builtins and the prelude 216 187 if ( ! nopreludep ) { // include gcc builtins 217 // -l is for initial build ONLY and builtins.cf is not in the lib directory so access it here. 218 FILE * builtins = fopen( libcfap | treep ? "builtins.cf" : CFA_LIBDIR "/builtins.cf", "r" ); 188 FILE * builtins = fopen( CFA_LIBDIR "/builtins.cf", "r" ); 219 189 if ( builtins == NULL ) { 220 std::cerr << "Error: can't open builtins .cf" << std::endl;221 exit( EXIT_FAILURE);190 std::cerr << "Error: can't open builtins" << std::endl; 191 exit( 1 ); 222 192 } // if 193 223 194 parse( builtins, LinkageSpec::Compiler ); 224 195 225 // read the extra prelude in, if not generating the cfa library 226 FILE * extras = fopen( libcfap | treep ? "extras.cf" : CFA_LIBDIR "/extras.cf", "r" ); 227 if ( extras == NULL ) { 228 std::cerr << "Error: can't open extras.cf" << std::endl; 229 exit( EXIT_FAILURE ); 196 if ( ! libcfap ) { 197 // read the prelude in, if we're not generating the cfa library 198 FILE * prelude = fopen( CFA_LIBDIR "/prelude.cf", "r" ); 199 if ( prelude == NULL ) { 200 std::cerr << "Error: can't open prelude" << std::endl; 201 exit( 1 ); 202 } // if 203 204 parse( prelude, LinkageSpec::Intrinsic ); 230 205 } // if 231 parse( extras, LinkageSpec::C ); 232 233 if ( ! libcfap ) { 234 // read the prelude in, if not generating the cfa library 235 FILE * prelude = fopen( treep ? "prelude.cf" : CFA_LIBDIR "/prelude.cf", "r" ); 236 if ( prelude == NULL ) { 237 std::cerr << "Error: can't open prelude.cf" << std::endl; 238 exit( EXIT_FAILURE ); 239 } // if 240 241 parse( prelude, LinkageSpec::Intrinsic ); 242 } // if 243 } // if 244 245 parse( input, libcfap ? LinkageSpec::Intrinsic : LinkageSpec::Cforall, grammarp ); 246 206 } // if 207 208 if ( libcfap ) { 209 parse( input, LinkageSpec::Intrinsic ); 210 } else { 211 parse( input, LinkageSpec::Cforall, grammarp ); 212 } 213 247 214 if ( parsep ) { 248 215 Parser::get_parser().get_parseTree()->printList( std::cout ); … … 259 226 } // if 260 227 261 // add the assignment statement after the initialization of a type parameter 228 // add the assignment statement after the 229 // initialization of a type parameter 262 230 OPTPRINT( "validate" ) 263 231 SymTab::validate( translationUnit, symtabp ); … … 279 247 OPTPRINT( "mutate" ) 280 248 ControlStruct::mutate( translationUnit ); 281 OPTPRINT( "fixNames" ) 249 OPTPRINT( "fixNames" ) 282 250 CodeGen::fixNames( translationUnit ); 283 OPTPRINT( "tweak Init" )284 InitTweak:: genInit( translationUnit );251 OPTPRINT( "tweak" ) 252 InitTweak::tweak( translationUnit ); 285 253 286 254 if ( libcfap ) { … … 298 266 if ( exprp ) { 299 267 dump( translationUnit ); 300 return 0;301 }302 303 // fix ObjectDecl - replaces ConstructorInit nodes304 OPTPRINT( "fixInit" )305 InitTweak::fix( translationUnit, filename, libcfap || treep );306 if ( ctorinitp ) {307 dump ( translationUnit );308 return 0;309 268 } 310 269 … … 312 271 GenPoly::copyParams( translationUnit ); 313 272 OPTPRINT( "convertSpecializations" ) 314 GenPoly::convertSpecializations( translationUnit ); 273 GenPoly::convertSpecializations( translationUnit ); 315 274 OPTPRINT( "convertLvalue" ) 316 275 GenPoly::convertLvalue( translationUnit ); 317 318 if ( bboxp ) {319 dump( translationUnit );320 return 0;321 }322 276 OPTPRINT( "box" ) 323 277 GenPoly::box( translationUnit ); … … 336 290 } catch ( SemanticError &e ) { 337 291 if ( errorp ) { 338 std::cerr << "---AST at error:---" << std::endl; 339 dump( translationUnit, std::cerr ); 340 std::cerr << std::endl << "---End of AST, begin error message:---\n" << std::endl; 292 dump( translationUnit ); 341 293 } 342 294 e.print( std::cerr ); … … 360 312 } // try 361 313 362 deleteAll( translationUnit );363 314 return 0; 364 315 } // main … … 378 329 } 379 330 380 static void dump( std::list< Declaration * > & translationUnit , std::ostream & out) {331 static void dump( std::list< Declaration * > & translationUnit ) { 381 332 std::list< Declaration * > decls; 382 333 if ( noprotop ) { 383 filter( translationUnit.begin(), translationUnit.end(), 334 filter( translationUnit.begin(), translationUnit.end(), 384 335 std::back_inserter( decls ), notPrelude ); 385 336 } else { … … 387 338 } 388 339 389 printAll( decls, out ); 390 deleteAll( translationUnit ); 340 printAll( decls, std::cout ); 391 341 } 392 342
Note:
See TracChangeset
for help on using the changeset viewer.