s37dbtyp.c

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

C
668
字号
        if( curr == NULL ) break;
        if( val < curr->val ) break;
        owner = &curr->next;
    }
    cons->next = curr;
    *owner = cons;
    en->index++;
}

extern  dbg_type DBEndEnum( cdebug_type_enums *en ){
/*******Add enum type******************************/
    return( AddType( en ) );
}


extern  proc_list       *DBBegProc(  cg_type call_type,  dbg_type  ret ) {
/****start proc type ****************************************************/

    proc_list   *pr;

    call_type = 0;
    _Alloc( pr, sizeof( proc_list ) );
    pr->num = 0;
    pr->list = NULL;
    pr->call = NULL;
    pr->ret = ret;
    return(pr);
}


extern  void    DBAddParm( proc_list *pr, dbg_type tipe ) {
/*********************************************************/
#if 0  /* not sure if needed */
    parm_entry  *parm;
    parm_entry  **owner;

    _Alloc( parm, sizeof( parm_entry ) );
    pr->num++;
    owner = &pr->list;
    while( *owner != NULL ) {
        owner = &(*owner)->next;
    }
    *owner = parm;
    parm->tipe = tipe;
    parm->next = NULL;
#else
    pr = NULL;
    tipe = 0;
#endif
}


extern  dbg_type        DBEndProc( proc_list  *pr ) {
/*****Add proc type*********************************/

    parm_entry  *parm;
    parm_entry  *old;

    parm = pr->list;
    while( parm != NULL ){
        old = parm;
        parm = parm->next;
        _Free( old, sizeof( *old ) );
    }
    _Free( pr, sizeof( *pr ) );
    return( 0 );
}


static dbg_type AddType( cdebug_type_any *new ) {
/** Add type to type list and bump type index */
    new->common.next = *TypeNext;
    new->common.refno = ++TypeIdx;
    *TypeNext = new;
    ++TTagCount;
    TypeNext = &new->common.next;
    return( TypeIdx );
}

static cdebug_type_any *FindType( dbg_type refno ) {
/** Look up type refno if no there return NULL  ***/
    cdebug_type_any *curr;

    curr = TypeHead;
    while( curr != NULL ) {
        if( curr->common.refno == refno ) {
            break;
        }
        curr = curr->common.next;
    }
    return( curr );
}

static void AddTName( char *name, dbg_type tref ) {
/** Add name to type name list and bump type name index */
    cdebug_type_name *new;
    uint              len;

    len = Length( name );
    _Alloc( new, sizeof( *new )-1 + len );
    new->tref = tref;
    new->id.len = len;
    Copy( name, new->id.name, len );
    new->next = *TNameNext;
    *TNameNext = new;
    TNameNext = &new->next;
    NTagCount++;   /* bump type name count */
}

static void  AddTId( id_entry *id, dbg_type tref ) {
/** Add id to type name list and bump type name index */
    cdebug_type_name *new;

    _Alloc( new, sizeof( *new )-1 + id->len );
    new->tref = tref;
    new->id.len = id->len;
    Copy( id->name, new->id.name, id->len );
    new->next = *TNameNext;
    *TNameNext = new;
    TNameNext = &new->next;
    NTagCount++;   /* bump type name count */
}

static dbg_type MkBitType( byte start, byte len ){
/**** make a cdebug bitfield type****************/
    cdebug_type_field *new;
    unsigned long mask;

    new = _Alloc( new, sizeof( *new ) );
    new->common.class = CDEBUG_TYPE_FIELD;
    new->common.len = 0;
    new->len = len;
    new->shift = sizeof(mask)*8-(start+len);
    mask = 0xffffffff;
    mask <<= sizeof(mask)*8-len;
    mask >>= start;
    new->mask = mask;
    return( AddType( new ) );
}

