dg.c

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

C
1,246
字号
            stkop = LOP_ZEB;
            break;
        case 2:
            stkop = LOP_ZEW;
            break;
        default:
            CGError( "invalid ZEX size with type %d\n", other );
            break;
        }
        loc = LocCreate( loc, stkop );
        break;
    case DB_OP_XCHG:
        loc = LocCreate( loc, LOP_XCHG );
        loc->u.stk = other;
        break;
    case DB_OP_MK_FP:
        loc = LocCreate( loc, LOP_MK_FP );
        break;
    case DB_OP_ADD:
        loc = LocCreate( loc, LOP_ADD );
        break;
    case DB_OP_DUP:
        loc = LocCreate( loc, LOP_DUP );
        break;
    case DB_OP_POP:
        loc = LocCreate( loc, LOP_POP );
        break;
    default:
        CGError( "invalid location expression operator" );
        break;
    }
    Action( "%p%n", loc );
    return( loc );
}
extern  void _CGAPI             DBLocFini( dbg_loc loc ) {
/********************************************************/

    Action( "DBLocFini( %p )%n", loc );
}

static fname_lst  *SrcFiles;

static  void    SrcFileNoInit( void ){
/*****************************/
    SrcFiles = NULL;
}

static  void    DBSrcFileFini( void ){
/*****************************/
    fname_lst   *curr, *old;
    curr = SrcFiles;
    while( curr != NULL ){
        old = curr;
        curr = curr->next;
        _Free( old, sizeof( *old ) );
    }
    SrcFiles = NULL;
}

extern  uint    DBSrcFile( char *fname ){
/****************************************/
    int          index;
    int          len;
    fname_lst   *curr, **lnk;

    lnk  = &SrcFiles;
    curr = *lnk;
    index = 0;
    while( (curr = *lnk) != NULL ){
       if( strcmp( fname, curr->fname ) == 0 ){
            goto found;
       }
       ++index;
       lnk = &curr->next;
    }
    len = strlen( fname );
    _Alloc( curr, sizeof( *curr )+len );
    curr->next = NULL;
    strcpy( curr->fname, fname );
    *lnk = curr;
found:
    return( index );
}

extern  void    InitDbgInfo() {
/******************************/
    char       *fname;
    uint        fno;

    SrcFileNoInit();
    fname = FEAuxInfo( NULL, SOURCE_NAME );
    fno = DBSrcFile( fname );
}


extern  void    FiniDbgInfo() {
/******************************/

    DBSrcFileFini();
}

extern  void    DBLineNum( uint no ) {
//====================================

    Action( "%nDBLineNum( %d )%n", no );
    if( CodeSeg != -1 ) {
        Code( "<%d> ", no );
    }
}


extern  void    DBSrcCue( uint fno, uint line, uint col ) {
/************************************/

    Action( "%nDBSrcCue( %d, %d, %d )%n", fno, line, col );
}

extern  void    DBModSym( pointer sym, cg_type tipe ) {
//=====================================================

    Action( "DBModSym" );
    Action( "( %s, %s )%n", FEName(sym), Tipe( tipe ) );
    if( (FEAttr(sym) & FE_IMPORT) == 0 ) {
        /* Should remember and print FEDbgType(sym) later! */
        SymDbg( "ModSym '%s' %d (%s)%n", FEName(sym), 0,
                Tipe(tipe) );
    }
}
extern  void    DBLocalSym( pointer sym, cg_type tipe ) {
//=======================================================

    Action( "DBLocalSym" );
    Action( "( %s )%n", FEName(sym) );
    if( (FEAttr(sym) & FE_IMPORT) == 0 ) {
        /* Should remember and print FEDbgType(sym) later! */
        SymDbg( "LocalSym '%s' %d (%s)%n", FEName(sym), 0,
                Tipe(tipe));
    }
}
extern  void            DBTypeDef( char *nm, dbg_type  tipe ){
/********************************************************/
    Action( "DBTypeDef( %s, %l ) ==>", nm, tipe );
}

extern  void            DBLocalType(pointer sym, char kind ){
/********************************************************/
    Action( "DBLocalType( %s, %d ) ==>", FEName((pointer)sym), kind );
}

