dg.c
来自「开放源码的编译器open watcom 1.6.0版的源代码」· C语言 代码 · 共 1,246 行 · 第 1/3 页
C
1,246 行
/****************************************************************************
*
* 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 <stdio.h>
#include <string.h>
#include <stdarg.h>
#include "standard.h"
#include "cg.h"
#include "bckdef.h"
#include "cgdefs.h"
#include "sysmacro.h"
#include "typclass.h"
#include "typedef.h"
#include "cfloat.h"
#include "cgaux.h"
#include "model.h"
#include "hostsys.h"
#include "cgstub.h"
#include "dbcue.h"
#include "feprotos.h"
#include "stubdata.h"
extern unsigned_16 TypeIdx;
extern type_def *TypeAddress(cg_type);
extern char *ACopyOf(char *);
extern void VerTipe(cg_type ,cg_type *);
extern void CGFree(pointer );
extern char *Tipe(cg_type );
extern char *FtnTipe(dbg_ftn_type );
extern char *Label(l *);
extern void Action(char *,... );
extern void TypDbg(char *,... );
extern void Code(char *,... );
extern char *Name(pointer );
extern void Put(char *,... );
extern void SymDbg(char *,... );
extern void VerBack(b *);
extern char *LToS(signed_32 );
extern void CGError(char *, ... );
extern void DDefLabel(l *);
extern void DRefLabel(l *);
extern void Find(char *,pointer *,pointer );
extern void DGAlign( uint algn ) {
//====================================
Action( "DGAlign( %d )%n", algn );
Locs[ CurSeg ] += (Locs[ CurSeg ] + algn - 1) % algn;
Put(" align to %d byte boundry (%d)%n", algn, Locs[ CurSeg ] );
}
extern uint DGSeek( unsigned_32 where ) {
//====================================
unsigned_32 old;
Action( "DGSeek( %l )", where );
Put( " seek to location %l%n", where );
old = Locs[ CurSeg ];
Locs[ CurSeg ] = where;
Action( " -> %l%n", old );
return( old );
}
extern void DGUBytes( unsigned_32 len ) {
//===========================================
Action( "DGUBytes( %l )%n", len );
Put(" %l B(?)%n", len );
Locs[ CurSeg ] += len;
}
extern void DGIBytes( unsigned_32 len, byte pat ) {
//=============================================
Action( "DGIBytes( %l, %h )%n", len, pat );
Put(" %d B(%h)%n", len, pat );
Locs[ CurSeg ] += len;
}
extern void DGLabel( b *bk ) {
//================================
Action( "DGLabel" );
Action( "( %s = %s )%n", Label( bk->lp ), Name( bk->s ) );
DDefLabel( bk->lp );
VerBack(bk);
PutName(bk);
bk->loc = Locs[ CurSeg ];
Put(":%n");
}
extern unsigned_32 DGTell() {
//========================
Action( "DGTell() -> %l%n", Locs[ CurSeg ] );
return( Locs[ CurSeg ] );
}
extern unsigned_32 DGBackTell( b *bk ) {
//===================================
Action( "DGBackTell" );
VerBack(bk);
if( !bk->lp->ddef ) {
CGError( "Label not yet defined in data segment" );
}
DRefLabel( bk->lp );
Action( "( %s ) -> %l%n", Label( bk->lp ), bk->loc );
return( bk->loc );
}
extern void DGFEPtr( sym s, cg_type t, signed_32 o ) {
//==========================================================
b *bk;
Action( "DGFEPtr" );
Action( "( %s, %s, %l )%n", Name( s ), Tipe( t ), o );
bk = (b*)FEBack(s);
VerBack(bk);
if( !( FEAttr( s ) & FE_IMPORT ) ) DRefLabel( bk->lp );
Put( " A(" );
PutName(bk);
Put( ") + %l %s%n",o,Tipe(t) );
Locs[ CurSeg ] += TypeAddress( t )->length;
}
extern void DGBackPtr( b *bk, segment_id s, signed_32 o, cg_type t ) {
//==========================================================================
Action( "DGBackPtr" );
Action( "( %s, %d, %l, %s )%n", Label( bk->lp ), s, o, Tipe( t ) );
VerBack(bk);
DRefLabel( bk->lp );
Put( " A(" );
PutName(bk);
Put( ") + %l (seg %d) %s%n",o,s,Tipe(t) );
Locs[ CurSeg ] += TypeAddress( t )->length;
}
extern void DGBytes( unsigned_32 len, byte *bp ) {
//============================================
Action( "DGBytes( %l, ... )%n", len );
Put( " " );
while( len != 0 ) {
Put( "%h ",*bp++ );
--len;
}
Put( "%n" );
Locs[ CurSeg ] += len;
}
extern void PutName( b *bk ) {
//================================
Put( "%s", Label( bk->lp ) );
if( bk->s != NULL ) {
Put( " [ %s ]", Name( bk->s ) );
}
}
extern void DGInteger( unsigned_32 i, cg_type t ) {
//======================================================
Action( "DGInteger" );
VerTipe( t,DGIntTypes );
Action( "( %l, %s )%n", i, Tipe( t ) );
Put( " I(%l)", i );
Put( " %s%n", Tipe(t) );
Locs[ CurSeg ] += TypeAddress( t )->length;
}
extern void DGCFloat( pointer f, cg_type t ) {
//================================================
char buffer[ 80 ];
CFCnvFS( f, buffer, 80 );
Put( " F(%s)", buffer );
Put( " %s%n", Tipe(t) );
Locs[ CurSeg ] += TypeAddress( t )->length;
}
extern void DGFloat( char *f, cg_type t ) {
//=============================================
Action( "DGFloat" );
VerTipe( t,FloatTypes );
Put( " F(%s) %s%n", f, Tipe(t) );
Action( "( %s, %s )%n", f, Tipe( t ) );
Locs[ CurSeg ] += TypeAddress( t )->length;
}
extern void DGChar( char c ) {
//================================
Action( "DGChar( %c )%n", c );
Put( " C(%c)%n",c );
Locs[ CurSeg ] += sizeof( char );
}
extern void DGString( char *s, uint len ) {
//============================================
Action( "DGString( ..., %d )%n", len );
Locs[ CurSeg ] += len;
Put( " S(" );
for( ; len != 0; --len ) {
Put( "%c", *s++ );
}
Put( ")%n",s );
}
enum {
LOC_SYM,
LOC_CONST,
LOC_TEMP,
LOP_IND_2,
LOP_IND_4,
LOP_IND_ADDR286,
LOP_IND_ADDR386,
LOP_ZEB,
LOP_ZEW,
LOP_MK_FP,
LOP_POP,
LOP_XCHG,
LOP_ADD,
LOP_DUP
};
static char *LopNames[] = {
"",
"",
"IND_2",
"IND_4",
"IND_A286",
"IND_A386",
"ZEB",
"ZEW",
"MK_FP",
"POP",
"XCHG",
"ADD",
"DUP"
};
typedef struct location {
struct location *next;
union {
t *be_sym;
cg_sym_handle fe_sym;
unsigned stk;
unsigned_32 val;
} u;
byte class;
} location;
static char *DBOpNames[] = {
"DB_OP_POINTS",
"DB_OP_ZEX",
"DB_OP_XCHG",
"DB_OP_MK_FP",
"DB_OP_ADD",
"DB_OP_DUP",
"DB_OP_POP"
};
static char *DoLocation( char *str, dbg_loc loc ) {
/*************************************************/
if( loc == NULL ) return( str );
str = DoLocation( str, loc->next );
*str++ = ' ';
switch( loc->class ) {
case LOC_SYM:
sprintf( str, "{%s}", FEName( (pointer)loc->u.fe_sym ) );
break;
case LOC_TEMP:
sprintf( str, "{T%ld}", loc->u.be_sym->i );
break;
case LOC_CONST:
sprintf( str, "{%ld}", loc->u.val );
break;
case LOP_XCHG:
sprintf( str, "XCHG[%d]", loc->u.stk );
break;
default:
strcpy( str, LopNames[loc->class] );
break;
}
str += strlen( str );
return( str );
}
static char *Location(dbg_loc loc) {
/**********************************/
static char buff[256];
char *p;
buff[0] = '(';
p = DoLocation( buff+1, loc );
*p++ = ')';
*p = '\0';
return( buff );
}
static dbg_loc LocCreate( dbg_loc loc, unsigned typ ) {
/**************************************************************/
dbg_loc new;
new = CGAlloc( sizeof( location ) );
new->next = loc;
new->class = typ;
return( new );
}
extern dbg_loc DBLocInit() {
/***********************************/
Action( "DBLocInit ==> NULL%n" );
return( NULL );
}
extern dbg_loc DBLocSym( dbg_loc loc, cg_sym_handle sym ) {
/****************************************************************/
Action( "DBLocSym( %p, %s ) ==>", loc, FEName((pointer)sym) );
loc = LocCreate( loc, LOC_SYM );
loc->u.fe_sym = sym;
Action( "%p%n", loc );
return( loc );
}
extern dbg_loc DBLocTemp( dbg_loc loc, t *tm ) {
/****************************************************************/
Action( "DBLocTemp" );
Find( "back end temp", (pointer *)TempList, tm );
Action( "( %p, T%ld ) ==>", loc, tm->i );
loc = LocCreate( loc, LOC_TEMP );
loc->u.be_sym = tm;
Action( "%p%n", loc );
return( loc );
}
extern dbg_loc DBLocConst( dbg_loc loc, unsigned_32 val ) {
/******************************************************************/
Action( "DBLocConst( %p, %l ) ==>", loc, val );
loc = LocCreate( loc, LOC_CONST );
loc->u.val = val;
Action( "%p%n", loc );
return( loc );
}
extern dbg_loc DBLocOp(dbg_loc loc, dbg_loc_op op, unsigned other) {
/***************************************************************************/
unsigned stkop;
Action( "DBLocOp( %p, %s, %d ) ==>", loc, DBOpNames[ op ], other );
stkop = 0;
switch( op ) {
case DB_OP_POINTS:
VerTipe( other, NULL );
switch( TypeAddress( other )->refno ) {
#if !(_TARGET & _TARG_80386)
case T_NEAR_POINTER:
case T_NEAR_CODE_PTR:
#endif
case T_UINT_2:
case T_INT_2:
stkop = LOP_IND_2;
break;
#if _TARGET & _TARG_80386
case T_NEAR_POINTER:
case T_NEAR_CODE_PTR:
#endif
case T_UINT_4:
case T_INT_4:
stkop = LOP_IND_4;
break;
case T_LONG_POINTER:
case T_HUGE_POINTER:
case T_LONG_CODE_PTR:
#if _TARGET & _TARG_80386
stkop = LOP_IND_ADDR386;
#else
stkop = LOP_IND_ADDR286;
#endif
break;
default:
CGError( "Invalid DB points type %d\n", other );
break;
}
loc = LocCreate( loc, stkop );
break;
case DB_OP_ZEX:
VerTipe( other, NULL );
switch( TypeAddress( other )->length ) {
case 1:
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?