Exemple #1
0
void CgDeclParms(               // DEFINE ARGS FOR CURRENT FN IN CORRECT ORDER
    FN_CTL *fctl,               // - current function control pointer
    SCOPE scope )               // - argument scope
{
    SYMBOL curr;
    SYMBOL stop;
    SYMBOL *psym;               // - addr[ parameter symbol ]
    TYPE fn_type;
    auto VSTK_CTL sym_stack;
    SYMBOL ret_sym;
    NAME ret_name;

    fn_type = FunctionDeclarationType( fctl->func->sym_type );
    VstkOpen( &sym_stack, sizeof( SYMBOL ), 16 );
    stop = ScopeOrderedStart( scope );
    ret_name = CppSpecialName( SPECIAL_RETURN_VALUE );
    ret_sym = NULL;
    curr = NULL;
    for(;;) {
        curr = ScopeOrderedNext( stop, curr );
        if( curr == NULL ) break;
        if( ( curr->name != NULL ) && ( ret_name == curr->name->name ) ) {
            ret_sym = curr;
        } else {
            psym = VstkPush( &sym_stack );
            *psym = curr;
        }
    }
    IbpDefineParms();
    declareParameter( fctl->this_sym );
    declareParameter( fctl->cdtor_sym );
    declareParameter( ret_sym );
    switch( PcCallImpl( fn_type ) ) {
      case CALL_IMPL_REV_CPP :
      case CALL_IMPL_REV_C :
        for(;;) {
            psym = VstkPop( &sym_stack );
            if( psym == NULL ) break;
            declareParameter( *psym );
        }
        break;
      case CALL_IMPL_CPP :
      case CALL_IMPL_C :
      case CALL_IMPL_ELL_CPP :
      case CALL_IMPL_ELL_C :
      { unsigned index;             // - parameter index
        unsigned max_parms;         // - # parameters
        SYMBOL *psym1;              // - addr[ parameter symbol ]
        max_parms = VstkDimension( &sym_stack );
        for( index = 0; index < max_parms; ++index ) {
            psym1 = VstkIndex( &sym_stack, index );
            declareParameter( *psym1 );
        }
      } break;
    }
    VstkClose( &sym_stack );
    CGLastParm();
}
Exemple #2
0
void CgSwitchEnd                // GENERATE CODE FOR END OF SWITCH STMT
    ( void )
{
    SW_CTL *ctl;                // - control for switch

    ctl = VstkTop( &stack_switches );
    CgLabel( ctl->label );
    CGSelect( ctl->id, CgFetchTemp( ctl->temp, ctl->type ) );
    BEFiniLabel( ctl->label );
    VstkPop( &stack_switches );
    CgLabelsPop( &stack_labs_sw, ctl->cases );
}
Exemple #3
0
void SymTransFuncEnd(           // COMPLETE FUNCTION TRANSLATION
    FN_CTL* fctl )              // - function control
{
    SYM_TRANS* top;             // - top translation

    sym_trans_id = fctl->sym_trans_id;
    for( ; ; VstkPop( &stack_sym_trans ) ) {
        top = VstkTop( &stack_sym_trans );
        if( top == NULL ) break;
        if( top->id < sym_trans_id ) break;
        dump( "freed", top );
    }
}
Exemple #4
0
void CmdLnCtxPop(               // POP A CONTEXT
    void )
{
    CTX_CL* entry;              // - new entry

    entry = VstkPop( &cmdLnContexts );
    if( CTX_CLTYPE_ENV == entry->base.ctx_type ) {
        CMemFree( (void*)entry->env.var );
    }
    if( CTX_CLTYPE_PGM != entry->base.ctx_type ) {
        CmdScanInit( entry->base.cmd_line );
        CtxSwitchAddr( entry->base.cmd_scan );
    }
}
Exemple #5
0
static DUMP_INFO* dumpStruct(   // DUMP A STRUCTURE
    TYPE type,                  // - structure type
    DUMP_INFO* di,              // - dump information
    char* title,                // - title for dump
    ds_control control )        // - control word
{
    CLASSINFO* info;            // - class information
    NAME *parent;               // - where parent ptr is stored

    control = control;
    type = StructType( type );
    info = type->u.c.info;
    parent = VstkPush( &di->stack );
    *parent = info->name;
    di = dumpTitle( di, title, NameStr( info->name ) );
    if( type != di->original ) {
        di = bufferInit( di );
        di = bufferStr( di, "embedded size: " );
        di = bufferNmb( di, info->vsize );
        di = bufferWrite( di );
        di = dumpOffset( di );
        di = dumpParentage( di );
    } else {
        di = bufferInit( di );
        di = bufferStr( di, "size: " );
        di = bufferNmb( di, info->size );
        di = bufferWrite( di );
    }
    if( info->has_vbptr ) {
        di = dumpDataMemb( di
                           , "[virtual"
                           , "base pointer]"
                           , info->vb_offset + di->offset
                           , CgMemorySize( TypePtrToVoid() ) );
    }
    if( info->has_vfptr ) {
        di = dumpDataMemb( di
                           , "[virtual"
                           , "functions pointer]"
                           , info->vf_offset + di->offset
                           , CgMemorySize( TypePtrToVoid() ) );
    }
    ScopeWalkDataMembers( type->u.c.scope, dumpMember, di );
    if( type == di->original ) {
        ScopeWalkVirtualBases( type->u.c.scope, dumpVirtual, di );
    }
    ScopeWalkDirectBases( type->u.c.scope, dumpDirect, di );
    VstkPop( &di->stack );
    return di;
}
Exemple #6
0
boolean CgExprPopGarbage(       // POP EXPR STACK IF TOP EXPR IS GARBAGE
    void )
{
    CGEXPR* top;                // - top of stack
    boolean retn;               // - TRUE ==> garbage was popped

    top = VstkTop( &expressions );
    if( top == NULL ) {
        retn = TRUE;
    } else if( top->garbage ) {
        VstkPop( &expressions );
        retn = TRUE;
    } else {
        retn = FALSE;
    }
    return retn;
}
Exemple #7
0
cg_name CgExprPopType(          // POP CG EXPRESSION and TYPE
    cg_type* a_type )           // - addr[ type ]
{
    CGEXPR* top;                // - next top of stack
    cg_name retn;               // - NULL or top expression

    top = VstkPop( &expressions );
    if( top == NULL ) {
        retn = NULL;
    } else if( top->garbage ) {
        *a_type = TY_UINT_4;
        retn = CGInteger( 12345, TY_UINT_4 );
    } else {
        *a_type = top->type;
        retn = top->expr;
    }
    return retn;
}
Exemple #8
0
static void writeIns            // WRITE AN INSTRUCTION
    ( CGINTEROP opcode          // - opcode
    , void const * parm         // - parm for instruction
    , TOKEN_LOCN const * locn ) // - location for instruction
{
    TOKEN_LOCN* curr_locn;      // - location
    SRCDEP const* sd;           // - dependency for open

    switch( opcode ) {
      case IC_BR_SRC_BEG :
        curr_locn = VstkPush( &open_src );
        TokenLocnAssign( *curr_locn, cursor );
        sd = parm;
        cursor.src_file = BrinfDepSrcfile( sd );
        cursor.line = 0;
        cursor.column = 0;
        BrinfWriteIns( opcode, parm );
        break;
      case IC_BR_SRC_END :
        locn = VstkPop( &open_src );
        if( NULL == locn ) {
            cursor.src_file = NULL;
        } else {
            TokenLocnAssign( cursor, *locn );
        }
        BrinfWriteIns( opcode, parm );
        break;
      case IC_BR_REF_MACRO :
        TokenLocnAssign( cursor, *locn );
        BrinfIcReference( opcode, parm, locn );
        break;
      default :
        TokenLocnAssign( cursor, *locn );
        BrinfWriteIns( opcode, parm );
        break;
    }
}
Exemple #9
0
static void dumpPTreeNode(      // DUMP A PARSE TREE NODE
    PTREE node )                // - node in parse tree
{
    static char buffer[128];    // - debugging buffer
    char *node_name;            // - name of node
    VSTK_CTL ctl;               // - VSTK control information (nodes)
    VSTK_CTL dup;               // - VSTK control information (duplicates)
    int dup_out;                // - last duplicate printed

    VstkOpen( &ctl, sizeof( PTREE ), 32 );
    VstkOpen( &dup, sizeof( PTREE ), 8 );
    dup_out = -1;
    for( ; ; ) {
        switch( node->op ) {
          case PT_ERROR :
            printf( "PT_ERROR"      F_BADDR
                    " ***** ERROR TREE *****" F_EOL
                  , node
                  );
            break;
          case PT_INT_CONSTANT :
            node_name = "PT_INT_CONSTANT";
            printf( F_NAME          F_BADDR
                    " flags"        F_HEX_4
                    " type"         F_PTR
                  , node_name
                  , node
                  , node->flags
                  , node->type
                  );
            if( NULL == Integral64Type( node->type ) ) {
                printf( " integer"      F_HEX_4
                      , node->u.int_constant
                      );
            } else {
                printf( " integer-64" F_S64
                      , VAL64( node->u.int64_constant )
                      );
            }
            dumpNodeType( node );
            dumpLocation( &node->locn );
            dumpPtreeFlags( node );
            break;
          case PT_FLOATING_CONSTANT : {
            char buffer[256];

            BFCnvFS( node->u.floating_constant, buffer, 256 );
            printf( "PT_FLOATING_CONSTANT" F_BADDR
                    " flags"        F_HEX_4
                    " float"        F_CPP_FLOAT
                  , node
                  , node->flags
                  , buffer
                  );
            dumpNodeType( node );
            dumpLocation( &node->locn );
            dumpPtreeFlags( node );
          }
            break;
          case PT_STRING_CONSTANT :
            stvcpy( buffer, node->u.string->string, node->u.string->len );
            printf( "PT_STRING_CONSTANT" F_BADDR
                    " flags"        F_HEX_4
                    " string"       F_STRING
                  , node
                  , node->flags
                  , buffer
                  );
            dumpNodeType( node );
            dumpLocation( &node->locn );
            dumpPtreeFlags( node );
            break;
          case PT_ID :
            printf( "PT_ID"         F_BADDR
                    " flags"        F_HEX_4
                    " cgop"         F_STRING F_NL
                    " id"           F_PTR
                    "="             F_STRING
                    " id_cgop"      F_STRING
                    " u.id.scope"   F_PTR
                  , node
                  , node->flags
                  , DbgOperator( node->cgop )
                  , node->u.id.name
                  , NameStr( node->u.id.name )
                  , DbgOperator( node->id_cgop )
                  , node->u.id.scope
                  );
            dumpNodeType( node );
            dumpLocation( &node->locn );
            dumpPtreeFlags( node );
            break;
          case PT_TYPE :
            printf( "PT_TYPE"       F_BADDR
                    " cgop"         F_STRING
                    " flags"        F_HEX_4
                    " next"         F_PTR
                    " scope"        F_PTR
                  , node
                  , DbgOperator( node->cgop )
                  , node->flags
                  , node->u.type.next
                  , node->u.type.scope
                  );
            dumpNodeType( node );
            dumpLocation( &node->locn );
            dumpPtreeFlags( node );
            break;
          case PT_SYMBOL :
            if( node->cgop == CO_NAME_THIS ) {
                printf( "PT_SYMBOL"     F_BADDR
                        " flags"        F_HEX_4
                        " this "
                      , node
                      , node->flags
                      );
                dumpNodeType( node );
                dumpLocation( &node->locn );
                dumpPtreeFlags( node );
            } else if( node->cgop == CO_NAME_CDTOR_EXTRA ) {
                printf( "PT_SYMBOL"     F_BADDR
                        " flags"        F_HEX_4
                        " cdtor_extra_parm "
                      , node
                      , node->flags
                      );
                dumpNodeType( node );
                dumpLocation( &node->locn );
                dumpPtreeFlags( node );
            } else {
                printf( "PT_SYMBOL"     F_BADDR
                        " flags"        F_HEX_4
                        " cgop"         F_STRING F_NL
                        " symbol"       F_PTR
                        " result"       F_PTR
                      , node
                      , node->flags
                      , DbgOperator( node->cgop )
                      , node->u.symcg.symbol
                      , node->u.symcg.result
                      );
                dumpNodeType( node );
                dumpLocation( &node->locn );
                dumpPtreeFlags( node );
                DumpSymbol( node->u.symcg.symbol );
            }
            break;
          case PT_UNARY :
            printf( "PT_UNARY"      F_BADDR
                    F_POINTS        F_ADDR
                    " flags"        F_HEX_4
                    " cgop"         F_STRING
                  , node
                  , node->u.subtree[0]
                  , node->flags
                  , DbgOperator( node->cgop )
                  );
            dumpNodeType( node );
            dumpLocation( &node->locn );
            dumpPtreeFlags( node );
            PUSH_NODE( ctl, node->u.subtree[0] );
            break;
          case PT_BINARY :
            printf( "PT_BINARY"     F_BADDR
                    F_POINTS        F_ADDR
                    ","             F_ADDR
                    " flags"        F_HEX_4
                    " cgop"         F_STRING
                  , node
                  , node->u.subtree[0]
                  , node->u.subtree[1]
                  , node->flags
                  , DbgOperator( node->cgop )
                  );
            dumpNodeType( node );
            dumpLocation( &node->locn );
            dumpPtreeFlags( node );
            PUSH_NODE( ctl, node->u.subtree[1] );
            PUSH_NODE( ctl, node->u.subtree[0] );
            break;
          case PT_DUP_EXPR :
          { PTREE *duped;       // - duplicated expression
            printf( "PT_DUP_EXPR"   F_BADDR
                    F_POINTS        F_ADDR
                    " flags"        F_HEX_4
                    " node"         F_ADDR
                  , node
                  , node->u.dup.subtree[0]
                  , node->flags
                  , node->u.dup.node
                  );
            dumpNodeType( node );
            dumpLocation( &node->locn );
            dumpPtreeFlags( node );
            if( node->u.subtree[0] != NULL ) {
                for( duped = VstkTop( &dup )
                   ;
                   ; duped = VstkNext( &dup, duped ) ) {
                    if( duped == NULL ) {
                        PUSH_NODE( dup, node->u.subtree[0] );
                    } else if( *duped == node->u.subtree[0] ) {
                        break;
                    }
                }
            }
          } break;
          case PT_IC :
            printf( "PT_IC"         F_BADDR
                    " "             F_NAME
                    " value"        F_ADDR
                  , node
                  , DbgIcOpcode( node->u.ic.opcode )
                  , node->u.ic.value.pvalue
                  );
            dumpNodeType( node );
            dumpLocation( &node->locn );
            dumpPtreeFlags( node );
            break;
          default :
            printf( "***INVALID***" F_BADDR
                    " flags"        F_HEX_4
                    " op"           F_HEX_1
                  , node
                  , node->flags
                  , node->op
                  );
            dumpNodeType( node );
            dumpLocation( &node->locn );
            dumpPtreeFlags( node );
            break;
        }
        {
            PTREE *next;            // - addr[next node]
            next = VstkPop( &ctl );
            if( next != NULL ) {
                node = *next;
            } else {
                ++dup_out;
                if( dup_out > VstkDimension( &dup ) ) break;
                next = VstkIndex( &dup, dup_out );
                printf( "--------------- duplicate ------------\n" );
                node = *next;
            }
        }
    }
    VstkClose( &ctl );
    VstkClose( &dup );
}
Exemple #10
0
call_handle CallStackPop(       // POP CALL STACK
    void )
{
    return ((CALL_STK*)VstkPop( &stack_calls ))->handle;
}
Exemple #11
0
static void rptRepository       // PRINT REPOSITORY REPORT
    ( INITFINI* defn )          // - definition
{
    REPO_STAT** last;           // - addr[ REPO_STAT ]
    REPO_STAT* repo;            // - REPO_STAT for source file
    long ref_syms;              // - # symbol references
    long ref_types;             // - # type references
    long avg_defs;              // - average definitions
    long avg_syms;              // - average symbol references
    long avg_types;             // - average type references
    unsigned file_count;        // - # files

    defn = defn;
    if( ! CompFlags.extra_stats_wanted ) {
        for(;;) {
            last = VstkPop( &srcFiles );
            if( NULL == last ) break;
            repo = *last;
            VstkClose( &repo->refset );
            VstkClose( &repo->typeset );
        }
        return;
    }
    MsgDisplayLine( "" );
    MsgDisplayLine( "Repository Statistics" );
    MsgDisplayLine( "" );
    MsgDisplayLine( "Defns  Syms Types Total File" );
    MsgDisplayLine( "" );
    avg_defs = 0;
    avg_syms = 0;
    avg_types = 0;
    file_count = 0;
    for(;;) {
        last = VstkPop( &srcFiles );
        if( NULL == last ) break;
        repo = *last;
        ref_syms = VstkDimension( &repo->refset ) + 1;
        ref_types = VstkDimension( &repo->typeset ) + 1;
        ++file_count;
        avg_syms += ref_syms;
        avg_types += ref_types;
        avg_defs += repo->defns;
        sprintf( sbuff
              , fmt_repos
              , repo->defns
              , ref_syms
              , ref_types
              , ref_syms + ref_types
              , SrcFileName( repo->srcfile )
              );
        MsgDisplayLine( sbuff );
        VstkClose( &repo->refset );
        VstkClose( &repo->typeset );
    }
    if( 0 < file_count ) {
        long fuzz = file_count / 2;
        MsgDisplayLine( "" );
        sprintf( sbuff
              , fmt_repos
              , avg_defs
              , avg_syms
              , avg_types
              , avg_syms + avg_types
              , "---- Totals ------"
              );
        MsgDisplayLine( sbuff );
        avg_defs = ( avg_defs + fuzz ) / file_count;
        avg_syms = ( avg_syms + fuzz ) / file_count;
        avg_types = ( avg_types + fuzz ) / file_count;
        sprintf( sbuff
              , fmt_repos
              , avg_defs
              , avg_syms
              , avg_types
              , avg_syms + avg_types
              , "---- Averages ----"
              );
        MsgDisplayLine( sbuff );
        MsgDisplayLine( "" );
        sprintf( sbuff, "%d files processed", file_count );
        MsgDisplayLine( sbuff );
        MsgDisplayLine( "" );
    }
    fflush( stdout );
}