Changeset e6955b1
- Timestamp:
- Aug 20, 2016, 7:04:17 PM (7 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:
- 80722d0
- Parents:
- 8b7ee09
- git-author:
- Peter A. Buhr <pabuhr@…> (08/20/16 13:18:07)
- git-committer:
- Peter A. Buhr <pabuhr@…> (08/20/16 19:04:17)
- Location:
- src
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Common/Assert.cc
r8b7ee09 re6955b1 10 10 // Created On : Thu Aug 18 13:26:59 2016 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Thu Aug 18 23:40:29201613 // Update Count : 812 // Last Modified On : Fri Aug 19 17:07:08 2016 13 // Update Count : 10 14 14 // 15 15 16 16 #include <assert.h> 17 #include <cstdarg> 18 #include <cstdio> 19 #include <cstdlib> 17 #include <cstdarg> // varargs 18 #include <cstdio> // fprintf 19 #include <cstdlib> // abort 20 20 21 21 extern const char * __progname; // global name of running executable (argv[0]) … … 26 26 void __assert_fail( const char *assertion, const char *file, unsigned int line, const char *function ) { 27 27 fprintf( stderr, CFA_ASSERT_FMT ".\n", __progname, function, line, file ); 28 exit( EXIT_FAILURE);28 abort(); 29 29 } 30 30 … … 35 35 va_start( args, fmt ); 36 36 vfprintf( stderr, fmt, args ); 37 exit( EXIT_FAILURE);37 abort(); 38 38 } 39 39 -
src/Makefile.am
r8b7ee09 re6955b1 11 11 ## Created On : Sun May 31 08:51:46 2015 12 12 ## Last Modified By : Peter A. Buhr 13 ## Last Modified On : Thu Aug 18 17:47:06201614 ## Update Count : 7 013 ## Last Modified On : Sat Aug 20 11:13:12 2016 14 ## Update Count : 71 15 15 ############################################################################### 16 16 … … 43 43 driver_cfa_cpp_SOURCES = ${SRC} 44 44 driver_cfa_cpp_LDADD = ${LEXLIB} # yywrap 45 driver_cfa_cpp_CXXFLAGS = -Wno-deprecated -Wall -DDEBUG_ALL - I${abs_top_srcdir}/src/include45 driver_cfa_cpp_CXXFLAGS = -Wno-deprecated -Wall -DDEBUG_ALL -rdynamic -I${abs_top_srcdir}/src/include 46 46 47 47 MAINTAINERCLEANFILES += ${libdir}/${notdir ${cfa_cpplib_PROGRAMS}} -
src/Makefile.in
r8b7ee09 re6955b1 427 427 driver_cfa_cpp_SOURCES = ${SRC} 428 428 driver_cfa_cpp_LDADD = ${LEXLIB} # yywrap 429 driver_cfa_cpp_CXXFLAGS = -Wno-deprecated -Wall -DDEBUG_ALL - I${abs_top_srcdir}/src/include429 driver_cfa_cpp_CXXFLAGS = -Wno-deprecated -Wall -DDEBUG_ALL -rdynamic -I${abs_top_srcdir}/src/include 430 430 all: $(BUILT_SOURCES) 431 431 $(MAKE) $(AM_MAKEFLAGS) all-am -
src/main.cc
r8b7ee09 re6955b1 10 10 // Created On : Fri May 15 23:12:02 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Fri Aug 19 08:31:22 201613 // Update Count : 35012 // Last Modified On : Sat Aug 20 12:52:22 2016 13 // Update Count : 403 14 14 // 15 15 16 16 #include <iostream> 17 17 #include <fstream> 18 #include <getopt.h> 18 #include <signal.h> // signal 19 #include <getopt.h> // getopt 20 #include <execinfo.h> // backtrace, backtrace_symbols_fd 21 #include <cxxabi.h> // __cxa_demangle 22 23 using namespace std; 24 19 25 #include "Parser/lex.h" 20 26 #include "Parser/parser.h" … … 35 41 #include "InitTweak/FixInit.h" 36 42 #include "Common/UnimplementedError.h" 37 38 43 #include "../config.h" 39 44 40 45 using namespace std; 41 46 42 #define OPTPRINT(x) if ( errorp ) std::cerr << x << std::endl;47 #define OPTPRINT(x) if ( errorp ) cerr << x << endl; 43 48 44 49 … … 68 73 static void parse_cmdline( int argc, char *argv[], const char *& filename ); 69 74 static void parse( FILE * input, LinkageSpec::Spec linkage, bool shouldExit = false ); 70 static void dump( std::list< Declaration * > & translationUnit, std::ostream & out = std::cout ); 75 static void dump( list< Declaration * > & translationUnit, ostream & out = cout ); 76 77 void sigSegvBusHandler( int sig_num ) { 78 enum { Frames = 50 }; 79 void * array[Frames]; 80 int size = backtrace( array, Frames ); 81 82 cerr << "*CFA runtime error* program cfa-cpp terminated with " 83 << (sig_num == SIGSEGV ? "segment fault" : "bus error") 84 << " backtrace:" << endl; 85 86 char ** messages = backtrace_symbols( array, size ); 87 88 // skip first stack frame (points here) 89 for ( int i = 2; i < size - 2 && messages != nullptr; i += 1 ) { 90 char * mangled_name = nullptr, * offset_begin = nullptr, * offset_end = nullptr; 91 for ( char *p = messages[i]; *p; ++p ) { // find parantheses and +offset 92 if (*p == '(') { 93 mangled_name = p; 94 } else if (*p == '+') { 95 offset_begin = p; 96 } else if (*p == ')') { 97 offset_end = p; 98 break; 99 } // if 100 } // for 101 102 // if line contains symbol, attempt to demangle 103 if ( mangled_name && offset_begin && offset_end && mangled_name < offset_begin ) { 104 *mangled_name++ = '\0'; 105 *offset_begin++ = '\0'; 106 *offset_end++ = '\0'; 107 108 int status; 109 char * real_name = __cxxabiv1::__cxa_demangle( mangled_name, 0, 0, &status ); 110 if ( status == 0 ) { // demangling successful ? 111 cerr << "(" << i - 2 << ") " << messages[i] << " : " 112 << real_name << "+" << offset_begin << offset_end << endl; 113 114 } else { // otherwise, output mangled name 115 cerr << "(" << i - 2 << ") " << messages[i] << " : " 116 << mangled_name << "+" << offset_begin << offset_end << endl; 117 } // if 118 free( real_name ); 119 } else { // otherwise, print the whole line 120 cerr << "(" << i - 2 << ") " << messages[i] << endl; 121 } // if 122 } // for 123 free( messages ); 124 exit( EXIT_FAILURE ); 125 } // sigSegvBusHandler 71 126 72 127 int main( int argc, char * argv[] ) { 73 128 FILE * input; // use FILE rather than istream because yyin is FILE 74 std::ostream *output = & std::cout; 75 std::list< Declaration * > translationUnit; 129 ostream *output = & cout; 76 130 const char *filename = nullptr; 131 list< Declaration * > translationUnit; 132 133 signal( SIGSEGV, sigSegvBusHandler ); 134 signal( SIGBUS, sigSegvBusHandler ); 77 135 78 136 parse_cmdline( argc, argv, filename ); // process command-line arguments … … 122 180 123 181 if ( parsep ) { 124 parseTree->printList( std::cout );182 parseTree->printList( cout ); 125 183 delete parseTree; 126 184 return 0; … … 144 202 145 203 if ( expraltp ) { 146 ResolvExpr::AlternativePrinter printer( std::cout );204 ResolvExpr::AlternativePrinter printer( cout ); 147 205 acceptAll( translationUnit, printer ); 148 206 return 0; … … 210 268 CodeGen::generate( translationUnit, *output, ! noprotop ); 211 269 212 if ( output != & std::cout ) {270 if ( output != &cout ) { 213 271 delete output; 214 272 } // if 215 273 } catch ( SemanticError &e ) { 216 274 if ( errorp ) { 217 std::cerr << "---AST at error:---" << std::endl;218 dump( translationUnit, std::cerr );219 std::cerr << std::endl << "---End of AST, begin error message:---\n" << std::endl;220 } // if 221 e.print( std::cerr );222 if ( output != & std::cout ) {275 cerr << "---AST at error:---" << endl; 276 dump( translationUnit, cerr ); 277 cerr << endl << "---End of AST, begin error message:---\n" << endl; 278 } // if 279 e.print( cerr ); 280 if ( output != &cout ) { 223 281 delete output; 224 282 } // if 225 283 return 1; 226 284 } catch ( UnimplementedError &e ) { 227 std::cout << "Sorry, " << e.get_what() << " is not currently implemented" << std::endl;228 if ( output != & std::cout ) {285 cout << "Sorry, " << e.get_what() << " is not currently implemented" << endl; 286 if ( output != &cout ) { 229 287 delete output; 230 288 } // if 231 289 return 1; 232 290 } catch ( CompilerError &e ) { 233 std::cerr << "Compiler Error: " << e.get_what() << std::endl;234 std::cerr << "(please report bugs to " << std::endl;235 if ( output != & std::cout ) {291 cerr << "Compiler Error: " << e.get_what() << endl; 292 cerr << "(please report bugs to " << endl; 293 if ( output != &cout ) { 236 294 delete output; 237 295 } // if … … 369 427 } // notPrelude 370 428 371 static void dump( std::list< Declaration * > & translationUnit, std::ostream & out ) {372 std::list< Declaration * > decls;429 static void dump( list< Declaration * > & translationUnit, ostream & out ) { 430 list< Declaration * > decls; 373 431 374 432 if ( noprotop ) { 375 filter( translationUnit.begin(), translationUnit.end(), std::back_inserter( decls ), notPrelude );433 filter( translationUnit.begin(), translationUnit.end(), back_inserter( decls ), notPrelude ); 376 434 } else { 377 435 decls = translationUnit;
Note: See TracChangeset
for help on using the changeset viewer.