source: src/main.cc@ 0182bfa

new-env with_gc
Last change on this file since 0182bfa was eba74ba, checked in by Aaron Moss <a3moss@…>, 7 years ago

Merge remote-tracking branch 'origin/master' into with_gc

  • Property mode set to 100644
File size: 19.9 KB
RevLine 
[c850687]1
[b87a5ed]2//
3// Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo
4//
5// The contents of this file are covered under the licence agreement in the
6// file "LICENCE" distributed with Cforall.
7//
[71f4e4f]8// main.cc --
[b87a5ed]9//
[843054c2]10// Author : Richard C. Bilson
[b87a5ed]11// Created On : Fri May 15 23:12:02 2015
[c59bde6]12// Last Modified By : Peter A. Buhr
[c5e5109]13// Last Modified On : Mon May 7 14:35:57 2018
14// Update Count : 492
[b87a5ed]15//
16
[bf2438c]17#include <cxxabi.h> // for __cxa_demangle
18#include <execinfo.h> // for backtrace, backtrace_symbols
19#include <getopt.h> // for no_argument, optind, geto...
20#include <signal.h> // for signal, SIGABRT, SIGSEGV
[08fc48f]21#include <cassert> // for assertf
[bf2438c]22#include <cstdio> // for fopen, FILE, fclose, stdin
23#include <cstdlib> // for exit, free, abort, EXIT_F...
24#include <cstring> // for index
[be9288a]25#include <fstream> // for ofstream
[bf2438c]26#include <iostream> // for operator<<, basic_ostream
27#include <iterator> // for back_inserter
28#include <list> // for list
[08fc48f]29#include <string> // for char_traits, operator<<
[e6955b1]30
[bf2438c]31#include "../config.h" // for CFA_LIBDIR
32#include "CodeGen/FixMain.h" // for FixMain
33#include "CodeGen/FixNames.h" // for fixNames
34#include "CodeGen/Generate.h" // for generate
35#include "CodeTools/DeclStats.h" // for printDeclStats
36#include "CodeTools/TrackLoc.h" // for fillLocations
37#include "Common/CompilerError.h" // for CompilerError
[ff29f08]38#include "Common/GC.h" // for GC
[cbbd5b48]39#include "Common/Heap.h"
40#include "Common/PassVisitor.h"
[bf2438c]41#include "Common/SemanticError.h" // for SemanticError
42#include "Common/UnimplementedError.h" // for UnimplementedError
43#include "Common/utility.h" // for deleteAll, filter, printAll
[9f5ecf5]44#include "Concurrency/Waitfor.h" // for generateWaitfor
[bf2438c]45#include "ControlStruct/ExceptTranslate.h" // for translateEHM
46#include "ControlStruct/Mutate.h" // for mutate
47#include "GenPoly/Box.h" // for box
48#include "GenPoly/InstantiateGeneric.h" // for instantiateGeneric
49#include "GenPoly/Lvalue.h" // for convertLvalue
50#include "GenPoly/Specialize.h" // for convertSpecializations
51#include "InitTweak/FixInit.h" // for fix
52#include "InitTweak/GenInit.h" // for genInit
53#include "MakeLibCfa.h" // for makeLibCfa
54#include "Parser/LinkageSpec.h" // for Spec, Cforall, Intrinsic
55#include "Parser/ParseNode.h" // for DeclarationNode, buildList
56#include "Parser/TypedefTable.h" // for TypedefTable
57#include "ResolvExpr/AlternativePrinter.h" // for AlternativePrinter
58#include "ResolvExpr/Resolver.h" // for resolve
59#include "SymTab/Validate.h" // for validate
60#include "SynTree/Declaration.h" // for Declaration
[68f9c43]61#include "SynTree/GcTracer.h" // for GC << TranslationUnit
[bf2438c]62#include "SynTree/Visitor.h" // for acceptAll
63#include "Tuples/Tuples.h" // for expandMemberTuples, expan...
[a5f0529]64#include "Virtual/ExpandCasts.h" // for expandCasts
[51b73452]65
66using namespace std;
67
[6edd210]68#define PASS(name, pass) \
[ecaeac6e]69 if ( errorp ) { cerr << name << endl; } \
70 HeapStats::newPass(name); \
[6edd210]71 pass;
[81419b5]72
[8b7ee09]73LinkageSpec::Spec linkage = LinkageSpec::Cforall;
[0da3e2c]74TypedefTable typedefTable;
[cbaee0d]75DeclarationNode * parseTree = nullptr; // program parse tree
[81419b5]76
[926af74]77extern int yydebug; // set for -g flag (Grammar)
[b87a5ed]78bool
79 astp = false,
[de62360d]80 bresolvep = false,
[fea7ca7]81 bboxp = false,
[8905f56]82 bcodegenp = false,
[ca1c11f]83 ctorinitp = false,
[41a7137]84 declstatsp = false,
[b87a5ed]85 exprp = false,
86 expraltp = false,
[53d3ab4b]87 genericsp = false,
[b87a5ed]88 libcfap = false,
[de62360d]89 nopreludep = false,
[1ab4ce2]90 noprotop = false,
[3fe34ae]91 nomainp = false,
[de62360d]92 parsep = false,
[b87a5ed]93 resolvep = false, // used in AlternativeFinder
94 symtabp = false,
[d3b7937]95 treep = false,
[626dbc10]96 tuplep = false,
[b87a5ed]97 validp = false,
[de62360d]98 errorp = false,
[35b1bf4]99 codegenp = false,
[c850687]100 prettycodegenp = false,
[6de43b6]101 linemarks = false;
[b87a5ed]102
[926af74]103static void parse_cmdline( int argc, char *argv[], const char *& filename );
[8b7ee09]104static void parse( FILE * input, LinkageSpec::Spec linkage, bool shouldExit = false );
[e6955b1]105static void dump( list< Declaration * > & translationUnit, ostream & out = cout );
106
[0afffee]107static void backtrace( int start ) { // skip first N stack frames
[e6955b1]108 enum { Frames = 50 };
109 void * array[Frames];
[0afffee]110 int size = ::backtrace( array, Frames );
111 char ** messages = ::backtrace_symbols( array, size ); // does not demangle names
112
113 *index( messages[0], '(' ) = '\0'; // find executable name
114 cerr << "Stack back trace for: " << messages[0] << endl;
[e6955b1]115
[b542bfb]116 // skip last 2 stack frames after main
117 for ( int i = start; i < size - 2 && messages != nullptr; i += 1 ) {
[e6955b1]118 char * mangled_name = nullptr, * offset_begin = nullptr, * offset_end = nullptr;
119 for ( char *p = messages[i]; *p; ++p ) { // find parantheses and +offset
[0afffee]120 if ( *p == '(' ) {
[46f6134]121 mangled_name = p;
[0afffee]122 } else if ( *p == '+' ) {
[e6955b1]123 offset_begin = p;
[0afffee]124 } else if ( *p == ')' ) {
[e6955b1]125 offset_end = p;
126 break;
127 } // if
128 } // for
129
130 // if line contains symbol, attempt to demangle
[b542bfb]131 int frameNo = i - start;
[e6955b1]132 if ( mangled_name && offset_begin && offset_end && mangled_name < offset_begin ) {
[0afffee]133 *mangled_name++ = '\0'; // delimit strings
[e6955b1]134 *offset_begin++ = '\0';
135 *offset_end++ = '\0';
136
[0afffee]137 int status;
[e6955b1]138 char * real_name = __cxxabiv1::__cxa_demangle( mangled_name, 0, 0, &status );
[0afffee]139 // bug in __cxa_demangle for single-character lower-case non-mangled names
[e6955b1]140 if ( status == 0 ) { // demangling successful ?
[b542bfb]141 cerr << "(" << frameNo << ") " << messages[i] << " : "
[e6955b1]142 << real_name << "+" << offset_begin << offset_end << endl;
143 } else { // otherwise, output mangled name
[b542bfb]144 cerr << "(" << frameNo << ") " << messages[i] << " : "
[0afffee]145 << mangled_name << "(/*unknown*/)+" << offset_begin << offset_end << endl;
[e6955b1]146 } // if
[0afffee]147
[e6955b1]148 free( real_name );
149 } else { // otherwise, print the whole line
[b542bfb]150 cerr << "(" << frameNo << ") " << messages[i] << endl;
[e6955b1]151 } // if
152 } // for
[b542bfb]153
[e6955b1]154 free( messages );
[b542bfb]155} // backtrace
156
157void sigSegvBusHandler( int sig_num ) {
158 cerr << "*CFA runtime error* program cfa-cpp terminated with "
159 << (sig_num == SIGSEGV ? "segment fault" : "bus error")
[0afffee]160 << "." << endl;
[b542bfb]161 backtrace( 2 ); // skip first 2 stack frames
[e6955b1]162 exit( EXIT_FAILURE );
163} // sigSegvBusHandler
[0da3e2c]164
[b3c36f4]165void sigAbortHandler( __attribute__((unused)) int sig_num ) {
[b542bfb]166 backtrace( 6 ); // skip first 6 stack frames
167 signal( SIGABRT, SIG_DFL); // reset default signal handler
168 raise( SIGABRT ); // reraise SIGABRT
169} // sigAbortHandler
170
171
[cbaee0d]172int main( int argc, char * argv[] ) {
[3b8e52c]173 FILE * input; // use FILE rather than istream because yyin is FILE
[e6955b1]174 ostream *output = & cout;
[926af74]175 const char *filename = nullptr;
[e6955b1]176 list< Declaration * > translationUnit;
177
178 signal( SIGSEGV, sigSegvBusHandler );
179 signal( SIGBUS, sigSegvBusHandler );
[b542bfb]180 signal( SIGABRT, sigAbortHandler );
[b87a5ed]181
[0da3e2c]182 parse_cmdline( argc, argv, filename ); // process command-line arguments
[13de47bc]183 CodeGen::FixMain::setReplaceMain( !nomainp );
[b87a5ed]184
185 try {
[81419b5]186 // choose to read the program from a file or stdin
[3b8e52c]187 if ( optind < argc ) { // any commands after the flags ? => input file name
[b87a5ed]188 input = fopen( argv[ optind ], "r" );
[3b8e52c]189 assertf( input, "cannot open %s\n", argv[ optind ] );
[d029162e]190 // if running cfa-cpp directly, might forget to pass -F option (and really shouldn't have to)
[926af74]191 if ( filename == nullptr ) filename = argv[ optind ];
[37024fd]192 // prelude filename comes in differently
193 if ( libcfap ) filename = "prelude.cf";
[b87a5ed]194 optind += 1;
[3b8e52c]195 } else { // no input file name
[b87a5ed]196 input = stdin;
[2a7e29b]197 // if running cfa-cpp directly, might forget to pass -F option. Since this takes from stdin, pass
198 // a fake name along
[926af74]199 if ( filename == nullptr ) filename = "stdin";
[b87a5ed]200 } // if
201
[159c62e]202 // read in the builtins, extras, and the prelude
[de62360d]203 if ( ! nopreludep ) { // include gcc builtins
[faf8857]204 // -l is for initial build ONLY and builtins.cf is not in the lib directory so access it here.
[807ce84]205
206 // Read to gcc builtins, if not generating the cfa library
[6ce3ae9]207 FILE * gcc_builtins = fopen( libcfap | treep ? "../prelude/gcc-builtins.cf" : CFA_LIBDIR "/gcc-builtins.cf", "r" );
208 assertf( gcc_builtins, "cannot open gcc-builtins.cf\n" );
209 parse( gcc_builtins, LinkageSpec::Compiler );
[81419b5]210
[159c62e]211 // read the extra prelude in, if not generating the cfa library
[375a068]212 FILE * extras = fopen( libcfap | treep ? "../prelude/extras.cf" : CFA_LIBDIR "/extras.cf", "r" );
[3b8e52c]213 assertf( extras, "cannot open extras.cf\n" );
[f0994a1]214 parse( extras, LinkageSpec::BuiltinC );
[159c62e]215
[81419b5]216 if ( ! libcfap ) {
[faf8857]217 // read the prelude in, if not generating the cfa library
[375a068]218 FILE * prelude = fopen( treep ? "../prelude/prelude.cf" : CFA_LIBDIR "/prelude.cf", "r" );
[3b8e52c]219 assertf( prelude, "cannot open prelude.cf\n" );
[35304009]220 parse( prelude, LinkageSpec::Intrinsic );
[fa4805f]221
222 // Read to cfa builtins, if not generating the cfa library
223 FILE * builtins = fopen( libcfap | treep ? "../prelude/builtins.cf" : CFA_LIBDIR "/builtins.cf", "r" );
224 assertf( builtins, "cannot open builtins.cf\n" );
[54d714e]225 parse( builtins, LinkageSpec::BuiltinCFA );
[b87a5ed]226 } // if
227 } // if
[81419b5]228
[926af74]229 parse( input, libcfap ? LinkageSpec::Intrinsic : LinkageSpec::Cforall, yydebug );
[71f4e4f]230
[b87a5ed]231 if ( parsep ) {
[e6955b1]232 parseTree->printList( cout );
[0da3e2c]233 delete parseTree;
[b87a5ed]234 return 0;
235 } // if
236
[0da3e2c]237 buildList( parseTree, translationUnit );
238 delete parseTree;
[cbaee0d]239 parseTree = nullptr;
[68f9c43]240 collect( translationUnit );
[b87a5ed]241
242 if ( astp ) {
[1ab4ce2]243 dump( translationUnit );
[b87a5ed]244 return 0;
245 } // if
246
[839ccbb]247 // add the assignment statement after the initialization of a type parameter
[6edd210]248 PASS( "validate", SymTab::validate( translationUnit, symtabp ) );
[68f9c43]249 if ( symtabp ) return 0;
[bd06384]250 collect( translationUnit );
[b87a5ed]251
[81419b5]252 if ( expraltp ) {
[bff09c8]253 PassVisitor<ResolvExpr::AlternativePrinter> printer( cout );
[81419b5]254 acceptAll( translationUnit, printer );
[b87a5ed]255 return 0;
256 } // if
257
258 if ( validp ) {
[1ab4ce2]259 dump( translationUnit );
[b87a5ed]260 return 0;
261 } // if
262
[6edd210]263 PASS( "mutate", ControlStruct::mutate( translationUnit ) );
264 PASS( "fixNames", CodeGen::fixNames( translationUnit ) );
265 PASS( "genInit", InitTweak::genInit( translationUnit ) );
266 PASS( "expandMemberTuples" , Tuples::expandMemberTuples( translationUnit ) );
[68f9c43]267 collect( translationUnit );
[81419b5]268 if ( libcfap ) {
269 // generate the bodies of cfa library functions
270 LibCfa::makeLibCfa( translationUnit );
[b87a5ed]271 } // if
272
[fa2de95]273 if ( declstatsp ) {
274 CodeTools::printDeclStats( translationUnit );
275 return 0;
276 }
277
[de62360d]278 if ( bresolvep ) {
[1ab4ce2]279 dump( translationUnit );
[de62360d]280 return 0;
281 } // if
282
[76b378d]283 CodeTools::fillLocations( translationUnit );
284
[6edd210]285 PASS( "resolve", ResolvExpr::resolve( translationUnit ) );
[68f9c43]286 collect( translationUnit );
[81419b5]287 if ( exprp ) {
[1ab4ce2]288 dump( translationUnit );
[ca1c11f]289 return 0;
[926af74]290 } // if
[81419b5]291
[71f4e4f]292 // fix ObjectDecl - replaces ConstructorInit nodes
[6edd210]293 PASS( "fixInit", InitTweak::fix( translationUnit, filename, libcfap || treep ) );
[68f9c43]294 collect( translationUnit );
[ca1c11f]295 if ( ctorinitp ) {
296 dump ( translationUnit );
297 return 0;
[926af74]298 } // if
[71f4e4f]299
[6edd210]300 PASS( "expandUniqueExpr", Tuples::expandUniqueExpr( translationUnit ) ); // xxx - is this the right place for this? want to expand ASAP so tha, sequent passes don't need to worry about double-visiting a unique expr - needs to go after InitTweak::fix so that copy constructed return declarations are reused
[626dbc10]301
[6edd210]302 PASS( "translateEHM" , ControlStruct::translateEHM( translationUnit ) );
[307a732]303
[6edd210]304 PASS( "generateWaitfor" , Concurrency::generateWaitFor( translationUnit ) );
[9f5ecf5]305
[6edd210]306 PASS( "convertSpecializations", GenPoly::convertSpecializations( translationUnit ) ); // needs to happen before tuple types are expanded
[626dbc10]307
[6edd210]308 PASS( "expandTuples", Tuples::expandTuples( translationUnit ) ); // xxx - is this the right place for this?
[68f9c43]309 collect( translationUnit );
[626dbc10]310 if ( tuplep ) {
311 dump( translationUnit );
312 return 0;
313 }
[141b786]314
[6edd210]315 PASS( "virtual expandCasts", Virtual::expandCasts( translationUnit ) ); // Must come after translateEHM
[a5f0529]316
[6edd210]317 PASS( "instantiateGenerics", GenPoly::instantiateGeneric( translationUnit ) );
[68f9c43]318 collect( translationUnit );
[53d3ab4b]319 if ( genericsp ) {
320 dump( translationUnit );
321 return 0;
322 }
[6edd210]323 PASS( "convertLvalue", GenPoly::convertLvalue( translationUnit ) );
[68f9c43]324 collect( translationUnit );
[fea7ca7]325 if ( bboxp ) {
326 dump( translationUnit );
327 return 0;
[926af74]328 } // if
[6edd210]329 PASS( "box", GenPoly::box( translationUnit ) );
[68f9c43]330 collect( translationUnit );
[8905f56]331 if ( bcodegenp ) {
332 dump( translationUnit );
333 return 0;
334 }
335
[13de47bc]336 if ( optind < argc ) { // any commands after the flags and input file ? => output file name
337 output = new ofstream( argv[ optind ] );
338 } // if
[0270824]339
[7b15d7a]340 CodeTools::fillLocations( translationUnit );
[6edd210]341 PASS( "codegen", CodeGen::generate( translationUnit, *output, ! noprotop, prettycodegenp, true, linemarks ) );
[0270824]342
[13de47bc]343 CodeGen::FixMain::fix( *output, treep ? "../prelude/bootloader.c" : CFA_LIBDIR "/bootloader.c" );
[e6955b1]344 if ( output != &cout ) {
[b87a5ed]345 delete output;
346 } // if
[a16764a6]347 } catch ( SemanticErrorException &e ) {
[b87a5ed]348 if ( errorp ) {
[e6955b1]349 cerr << "---AST at error:---" << endl;
350 dump( translationUnit, cerr );
351 cerr << endl << "---End of AST, begin error message:---\n" << endl;
[926af74]352 } // if
[d55d7a6]353 e.print();
[e6955b1]354 if ( output != &cout ) {
[b87a5ed]355 delete output;
356 } // if
357 return 1;
358 } catch ( UnimplementedError &e ) {
[e6955b1]359 cout << "Sorry, " << e.get_what() << " is not currently implemented" << endl;
360 if ( output != &cout ) {
[b87a5ed]361 delete output;
362 } // if
363 return 1;
364 } catch ( CompilerError &e ) {
[e6955b1]365 cerr << "Compiler Error: " << e.get_what() << endl;
[c850687]366 cerr << "(please report bugs to [REDACTED])" << endl;
[e6955b1]367 if ( output != &cout ) {
[b87a5ed]368 delete output;
369 } // if
370 return 1;
[4990812]371 } catch(...) {
372 std::exception_ptr eptr = std::current_exception();
373 try {
374 if (eptr) {
375 std::rethrow_exception(eptr);
376 }
377 else {
378 std::cerr << "Exception Uncaught and Unkown" << std::endl;
379 }
380 } catch(const std::exception& e) {
381 std::cerr << "Unaught Exception \"" << e.what() << "\"\n";
382 }
383 return 1;
384 }// try
[b87a5ed]385
[6d611fb]386 if(!libcfap && !treep) HeapStats::printStats();
[b87a5ed]387 return 0;
[d9a0e76]388} // main
[51b73452]389
[cbaee0d]390void parse_cmdline( int argc, char * argv[], const char *& filename ) {
[6de43b6]391 enum { Ast, Bbox, Bresolver, CtorInitFix, DeclStats, Expr, ExprAlt, Grammar, LibCFA, Linemarks, Nolinemarks, Nopreamble, Parse, Prototypes, Resolver, Symbol, Tree, TupleExpansion, Validate, };
[0da3e2c]392
393 static struct option long_opts[] = {
394 { "ast", no_argument, 0, Ast },
395 { "before-box", no_argument, 0, Bbox },
396 { "before-resolver", no_argument, 0, Bresolver },
397 { "ctorinitfix", no_argument, 0, CtorInitFix },
[41a7137]398 { "decl-stats", no_argument, 0, DeclStats },
[0da3e2c]399 { "expr", no_argument, 0, Expr },
400 { "expralt", no_argument, 0, ExprAlt },
401 { "grammar", no_argument, 0, Grammar },
402 { "libcfa", no_argument, 0, LibCFA },
[6de43b6]403 { "line-marks", no_argument, 0, Linemarks },
404 { "no-line-marks", no_argument, 0, Nolinemarks },
[0da3e2c]405 { "no-preamble", no_argument, 0, Nopreamble },
406 { "parse", no_argument, 0, Parse },
407 { "no-prototypes", no_argument, 0, Prototypes },
408 { "resolver", no_argument, 0, Resolver },
409 { "symbol", no_argument, 0, Symbol },
410 { "tree", no_argument, 0, Tree },
[626dbc10]411 { "tuple-expansion", no_argument, 0, TupleExpansion },
[0da3e2c]412 { "validate", no_argument, 0, Validate },
413 { 0, 0, 0, 0 }
414 }; // long_opts
415 int long_index;
416
417 opterr = 0; // (global) prevent getopt from printing error messages
418
[c5e5109]419 bool Wsuppress = false, Werror = false;
[0da3e2c]420 int c;
[44bca7f]421 while ( (c = getopt_long( argc, argv, "abBcCdefgGlLmnNpqrstTvwW:yzZD:F:", long_opts, &long_index )) != -1 ) {
[0da3e2c]422 switch ( c ) {
423 case Ast:
424 case 'a': // dump AST
425 astp = true;
426 break;
427 case Bresolver:
428 case 'b': // print before resolver steps
429 bresolvep = true;
430 break;
[626dbc10]431 case 'B': // print before box steps
[0da3e2c]432 bboxp = true;
433 break;
434 case CtorInitFix:
[e39241b]435 case 'c': // print after constructors and destructors are replaced
[0da3e2c]436 ctorinitp = true;
437 break;
[8905f56]438 case 'C': // print before code generation
439 bcodegenp = true;
440 break;
[41a7137]441 case DeclStats:
442 case 'd':
443 declstatsp = true;
444 break;
[0da3e2c]445 case Expr:
446 case 'e': // dump AST after expression analysis
447 exprp = true;
448 break;
449 case ExprAlt:
450 case 'f': // print alternatives for expressions
451 expraltp = true;
452 break;
453 case Grammar:
454 case 'g': // bison debugging info (grammar rules)
[926af74]455 yydebug = true;
[0da3e2c]456 break;
[44bca7f]457 case 'G': // dump AST after instantiate generics
[53d3ab4b]458 genericsp = true;
459 break;
[0da3e2c]460 case LibCFA:
461 case 'l': // generate libcfa.c
462 libcfap = true;
463 break;
[6de43b6]464 case Linemarks:
465 case 'L': // print lines marks
466 linemarks = true;
[c850687]467 break;
[0da3e2c]468 case Nopreamble:
469 case 'n': // do not read preamble
470 nopreludep = true;
471 break;
[6de43b6]472 case Nolinemarks:
473 case 'N': // suppress line marks
474 linemarks = false;
[c59bde6]475 break;
[0da3e2c]476 case Prototypes:
477 case 'p': // generate prototypes for preamble functions
478 noprotop = true;
479 break;
[3fe34ae]480 case 'm': // don't replace the main
481 nomainp = true;
482 break;
[0da3e2c]483 case Parse:
484 case 'q': // dump parse tree
485 parsep = true;
486 break;
487 case Resolver:
488 case 'r': // print resolver steps
489 resolvep = true;
490 break;
491 case Symbol:
492 case 's': // print symbol table events
493 symtabp = true;
494 break;
495 case Tree:
496 case 't': // build in tree
497 treep = true;
498 break;
[626dbc10]499 case TupleExpansion:
500 case 'T': // print after tuple expansion
501 tuplep = true;
502 break;
[0da3e2c]503 case 'v': // dump AST after decl validation pass
504 validp = true;
505 break;
[44bca7f]506 case 'w':
[c5e5109]507 Wsuppress = true;
[44bca7f]508 break;
509 case 'W':
510 if ( strcmp( optarg, "all" ) == 0 ) {
[68e9ace]511 SemanticWarning_EnableAll();
[44bca7f]512 } else if ( strcmp( optarg, "error" ) == 0 ) {
513 Werror = true;
514 } else {
515 char * warning = optarg;
516 Severity s;
517 if ( strncmp( optarg, "no-", 3 ) == 0 ) {
518 warning += 3;
519 s = Severity::Suppress;
520 } else {
521 s = Severity::Warn;
522 } // if
[68e9ace]523 SemanticWarning_Set( warning, s );
[44bca7f]524 } // if
525 break;
[e39241b]526 case 'y': // dump AST on error
[0da3e2c]527 errorp = true;
528 break;
[e39241b]529 case 'z': // dump as codegen rather than AST
[0da3e2c]530 codegenp = true;
[e39241b]531 break;
532 case 'Z': // prettyprint during codegen (i.e. print unmangled names, etc.)
[35b1bf4]533 prettycodegenp = true;
[0da3e2c]534 break;
535 case 'D': // ignore -Dxxx
536 break;
537 case 'F': // source file-name without suffix
538 filename = optarg;
539 break;
540 case '?':
[ae47a23]541 if ( optopt ) { // short option ?
542 assertf( false, "Unknown option: -%c\n", (char)optopt );
543 } else {
544 assertf( false, "Unknown option: %s\n", argv[optind - 1] );
545 } // if
[b6d7f44]546 #if defined(__GNUC__) && __GNUC__ >= 7
[af98d27]547 __attribute__((fallthrough));
548 #endif
[0da3e2c]549 default:
550 abort();
551 } // switch
552 } // while
[44bca7f]553
554 if ( Werror ) {
[68e9ace]555 SemanticWarning_WarningAsError();
[44bca7f]556 } // if
[c5e5109]557 if ( Wsuppress ) {
558 SemanticWarning_SuppressAll();
559 } // if
[44bca7f]560 // for ( const auto w : WarningFormats ) {
561 // cout << w.name << ' ' << (int)w.severity << endl;
562 // } // for
[0da3e2c]563} // parse_cmdline
564
[8b7ee09]565static void parse( FILE * input, LinkageSpec::Spec linkage, bool shouldExit ) {
[0da3e2c]566 extern int yyparse( void );
[cbaee0d]567 extern FILE * yyin;
[0da3e2c]568 extern int yylineno;
569
[8b7ee09]570 ::linkage = linkage; // set globals
[0da3e2c]571 yyin = input;
572 yylineno = 1;
573 typedefTable.enterScope();
574 int parseStatus = yyparse();
[81419b5]575
576 fclose( input );
[0da3e2c]577 if ( shouldExit || parseStatus != 0 ) {
578 exit( parseStatus );
[81419b5]579 } // if
[0da3e2c]580} // parse
[81419b5]581
[1ab4ce2]582static bool notPrelude( Declaration * decl ) {
583 return ! LinkageSpec::isBuiltin( decl->get_linkage() );
[0da3e2c]584} // notPrelude
[1ab4ce2]585
[e6955b1]586static void dump( list< Declaration * > & translationUnit, ostream & out ) {
587 list< Declaration * > decls;
[926af74]588
[1ab4ce2]589 if ( noprotop ) {
[e6955b1]590 filter( translationUnit.begin(), translationUnit.end(), back_inserter( decls ), notPrelude );
[1ab4ce2]591 } else {
592 decls = translationUnit;
[926af74]593 } // if
[1ab4ce2]594
[e39241b]595 // depending on commandline options, either generate code or dump the AST
596 if ( codegenp ) {
597 CodeGen::generate( decls, out, ! noprotop, prettycodegenp );
598 } else {
599 printAll( decls, out );
600 }
[0da3e2c]601} // dump
[1ab4ce2]602
[51b73452]603// Local Variables: //
[b87a5ed]604// tab-width: 4 //
605// mode: c++ //
606// compile-command: "make install" //
[51b73452]607// End: //
Note: See TracBrowser for help on using the repository browser.