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