intrface.c

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

C
1,942
字号
#endif

    addr = TGen( name, TypeAddress( T_DEFAULT ) );
    CGDuplicateArray[ 0 ] = TGReLeaf( BGCopy( addr ) );
    CGDuplicateArray[ 1 ] = TGReLeaf( addr );

#ifndef NDEBUG
    retn = CGDuplicateArray;
    EchoAPI( " -> %n %n\n", retn[0], retn[1] );
    hdlAdd( CG_NAMES, retn[0] );
    hdlAdd( CG_NAMES, retn[1] );
    return retn;
#else
    return( CGDuplicateArray );
#endif
}

/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
/*%                                              %%*/
/*%   Data generator actions                     %%*/
/*%                                              %%*/
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/

extern  void _CGAPI     DGLabel( bck_info *bck )
/**********************************************/
{
#ifndef NDEBUG
    EchoAPI( "DGLabel( %B )\n", bck );
#endif
    if( !REAL_BACK( bck ) ) _Zoiks( ZOIKS_068 );
    DGBlip();
    DataLabel( bck->lbl );
    bck->seg = AskOP();
}

extern  void _CGAPI     DGBackPtr( bck_info *bck, segment_id seg,
                                   signed_32 offset, cg_type tipe )
/*****************************************************************/
{
#ifndef NDEBUG
    EchoAPI( "DGBackPtr( %B, %S, %i, %t )\n", bck, seg, offset, tipe );
#endif
    if( !REAL_BACK( bck ) ) _Zoiks( ZOIKS_068 );
    DGBlip();
    BackPtr( bck, seg, offset, TypeAddress( tipe ) );
}

extern  void _CGAPI DGFEPtr( cg_sym_handle sym, cg_type tipe, signed_32 offset )
/******************************************************************************/
{
#ifndef NDEBUG
    EchoAPI( "DGFEPtr( %S, %t, %i )\n", sym, tipe, offset );
#endif
    DGBlip();
    FEPtr( sym, TypeAddress( tipe ), offset );
}

extern  void _CGAPI     DGBytes( unsigned_32 len, void *src )
/***********************************************************/
{
#ifndef NDEBUG
    EchoAPI( "DGBytes( %x, %x )\n", len, src );
#endif
    DGBlip();
    DataBytes( len, src );
}

extern  void _CGAPI     DGInteger( unsigned_32 value, cg_type tipe )
/******************************************************************/
{
    type_length len;
    int         i;
    byte        buff[6];
    byte        *form;

#ifndef NDEBUG
    EchoAPI( "DGInteger( %i, %t )\n", value, tipe );
#endif
    len = TypeLength( tipe );
    i = 0;
#if _TARG_MEMORY & _TARG_LOW_FIRST
    form = buff;
    while( i < len ) {
        *form++ = value & 0xff;
        value /= 256;
        ++i;
    }
    form = buff;
#else
    form = buff + 6;
    while( i < len ) {
        *--form = value & 0xff;
        value /= 256;
        ++i;
    }
#endif
    DGBytes( len, form );
}

extern  void _CGAPI     DGInteger64( unsigned_64 value, cg_type tipe )
/********************************************************************/
{
    type_length len;
    int         i;
    union{
        unsigned_32 vall;
        unsigned_64 val;
        byte        buff[8];
    } data;
    byte        *form;

    i = 0;
#if !( _TARG_MEMORY & _TARG_LOW_FIRST) == !(_HOST_MEMORY & _LOW_FIRST)
    data.val = value;
#else
    {  // reverse them
        union{
            unsigned_64 val;
            byte        buff[8];
        }temp;
        temp.val = value;
        while( i <= 7 ) {
            data.buf[i] = temp.buff[7-i];
            ++i;
        }
    }
#endif
#ifndef NDEBUG
// fix this up when we get printf support for int64
    EchoAPI( "DGInteger64( %x %x, %t )\n"
           , data.val.u._32[0]
           , data.val.u._32[1]
           , tipe );
#endif
    form = data.buff;
    len = TypeLength( tipe );
    DGBytes( len, form );
}

extern  void _CGAPI     DGFloat( char *value, cg_type tipe )
/**********************************************************/
{
    pointer     cf;
    flt         buff;

#ifndef NDEBUG
    EchoAPI( "DGFloat( %c, %t )\n", value, tipe );
#endif
    cf = CFCnvSF( value, value + Length( value ) );
    CFCnvTarget( cf, &buff, TypeLength( tipe ) );
    CFFree( cf );
    DGBytes( TypeLength( tipe ), &buff );
}

