Exemplo n.º 1
0
PTREE FoldUnary( PTREE expr )
/***************************/
{
    PTREE op1;
    TYPE result_type;
    bool dont_care;

    op1 = expr->u.subtree[0];
    if( notFoldable( op1 ) ) {
        switch( expr->cgop ) {
        case CO_EXCLAMATION:
            if( nonZeroExpr( op1 ) ) {
                expr = makeTrueFalse( expr, op1, 0 );
            }
            break;
        }
        return( expr );
    }
    result_type = expr->type;
    if( op1->op == PT_FLOATING_CONSTANT ) {
        switch( expr->cgop ) {
        case CO_EXCLAMATION:
            op1->u.int64_constant.u._32[ I64HI32 ] = 0;
            op1->u.int64_constant.u._32[ I64LO32 ]
                = ( BFSign( op1->u.floating_constant ) == 0 );
            op1->op = PT_INT_CONSTANT;
            op1 = NodeSetBooleanType( op1 );
            break;
        case CO_UMINUS:
            BFNegate( op1->u.floating_constant );
            break;
        case CO_UPLUS:
            break;
        default:
            return( expr );
        }
        op1 = PTreeCopySrcLocation( op1, expr );
        PTreeFree( expr );
        return( castConstant( op1, result_type, &dont_care ) );
    }
    switch( expr->cgop ) {
    case CO_TILDE:
        op1->u.int64_constant.u._32[0] = ~ op1->u.int64_constant.u._32[0];
        op1->u.int64_constant.u._32[1] = ~ op1->u.int64_constant.u._32[1];
        break;
    case CO_EXCLAMATION:
        op1 = makeBooleanConst( op1, ! nonZeroExpr( op1 ) );
        break;
    case CO_UMINUS:
        U64Neg( &op1->u.int64_constant, &op1->u.int64_constant );
        break;
    case CO_UPLUS:
        break;
    default:
        return( expr );
    }
    op1 = PTreeCopySrcLocation( op1, expr );
    PTreeFree( expr );
    return( castConstant( op1, result_type, &dont_care ) );
}
Exemplo n.º 2
0
BOOL StrToU64( char *str, unsigned_64 *u64, BOOL neg )
{
    unsigned_64 r64;
    unsigned_64 v64;
    int         value;
    int         radix;

    str = eatSpace( str );
    U32ToU64( 0, u64 );
    if( neg == TRUE ) {
        if( *str == '-') {
            str++;
        } else {
            if( *str == '+' ) {
                str++;
                neg = FALSE;
            }
        }
    }
    str = eatSpace( str );
    switch( *str ){
    case '\0':
        return( FALSE );
    case '0':
        str++;
        if( tolower(*str) == 'x' ) {
            radix = 16;
            str++;
        } else {
            radix = 8;
        }
        break;
    default:
        radix = 10;
    }
    U32ToU64( radix, &r64 );
    while( *str != '\0' ) {
        if( isdigit( *str ) ) {
            value = *str - '0';
        } else {
            value = 10 + tolower( *str ) - 'a';
        }
        if( value < 0 || value >= radix ) {
            return ( FALSE );
        }
        U32ToU64( value, &v64 );
        U64Mul( u64, &r64, u64 );
        U64Add( &v64, u64, u64 );
        str++;
    }
    if( neg == TRUE) {
        U64Neg( u64, u64 );
    }
    return( TRUE );
}
Exemplo n.º 3
0
static
signed_64 BFCnvF64( float_handle flt )
{
    signed_64 result;
    float_handle absol, t0, t1, t2, t3;
    bool positive;

    int sign = BFSign( flt );
    if( 0 == sign ) {
        result.u._32[0] = 0;
        result.u._32[1] = 0;
        return result;
    }
    positive = true;
    absol = flt;
    if( sign < 0 ) {
        positive = false;
        absol = BFCopy( flt );
        BFNegate( absol );
    }
    t0 = TwoTo32();
    t1 = BFDiv( flt, t0 );
    t3 = BFTrunc( t1 );
    BFFree( t1 );
    result.u._32[ I64HI32 ] = BFCnvF32( t3 );
    BFFree( t3 );
    t1 = BFCnvUF( result.u._32[ I64HI32 ] );
    t2 = BFMul( t0, t1 );
    BFFree( t0 );
    BFFree( t1 );
    t0 = BFSub( flt, t2 );
    BFFree( t2 );
    t3 = BFTrunc( t0 );
    BFFree( t0 );
    result.u._32[ I64LO32 ] = BFCnvF32( t3 );
    BFFree( t3 );
    if( ! positive ) {
        signed_64 neg;
        BFFree( absol );
        neg = result;
        U64Neg( &neg, &result );
    }
    return result;
}
Exemplo n.º 4
0
 int64 operator-() const
 {
     int64 neg;
     U64Neg( &this->_d, &neg._d );
     return( neg );
 }