extern  void    DBObject( dbg_type tipe, dbg_loc loc ) {
//=====================================================

    Action( "DBObject" );
    Action( "( %d, %s )%n", tipe, Location( loc ) );
    SymDbg( "Object %d (%s)%n", tipe, Location( loc ) );
}
extern  void    DBBegBlock( ) {
//=============================

    Action( "DBBegBlock()%n" );
    SymDbg( "DBBegBlock%n" );
}
extern  void    DBEndBlock() {
//============================

    Action( "DBEndBlock()%n" );
    SymDbg( "DBEndBlock%n" );
}
extern  dbg_type        DBFtnType( char *nm, dbg_ftn_type tipe ) {
//================================================================

    Action( "DBFtnType" );
    Action( "( %s, %d )", nm, tipe );
    TypDbg( "(%d) Fortran '%s' == %s%n", ++TypeIdx, nm, FtnTipe( tipe ) );
    Action( " -> %d%n", TypeIdx );
    return( TypeIdx );
}
extern  dbg_type        DBScalar( char *nm, cg_type tipe ) {
//==========================================================

    Action( "DBScalar" );
    Action( "( %s, %s )", nm, Tipe( tipe ) );
    TypDbg( "(%d) Scalar '%s' == %s%n", ++TypeIdx, nm, Tipe( tipe ) );
    Action( " -> %d%n", TypeIdx );
    return( TypeIdx );
}
extern  dbg_type        DBScope( char *nm ) {
//===========================================

    Action( "DBScope( %s )", nm );
    TypDbg( "(%d) Scope Name '%s'%n", ++TypeIdx, nm );
    Action( " -> %d%n", TypeIdx );
    return( TypeIdx );
}
extern  dbg_name        DBBegName( char *nm, dbg_type scope ) {
//=============================================================

    name_entry  *name;

    Action( "DBBegName( %s, %d )", nm, scope );
    name = CGAlloc( sizeof( name_entry ) );
    name->name = (char*)ACopyOf( nm );
    name->scope = scope;
    name->refno = DBG_NIL_TYPE;
    Action( " -> %p%n", name );
    return( name );
}
extern  void    DumpName( name_entry *nm, dbg_type tipe ) {
//=========================================================

    TypDbg( "(%d) Type Name '%s' scope==%d, type==%d%n", ++TypeIdx,
            nm->name, nm->scope, tipe );
    nm->refno = TypeIdx;
}
extern  dbg_type        DBForward( name_entry *nm ) {
//===================================================

    Action( "DBForward( %p )", nm );
    if( nm->refno == DBG_NIL_TYPE ) {
       DumpName( nm, DBG_FWD_TYPE );
    }
    Action( " -> %d%n", nm->refno );
    return( nm->refno );
}
extern  dbg_type        DBEndName( name_entry *nm, dbg_type tipe ) {
//==================================================================

    dbg_type    retv;

    Action( "DBEndName( %p, %d )", nm, tipe );
    if( nm->refno == DBG_NIL_TYPE ) {
        DumpName( nm, tipe );
    } else {
        TypDbg( "Patch refno %d with %d%n", nm->refno, tipe );
    }
    retv = nm->refno;
    CGFree( nm->name );
    CGFree( nm );
    Action( " -> %d%n", retv );
    return( retv );
}
extern  dbg_type        DBCharBlock( unsigned_32 len ) {
//======================================================

    Action( "DBCharBlock( %l )", len );
    TypDbg( "(%d) CharBlock len==%l%n", ++TypeIdx, len );
    Action( " -> %d%n", TypeIdx );
    return( TypeIdx );
}
extern  dbg_type        DBIndCharBlock( b *len, cg_type len_type, int off ) {
//=========================================================

    Action( "DBIndCharBlock" );
    Action( "( %s, %s, %d )", Label( len->lp ), Tipe( len_type ), off );
    TypDbg( "(%d) IndCharBlock len==%s, len_type==%s, offset==%d%n", ++TypeIdx,
            Label( len->lp ), Tipe( len_type ), off );
    Action( " -> %d%n", TypeIdx );
    if( !len->lp->ddef ) {
        CGError( "Label not defined in data segment" );
    }
    DRefLabel( len->lp );
    return( TypeIdx );
}
extern  dbg_type        DBLocCharBlock( dbg_loc loc, cg_type len_type ) {
//=======================================================================

    Action( "DBLocCharBlock" );
    Action( "( %s, %s )", Location( loc ), Tipe( len_type ) );
    TypDbg( "(%d) LocCharBlock len==%s, len_type==%s", ++TypeIdx,
            Location( loc ), Tipe( len_type ) );
    Action( " -> %d%n", TypeIdx );
    return( TypeIdx );
}
extern  dbg_type        DBDereference( cg_type ptr_type, dbg_type base ) {
//=======================================================================

    Action( "DBDereference" );
    Action( "( %s, %d )", Tipe( ptr_type ), base );
    TypDbg( "(%d) DeReference ptr_type==%s, base==%d%n", ++TypeIdx,
            Tipe(ptr_type), base );
    Action( " -> %d%n", TypeIdx );
    return( TypeIdx );
}
extern  dbg_type        DBFtnArray( b *bk, cg_type lo_bound,
                                    cg_type num_elts, int dim_off,dbg_type base ) {
//=======================================================================

    Action( "DBFtnArray" );
    Action( "( %s, %s, %s, %d, %d )", Label( bk->lp ),
            Tipe( lo_bound ), Tipe( num_elts ), dim_off, base );
    TypDbg( "(%d) ADV==%s, lo_bound=%s, num_elts=%s, offset=%d, base==%d%n",
            ++TypeIdx, Label( bk->lp ),
            Tipe( lo_bound ), Tipe( num_elts ),dim_off, base );
    Action( " -> %d%n", TypeIdx );
    if( !bk->lp->ddef ) {
        CGError( "Label not defined in data segment" );
    }
    DRefLabel( bk->lp );
    return( TypeIdx );
}
extern  dbg_type        DBArray( dbg_type idx, dbg_type base ) {
//==============================================================

    Action( "DBArray( %d, %d )", idx, base );
    TypDbg( "(%d) Array index==%d, base==%d%n", ++TypeIdx, idx, base );
    Action( " -> %d%n", TypeIdx );
    return( TypeIdx );
}
extern  dbg_type        DBIntArray( unsigned_32 hi, dbg_type base ) {
//===================================================================

    Action( "DBIntArray( %l, %d )", hi, base );
    TypDbg( "(%d) Int Array hi==%l, base==%d%n", ++TypeIdx, hi, base );
    Action( " -> %d%n", TypeIdx );
    return( TypeIdx );
}
extern  dbg_type        DBIntArrayCG( cg_type tipe, unsigned_32 hi, dbg_type base ) {
/*******************************************************************/

    Action( "DBIntArrayCg( %s, %l, %d )", Tipe(tipe), hi, base );
    TypDbg( "(%d) Int Array hi==%l, base==%d%n", ++TypeIdx, hi, base );
    Action( " -> %d%n", TypeIdx );
    return( TypeIdx );
}

