source: src/main.cc @ cbbd5b48

ADTaaron-thesisarm-ehast-experimentalcleanup-dtorsdeferred_resndemanglerenumforall-pointer-decayjacob/cs343-translationjenkins-sandboxnew-astnew-ast-unique-exprnew-envno_listpersistent-indexerpthread-emulationqualifiedEnumwith_gc
Last change on this file since cbbd5b48 was cbbd5b48, checked in by Rob Schluntz <rschlunt@…>, 6 years ago

fix include error

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