Changeset 937e51d for src/main.cc
- Timestamp:
- Jun 26, 2015, 4:00:26 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, string, with_gc
- Children:
- 0df292b, e0ff3e6
- Parents:
- eb50842 (diff), 1869adf (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) (13 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/main.cc
reb50842 r937e51d 10 10 // Created On : Fri May 15 23:12:02 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Thu May 21 21:15:54201513 // Update Count : 912 // Last Modified On : Mon Jun 22 17:02:11 2015 13 // Update Count : 73 14 14 // 15 15 … … 51 51 using namespace std; 52 52 53 #define OPTPRINT(x) \ 54 if ( errorp ) std::cerr << x << std::endl; 55 56 void parse( FILE * input, LinkageSpec::Type t, bool shouldExit = false ); 57 53 58 bool 54 59 astp = false, 60 bresolvep = false, 55 61 exprp = false, 56 62 expraltp = false, 57 63 grammarp = false, 58 64 libcfap = false, 65 nopreludep = false, 66 protop = false, 67 parsep = false, 59 68 resolvep = false, // used in AlternativeFinder 60 69 symtabp = false, 61 parsep = false,62 70 validp = false, 63 preludep = true, 64 protop = false, 65 codegenp = false, 66 errorp = false; 67 68 enum { Ast, Expr, ExprAlt, Grammar, LibCFA, Nopreamble, Prototypes, Resolver, Symbol, Parse, }; 71 errorp = false, 72 codegenp = false; 73 74 enum { Ast, Bresolver, Expr, ExprAlt, Grammar, LibCFA, Nopreamble, Parse, Prototypes, Resolver, Symbol, Validate, }; 69 75 70 76 static struct option long_opts[] = { 71 77 { "ast", no_argument, 0, Ast }, 78 { "before-resolver", no_argument, 0, Bresolver }, 72 79 { "expr", no_argument, 0, Expr }, 73 80 { "expralt", no_argument, 0, ExprAlt }, … … 75 82 { "libcfa", no_argument, 0, LibCFA }, 76 83 { "nopreamble", no_argument, 0, Nopreamble }, 84 { "parse", no_argument, 0, Parse }, 77 85 { "prototypes", no_argument, 0, Prototypes }, 78 86 { "resolver", no_argument, 0, Resolver }, 79 87 { "symbol", no_argument, 0, Symbol }, 80 { " parse", no_argument, 0, Parse },88 { "validate", no_argument, 0, Validate }, 81 89 { 0, 0, 0, 0 } 82 90 }; … … 91 99 92 100 int c; 93 while ( (c = getopt_long( argc, argv, "a efglnpqrsxyzD:", long_opts, &long_index )) != -1 ) {101 while ( (c = getopt_long( argc, argv, "abefglnpqrsvyzD:", long_opts, &long_index )) != -1 ) { 94 102 switch ( c ) { 95 103 case Ast: … … 97 105 astp = true; 98 106 break; 107 case Bresolver: 108 case 'b': // print before resolver steps 109 bresolvep = true; 110 break; 99 111 case Expr: 100 112 case 'e': // dump AST after expression analysis … … 115 127 case Nopreamble: 116 128 case 'n': // do not read preamble 117 preludep = false;129 nopreludep = true; 118 130 break; 119 131 case Prototypes: … … 133 145 symtabp = true; 134 146 break; 135 case ' x': // dump AST after decl validation pass147 case 'v': // dump AST after decl validation pass 136 148 validp = true; 137 149 break; … … 153 165 154 166 try { 167 // choose to read the program from a file or stdin 155 168 if ( optind < argc ) { 156 169 input = fopen( argv[ optind ], "r" ); … … 169 182 170 183 Parser::get_parser().set_debug( grammarp ); 171 172 if ( preludep ) { // include gcc builtins 173 FILE *builtins = fopen( CFA_LIBDIR "/builtins.cf", "r" ); 184 185 // read in the builtins and the prelude 186 if ( ! nopreludep ) { // include gcc builtins 187 FILE * builtins = fopen( CFA_LIBDIR "/builtins.cf", "r" ); 174 188 if ( builtins == NULL ) { 175 std::c out<< "Error: can't open builtins" << std::endl;189 std::cerr << "Error: can't open builtins" << std::endl; 176 190 exit( 1 ); 177 191 } // if 178 179 Parser::get_parser().set_linkage( LinkageSpec::Compiler ); 180 Parser::get_parser().parse( builtins ); 181 182 if ( Parser::get_parser().get_parseStatus() != 0 ) { 183 return Parser::get_parser().get_parseStatus(); 192 193 parse( builtins, LinkageSpec::Compiler ); 194 195 if ( ! libcfap ) { 196 // read the prelude in, if we're not generating the cfa library 197 FILE * prelude = fopen( CFA_LIBDIR "/prelude.cf", "r" ); 198 if ( prelude == NULL ) { 199 std::cerr << "Error: can't open prelude" << std::endl; 200 exit( 1 ); 201 } // if 202 203 parse( prelude, LinkageSpec::Intrinsic ); 184 204 } // if 185 fclose( builtins ); 186 187 FILE *prelude; 188 if ( libcfap ) { // include cfa prelude 189 prelude = input; 190 } else { 191 prelude = fopen( CFA_LIBDIR "/prelude.cf", "r" ); 192 } // if 193 if ( prelude == NULL ) { 194 std::cout << "Error: can't open prelude" << std::endl; 195 exit( 1 ); 196 } // if 197 198 Parser::get_parser().set_linkage( LinkageSpec::Intrinsic ); 199 Parser::get_parser().parse( prelude ); 200 201 if ( Parser::get_parser().get_parseStatus() != 0 ) { 202 return Parser::get_parser().get_parseStatus(); 203 } // if 204 fclose( prelude ); 205 } // if 206 205 } // if 206 207 207 if ( libcfap ) { 208 std::list< Declaration* > translationUnit; 209 buildList( Parser::get_parser().get_parseTree(), translationUnit ); 210 Parser::get_parser().freeTree(); 211 SymTab::validate( translationUnit, false ); 212 CodeGen::fixNames( translationUnit ); 213 LibCfa::makeLibCfa( translationUnit ); 214 ResolvExpr::resolve( translationUnit ); 215 GenPoly::convertLvalue( translationUnit ); 216 GenPoly::box( translationUnit ); 217 CodeGen::generate( translationUnit, *output, true ); 218 if ( output != &std::cout ) { 219 delete output; 220 } // if 221 return 0; 222 } // if 223 224 Parser::get_parser().set_linkage( LinkageSpec::Cforall ); 225 226 Parser::get_parser().parse( input ); 227 if ( grammarp || Parser::get_parser().get_parseStatus() != 0 ) { 228 return Parser::get_parser().get_parseStatus(); 229 } // if 230 fclose( input ); 208 parse( input, LinkageSpec::Intrinsic ); 209 } else { 210 parse( input, LinkageSpec::Cforall, grammarp ); 211 } 231 212 232 213 if ( parsep ) { … … 244 225 } // if 245 226 227 // add the assignment statement after the 228 // initialization of a type parameter 229 OPTPRINT( "tweak" ) 230 InitTweak::tweak( translationUnit ); 231 OPTPRINT( "validate" ) 232 SymTab::validate( translationUnit, symtabp ); 233 if ( symtabp ) { 234 return 0; 235 } // if 236 246 237 if ( expraltp ) { 247 SymTab::validate( translationUnit, false );248 238 ResolvExpr::AlternativePrinter printer( std::cout ); 249 239 acceptAll( translationUnit, printer ); … … 251 241 } // if 252 242 253 if ( symtabp ) {254 SymTab::validate( translationUnit, true );255 return 0;256 } // if257 258 243 if ( validp ) { 259 SymTab::validate( translationUnit, false ); 260 printAll( translationUnit, std::cout ); 261 return 0; 262 } // if 263 244 printAll( translationUnit, std::cout ); 245 return 0; 246 } // if 247 248 OPTPRINT( "mutate" ) 249 ControlStruct::mutate( translationUnit ); 250 OPTPRINT( "fixNames" ) 251 CodeGen::fixNames( translationUnit ); 252 253 if ( libcfap ) { 254 protop = true; 255 // generate the bodies of cfa library functions 256 LibCfa::makeLibCfa( translationUnit ); 257 } // if 258 259 if ( bresolvep ) { 260 printAll( translationUnit, std::cout ); 261 return 0; 262 } // if 263 264 OPTPRINT( "resolve" ) 265 ResolvExpr::resolve( translationUnit ); 264 266 if ( exprp ) { 265 InitTweak::tweak( translationUnit ); 266 SymTab::validate( translationUnit, false ); 267 ControlStruct::mutate( translationUnit ); 268 CodeGen::fixNames( translationUnit ); 269 ResolvExpr::resolve( translationUnit ); 270 printAll( translationUnit, std::cout ); 271 return 0; 272 } // if 273 267 printAll( translationUnit, std::cout ); 268 } 269 270 OPTPRINT( "copyParams" ); 271 GenPoly::copyParams( translationUnit ); 272 OPTPRINT( "convertSpecializations" ) 273 GenPoly::convertSpecializations( translationUnit ); 274 OPTPRINT( "convertLvalue" ) 275 GenPoly::convertLvalue( translationUnit ); 276 OPTPRINT( "box" ) 277 GenPoly::box( translationUnit ); 278 279 // print the tree right before code generation 274 280 if ( codegenp ) { 275 // print the tree right before code generation 276 cerr << "tweak" << endl; 277 InitTweak::tweak( translationUnit ); 278 cerr << "validate" << endl; 279 SymTab::validate( translationUnit, false ); 280 cerr << "mutate" << endl; 281 ControlStruct::mutate( translationUnit ); 282 cerr << "fixNames" << endl; 283 CodeGen::fixNames( translationUnit ); 284 cerr << "resolve" << endl; 285 ResolvExpr::resolve( translationUnit ); 286 cerr << "copyParams" << endl; 287 GenPoly::copyParams( translationUnit ); 288 cerr << "convertSpecializations" << endl; 289 GenPoly::convertSpecializations( translationUnit ); 290 cerr << "convertLvalue" << endl; 291 GenPoly::convertLvalue( translationUnit ); 292 cerr << "box" << endl; 293 GenPoly::box( translationUnit ); 294 if ( errorp ) { 295 printAll( translationUnit, std::cout ); 296 } 297 return 0; 298 } // if 299 300 // add the assignment statement after the 301 // initialization of a type parameter 302 InitTweak::tweak( translationUnit ); 303 304 //std::cerr << "before validate" << std::endl; 305 SymTab::validate( translationUnit, false ); 306 //Try::visit( translationUnit ); 307 //Tuples::mutate( translationUnit ); 308 //InitTweak::mutate( translationUnit ); 309 //std::cerr << "before mutate" << std::endl; 310 ControlStruct::mutate( translationUnit ); 311 //std::cerr << "before fixNames" << std::endl; 312 CodeGen::fixNames( translationUnit ); 313 //std::cerr << "before resolve" << std::endl; 314 ResolvExpr::resolve( translationUnit ); 315 //Tuples::checkFunctions( translationUnit ); 316 // std::cerr << "Finished tuple checkfunctions" << std::endl; 317 //printAll( translationUnit, std::cerr ); 318 //std::cerr << "before copyParams" << std::endl; 319 GenPoly::copyParams( translationUnit ); 320 //std::cerr << "before convertSpecializations" << std::endl; 321 GenPoly::convertSpecializations( translationUnit ); 322 //std::cerr << "before convertLvalue" << std::endl; 323 GenPoly::convertLvalue( translationUnit ); 324 //std::cerr << "before box" << std::endl; 325 GenPoly::box( translationUnit ); 326 //Tuples::mutate( translationUnit ); 281 printAll( translationUnit, std::cout ); 282 return 0; 283 } // if 327 284 328 285 CodeGen::generate( translationUnit, *output, protop ); … … 331 288 delete output; 332 289 } // if 333 334 290 } catch ( SemanticError &e ) { 335 291 if ( errorp ) { 336 printAll( translationUnit, std::c out);292 printAll( translationUnit, std::cerr ); 337 293 } 338 e.print( cout);294 e.print( std::cerr ); 339 295 if ( output != &std::cout ) { 340 296 delete output; … … 359 315 } // main 360 316 317 void parse( FILE * input, LinkageSpec::Type linkage, bool shouldExit ) { 318 Parser::get_parser().set_linkage( linkage ); 319 Parser::get_parser().parse( input ); 320 321 fclose( input ); 322 if ( shouldExit || Parser::get_parser().get_parseStatus() != 0 ) { 323 exit( Parser::get_parser().get_parseStatus() ); 324 } // if 325 } 326 361 327 // Local Variables: // 362 328 // tab-width: 4 //
Note:
See TracChangeset
for help on using the changeset viewer.