Changeset 3b8e52c for src/main.cc
- Timestamp:
- Aug 17, 2016, 11:09:11 PM (8 years ago)
- Branches:
- ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, ctor, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, memory, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
- Children:
- 1cb2282, 7a5d773
- Parents:
- 926af74
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/main.cc
r926af74 r3b8e52c 10 10 // Created On : Fri May 15 23:12:02 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Wed Aug 17 09:08:43201613 // Update Count : 27412 // Last Modified On : Wed Aug 17 22:13:38 2016 13 // Update Count : 341 14 14 // 15 15 … … 70 70 static void dump( std::list< Declaration * > & translationUnit, std::ostream & out = std::cout ); 71 71 72 //************************************************ 73 74 #define __STRINGIFY__(str) #str 75 #define __VSTRINGIFY__(str) __STRINGIFY__(str) 76 #define assertf(expr, fmt, ...) ((expr) ? static_cast<void>(0) : __assert_fail_f(__VSTRINGIFY__(expr), __FILE__, __LINE__, __PRETTY_FUNCTION__, fmt, ## __VA_ARGS__ )) 77 #define CFA_ASSERT_FMT "*CFA assertion error* from program \"%s\" in \"%s\" at line %d in file \"%s\": " 78 79 extern const char * __progname; // global name of running executable (argv[0]) 80 // called by macro assert in assert.h 81 void __assert_fail( const char *assertion, const char *file, unsigned int line, const char *function ) { 82 fprintf( stderr, CFA_ASSERT_FMT, __progname, function, line, file ); 83 exit( EXIT_FAILURE ); 84 } 85 86 #include <cstdarg> 87 // called by macro assertf 88 void __assert_fail_f( const char *assertion, const char *file, unsigned int line, const char *function, const char *fmt, ... ) { 89 fprintf( stderr, CFA_ASSERT_FMT, __progname, function, line, file ); 90 va_list args; 91 va_start( args, fmt ); 92 vfprintf( stderr, fmt, args ); 93 exit( EXIT_FAILURE ); 94 } 95 96 //************************************************ 72 97 73 98 int main( int argc, char * argv[] ) { 74 FILE * input; 99 FILE * input; // use FILE rather than istream because yyin is FILE 75 100 std::ostream *output = & std::cout; 76 101 std::list< Declaration * > translationUnit; … … 81 106 try { 82 107 // choose to read the program from a file or stdin 83 if ( optind < argc ) { 108 if ( optind < argc ) { // any commands after the flags ? => input file name 84 109 input = fopen( argv[ optind ], "r" ); 85 if ( ! input ) { 86 std::cout << "Error: cannot open " << argv[ optind ] << std::endl; 87 exit( EXIT_FAILURE ); 88 } // if 110 assertf( input, "cannot open %s\n", argv[ optind ] ); 89 111 // if running cfa-cpp directly, might forget to pass -F option (and really shouldn't have to) 90 112 if ( filename == nullptr ) filename = argv[ optind ]; … … 92 114 if ( libcfap ) filename = "prelude.cf"; 93 115 optind += 1; 94 } else { 116 } else { // no input file name 95 117 input = stdin; 96 118 // if running cfa-cpp directly, might forget to pass -F option. Since this takes from stdin, pass … … 99 121 } // if 100 122 101 if ( optind < argc ) { 123 if ( optind < argc ) { // any commands after the flags and input file ? => output file name 102 124 output = new ofstream( argv[ optind ] ); 103 125 } // if … … 107 129 // -l is for initial build ONLY and builtins.cf is not in the lib directory so access it here. 108 130 FILE * builtins = fopen( libcfap | treep ? "builtins.cf" : CFA_LIBDIR "/builtins.cf", "r" ); 109 if ( builtins == nullptr ) { 110 std::cerr << "Error: cannot open builtins.cf" << std::endl; 111 exit( EXIT_FAILURE ); 112 } // if 131 assertf( builtins, "cannot open builtins.cf\n" ); 113 132 parse( builtins, LinkageSpec::Compiler ); 114 133 115 134 // read the extra prelude in, if not generating the cfa library 116 135 FILE * extras = fopen( libcfap | treep ? "extras.cf" : CFA_LIBDIR "/extras.cf", "r" ); 117 if ( extras == nullptr ) { 118 std::cerr << "Error: cannot open extras.cf" << std::endl; 119 exit( EXIT_FAILURE ); 120 } // if 136 assertf( extras, "cannot open extras.cf\n" ); 121 137 parse( extras, LinkageSpec::C ); 122 138 … … 124 140 // read the prelude in, if not generating the cfa library 125 141 FILE * prelude = fopen( treep ? "prelude.cf" : CFA_LIBDIR "/prelude.cf", "r" ); 126 if ( prelude == nullptr ) { 127 std::cerr << "Error: cannot open prelude.cf" << std::endl; 128 exit( EXIT_FAILURE ); 129 } // if 130 142 assertf( prelude, "cannot open prelude.cf\n" ); 131 143 parse( prelude, LinkageSpec::Intrinsic ); 132 144 } // if … … 355 367 break; 356 368 case '?': 357 cout << "Unknown option: '" << (char)optopt << "'" << endl; 358 exit( EXIT_FAILURE ); 369 assertf( false, "Unknown option: '%c'\n", (char)optopt ); 359 370 default: 360 371 abort(); … … 397 408 } // dump 398 409 410 411 399 412 // Local Variables: // 400 413 // tab-width: 4 //
Note: See TracChangeset
for help on using the changeset viewer.