extern  void _CGAPI     DGIBytes( unsigned_32 len, byte pat )
/***********************************************************/
{
#ifndef NDEBUG
    EchoAPI( "DGIBytes( %x, %x )\n", len, pat );
#endif
    DGBlip();
    IterBytes( len, pat );
}

extern  void _CGAPI     DGChar( char value )
/******************************************/
{
#ifndef NDEBUG
    EchoAPI( "DGChar( %x )\n", value );
#endif
    DGIBytes( 1, value );
}

extern  void _CGAPI     DGString( char *value, uint len )
/*******************************************************/
{
#ifndef NDEBUG
    char        data[40];
    unsigned    slen = len;
    char        *d = data;
    char        *dt = &data[sizeof(data)-1];
    char        *s = value;
    char        *hex = "0123456789abcdef";
    char        c;

    for( ;; ) {
        assert( d <= dt );
        if( slen == 0 ) break;
        --slen;
        c = *s++;
        if( !iscntrl(c) && isascii(c)) {
            if(( d + (1+1)) >= dt ) break;
            *d++ = c;
        } else {
            if(( d + (4+1) ) >= dt ) break;
            *d++ = '\\';
            *d++ = 'x';
            *d++ = hex[ ( c >> 4 ) & 0x0f ];
            *d++ = hex[ ( c >> 0 ) & 0x0f ];
        }
    }
    *d = '\0';
    assert( strlen( data ) < sizeof( data ) );
    if( slen != 0 ) {
        EchoAPI( "DGString( \"%c...\", %x )\n", data, len );
    } else {
        EchoAPI( "DGString( \"%c\", %x )\n", data, len );
    }
#endif

#if 1
    DGBytes( len, value );
#else
    // this code is only useful if we do ASCII<->EBCDIC translation
    // but since we don't do conversions; it's only slow
    while( len > 0 ) {
        DGChar( *value++ );
        --len;
    }
#endif
}

extern  void _CGAPI     DGUBytes( unsigned_32 len )
/*************************************************/
{
#ifndef NDEBUG
    EchoAPI( "DGUBytes( %x )\n", len );
#endif
    DGBlip();
    IncLocation( len );
}

extern  void _CGAPI     DGAlign( uint align )
/*******************************************/
{
#ifndef NDEBUG
    EchoAPI( "DGAlign( %i )\n", align );
#endif
    DGBlip();
    DataAlign( align );
}


extern  unsigned_32 _CGAPI  DGSeek( unsigned_32 where )
/*****************************************************/
{
    uint        old;

#ifndef NDEBUG
    EchoAPI( "DGSeek( %x )", where );
#endif

    DGBlip();
    old = AskLocation();
    SetLocation( where );

#ifndef NDEBUG
    return( EchoAPIHexReturn( old ) );
#else
    return( old );
#endif
}

extern  unsigned_32 _CGAPI      DGTell( void )
/********************************************/
{
#ifndef NDEBUG
    unsigned_32     retn;

    EchoAPI( "DGTell()" );
    retn = AskLocation();
    return( EchoAPIIntReturn( retn ) );
#else
    return( AskLocation() );
#endif
}


extern  unsigned_32 _CGAPI      DGBackTell( bck_info *bck )
/*********************************************************/
{
#ifndef NDEBUG
    unsigned_32 retn;
    EchoAPI( "DGBackTell( %B )", bck );
#endif

    if( !REAL_BACK( bck ) ) _Zoiks( ZOIKS_068 );

#ifndef NDEBUG
    retn = AskAddress( bck->lbl );
    return EchoAPIIntReturn( retn );
#else
    return( AskAddress( bck->lbl ) );
#endif
}


/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
/*%                                              %%*/
/*%   Internal routines                          %%*/
/*%                                              %%*/
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/

extern  void _CGAPI     DGCFloat( pointer cf, cg_type tipe )
/**********************************************************/
{
    flt        buff;

#ifndef NDEBUG
    EchoAPI( "DGCFloat( %x, %t )\n", cf, tipe );
#endif
    CFCnvTarget( cf, &buff, TypeLength( tipe ) );
    DGBytes( TypeLength( tipe ), &buff );
}

