Changeset eef8dfb for src/main.cc


Ignore:
Timestamp:
Jan 7, 2021, 2:55:57 PM (5 years ago)
Author:
Thierry Delisle <tdelisle@…>
Branches:
ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast-unique-expr, pthread-emulation, qualifiedEnum
Children:
58fe85a
Parents:
bdfc032 (diff), 44e37ef (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'master' into dkobets-vector

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/main.cc

    rbdfc032 reef8dfb  
    99// Author           : Peter Buhr and Rob Schluntz
    1010// Created On       : Fri May 15 23:12:02 2015
    11 // Last Modified By : Peter A. Buhr
    12 // Last Modified On : Mon Dec 16 17:55:53 2019
    13 // Update Count     : 627
     11// Last Modified By : Andrew Beach
     12// Last Modified On : Mon Dec  7 15:29:00 2020
     13// Update Count     : 639
    1414//
    1515
     
    3131using namespace std;
    3232
    33 
     33#include "AST/Convert.hpp"
    3434#include "CompilationState.h"
    3535#include "../config.h"                      // for CFA_LIBDIR
     
    4040#include "CodeTools/ResolvProtoDump.h"      // for dumpAsResolvProto
    4141#include "CodeTools/TrackLoc.h"             // for fillLocations
     42#include "Common/CodeLocationTools.hpp"     // for forceFillCodeLocations
    4243#include "Common/CompilerError.h"           // for CompilerError
    4344#include "Common/Stats.h"
     
    105106
    106107static void backtrace( int start ) {                                    // skip first N stack frames
    107         enum { Frames = 50 };
     108        enum { Frames = 50, };                                                          // maximum number of stack frames
    108109        void * array[Frames];
    109         int size = ::backtrace( array, Frames );
     110        size_t size = ::backtrace( array, Frames );
    110111        char ** messages = ::backtrace_symbols( array, size ); // does not demangle names
    111112
     
    114115
    115116        // skip last 2 stack frames after main
    116         for ( int i = start; i < size - 2 && messages != nullptr; i += 1 ) {
     117        for ( unsigned int i = start; i < size - 2 && messages != nullptr; i += 1 ) {
    117118                char * mangled_name = nullptr, * offset_begin = nullptr, * offset_end = nullptr;
    118119
     
    180181} // sigSegvBusHandler
    181182
     183static void sigFpeHandler( SIGPARMS ) {
     184        const char * msg;
     185
     186        switch ( sfp->si_code ) {
     187          case FPE_INTDIV: case FPE_FLTDIV: msg = "divide by zero"; break;
     188          case FPE_FLTOVF: msg = "overflow"; break;
     189          case FPE_FLTUND: msg = "underflow"; break;
     190          case FPE_FLTRES: msg = "inexact result"; break;
     191          case FPE_FLTINV: msg = "invalid operation"; break;
     192          default: msg = "unknown";
     193        } // choose
     194        cerr << "Computation error " << msg << " at location " << sfp->si_addr << endl
     195                 << "Possible cause is constant-expression evaluation invalid." << endl;
     196        backtrace( 2 );                                                                         // skip first 2 stack frames
     197        abort();                                                                                        // cause core dump for debugging
     198} // sigFpeHandler
     199
    182200static void sigAbortHandler( SIGPARMS ) {
    183201        backtrace( 6 );                                                                         // skip first 6 stack frames
     
    193211        Signal( SIGSEGV, sigSegvBusHandler, SA_SIGINFO );
    194212        Signal( SIGBUS, sigSegvBusHandler, SA_SIGINFO );
     213        Signal( SIGFPE, sigFpeHandler, SA_SIGINFO );
    195214        Signal( SIGABRT, sigAbortHandler, SA_SIGINFO );
    196215
     
    294313                } // if
    295314
     315                PASS( "Translate Throws", ControlStruct::translateThrows( translationUnit ) );
    296316                PASS( "Fix Labels", ControlStruct::fixLabels( translationUnit ) );
    297317                PASS( "Fix Names", CodeGen::fixNames( translationUnit ) );
     
    321341                } // if
    322342
    323                 PASS( "Resolve", ResolvExpr::resolve( translationUnit ) );
    324                 if ( exprp ) {
    325                         dump( translationUnit );
    326                         return EXIT_SUCCESS;
    327                 } // if
     343                if( useNewAST ) {
     344                        if (Stats::Counters::enabled) {
     345                                ast::pass_visitor_stats.avg = Stats::Counters::build<Stats::Counters::AverageCounter<double>>("Average Depth - New");
     346                                ast::pass_visitor_stats.max = Stats::Counters::build<Stats::Counters::MaxCounter<double>>("Max depth - New");
     347                        }
     348                        auto transUnit = convert( move( translationUnit ) );
     349                        PASS( "Resolve", ResolvExpr::resolve( transUnit ) );
     350                        if ( exprp ) {
     351                                translationUnit = convert( move( transUnit ) );
     352                                dump( translationUnit );
     353                                return EXIT_SUCCESS;
     354                        } // if
     355
     356                        forceFillCodeLocations( transUnit );
     357
     358                        PASS( "Fix Init", InitTweak::fix(transUnit, buildingLibrary()));
     359                        translationUnit = convert( move( transUnit ) );
     360                } else {
     361                        PASS( "Resolve", ResolvExpr::resolve( translationUnit ) );
     362                        if ( exprp ) {
     363                                dump( translationUnit );
     364                                return EXIT_SUCCESS;
     365                        }
     366
     367                        PASS( "Fix Init", InitTweak::fix( translationUnit, buildingLibrary() ) );
     368                }
    328369
    329370                // fix ObjectDecl - replaces ConstructorInit nodes
    330                 PASS( "Fix Init", InitTweak::fix( translationUnit, buildingLibrary() ) );
    331371                if ( ctorinitp ) {
    332372                        dump ( translationUnit );
     
    336376                PASS( "Expand Unique Expr", 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
    337377
    338                 PASS( "Translate EHM" , ControlStruct::translateEHM( translationUnit ) );
     378                PASS( "Translate Tries" , ControlStruct::translateTries( translationUnit ) );
    339379
    340380                PASS( "Gen Waitfor" , Concurrency::generateWaitFor( translationUnit ) );
     
    425465
    426466
    427 static const char optstring[] = ":c:ghlLmNnpP:S:twW:D:";
     467static const char optstring[] = ":c:ghlLmNnpdOAP:S:twW:D:";
    428468
    429469enum { PreludeDir = 128 };
     
    438478        { "no-prelude", no_argument, nullptr, 'n' },
    439479        { "prototypes", no_argument, nullptr, 'p' },
     480        { "deterministic-out", no_argument, nullptr, 'd' },
     481        { "old-ast", no_argument, nullptr, 'O'},
     482        { "new-ast", no_argument, nullptr, 'A'},
    440483        { "print", required_argument, nullptr, 'P' },
    441484        { "prelude-dir", required_argument, nullptr, PreludeDir },
     
    449492
    450493static const char * description[] = {
    451         "diagnostic color: never, always, or auto.",          // -c
    452         "wait for gdb to attach",                             // -g
    453         "print help message",                                 // -h
    454         "generate libcfa.c",                                  // -l
    455         "generate line marks",                                // -L
    456         "do not replace main",                                // -m
    457         "do not generate line marks",                         // -N
    458         "do not read prelude",                                // -n
     494        "diagnostic color: never, always, or auto.",            // -c
     495        "wait for gdb to attach",                                                       // -g
     496        "print help message",                                                           // -h
     497        "generate libcfa.c",                                                            // -l
     498        "generate line marks",                                                          // -L
     499        "do not replace main",                                                          // -m
     500        "do not generate line marks",                                           // -N
     501        "do not read prelude",                                                          // -n
    459502        "generate prototypes for prelude functions",            // -p
    460         "print",                                              // -P
     503        "only print deterministic output",                  // -d
     504        "Use the old-ast",                                                                      // -O
     505        "Use the new-ast",                                                                      // -A
     506        "print",                                                                                        // -P
    461507        "<directory> prelude directory for debug/nodebug",      // no flag
    462508        "<option-list> enable profiling information:\n          counters,heap,time,all,none", // -S
    463         "building cfa standard lib",                          // -t
    464         "",                                                   // -w
    465         "",                                                   // -W
    466         "",                                                   // -D
     509        "building cfa standard lib",                                            // -t
     510        "",                                                                                                     // -w
     511        "",                                                                                                     // -W
     512        "",                                                                                                     // -D
    467513}; // description
    468514
     
    562608                        genproto = true;
    563609                        break;
     610                  case 'd':                                     // don't print non-deterministic output
     611                        deterministic_output = true;
     612                        break;
     613                  case 'O':                                     // don't print non-deterministic output
     614                        useNewAST = false;
     615                        break;
     616                  case 'A':                                     // don't print non-deterministic output
     617                        useNewAST = true;
     618                        break;
    564619                  case 'P':                                                                             // print options
    565620                        for ( int i = 0;; i += 1 ) {
Note: See TracChangeset for help on using the changeset viewer.