extern  void    DBTypInit( void ) {
/*****************************/

    TypeIdx   = 0;  /* type refno      */
    TTagCount = 0;  /* type tag count  */
    NTagCount = 0;   /* type name count */
    TypeHead = NULL;
    TypeNext = &TypeHead;
    TNameHead = NULL;
    TNameNext = &TNameHead;
}

extern  void    DbgTypeTags( handle dbgfile ) {
/*** write dbg info on types  *************/

    TTags( dbgfile, TypeHead, TTagCount );
    NTags( dbgfile, TNameHead, NTagCount );
}

static void TTags( handle dbgfile, cdebug_type_any *list, int index ) {
/**** Put out type count and type tags************/
    char             tagbuff[1+4+4+4];
    cdebug_type_any *old;
    int              size;

    tagbuff[0] = 't';
    DbgFmtInt( &tagbuff[1], index );
    PutStream( dbgfile, tagbuff, 5 );
    tagbuff[0] = 'T';
    while( list != NULL ) {
        DbgFmtInt( &tagbuff[1], list->common.refno );
        DbgFmtInt( &tagbuff[5], list->common.len );
        DbgFmtInt( &tagbuff[9], list->common.class );
        PutStream( dbgfile, tagbuff, 13 );
        switch( list->common.class ) {
        case CDEBUG_TYPE_INTEGER: /* #bits & sign */
            DbgFmtInt( &tagbuff[1], list->common.len*8 );
            DbgFmtInt( &tagbuff[5], list->scalar.sign );
            PutStream( dbgfile, &tagbuff[1], 8 );
            size = sizeof( cdebug_type_scalar );
            break;
        case CDEBUG_TYPE_FLOAT: /* precision */
            DbgFmtInt( &tagbuff[1], (list->common.len-1)*2 );
            PutStream( dbgfile, &tagbuff[1], 4 );
            size = sizeof( cdebug_type_scalar );
            break;
        case CDEBUG_TYPE_FIELD:
            DbgFmtInt( &tagbuff[1], list->field.len );
            DbgFmtInt( &tagbuff[5], list->field.shift );
            DbgFmtInt( &tagbuff[9], list->field.mask );
            PutStream( dbgfile, &tagbuff[1], 12 );
            size = sizeof( cdebug_type_field );
            break;
        case CDEBUG_TYPE_POINTER:
            DbgFmtInt( &tagbuff[1], list->pointer.base );
            PutStream( dbgfile, &tagbuff[1], 4 );
            size = sizeof( cdebug_type_pointer );
            break;
        case CDEBUG_TYPE_ARRAY:
            DbgFmtInt( &tagbuff[1], list->array.base );
            DbgFmtInt( &tagbuff[5], list->array.length );
            PutStream( dbgfile, &tagbuff[1], 8 );
            size = sizeof( cdebug_type_array );
            break;
        case CDEBUG_TYPE_STRUCT:
            DbgStruct( dbgfile, list );
            size = sizeof( cdebug_type_tags );
            break;
        case CDEBUG_TYPE_UNION:
            DbgUnion( dbgfile, list );
            size = sizeof( cdebug_type_tags );
            break;
        case CDEBUG_TYPE_ENUMS:
            DbgEnum( dbgfile, list );
            size = sizeof( cdebug_type_enums );
            break;
        }
        old = list;
        list = list->common.next;
        _Free( old, size );
    }

}

