source: src/main.cc @ 2472a19

new-envwith_gc
Last change on this file since 2472a19 was ff29f08, checked in by Aaron Moss <a3moss@…>, 6 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
[51b7345]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 ] );
[d029162]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
[141b786]301                Tuples::expandUniqueExpr( translationUnit );
[626dbc10]302
[6edd210]303                PASS( "translateEHM" , ControlStruct::translateEHM( translationUnit ) );
[307a732]304
[6edd210]305                PASS( "generateWaitfor" , Concurrency::generateWaitFor( translationUnit ) );
[9f5ecf5]306
[6edd210]307                PASS( "convertSpecializations",  GenPoly::convertSpecializations( translationUnit ) ); // needs to happen before tuple types are expanded
[626dbc10]308
[6edd210]309                PASS( "expandTuples", Tuples::expandTuples( translationUnit ) ); // xxx - is this the right place for this?
[68f9c43]310                collect( translationUnit );
[626dbc10]311                if ( tuplep ) {
312                        dump( translationUnit );
313                        return 0;
314                }
[141b786]315
[6edd210]316                PASS( "virtual expandCasts", Virtual::expandCasts( translationUnit ) ); // Must come after translateEHM
[a5f0529]317
[6edd210]318                PASS( "instantiateGenerics", GenPoly::instantiateGeneric( translationUnit ) );
[68f9c43]319                collect( translationUnit );
[53d3ab4b]320                if ( genericsp ) {
321                        dump( translationUnit );
322                        return 0;
323                }
[6edd210]324                PASS( "convertLvalue", GenPoly::convertLvalue( translationUnit ) );
[68f9c43]325                collect( translationUnit );
[fea7ca7]326                if ( bboxp ) {
327                        dump( translationUnit );
328                        return 0;
[926af74]329                } // if
[6edd210]330                PASS( "box", GenPoly::box( translationUnit ) );
[68f9c43]331                collect( translationUnit );
[8905f56]332                if ( bcodegenp ) {
333                        dump( translationUnit );
334                        return 0;
335                }
336
[13de47bc]337                if ( optind < argc ) {                                                  // any commands after the flags and input file ? => output file name
338                        output = new ofstream( argv[ optind ] );
339                } // if
[0270824]340
[7b15d7a]341                CodeTools::fillLocations( translationUnit );
[6edd210]342                PASS( "codegen", CodeGen::generate( translationUnit, *output, ! noprotop, prettycodegenp, true, linemarks ) );
[0270824]343
[13de47bc]344                CodeGen::FixMain::fix( *output, treep ? "../prelude/bootloader.c" : CFA_LIBDIR "/bootloader.c" );
[e6955b1]345                if ( output != &cout ) {
[b87a5ed]346                        delete output;
347                } // if
[a16764a6]348        } catch ( SemanticErrorException &e ) {
[b87a5ed]349                if ( errorp ) {
[e6955b1]350                        cerr << "---AST at error:---" << endl;
351                        dump( translationUnit, cerr );
352                        cerr << endl << "---End of AST, begin error message:---\n" << endl;
[926af74]353                } // if
[d55d7a6]354                e.print();
[e6955b1]355                if ( output != &cout ) {
[b87a5ed]356                        delete output;
357                } // if
358                return 1;
359        } catch ( UnimplementedError &e ) {
[e6955b1]360                cout << "Sorry, " << e.get_what() << " is not currently implemented" << endl;
361                if ( output != &cout ) {
[b87a5ed]362                        delete output;
363                } // if
364                return 1;
365        } catch ( CompilerError &e ) {
[e6955b1]366                cerr << "Compiler Error: " << e.get_what() << endl;
[c850687]367                cerr << "(please report bugs to [REDACTED])" << endl;
[e6955b1]368                if ( output != &cout ) {
[b87a5ed]369                        delete output;
370                } // if
371                return 1;
[4990812]372        } catch(...) {
373                std::exception_ptr eptr = std::current_exception();
374                try {
375                        if (eptr) {
376                                std::rethrow_exception(eptr);
377                        }
378                        else {
379                                std::cerr << "Exception Uncaught and Unkown" << std::endl;
380                        }
381                } catch(const std::exception& e) {
382                        std::cerr << "Unaught Exception \"" << e.what() << "\"\n";
383                }
384                return 1;
385        }// try
[b87a5ed]386
[6d611fb]387        if(!libcfap && !treep) HeapStats::printStats();
[b87a5ed]388        return 0;
[d9a0e76]389} // main
[51b7345]390
[cbaee0d]391void parse_cmdline( int argc, char * argv[], const char *& filename ) {
[6de43b6]392        enum { Ast, Bbox, Bresolver, CtorInitFix, DeclStats, Expr, ExprAlt, Grammar, LibCFA, Linemarks, Nolinemarks, Nopreamble, Parse, Prototypes, Resolver, Symbol, Tree, TupleExpansion, Validate, };
[0da3e2c]393
394        static struct option long_opts[] = {
395                { "ast", no_argument, 0, Ast },
396                { "before-box", no_argument, 0, Bbox },
397                { "before-resolver", no_argument, 0, Bresolver },
398                { "ctorinitfix", no_argument, 0, CtorInitFix },
[41a7137]399                { "decl-stats", no_argument, 0, DeclStats },
[0da3e2c]400                { "expr", no_argument, 0, Expr },
401                { "expralt", no_argument, 0, ExprAlt },
402                { "grammar", no_argument, 0, Grammar },
403                { "libcfa", no_argument, 0, LibCFA },
[6de43b6]404                { "line-marks", no_argument, 0, Linemarks },
405                { "no-line-marks", no_argument, 0, Nolinemarks },
[0da3e2c]406                { "no-preamble", no_argument, 0, Nopreamble },
407                { "parse", no_argument, 0, Parse },
408                { "no-prototypes", no_argument, 0, Prototypes },
409                { "resolver", no_argument, 0, Resolver },
410                { "symbol", no_argument, 0, Symbol },
411                { "tree", no_argument, 0, Tree },
[626dbc10]412                { "tuple-expansion", no_argument, 0, TupleExpansion },
[0da3e2c]413                { "validate", no_argument, 0, Validate },
414                { 0, 0, 0, 0 }
415        }; // long_opts
416        int long_index;
417
418        opterr = 0;                                                                                     // (global) prevent getopt from printing error messages
419
[c5e5109]420        bool Wsuppress = false, Werror = false;
[0da3e2c]421        int c;
[44bca7f]422        while ( (c = getopt_long( argc, argv, "abBcCdefgGlLmnNpqrstTvwW:yzZD:F:", long_opts, &long_index )) != -1 ) {
[0da3e2c]423                switch ( c ) {
424                  case Ast:
425                  case 'a':                                                                             // dump AST
426                        astp = true;
427                        break;
428                  case Bresolver:
429                  case 'b':                                                                             // print before resolver steps
430                        bresolvep = true;
431                        break;
[626dbc10]432                  case 'B':                                                                             // print before box steps
[0da3e2c]433                        bboxp = true;
434                        break;
435                  case CtorInitFix:
[e39241b]436                  case 'c':                                                                             // print after constructors and destructors are replaced
[0da3e2c]437                        ctorinitp = true;
438                        break;
[8905f56]439                  case 'C':                                                                             // print before code generation
440                        bcodegenp = true;
441                        break;
[41a7137]442                  case DeclStats:
443                  case 'd':
444                    declstatsp = true;
445                        break;
[0da3e2c]446                  case Expr:
447                  case 'e':                                                                             // dump AST after expression analysis
448                        exprp = true;
449                        break;
450                  case ExprAlt:
451                  case 'f':                                                                             // print alternatives for expressions
452                        expraltp = true;
453                        break;
454                  case Grammar:
455                  case 'g':                                                                             // bison debugging info (grammar rules)
[926af74]456                        yydebug = true;
[0da3e2c]457                        break;
[44bca7f]458                  case 'G':                                                                             // dump AST after instantiate generics
[53d3ab4b]459                        genericsp = true;
460                        break;
[0da3e2c]461                  case LibCFA:
462                  case 'l':                                                                             // generate libcfa.c
463                        libcfap = true;
464                        break;
[6de43b6]465                  case Linemarks:
466                  case 'L':                                                                             // print lines marks
467                        linemarks = true;
[c850687]468                        break;
[0da3e2c]469                  case Nopreamble:
470                  case 'n':                                                                             // do not read preamble
471                        nopreludep = true;
472                        break;
[6de43b6]473                  case Nolinemarks:
474                  case 'N':                                                                             // suppress line marks
475                        linemarks = false;
[c59bde6]476                        break;
[0da3e2c]477                  case Prototypes:
478                  case 'p':                                                                             // generate prototypes for preamble functions
479                        noprotop = true;
480                        break;
[3fe34ae]481                  case 'm':                                                                             // don't replace the main
482                        nomainp = true;
483                        break;
[0da3e2c]484                  case Parse:
485                  case 'q':                                                                             // dump parse tree
486                        parsep = true;
487                        break;
488                  case Resolver:
489                  case 'r':                                                                             // print resolver steps
490                        resolvep = true;
491                        break;
492                  case Symbol:
493                  case 's':                                                                             // print symbol table events
494                        symtabp = true;
495                        break;
496                  case Tree:
497                  case 't':                                                                             // build in tree
498                        treep = true;
499                        break;
[626dbc10]500                  case TupleExpansion:
501                  case 'T':                                                                             // print after tuple expansion
502                        tuplep = true;
503                        break;
[0da3e2c]504                  case 'v':                                                                             // dump AST after decl validation pass
505                        validp = true;
506                        break;
[44bca7f]507                  case 'w':
[c5e5109]508                        Wsuppress = true;
[44bca7f]509                        break;
510                  case 'W':
511                        if ( strcmp( optarg, "all" ) == 0 ) {
[68e9ace]512                                SemanticWarning_EnableAll();
[44bca7f]513                        } else if ( strcmp( optarg, "error" ) == 0 ) {
514                                Werror = true;
515                        } else {
516                                char * warning = optarg;
517                                Severity s;
518                                if ( strncmp( optarg, "no-", 3 ) == 0 ) {
519                                        warning += 3;
520                                        s = Severity::Suppress;
521                                } else {
522                                        s = Severity::Warn;
523                                } // if
[68e9ace]524                                SemanticWarning_Set( warning, s );
[44bca7f]525                        } // if
526                        break;
[e39241b]527                  case 'y':                                                                             // dump AST on error
[0da3e2c]528                        errorp = true;
529                        break;
[e39241b]530                  case 'z':                                                                             // dump as codegen rather than AST
[0da3e2c]531                        codegenp = true;
[e39241b]532                        break;
533                        case 'Z':                                                                       // prettyprint during codegen (i.e. print unmangled names, etc.)
[35b1bf4]534                        prettycodegenp = true;
[0da3e2c]535                        break;
536                  case 'D':                                                                             // ignore -Dxxx
537                        break;
538                  case 'F':                                                                             // source file-name without suffix
539                        filename = optarg;
540                        break;
541                  case '?':
[ae47a23]542                        if ( optopt ) {                                                         // short option ?
543                                assertf( false, "Unknown option: -%c\n", (char)optopt );
544                        } else {
545                                assertf( false, "Unknown option: %s\n", argv[optind - 1] );
546                        } // if
[b6d7f44]547                        #if defined(__GNUC__) && __GNUC__ >= 7
[af98d27]548                                __attribute__((fallthrough));
549                        #endif
[0da3e2c]550                  default:
551                        abort();
552                } // switch
553        } // while
[44bca7f]554
555        if ( Werror ) {
[68e9ace]556                SemanticWarning_WarningAsError();
[44bca7f]557        } // if
[c5e5109]558        if ( Wsuppress ) {
559                SemanticWarning_SuppressAll();
560        } // if
[44bca7f]561        // for ( const auto w : WarningFormats ) {
562        //      cout << w.name << ' ' << (int)w.severity << endl;
563        // } // for
[0da3e2c]564} // parse_cmdline
565
[8b7ee09]566static void parse( FILE * input, LinkageSpec::Spec linkage, bool shouldExit ) {
[0da3e2c]567        extern int yyparse( void );
[cbaee0d]568        extern FILE * yyin;
[0da3e2c]569        extern int yylineno;
570
[8b7ee09]571        ::linkage = linkage;                                                            // set globals
[0da3e2c]572        yyin = input;
573        yylineno = 1;
574        typedefTable.enterScope();
575        int parseStatus = yyparse();
[81419b5]576
577        fclose( input );
[0da3e2c]578        if ( shouldExit || parseStatus != 0 ) {
579                exit( parseStatus );
[81419b5]580        } // if
[0da3e2c]581} // parse
[81419b5]582
[1ab4ce2]583static bool notPrelude( Declaration * decl ) {
584        return ! LinkageSpec::isBuiltin( decl->get_linkage() );
[0da3e2c]585} // notPrelude
[1ab4ce2]586
[e6955b1]587static void dump( list< Declaration * > & translationUnit, ostream & out ) {
588        list< Declaration * > decls;
[926af74]589
[1ab4ce2]590        if ( noprotop ) {
[e6955b1]591                filter( translationUnit.begin(), translationUnit.end(), back_inserter( decls ), notPrelude );
[1ab4ce2]592        } else {
593                decls = translationUnit;
[926af74]594        } // if
[1ab4ce2]595
[e39241b]596        // depending on commandline options, either generate code or dump the AST
597        if ( codegenp ) {
598                CodeGen::generate( decls, out, ! noprotop, prettycodegenp );
599        } else {
600                printAll( decls, out );
601        }
[0da3e2c]602} // dump
[1ab4ce2]603
[51b7345]604// Local Variables: //
[b87a5ed]605// tab-width: 4 //
606// mode: c++ //
607// compile-command: "make install" //
[51b7345]608// End:  //
Note: See TracBrowser for help on using the repository browser.