Changeset 81419b5
- Timestamp:
- Jun 9, 2015, 3:13:42 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:
- 0b2961f
- Parents:
- 5f2f2d7
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
TabularUnified src/main.cc ¶
r5f2f2d7 r81419b5 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 : Mon Jun 8 16:50:31201513 // Update Count : 1111 // Last Modified By : Rob Schluntz 12 // Last Modified On : Tue Jun 09 15:10:05 2015 13 // Update Count : 68 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, … … 153 158 154 159 try { 160 // choose to read the program from a file or stdin 155 161 if ( optind < argc ) { 156 162 input = fopen( argv[ optind ], "r" ); … … 169 175 170 176 Parser::get_parser().set_debug( grammarp ); 171 177 178 // read in the builtins and the prelude 172 179 if ( preludep ) { // include gcc builtins 173 FILE * builtins = fopen( CFA_LIBDIR "/builtins.cf", "r" );180 FILE * builtins = fopen( CFA_LIBDIR "/builtins.cf", "r" ); 174 181 if ( builtins == NULL ) { 175 std::c out<< "Error: can't open builtins" << std::endl;182 std::cerr << "Error: can't open builtins" << std::endl; 176 183 exit( 1 ); 177 184 } // 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(); 185 186 parse( builtins, LinkageSpec::Compiler ); 187 188 if ( ! libcfap ) { 189 // read the prelude in, if we're not generating the cfa library 190 FILE * prelude = fopen( CFA_LIBDIR "/prelude.cf", "r" ); 191 if ( prelude == NULL ) { 192 std::cerr << "Error: can't open prelude" << std::endl; 193 exit( 1 ); 194 } // if 195 196 parse( prelude, LinkageSpec::Intrinsic ); 184 197 } // 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 198 } // if 199 207 200 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 ); 201 parse( input, LinkageSpec::Intrinsic ); 202 } else { 203 parse( input, LinkageSpec::Cforall, grammarp ); 204 } 231 205 232 206 if ( parsep ) { … … 244 218 } // if 245 219 220 // add the assignment statement after the 221 // initialization of a type parameter 222 OPTPRINT( "tweak" ) 223 InitTweak::tweak( translationUnit ); 224 OPTPRINT( "validate" ) 225 SymTab::validate( translationUnit, symtabp ); 226 if ( symtabp ) { 227 return 0; 228 } // if 229 246 230 if ( expraltp ) { 247 SymTab::validate( translationUnit, false );248 231 ResolvExpr::AlternativePrinter printer( std::cout ); 249 232 acceptAll( translationUnit, printer ); … … 251 234 } // if 252 235 253 if ( symtabp ) {254 SymTab::validate( translationUnit, true );255 return 0;256 } // if257 258 236 if ( validp ) { 259 SymTab::validate( translationUnit, false );260 237 printAll( translationUnit, std::cout ); 261 238 return 0; 262 239 } // if 263 240 241 OPTPRINT( "mutate" ) 242 ControlStruct::mutate( translationUnit ); 243 OPTPRINT( "fixNames" ) 244 CodeGen::fixNames( translationUnit ); 245 246 if ( libcfap ) { 247 protop = true; 248 // generate the bodies of cfa library functions 249 LibCfa::makeLibCfa( translationUnit ); 250 } // if 251 252 OPTPRINT( "resolve" ) 253 ResolvExpr::resolve( translationUnit ); 264 254 if ( exprp ) { 265 InitTweak::tweak( translationUnit );266 SymTab::validate( translationUnit, false );267 ControlStruct::mutate( translationUnit );268 CodeGen::fixNames( translationUnit );269 ResolvExpr::resolve( translationUnit );270 255 printAll( translationUnit, std::cout ); 271 return 0; 272 } // if 273 256 } 257 258 OPTPRINT( "copyParams" ); 259 GenPoly::copyParams( translationUnit ); 260 OPTPRINT( "convertSpecializations" ) 261 GenPoly::convertSpecializations( translationUnit ); 262 OPTPRINT( "convertLvalue" ) 263 GenPoly::convertLvalue( translationUnit ); 264 OPTPRINT( "box" ) 265 GenPoly::box( translationUnit ); 266 267 // print the tree right before code generation 274 268 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 ); 269 printAll( translationUnit, std::cout ); 270 return 0; 271 } // if 327 272 328 273 CodeGen::generate( translationUnit, *output, protop ); … … 334 279 } catch ( SemanticError &e ) { 335 280 if ( errorp ) { 336 printAll( translationUnit, std::c out);281 printAll( translationUnit, std::cerr ); 337 282 } 338 e.print( cout);283 e.print( std::cerr ); 339 284 if ( output != &std::cout ) { 340 285 delete output; … … 359 304 } // main 360 305 306 void parse(FILE * input, LinkageSpec::Type linkage, bool shouldExit) { 307 Parser::get_parser().set_linkage( linkage ); 308 Parser::get_parser().parse( input ); 309 310 fclose( input ); 311 if ( shouldExit || Parser::get_parser().get_parseStatus() != 0 ) { 312 exit( Parser::get_parser().get_parseStatus() ); 313 } // if 314 } 315 361 316 // Local Variables: // 362 317 // tab-width: 4 //
Note: See TracChangeset
for help on using the changeset viewer.