static void DbgStruct( handle dbgfile, cdebug_type_tags *tags ) {
/**** Put out structure member list info*************************/
    char                *tag, tagbuff[1+4+4+4+256];
    cdebug_member_entry *list, *old;
    int                  index;

    if( tags->id != NULL ){
        tag=DbgFmtStr( &tagbuff[0], tags->id->name, tags->id->len );
        _Free( tags->id, sizeof( *tags->id )-1 +tags->id->len );
    }else{
        tag=DbgFmtInt( &tagbuff[0], 0 );
    }
    PutStream( dbgfile, tagbuff, tag-tagbuff );
    tagbuff[0] = 'f';
    DbgFmtInt( &tagbuff[1], tags->index );
    PutStream( dbgfile, tagbuff, 5 );
    list = tags->list;
    index = 0;
    tagbuff[0] = 'F';
    while( list != NULL ){
        DbgFmtInt( &tagbuff[1], ++index );
        DbgFmtInt( &tagbuff[5], list->tref  );
        DbgFmtInt( &tagbuff[9], list->off  );
        tag=DbgFmtStr( &tagbuff[13], list->id.name, list->id.len );
        PutStream( dbgfile, tagbuff, tag-tagbuff );
        old = list;
        list = list->next;
        _Free( old, sizeof( *old ) + old->id.len );
    }

}

static void DbgUnion( handle dbgfile, cdebug_type_tags *tags ) {
/**** Put out union member list info*************************/
    char                *tag, tagbuff[1+4+4+4+256];
    cdebug_member_entry *list, *old;

    if( tags->id != NULL ){
        tag=DbgFmtStr( &tagbuff[0], tags->id->name, tags->id->len );
        _Free( tags->id, sizeof( *tags->id )-1 +tags->id->len );
    }else{
        tag=DbgFmtInt( &tagbuff[0], 0 );
    }
    PutStream( dbgfile, tagbuff, tag-tagbuff );
    tagbuff[0] = 'u';
    DbgFmtInt( &tagbuff[1], tags->index );
    PutStream( dbgfile, tagbuff, 5 );
    list = tags->list;
    tagbuff[0] = 'U';
    while( list != NULL ){
        DbgFmtInt( &tagbuff[1], list->tref  );
        tag=DbgFmtStr( &tagbuff[5], list->id.name, list->id.len );
        PutStream( dbgfile, tagbuff, tag-tagbuff );
        old = list;
        list = list->next;
        _Free( old, sizeof( *old ) + old->id.len );
    }

}

static void DbgEnum( handle dbgfile, cdebug_type_enums *enums ) {
/**** Put out union member list info*************************/
    char                *tag, tagbuff[1+4+4+4+256];
    cdebug_enum         *list, *old;

    if( enums->id != NULL ){
        tag=DbgFmtStr( &tagbuff[0], enums->id->name, enums->id->len );
        _Free( enums->id, sizeof( *enums->id )-1 +enums->id->len );
    }else{
        tag=DbgFmtInt( &tagbuff[0], 0 );
    }
    PutStream( dbgfile, tagbuff, tag-tagbuff );
    tagbuff[0] = 'e';
    DbgFmtInt( &tagbuff[1], enums->index );
    PutStream( dbgfile, tagbuff, 5 );
    list = enums->list;
    tagbuff[0] = 'E';
    while( list != NULL ){
        tag=DbgFmtStr( &tagbuff[1], list->id.name, list->id.len );
        tag=DbgFmtInt( tag, list->val );
        PutStream( dbgfile, tagbuff, tag-tagbuff );
        old = list;
        list = list->next;
        _Free( old, sizeof( *old ) + old->id.len );
    }

}

static void NTags( handle dbgfile, cdebug_type_name *list, int index ) {
/**** Put out type name count and type name tags************/
    char             *tag, tagbuff[1+4+256];
    cdebug_type_name *old;
    int              size;

    tagbuff[0] = 'n';
    DbgFmtInt( &tagbuff[1], index );
    PutStream( dbgfile, tagbuff, 5 );
    tagbuff[0] = 'N';
    while( list != NULL ) {
        DbgFmtInt( &tagbuff[1], list->tref );
        tag=DbgFmtStr( &tagbuff[5], list->id.name, list->id.len );
        PutStream( dbgfile, tagbuff, tag-tagbuff );
        old = list;
        size = sizeof( *list ) + list->id.len;
        list = list->next;
        _Free( old, size );
    }

}

⌨️ 快捷键说明

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