s37enc.c

来自「开放源码的编译器open watcom 1.6.0版的源代码」· C语言 代码 · 共 1,197 行 · 第 1/3 页

C
1,197
字号
        hwop->sx.disp = 0;
        hwop->sx.b  = 0xff; /* not known yet */
        tlen = TypeClassSize[ tipe ];
        if( _IsFloating( tipe )  ){
            hwop->sx.ref = HWLitFltGen( op->c.value, tlen );
        }else{
            hwop->sx.ref = HWLitIntGen( op->c.int_value, tlen );
        }
    }else{
        GetOpName( hwop, op );
    }
}

extern void GetOpName( hwins_op_any *hwop, name *op ) {
/**************************************/

    hw_reg_set  regs;
    name        *base;

    hwop->sx.a = 0;
    hwop->sx.b = 0;
    hwop->sx.disp = 0;
    hwop->sx.ref  = NULL;
    switch( op->n.class ) {
    case N_CONSTANT: /* ref a lit constant */
        GetConsLit( hwop, op );
        break;
    case N_MEMORY:
        /* ref memory label */;
        GetMemRef( hwop, op );
        break;
    case N_TEMP:
        base = DeAlias( op );
        if( base->t.location == NO_LOCATION ) {
            _Zoiks( ZOIKS_030 );
        }
        hwop->sx.disp = base->t.location + op->v.offset - base->v.offset;
        hwop->sx.b = TempBase( base );
        hwop->sx.a = 0;
        break;
    case N_INDEXED:
        regs = op->i.index->r.reg;
        if( op->i.index_flags ==( X_FAKE_BASE | X_BASE_IS_INDEX) ){
            GetMemDisp( hwop, op );
        }else{
            hwop->sx.disp  = op->i.constant;              /* use integer value*/
        }
        GetIdx( hwop, regs, op->i.index_flags );
        if( HasTrueBase( op ) ) {
            op = op->i.base;
            if( op->n.class != N_TEMP ) _Zoiks( ZOIKS_030 );
            base = DeAlias( op );
            if( hwop->sx.b == 0 ) {
                hwop->sx.b = TempBase( base );
            } else if( hwop->sx.a == 0 ) {
                hwop->sx.a = TempBase( base );
            } else {
                _Zoiks( ZOIKS_030 );
            }
        }
        break;
    case N_REGISTER:
        hwop->r = RegOp( op );
        break;
    }
}

extern unsigned DepthAlign( unsigned depth ) {
/********************************************/
    depth = 1;
    return( 2 );
}

extern  hw_sym  *CodeLabel( label_handle label, unsigned align ) {
/****************************************************************/
 align = 2;
 return(  EncLabel( label, align ) );
}

extern  hw_sym  *EncLabel( label_handle label, char align ) {
/****************************************************************/

    sym_handle  sym;
    fe_attr     attr;
    hw_sym    *hwlabel;

    hwlabel = AskForHWLabel( label );
    sym = AskForLblSym( label );
    if( AskIfRTLabel( label ) ) {
        attr = FE_STATIC;
    } else if( sym != NULL ){
        attr = FEAttr( sym );
    }else{
        attr = FE_STATIC;
    }
    HWLabelGen( hwlabel, align );
    if( attr &  FE_GLOBAL ){
        HWEntry( hwlabel  );
    }

#ifndef NXDEBUG
    if( _IsModel( INTERNAL_DBG_OUTPUT ) ) { /* debug dump */
        if( sym != NULL ) {
            DumpString( FEName( sym ) );
        } else if( AskIfRTLabel( label ) ) {
            DumpString( AskRTName( (int)AskForLblSym( label ) ) );
        } else {
            DumpString( "L" );
            DumpPtr( label );
        }
        DumpString( ":" );
        DumpNL();
    }
#endif
    return( hwlabel );
}

extern  void    CodeLineNum( unsigned_16 line ) {
/**********************************************/

    HWQueue( line );

#ifndef NXDEBUG
    if( _IsModel( INTERNAL_DBG_OUTPUT ) ) { /* debug dump */
        DumpString( "Source Line: " );
        DumpInt( line );
        DumpNL();
    }
#endif
}