extern  char    *AskName( pointer hdl, cg_class class )
/*****************************************************/
{
    switch( class ) {
    case CG_FE:
        return( FEName( hdl ) );
    case CG_LBL:
        return( "(LBL)" );
    case CG_CLB:
        return( "(CLB)" );
    case CG_BACK:
        return( "(BCK)" );
    case CG_TBL:
        return( "(TBL)" );
    case CG_VTB:
        return( "(VTB)" );
    default:
        _Zoiks( ZOIKS_130 );
        return( "" );
    }
}

extern  label_handle    AskForSymLabel( pointer hdl, cg_class class )
/*******************************************************************/
{
    switch( class ) {
    case CG_FE:
        return( FEBack( hdl )->lbl );
    case CG_LBL:
        return( (label_handle)hdl );
    case CG_CLB:
        return( (label_handle)hdl );
    case CG_BACK:
        return( ((bck_info*)hdl)->lbl );
    case CG_TBL:
        return( ((tbl_control*)hdl)->lbl );
    case CG_VTB:
        return( ((tbl_control*)hdl)->value_lbl );
    default:
        _Zoiks( ZOIKS_130 );
        return( NULL );
    }
}

extern  import_handle   AskImportHandle( sym_handle sym )
/*******************************************************/
{
    return( FEBack( sym )->imp );
}

extern  void    TellImportHandle( sym_handle sym, import_handle imp )
/*******************************************************************/
{
    FEBack( sym )->imp = imp;
}

/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
/*%                                              %%*/
/*%   CFloat routines                            %%*/
/*%                                              %%*/
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/


extern  char * _CGAPI             BFCnvFS( float_handle cf, char *buff, int buff_len )
/************************************************************************************/
{
    return( CFCnvFS( (cfloat *)cf, buff, buff_len ) );
}

extern  float_handle _CGAPI     BFCnvSF( char *start, char *end )
/***************************************************************/
{
    return( CFCnvSF( start, end ) );
}

extern  float_handle _CGAPI     BFMul( float_handle c1, float_handle c2 )
/***********************************************************************/
{
    return( CFMul( (cfloat *)c1, (cfloat *)c2 ) );
}

extern  float_handle _CGAPI     BFAdd( float_handle c1, float_handle c2 )
/***********************************************************************/
{
    return( CFAdd( (cfloat *)c1, (cfloat *)c2 ) );
}

extern  float_handle _CGAPI     BFDiv( float_handle c1, float_handle c2 )
/***********************************************************************/
{
    return( CFDiv( (cfloat *)c1, (cfloat *)c2 ) );
}

extern  float_handle _CGAPI     BFSub( float_handle c1, float_handle c2 )
/***********************************************************************/
{
    return( CFSub( (cfloat *)c1, (cfloat *)c2 ) );
}

extern  void _CGAPI             BFNegate( float_handle c1 )
/*********************************************************/
{
     CFNegate( (cfloat *) c1 );
}

extern  float_handle _CGAPI     BFTrunc( float_handle c1 )
/********************************************************/
{
     return( CFTrunc( (cfloat *) c1 ) );
}

extern  float_handle _CGAPI     BFCopy( float_handle c1 )
/*******************************************************/
{
     return( CFCopy( (cfloat *) c1 ) );
}

extern  int _CGAPI              BFSign( float_handle c1 )
/*******************************************************/
{
     return( CFTest((cfloat *) c1) );
}

extern  float_handle _CGAPI     BFCnvIF( int data )
/*************************************************/
{
    return( CFCnvIF( data ) );
}

extern  float_handle _CGAPI     BFCnvUF( uint data )
/**************************************************/
{
    return( CFCnvUF( data ) );
}

extern  signed_32 _CGAPI       BFCnvF32( float_handle f )
/*******************************************************/
{
    return( CFCnvF32( (cfloat*) f ) );
}

extern  int _CGAPI              BFCmp( float_handle l, float_handle r )
/*********************************************************************/
{
    return( CFCompare( (cfloat *)l, (cfloat *)r ) );
}

extern  void _CGAPI             BFFree( float_handle cf )
/*******************************************************/
{
    CFFree( (cfloat *)cf );
}

extern  void _CGAPI     DBSrcCue( uint fno, uint line, uint col );
extern  void _CGAPI     DBBegBlock( void );
extern  void _CGAPI     DBEndBlock( void );

#ifndef _CGDLL
extern  int _CGAPI              BEDLLLoad( char *name )
/*****************************************************/
{
    return( TRUE );
}

extern  void _CGAPI             BEDLLUnload() {
/*********************************************/
}
#endif

⌨️ 快捷键说明

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