dftypes.c
来自「开放源码的编译器open watcom 1.6.0版的源代码」· C语言 代码 · 共 794 行 · 第 1/2 页
C
794 行
/****************************************************************************
*
* Open Watcom Project
*
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
*
* ========================================================================
*
* This file contains Original Code and/or Modifications of Original
* Code as defined in and that are subject to the Sybase Open Watcom
* Public License version 1.0 (the 'License'). You may not use this file
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
* provided with the Original Code and Modifications, and is also
* available at www.sybase.com/developer/opensource.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
* NON-INFRINGEMENT. Please see the License for the specific language
* governing rights and limitations under the License.
*
* ========================================================================
*
* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE
* DESCRIBE IT HERE!
*
****************************************************************************/
#include "standard.h"
#include "coderep.h"
#include "cgdefs.h"
#include "sysmacro.h"
#include "symdbg.h"
#include "model.h"
#include "typedef.h"
#include "zoiks.h"
#include "dbgstrct.h"
#include <stdio.h>
#include <stdarg.h>
#include <setjmp.h>
#include <stdlib.h>
#include <string.h>
#include "dw.h"
#include "dwarf.h"
#define BY_CG
#include "cgprotos.h"
extern uint Length(char*);
extern byte *Copy(void*,void*,uint);
extern type_def *TypeAddress(cg_type);
extern type_length NewBase(name*);
extern dw_loc_handle DBGLoc2DF( dbg_loc loc );
extern void DBLocFini( dbg_loc loc );
extern uint DFRegMap( hw_reg_set hw_reg );
extern void DFOutReg( dw_loc_id locid, name *reg );
extern void DFOutRegInd( dw_loc_id locid, name *reg );
extern dw_client Client;
extern dbg_type DFFtnType( char *name, dbg_ftn_type tipe ) {
/*****************************************************************/
dbg_type ret;
unsigned size;
size = (tipe & 0x0f)+1;
ret = DWFundamental( Client, name, DW_FT_COMPLEX_FLOAT, size );
return( ret );
}
extern dbg_type DFScalar( char *name, cg_type tipe ) {
/************************************************************/
type_def *tipe_addr;
int class;
dbg_type ret;
tipe_addr = TypeAddress( tipe );
if( tipe_addr->attr & TYPE_FLOAT ){
class = DW_FT_FLOAT;
}else if( strcmp( "char", name ) == 0 ){
if( tipe_addr->attr & TYPE_SIGNED ){
class = DW_FT_SIGNED_CHAR;
}else{
class = DW_FT_UNSIGNED_CHAR;
}
}else if( strcmp( "unsigned char", name ) == 0 ){
class = DW_FT_UNSIGNED_CHAR;
}else if( strcmp( "signed char", name ) == 0 ){
class = DW_FT_SIGNED_CHAR;
}else if( tipe_addr->attr & TYPE_SIGNED ){
class = DW_FT_SIGNED;
}else{
class = DW_FT_UNSIGNED;
}
ret = DWFundamental( Client, name, class, tipe_addr->length );
return( ret );
}
enum scope_name {
SCOPE_TYPEDEF = 0,
SCOPE_STRUCT = 1,
SCOPE_UNION = 2,
SCOPE_ENUM = 3,
SCOPE_CLASS = 4,
SCOPE_MAX
};
static char const ScopeNames[SCOPE_MAX][7] = {
"",
"struct",
"union",
"enum",
"class"
};
extern char const *DFScopeName( dbg_type scope ){
return( ScopeNames[scope] );
}
extern dbg_type DFScope( char *name ) {
/*********************************************/
enum scope_name index;
for( index = 0; index < SCOPE_MAX; ++index ){
if( strcmp( name, ScopeNames[index] ) == 0 )break;
}
return( index );
}
extern void DFDumpName( name_entry *name, dbg_type tipe ) {
/***********************************************************/
if( name->scope == SCOPE_TYPEDEF ){
tipe = DWTypedef( Client, tipe, name->name, 0, 0 );
}
name->refno = tipe; /* link in typedef sym to type */
}
extern void DFBackRefType( name_entry *name, dbg_type tipe ){
/******************************************************/
name = name;
tipe = tipe;
Zoiks( ZOIKS_108 );
}
extern dbg_type DFCharBlock( unsigned_32 len ) {
/******************************************************/
dbg_type ret;
ret = DWString( Client, NULL, len, NULL, NULL, 0 );
return( ret );
}
extern dbg_type DFIndCharBlock( back_handle len, cg_type len_type,
int off ) {
/************************************************************************/
dbg_type ret;
dw_loc_id len_locid;
dw_loc_handle len_loc;
type_def *tipe_addr;
len_locid = DWLocInit( Client );
DWLocSym( Client, len_locid, (dw_sym_handle)len, DW_W_LABEL );
DWLocOp( Client, len_locid, DW_LOC_plus_uconst, off );
len_loc = DWLocFini( Client, len_locid );
tipe_addr = TypeAddress( len_type );
ret = DWString( Client, len_loc, tipe_addr->length, NULL, 0, 0 );
DWLocTrash( Client, len_loc );
return( ret );
}
extern dbg_type DFLocCharBlock( dbg_loc loc, cg_type len_type ) {
/***********************************************************************/
dw_loc_handle len_loc;
type_def *tipe_addr;
dbg_type ret;
//NYI: damned if I know what to do.
len_loc = DBGLoc2DF( loc );
tipe_addr = TypeAddress( len_type );
ret = DWString( Client, len_loc, tipe_addr->length, NULL, 0, 0 );
if( len_loc != NULL ){
DWLocTrash( Client, len_loc );
}
return( ret );
}
extern dbg_type DFArray( dbg_type idx, dbg_type base ) {
/**************************************************************/
dbg_type ret;
dw_dim_info info;
/* need subrange types in dwarf library */
ret = DWBeginArray( Client, base, 0, NULL, 0, 0 );
info.index_type = idx;
info.lo_data = 0;
info.hi_data = 0;
DWArrayDimension( Client, &info );
DWEndArray( Client );
return( ret );
}
extern dbg_type DFIntArray( unsigned_32 hi, dbg_type base ) {
/*******************************************************************/
dbg_type ret;
ret = DWSimpleArray( Client, base, hi+1 );
return( ret );
}
static dw_handle MKBckVar( back_handle bck, int off, dw_handle tipe ){
dw_loc_id locid;
dw_loc_handle dw_loc;
dw_loc_handle dw_segloc;
dw_handle obj;
locid = DWLocInit( Client );
DWLocSym( Client, locid, (dw_sym_handle)bck, DW_W_LABEL );
DWLocOp( Client, locid, DW_LOC_plus_uconst, off );
dw_loc = DWLocFini( Client, locid );
#if _TARGET &( _TARG_IAPX86 | _TARG_80386 )
if( _IsTargetModel( FLAT_MODEL ) ) {
dw_segloc = NULL;
}else{
locid = DWLocInit( Client );
DWLocSym( Client, locid, (dw_sym_handle)bck, DW_W_LABEL_SEG );
dw_segloc = DWLocFini( Client, locid );
}
#else
dw_segloc = NULL;
#endif
obj = DWVariable( Client, tipe, dw_loc,
NULL, dw_segloc, "__bck", NULL, 0 );
DWLocTrash( Client, dw_loc );
if( dw_segloc != NULL ){
DWLocTrash( Client, dw_segloc );
}
return( obj );
}
extern dbg_type DFEndArray( array_list *ar ){
/************************************************/
dw_dim_info info;
dw_vardim_info varinfo;
dbg_type lo_tipe;
dbg_type count_tipe;
type_def *tipe_addr;
dim_any *dim;
dbg_type ret;
ret = DWBeginArray( Client, ar->base, 0, NULL, 0, 0 );
lo_tipe = DBG_NIL_TYPE;
tipe_addr = NULL;
count_tipe = DBG_NIL_TYPE;
for(;;) {
dim = ar->list;
if( dim == NULL ) break;
switch( dim->entry.kind ) {
case DIM_CON:
info.index_type = dim->con.idx;
info.lo_data = dim->con.lo;
info.hi_data = dim->con.hi;
DWArrayDimension( Client, &info );
break;
case DIM_VAR:
if( lo_tipe == DBG_NIL_TYPE ){
tipe_addr = TypeAddress( dim->var.lo_bound_tipe );
lo_tipe = DFScalar( "", dim->var.lo_bound_tipe );
count_tipe = DFScalar( "", dim->var.num_elts_tipe );
}
varinfo.index_type = lo_tipe;
varinfo.lo_data = MKBckVar( dim->var.dims,
dim->var.off, lo_tipe);
varinfo.count_data = MKBckVar( dim->var.dims,
dim->var.off+tipe_addr->length, count_tipe);
DWArrayVarDim( Client, &varinfo );
break;
}
ar->list = dim->entry.next;
_Free( dim, sizeof( field_entry ) );
}
DWEndArray( Client );
return( ret );
}
extern dbg_type DFFtnArray( back_handle dims, cg_type lo_bound_tipe,
cg_type num_elts_tipe, int off,
dbg_type base ) {
/***************************************************************************/
dw_vardim_info varinfo;
dbg_type lo_tipe;
dbg_type count_tipe;
type_def *tipe_addr;
dbg_type ret;
ret = DWBeginArray( Client, base, 0,NULL, 0, 0 );
tipe_addr = TypeAddress( lo_bound_tipe );
lo_tipe = DFScalar( "", lo_bound_tipe );
count_tipe = DFScalar( "", num_elts_tipe );
varinfo.index_type = lo_tipe;
varinfo.lo_data = MKBckVar( dims, off, lo_tipe);
varinfo.count_data = MKBckVar( dims, off+tipe_addr->length, count_tipe);
DWArrayVarDim( Client, &varinfo );
DWEndArray( Client );
return( ret );
}
extern dbg_type DFSubRange( signed_32 lo, signed_32 hi,
dbg_type base ) {
/***************************************************/
/* need some dwarflib support */
lo = lo;
hi = hi;
base = base;
return( 0 );
}
static uint DFPtrClass( cg_type ptr_type ){
/*******************************************************************/
type_def *tipe_addr;
uint flags;
if( (ptr_type == T_POINTER || ptr_type == T_CODE_PTR)
#if _TARGET &( _TARG_IAPX86 | _TARG_80386 )
&& _IsTargetModel( FLAT_MODEL ) ){
#else
){
#endif
flags = DW_PTR_TYPE_DEFAULT;
}else{
tipe_addr = TypeAddress( ptr_type );
switch( tipe_addr->refno ) {
case T_HUGE_POINTER:
flags = DW_PTR_TYPE_HUGE16;
// flags = DW_PTR_TYPE_FAR16;
break;
case T_LONG_POINTER:
case T_LONG_CODE_PTR:
if( tipe_addr->length == 6 ){
flags = DW_PTR_TYPE_FAR32;
}else{
flags = DW_PTR_TYPE_FAR16;
}
break;
case T_NEAR_POINTER:
case T_NEAR_CODE_PTR:
if( tipe_addr->length == 4 ){
flags = DW_PTR_TYPE_NEAR32;
}else{
flags = DW_PTR_TYPE_NEAR16;
}
break;
}
}
return( flags );
}
extern dbg_type DFDereference( cg_type ptr_type, dbg_type base ) {
/************************************************************************/
dbg_type ret;
uint flags;
flags = DFPtrClass( ptr_type );
ret = DWPointer( Client, base, flags | DW_FLAG_REFERENCE );
return( ret );
}
extern dbg_type DFPtr( cg_type ptr_type, dbg_type base ) {
/****************************************************************/
dbg_type ret;
uint flags;
flags = DFPtrClass( ptr_type );
ret = DWPointer( Client, base, flags );
return( ret );
}
extern void DFBegStruct( struct_list *st ){
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?