extern  void    GenJumpLabel( label_handle label ) {
/**********************************************/

    hw_sym   *hwlabel;
    hwins_op_any  dst;

    hwlabel =  AskForHWLabel( label );
    dst.sx.ref = HWSymRef( hwlabel );
    dst.sx.disp = 0;
    dst.sx.a = 0;
    dst.sx.b = 0;
    HWBRGen( 15,  &dst );

#ifndef NXDEBUG
    if( _IsModel( INTERNAL_DBG_OUTPUT ) ) { /* debug dump */
        DumpString( "JMP L" );
        DumpPtr( label );
        DumpNL();
    }
#endif
}


static void    GenJumpIf( instruction *cond, label_handle label ) {
/*************************************************************/

    hw_sym   *hwlabel;
    hwins_op_any  dst;

    hwlabel =  AskForHWLabel( label );
    dst.sx.ref = HWSymRef( hwlabel );
    dst.sx.disp = 0;
    dst.sx.a = 0;
    dst.sx.b = 0;
    HWBRGen( CondCode( cond ),  &dst );
#ifndef NXDEBUG
    if( _IsModel( INTERNAL_DBG_OUTPUT ) ) { /* debug dump */
        DumpString( "Jcc L" );
        DumpPtr( label );
        DumpNL();
   }
#endif
}


extern  void    GenKillLabel( pointer label ) {
/**********************************************/
    label = label;      /* NYI */
}


extern  void    GenCallLabel( pointer label ) {
/**********************************************/
    label = label;      /* NYI */
}


extern  void    GenLabelReturn() {
/**********************************************/
        /* NYI */
}


static  byte    CondCode( instruction *cond ) {
/*********************************************/

    if(  Signed[  cond->type_class  ] ) {
        return( SCondTable[ cond->head.opcode-FIRST_CONDITION ] );
    } else {
        return( UCondTable[ cond->head.opcode-FIRST_CONDITION ] );
    }
}


extern  label_handle    LocateLabel( instruction *ins, int index ) {
/******************************************************************/

    if( index == NO_JUMP ) return( NULL );
    for(;;) {
        ins = ins->head.next;
        if( ins->head.opcode == OP_BLOCK ) break;
    }
    return( _BLOCK( ins )->edge[  index  ].destination );
}


extern  void    GenCondJump( instruction *cond ) {
/************************************************/

    label_handle        dest_false;
    label_handle        dest_true;
    label_handle        dest_next;
    instruction         *next;

    next = cond->head.next;
    while( next->head.opcode != OP_BLOCK ) {
        next = next->head.next;
    }
    dest_next = NULL;
    if( _BLOCK( next )->next_block != NULL ) {
        dest_next = _BLOCK( next )->next_block->label;
    }
    dest_false = LocateLabel( cond, _FalseIndex( cond ) );
    dest_true = LocateLabel( cond, _TrueIndex( cond ) );
    if( dest_true == dest_next ) {
        FlipCond( cond );
        dest_true = dest_false;
        dest_false = dest_next;
    }
    if( dest_false != dest_true && dest_true != dest_next ) {
        GenJumpIf( cond, dest_true );
    }
    if( dest_false != dest_next ) {
        GenJumpLabel( dest_false );
    }
}


extern void GetRALN( name *op, char *ra, char *ln ) {
/***************************************************/

    pointer             aux;
    linkage_regs        *link;
    label_handle        label;

    *ra = 13;
    *ln = 11;
    if( op != NULL ) {
        if( op->m.memory_type == CG_FE ) {
            aux = FEAuxInfo( op->v.symbol, AUX_LOOKUP );
            link = FEAuxInfo( aux, LINKAGE_REGS );
            *ra = RegTrans( link->ra );
            *ln = RegTrans( link->ln );
        } else if( op->m.memory_type == CG_LBL ) {
            label = (label_handle)op->v.symbol;
            if( AskIfRTLabel( label ) ) {
                AskRTRALN( (int)AskForLblSym( label ), ra, ln );
            }
        }
    }
}


