intrface.c
来自「开放源码的编译器open watcom 1.6.0版的源代码」· C语言 代码 · 共 1,942 行 · 第 1/4 页
C
1,942 行
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
/*% %%*/
/*% Back Handles %%*/
/*% %%*/
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
#define PTR_INT( x ) (*(pointer_int*)&(x))
#define FAKE_BACK ((pointer_int)1)
#define REAL_BACK( bck ) ( ( PTR_INT( bck ) & FAKE_BACK ) == 0 )
#define RETURN_NULL (pointer)1
#define RETURN_NORMAL NULL
static pointer NewBackReturn = RETURN_NORMAL;
extern pointer LkAddBack( sym_handle sym, pointer curr_back )
/************************************************************/
{
bck_info *bck;
if( curr_back == NULL ) {
NewBackReturn = RETURN_NULL;
} else {
NewBackReturn = (pointer)( PTR_INT( curr_back ) | FAKE_BACK );
}
bck = FEBack( sym );
NewBackReturn = RETURN_NORMAL;
return( (pointer)( PTR_INT( bck ) & ~FAKE_BACK ) );
}
extern pointer SymBack( pointer sym )
/***********************************/
{
bck_info *bck;
bck = FEBack( sym );
return( (pointer)( PTR_INT( bck ) & ~FAKE_BACK ) );
}
static void AllocMoreBckInfo( void )
/**********************************/
{
uback_info *p;
bck_info_block *carve_block;
int i;
_Alloc( carve_block, sizeof( bck_info_block ) );
if( carve_block != NULL ) {
carve_block->next = BckInfoCarveHead; // link into big list
BckInfoCarveHead = carve_block;
p = &carve_block->bck_infos[0];
BckInfoHead = p;
for( i = 0; i < (MAX_BCK_INFO-1); i++ ) {
p->link = p + 1;
++p;
}
p->link = NULL;
}
}
extern back_handle _CGAPI BENewBack( sym_handle sym )
/*********************************************************/
{
bck_info *bck;
#ifndef NDEBUG
EchoAPI( "BENewBack( %s )", sym );
#endif
if( NewBackReturn == RETURN_NULL ) {
#ifndef NDEBUG
EchoAPI( " -> %B\n", NULL );
#endif
return( NULL );
}
if( NewBackReturn != RETURN_NORMAL ) {
#ifndef NDEBUG
EchoAPI( " -> %B\n", NewBackReturn );
#endif
return( NewBackReturn );
}
// _Alloc( bck, sizeof( bck_info ) );
if( BckInfoHead == NULL ) {
AllocMoreBckInfo();
}
bck = &BckInfoHead->bck;
BckInfoHead = BckInfoHead->link;
bck->lbl = AskForLabel( sym );
bck->imp = NOT_IMPORTED;
if( sym == 0 ) {
bck->seg = AskBackSeg();
} else {
bck->seg = FESegID( sym );
}
if( !REAL_BACK( bck ) ) _Zoiks( ZOIKS_067 );
#ifndef NDEBUG
EchoAPI( " -> %B\n", bck );
#endif
return( bck );
}
extern void _CGAPI BEFiniBack( bck_info *bck )
/*************************************************/
{
#ifndef NDEBUG
EchoAPI( "BEFiniBack( %L )\n", bck );
#endif
if( REAL_BACK( bck ) ) TellNoSymbol( bck->lbl );
}
extern void _CGAPI BEFreeBack( bck_info *bck )
/*************************************************/
{
#ifndef NDEBUG
EchoAPI( "BEFreeBack( %L )\n", bck );
#endif
if( REAL_BACK( bck ) ) {
// _Free( bck, sizeof( bck_info ) );
uback_info *p;
p = (uback_info *)bck;
p->link = BckInfoHead;
BckInfoHead = p;
}
}
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
/*% %%*/
/*% Typing information %%*/
/*% %%*/
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
extern void _CGAPI BEDefType( cg_type what, uint align, unsigned_32 len )
/****************************************************************************/
{
align = align;
#ifndef NDEBUG
EchoAPI( "BEDefType( %t, %x, %i )\n", what, align, len );
#endif
TypeDef( what, len, align );
}
extern void _CGAPI BEAliasType( cg_type what, cg_type to )
/*************************************************************/
{
#ifndef NDEBUG
EchoAPI( "BEAliasType( %t, %t )\n", what, to );
#endif
TypeAlias( what, to );
}
extern unsigned_32 _CGAPI BETypeLength( cg_type tipe )
/**********************************************************/
{
#ifndef NDEBUG
unsigned_32 retn;
EchoAPI( "BETypeLength( %t )\n", tipe );
retn = TypeLength( tipe) ;
return EchoAPIIntReturn( retn );
#else
return( TypeLength( tipe ) );
#endif
}
extern uint _CGAPI BETypeAlign( cg_type tipe )
/*************************************************/
{
#ifndef NDEBUG
uint retn;
EchoAPI( "BETypeAlign( %t )\n", tipe );
retn = 1;
return EchoAPIIntReturn( retn );
#else
tipe = tipe;
return( 1 );
#endif
}
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
/*% %%*/
/*% Procedure/parms/autos declaration %%*/
/*% %%*/
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
extern void _CGAPI CGProcDecl( pointer name, cg_type tipe )
/**************************************************************/
{
#ifndef NDEBUG
EchoAPI( "\n" );
EchoAPI( "CGProcDecl( %s, %t )\n", name, tipe );
#endif
if( BGInInline() ) {
BGProcInline( name, TypeAddress( tipe ) );
} else {
TellObjNewProc( name );
BGProcDecl( name, TypeAddress( tipe ) );
}
}
extern void _CGAPI CGParmDecl( pointer name, cg_type tipe )
/**************************************************************/
{
#ifndef NDEBUG
EchoAPI( "CGParmDecl( %s, %t )\n", name, tipe );
#endif
if( BGInInline() ) {
BGParmInline( name, TypeAddress( tipe ) );
} else {
BGParmDecl( name, TypeAddress( tipe ) );
}
}
extern label_handle _CGAPI CGLastParm( void )
/*******************************************/
{
label_handle top;
#ifndef NDEBUG
EchoAPI( "CGLastParm()\n" );
#endif
top = NULL;
if( _IsntModel( NO_OPTIMIZATION ) ) {
if( !BGInInline() ) {
top = BENewLabel();
BGGenCtrl( O_LABEL, NULL, top, TRUE );
}
}
return( top );
}
extern void _CGAPI CGAutoDecl( pointer name, cg_type tipe )
/**************************************************************/
{
#ifndef NDEBUG
EchoAPI( "CGAutoDecl( %s, %t )\n", name, tipe );
#endif
BGAutoDecl( name, TypeAddress( tipe ) );
}
extern void _CGAPI CGReturn( cg_name name, cg_type tipe )
/************************************************************/
{
type_def *new_tipe;
#ifndef NDEBUG
EchoAPI( "CGReturn( %n, %t )\n\n", name, tipe );
if( NULL != name ) {
hdlUseOnce( CG_NAMES, name );
hdlAllUsed( CG_NAMES );
}
#endif
new_tipe = TypeAddress( tipe );
if( name != NULL ) {
name = TGReturn( name, new_tipe ); /* special TGen()*/
}
if( BGInInline() ) {
BGRetInline( name, new_tipe );
} else {
BGReturn( name, new_tipe );
}
}
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
/*% %%*/
/*% Code generator actions %%*/
/*% %%*/
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
/**/
/* Leaf nodes*/
/**/
extern cg_name _CGAPI CGVarargsBasePtr( cg_type tipe )
/*****************************************************/
{
#ifndef NDEBUG
tn retn;
EchoAPI( "CGVarargsBasePtr( %t )", tipe );
retn = TGLeaf( BGVarargsBasePtr( TypeAddress( tipe ) ) );
hdlAdd( CG_NAMES, retn );
return EchoAPICgnameReturn( retn );
#else
return( TGLeaf( BGVarargsBasePtr( TypeAddress( tipe ) ) ) );
#endif
}
extern cg_name _CGAPI CGInteger( signed_32 val, cg_type tipe )
/*************************************************************/
{
#ifndef NDEBUG
tn retn;
EchoAPI( "CGInteger( %i, %t )", val, tipe );
verifyNotUserType( tipe );
retn = TGLeaf( BGInteger( val, TypeAddress( tipe ) ) );
hdlAdd( CG_NAMES, retn );
return EchoAPICgnameReturn( retn );
#else
return( TGLeaf( BGInteger( val, TypeAddress( tipe ) ) ) );
#endif
}
extern cg_name _CGAPI CGInt64( signed_64 val, cg_type tipe )
/***********************************************************/
{
#ifndef NDEBUG
tn retn;
EchoAPI( "CGInt64( %x %x, %t )"
, val.u._32[ I64LO32 ]
, val.u._32[ I64HI32 ]
, tipe );
verifyNotUserType( tipe );
retn = TGLeaf( BGInt64( val, TypeAddress( tipe ) ) );
hdlAdd( CG_NAMES, retn );
return EchoAPICgnameReturn( retn );
#else
return( TGLeaf( BGInt64( val, TypeAddress( tipe ) ) ) );
#endif
}
extern cg_name _CGAPI CGFloat( char *num, cg_type tipe )
/*******************************************************/
{
#ifndef NDEBUG
tn retn;
EchoAPI( "CGFloat( %c, %t )", num, tipe );
verifyNotUserType( tipe );
retn = TGLeaf( BGFloat( num, TypeAddress( tipe ) ) );
hdlAdd( CG_NAMES, retn );
return EchoAPICgnameReturn( retn );
#else
return( TGLeaf( BGFloat( num, TypeAddress( tipe ) ) ) );
#endif
}
extern cg_name _CGAPI CGBigInt( float_handle f, cg_type tipe )
/*************************************************************/
{
#ifndef NDEBUG
tn retn;
EchoAPI( "CGBigInt( %x, %t )", f, tipe );
verifyNotUserType( tipe );
retn = TGLeaf( MakeConst( f, TypeAddress( tipe ) ) );
hdlAdd( CG_NAMES, retn );
return EchoAPICgnameReturn( retn );
#else
return( TGLeaf( MakeConst( f, TypeAddress( tipe ) ) ) );
#endif
}
extern cg_name _CGAPI CGFEName( sym_handle sym, cg_type tipe )
/*************************************************************/
{
cg_name leaf;
if( (FEAttr( sym ) & FE_DLLIMPORT )
&& ( FEAuxInfo( sym, CALL_BYTES ) == NULL ) ){
leaf = TGLeaf( BGName( CG_FE, sym, TypeAddress( T_POINTER ) ) );
#ifndef NDEBUG
EchoAPI( "CGFEName( %s, %t ) declspec(dllimport)", sym, tipe );
hdlAdd( CG_NAMES, leaf );
#endif
leaf = CGUnary( O_POINTS, leaf, T_POINTER );
} else {
leaf = TGLeaf( BGName( CG_FE, sym, TypeAddress( tipe ) ) );
#ifndef NDEBUG
EchoAPI( "CGFEName( %s, %t )", sym, tipe );
hdlAdd( CG_NAMES, leaf );
#endif
}
#ifndef NDEBUG
return EchoAPICgnameReturn( leaf );
#else
return( leaf );
#endif
}
extern cg_name _CGAPI CGBackName( bck_info *bck, cg_type tipe )
/**************************************************************/
{
#ifndef NDEBUG
tn retn;
EchoAPI( "CGBackName( %B, %t )", bck, tipe );
#endif
if( !REAL_BACK( bck ) ) _Zoiks( ZOIKS_068 );
#ifndef NDEBUG
retn = TGLeaf( BGName( CG_BACK, bck, TypeAddress( tipe ) ) );
hdlAdd( CG_NAMES, retn );
return EchoAPICgnameReturn( retn );
#else
return( TGLeaf( BGName( CG_BACK, bck, TypeAddress( tipe ) ) ) );
#endif
}
extern cg_name _CGAPI CGTempName( temp_handle temp, cg_type tipe )
/*****************************************************************/
{
#ifndef NDEBUG
tn retn;
EchoAPI( "CGTempName( %T, %t )", temp, tipe );
retn = TGLeaf( BGTempName( temp, TypeAddress( T_POINTER ) ) );
hdlAdd( CG_NAMES, retn );
return EchoAPICgnameReturn( retn );
#else
tipe = tipe;
return( TGLeaf( BGTempName( temp, TypeAddress( T_POINTER ) ) ) );
#endif
}
extern temp_handle _CGAPI CGTemp( cg_type tipe )
/****************************************************/
{
#ifndef NDEBUG
temp_handle retn;
EchoAPI( "CGTemp( %t )", tipe );
retn = BGGlobalTemp( TypeAddress( tipe ) );
return EchoAPITempHandleReturn( retn );
#else
return( BGGlobalTemp( TypeAddress( tipe ) ) );
#endif
}
/**/
/* Assignment operations*/
/**/
extern cg_name _CGAPI CGAssign( cg_name dest, cg_name source, cg_type tipe )
/***************************************************************************/
{
#ifndef NDEBUG
tn retn;
EchoAPI( "CGAssign( %n, %n, %t )", dest, source, tipe );
hdlUseOnce( CG_NAMES, dest );
hdlUseOnce( CG_NAMES, source );
retn = TGAssign( dest, source, TypeAddress( tipe ) );
hdlAddBinary( CG_NAMES, retn, dest, source );
return EchoAPICgnameReturn( retn );
#else
return( TGAssign( dest, source, TypeAddress( tipe ) ) );
#endif
}
extern cg_name _CGAPI CGLVAssign( cg_name dest, cg_name source, cg_type tipe )
/*****************************************************************************/
{
#ifndef NDEBUG
cg_name retn;
EchoAPI( "CGLVAssign( %n, %n, %t )", dest, source, tipe );
hdlUseOnce( CG_NAMES, dest );
hdlUseOnce( CG_NAMES, source );
retn = TGLVAssign( dest, source, TypeAddress( tipe ) );
hdlAddBinary( CG_NAMES, retn, dest, source );
return EchoAPICgnameReturn( retn );
#else
return( TGLVAssign( dest, source, TypeAddress( tipe ) ) );
#endif
}
extern cg_name _CGAPI CGPostGets( cg_op op, cg_name dest,
cg_name src, cg_type tipe )
/********************************************************/
{
#ifndef NDEBUG
cg_name retn;
EchoAPI( "CGPostGets( %o, %n, %n, %t )", op, dest, src, tipe );
hdlUseOnce( CG_NAMES, dest );
hdlUseOnce( CG_NAMES, src );
retn = TGPostGets( op, dest, src, TypeAddress( tipe ) );
hdlAddBinary( CG_NAMES, retn, dest, src );
return EchoAPICgnameReturn( retn );
#else
return( TGPostGets( op, dest, src, TypeAddress( tipe ) ) );
#endif
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?