extern  array_list  *DBBegArray(  dbg_type base, cg_type tipe, bool is_col_major ){
/******************************************************************************/
    array_list *ar;
    type_def   *tipe_addr;

    Action( "DBBegArray( %l, %s, %d )", base, Tipe( tipe ),
                     is_col_major );
    ar = CGAlloc( sizeof( *ar ) );
    tipe_addr = TypeAddress( tipe );
    ar->num = 0;
    ar->size = tipe_addr->length;
    ar->list = NULL;
    ar->base = base;
    ar->is_col_major = is_col_major;
    Action( " -> %p%n", ar );
    return( ar );
}

static  void    AddDim( array_list *ar, dim_any *dim ){
/******************************************************/

    dim_entry *curr;
    dim_entry **owner;

    owner = &ar->list;
    for(;;) {
        curr = *owner;
        if( curr == NULL ) break;
        owner = &curr->next;
    }
    dim->entry.next = NULL;
    *owner = dim;
    ar->num++;
}

extern  void DBDimCon( array_list *ar, dbg_type idx, signed_32 lo, signed_32 hi ){
/***************************************************/
    dim_con *dim;

    Action( "DBDimCon( %p %d, %l, %l, %d)%n", ar, idx, lo, hi );
    dim = CGAlloc(  sizeof( *dim ) );
    dim->entry.kind = DIM_CON;
    dim->lo = lo;
    dim->hi = hi;
    dim->idx = idx;
    AddDim( ar, dim );
}

extern  void  DBDimVar( array_list *ar,
                        b      *dims, int off,
                        cg_type lo_bound_tipe,
                        cg_type num_elts_tipe ){
/*************************************************/
    dim_var *dim;

    Action( "DBDimVar" );
    Action( "( %p, %s, %s, %s, %d )%n", ar, Label( dims->lp ),
            Tipe( lo_bound_tipe ), Tipe( num_elts_tipe ), off );
    dim = CGAlloc( sizeof( *dim ) );
    dim->entry.kind = DIM_VAR;
    dim->dims = (back_handle)dims;
    dim->off = off;
    dim->lo_bound_tipe = lo_bound_tipe;
    dim->num_elts_tipe = num_elts_tipe;
    AddDim( ar, dim );
}

extern  dbg_type        DBEndArray( array_list  *ar ) {
/*******************************************************/


    Action( "DBEndArray( %p )", ar );
    TypDbg( "(%d) array #dim == %d%n", ++TypeIdx, ar->num );
    CGFree( ar );
    Action( " -> %d%n", TypeIdx );
    return( TypeIdx );
}

extern  dbg_type        DBSubRange( signed_32 lo, signed_32 hi, dbg_type base ) {
//=============================================================================

    Action( "DBSubRange( %l, %l, %d )", lo, hi, base );
    TypDbg( "(%d) Subrange  lo==%l, hi==%l, base==%d%n", ++TypeIdx,
             lo, hi, base );
    Action( " -> %d%n", TypeIdx );
    return( TypeIdx );
}
extern  dbg_type        DBPtr( cg_type ptr_tipe, dbg_type base ) {
//================================================================

    Action( "DBPtr" );

⌨️ 快捷键说明

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