extern  void    GenCall( instruction *ins ) {
/***************************************/

    name                *op;
    hwins_op_any hwop1;
    hwins_op_any hwop2;

    op = ins->operands[ CALL_OP_ADDR ];
    GetRALN( op, &hwop1.r, &hwop2.r );
    HWInsGen( HWOP_BALR, &hwop1, &hwop2, NULL );
}


extern  void    GenRCall( instruction *ins ) {
/********************************************/

    hwins_op_any hwop1;
    hwins_op_any hwop2;
    hwins_op_any hwop3;

    GetRALN( NULL, &hwop1.r, &hwop2.r );
    hwop3.r = RegOp( ins->operands[ CALL_OP_ADDR ] );
    HWInsGen( HWOP_LR, &hwop2, &hwop3, NULL );
    HWInsGen( HWOP_BALR, &hwop1, &hwop2, NULL );
}


extern  void    GenICall( instruction *ins ) {
/********************************************/

    hwins_op_any hwop1;
    hwins_op_any hwop2;
    hwins_op_any hwop3;

    GetRALN( NULL, &hwop1.r, &hwop2.r );
    GetOpName( &hwop3, ins->operands[ CALL_OP_ADDR ] );
    HWInsGen( HWOP_L, &hwop2, &hwop3, NULL );
    HWInsGen( HWOP_BALR, &hwop1, &hwop2, NULL );
}


static reg_num RegOp( name *r ) {
/***********************************/

    return ( RegTrans( r->r.reg ) );
}

static hw_reg_set RegNames[] = {
    HW_D( HW_G0 ),
    HW_D( HW_G1 ),
    HW_D( HW_G2 ),
    HW_D( HW_G3 ),
    HW_D( HW_G4 ),
    HW_D( HW_G5 ),
    HW_D( HW_G6 ),
    HW_D( HW_G7 ),
    HW_D( HW_G8 ),
    HW_D( HW_G9 ),
    HW_D( HW_G10 ),
    HW_D( HW_G11 ),
    HW_D( HW_G12 ),
    HW_D( HW_G13 ),
    HW_D( HW_G14 ),
    HW_D( HW_G15 ),
    HW_D( HW_EMPTY )
};

static reg_num GetRegNum( hw_reg_set regs ) {
/****************************************/

    reg_num i;

    i = 0;
    while( !HW_CEqual( RegNames[i], HW_EMPTY ) ) {
        if( HW_Ovlap( regs, RegNames[i] ) ) break;
        i++;
    }
    return( i );
}


static void GetIdx( hwins_op_any *hwop, hw_reg_set regs, i_flags flag ) {
/***********************************************************************/

    reg_num high;
    reg_num low;

    low = GetRegNum( regs );
    HW_TurnOff( regs, RegNames[ low ] );
    if( !HW_CEqual( regs, HW_EMPTY ) ) {
        high = GetRegNum( regs );
    } else {
        high = 0;
    }
    if( flag & X_HIGH_BASE ) {
        hwop->sx.b = high;
        hwop->sx.a = low;
    } else {
        hwop->sx.b = low;
        hwop->sx.a = high;
    }
}


extern reg_num RegTrans( hw_reg_set regs ) {
/*******************************************/

/* convert bit set into bit position which we'll use as the regname */

    HW_CTurnOff( regs, HW_UNUSED );
    if( HW_CEqual( regs, HW_EMPTY ) ) {
        _Zoiks( ZOIKS_031 );
    } else if( HW_COvlap( regs, HW_FLTS ) ) {
        if( HW_COvlap( regs, HW_Y0 ) ) return( 0 );
        if( HW_COvlap( regs, HW_Y2 ) ) return( 2 );
        if( HW_COvlap( regs, HW_Y4 ) ) return( 4 );
        if( HW_COvlap( regs, HW_Y6 ) ) return( 6 );
    } else {
        return( GetRegNum( regs ) );
    }
    _Zoiks( ZOIKS_117 );  /* if we get here bug */
    return( 0 );
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?