예제 #1
0
static void rewriteFini( INITFINI* defn )
{
    defn = defn;
    RewriteFree( currRewrite );
    currRewrite = NULL;
    DbgStmt( CarveVerifyAllGone( carveREWRITE, "REWRITE" ) );
    DbgStmt( CarveVerifyAllGone( carveREWRITE_TOKENS, "REWRITE_TOKENS" ) );
    DbgStmt( CarveVerifyAllGone( carveSRCFILE_HANDLE, "SRCFILE_HANDLE" ) );
    CarveDestroy( carveREWRITE );
    CarveDestroy( carveREWRITE_TOKENS );
    CarveDestroy( carveSRCFILE_HANDLE );
}
예제 #2
0
static PTREE recoverToken( PTREE tree )
{
    switch( tree->op ) {
    case PT_INT_CONSTANT:
    case PT_FLOATING_CONSTANT:
        /* these cases are not possible in correct C++ programs */
        /* Buffer and ConstType should still be set */
        CurToken = T_CONSTANT;
        break;
    case PT_ID:
        CurToken = T_SAVED_ID;
        SavedId = tree->u.id.name;
        break;
    case PT_UNARY:
    case PT_BINARY:
        switch( tree->cgop ) {
        case CO_INDIRECT:
            CurToken = T_TIMES;
            break;
        case CO_COLON_COLON:
            CurToken = T_COLON_COLON;
            break;
        case CO_OPERATOR:
            CurToken = T_OPERATOR;
            break;
        case CO_TILDE:
            CurToken = T_TILDE;
            break;
        case CO_NEW:
            CurToken = T_NEW;
            break;
        case CO_DELETE:
            CurToken = T_DELETE;
            break;
        case CO_STORAGE:
            return( tree );
        default:
            DbgStmt( CFatal( "recoverToken: unknown tree cgop" ) );
            return( tree );
        }
        break;
    default:
        DbgStmt( CFatal( "recoverToken: unknown tree cgop" ) );
        return( tree );
    }
    saveToken( currRewrite, currLocn );
    return( tree );
}
예제 #3
0
static void typeCompareFini(    // COMPLETION
    INITFINI* defn )            // - definition
{
    defn = defn;
    DbgStmt( CarveVerifyAllGone( carveTC_DATA, "TC_DATA" ) );
    CarveDestroy( carveTC_DATA );
}
예제 #4
0
static void deQueue             // TAKE (FIFO) INSTRUCTION FROM QUEUE
    ( void )
{
    PP_INS* ins;                // - queued instruction

    ins = ins_queue->next;
    DbgVerify( NULL != ins, "Empty instruction queue" );
    RingPrune( &ins_queue, ins );
    IfDbgToggle( browse ) {
        DbgStmt( printf( "dequeued %s %x\n   "
                       , DbgIcOpcode( ins->opcode )
                       , ins->parm ) );
        DbgStmt( DbgDumpTokenLocn( &ins->locn ) );
        DbgStmt( printf( "\n" ) );
    }
    writeIns( ins->opcode, ins->parm, &ins->locn );
    CarveFree( carvePpIns, ins );
}
예제 #5
0
static void linkageFini( INITFINI* defn )
{
    defn = defn;
    while( nestedLinkages != NULL ) {
        LinkagePop();
    }
    DbgStmt( CarveVerifyAllGone( carveSTACK, "linkage STACK" ) );
    CarveDestroy( carveSTACK );
}
예제 #6
0
static void typeSigAccessVar(   // ACCESS A DTOR, DEFAULT-CTOR, COPY-CTOR
    TYPE_SIG_ACCESS acc_var,    // - access type (variable)
    SYMBOL *a_sym,              // - addr[ symbol for item accessed ]
    ACCINFO *info )             // - access information
{
    SYMBOL sym;                 // - symbol for routine
    TYPE type;                  // - class type
    TOKEN_LOCN *err_locn;       // - error location
    bool fill_out;              // - true ==> fill out the entry

    sym = *a_sym;
    if( acc_var & info->acc ) {
        fill_out = ( (info->acc & TSA_FILL_OUT) != 0 );
        if( fill_out ) {
            SetCurrScope(info->class_scope);
        } else {
            SetCurrScope (info->access_scope);
        }
    } else {
        fill_out = true;
        SetCurrScope(info->class_scope);
    }
    if( ( GetCurrScope() != info->class_scope ) || ( sym == NULL ) ) {
        type = info->type;
        err_locn = info->err_locn;
        switch( acc_var ) {
        case TSA_DTOR :
            sym = DtorFindLocn( type, err_locn );
            break;
        case TSA_DEFAULT_CTOR :
            sym = DefaultCtorFind( type, err_locn, fill_out );
            break;
        case TSA_COPY_CTOR :
            sym = CopyCtorFind( type, err_locn );
            break;
        default :
            DbgStmt( CFatal( "typeSigAccessVar -- impossible type" ) );
            sym = NULL;
        }
        if( sym == NULL ) {
            if( ! fill_out ) {
                *info->err_occurred = true;
            }
        } else {
            sym = ClassFunMakeAddressable( sym );
            sym->flag |= SF_ADDR_TAKEN;
            if( (info->acc & TSA_NO_REF) == 0 ) {
                if( acc_var & info->acc ) {
                    sym = SymMarkRefed( sym );
                }
            }
            *a_sym = sym;
            CDtorScheduleArgRemap( sym );
        }
    }
}
예제 #7
0
static void queue               // PLACE INSTRUCTION ON QUEUE
    ( CGINTEROP opcode          // - opcode
    , void const * parm         // - parm for instruction
    , TOKEN_LOCN const * locn ) // - location for instruction
{
    if( cursor.src_file == locn->src_file
     && NULL != cursor.src_file
     && opcode != IC_BR_SRC_END ) {
        writeIns( opcode, parm, locn );
    } else {
        PP_INS* ins = RingCarveAlloc( carvePpIns, &ins_queue );
        ins->opcode = opcode;
        ins->parm = parm;
        TokenLocnAssign( ins->locn, *locn );
        IfDbgToggle( browse ) {
            DbgStmt( printf( "queued %s %x\n   ", DbgIcOpcode( opcode ), parm ) );
            DbgStmt( DbgDumpTokenLocn( locn ) );
            DbgStmt( printf( "\n" ) );
        }
    }
}
예제 #8
0
DWIOBUFF *DwioBuffSeek(         // POSITION TO SPECIFIED OFFSET FROM START
    DWIOBUFF *ctl,              // - current buffer control
    DISK_ADDR block,            // - starting disk address
    size_t offset )             // - where to position to
{
    DWIOBUFF *next;             // - next buffer control
    size_t required_block;
    size_t required_offset;

    required_block = offset / DWBLOCK_BSIZE;
    required_offset = offset % DWBLOCK_BSIZE;
    while( ctl->block_num != required_block ) {
        if( ctl->block_num < required_block ) {
            if( ctl->next_addr == 0 ) {
                next = findWrBuffer();
                ctl->next_addr = next->disk_addr;
                next->prev_addr = ctl->disk_addr;
                next->block_num = ctl->block_num + 1;
            } else {
                next = findReWrBuffer( ctl->next_addr );
            }
        } else {
            if( (ctl->block_num - required_block) > required_block ) {
                next = findReWrBuffer( block );
            } else {
                if( ctl->prev_addr == 0 ) {
                    DbgStmt( CFatal( "dwiobuff: attempt to seek off start of file" ) );
                }
                next = findReWrBuffer( ctl->prev_addr );
            }
        }
        finishWrBuffer( ctl );
        ctl = next;
    }
    ctl->current_offset = required_offset;
    return( ctl );
}
예제 #9
0
TYPE_SIG *TypeSigFind(          // FIND TYPE SIGNATURE
    TYPE_SIG_ACCESS acc,        // - access type
    TYPE type,                  // - type for signature
    TOKEN_LOCN* err_locn,       // - error location for access errors
    bool *error_occurred )      // - to set error indication
{
    TYPE_SIG *srch;             // - signature for searching
    TYPE_SIG *sig;              // - signature
    SYMBOL sym;                 // - symbol
    unsigned size;              // - size of R/O data
    NAME typesig_name;          // - name of type signature
    TYPE typesig_type;          // - type of type signature
    bool err_this_time;         // - true ==> we have error
    TYPE_SIG_ACCESS acc_ind;    // - indirect access

    err_this_time = false;
    type = TypeCanonicalThr( type );
    sig = NULL;
    RingIterBeg( type_sigs, srch ) {
        if( TypesSameExclude( srch->type, type, TC1_NOT_ENUM_CHAR ) ) {
            sig = srch;
            break;
        }
    } RingIterEnd( srch );
    if( sig == NULL ) {
        THROBJ thr;             // - category of object
        DbgVerify( 0 == ( acc & TSA_GEN )
                 , "TypeSigFind -- no type signature & TSA_GEN" );
        sig = RingCarveAlloc( carveTYPE_SIG, &type_sigs );
        sig->type = type;
        sig->default_ctor = NULL;
        sig->copy_ctor = NULL;
        sig->dtor = NULL;
        sig->sym = NULL;
        sig->base = NULL;
        sig->cgref = false;
        sig->cggen = false;
        sig->free = false;
        thr = ThrowCategory( type );
        if( acc & TSA_INDIRECT ) {
            acc_ind = acc | TSA_INDIRECT_ACCESS;
        } else if( acc & TSA_INDIRECT_ACCESS ) {
            acc_ind = ( acc & ~ TSA_INDIRECT ) | TSA_INDIRECT_GEN;
        } else {
            acc_ind = acc;
        }
        size = 0;
        switch( thr ) {
        case THROBJ_PTR_SCALAR :
        case THROBJ_PTR_CLASS :
            sig->base = TypeSigFind( acc_ind & TSA_INDIRECT
                                   , TypePointedAtModified( type )
                                   , err_locn
                                   , &err_this_time );
            size = typeSigHdrSize();
            break;
        case THROBJ_SCALAR :
        case THROBJ_PTR_FUN :
        case THROBJ_VOID_STAR :
            size = typeSigHdrSize() + SizeTargetSizeT();
            break;
        case THROBJ_REFERENCE :
            sig->base = TypeSigFind( acc_ind
                                   , TypeReference( type )
                                   , err_locn
                                   , &err_this_time );
            break;
        case THROBJ_CLASS :
        case THROBJ_CLASS_VIRT :
            size = 3 * CgCodePtrSize() + CgDataPtrSize() + typeSigHdrSize();
            break;
        case THROBJ_ANYTHING :
            break;
        default :
            DbgStmt( CFatal( "cgTypeSignature -- invalid throw category" ) );
        }
        size += typeSigNameSize( thr );
        if( size == 0 ) {
            sym = NULL;
        } else {                // - type for TYPE SIGNATURE variable
            typesig_name = CppNameTypeSig( type );
            sym = ScopeAlreadyExists( GetFileScope(), typesig_name );
            if( sym == NULL ) {
                typesig_type = MakeInternalType( size );
                typesig_type = MakeCompilerConstCommonData( typesig_type );
                sym = SymCreateFileScope( typesig_type
                                        , SC_PUBLIC
                                        , SF_REFERENCED | SF_ADDR_TAKEN
                                        , typesig_name );
                LinkageSet( sym, "C++" );
                CgSegId( sym );
            }
        }
        sig->sym = sym;
    }
    if( err_this_time ) {
        *error_occurred = true;
    } else {
        if( NULL != sig->sym ) {
            SegmentMarkUsed( sig->sym->segid );
        }
        *error_occurred = false;
        typeSigAccess( acc, sig, err_locn, error_occurred );
    }
    return( sig );
}