cgbkutil.c
来自「开放源码的编译器open watcom 1.6.0版的源代码」· C语言 代码 · 共 1,074 行 · 第 1/3 页
C
1,074 行
dtm = DTM_DIRECT_SMALL;
break;
case DTM_DIRECT_TABLE :
case DTM_TABLE :
dtm = DTM_DIRECT;
break;
}
return dtm;
}
static boolean dtmTabular( // DETERMINE IF METHOD IS TABULAR
DT_METHOD method ) // - the method
{
boolean retn; // - TRUE ==> is tabular
switch( method ) {
DbgDefault( "dtmTabular -- bad method" );
case DTM_DIRECT :
retn = FALSE;
break;
case DTM_DIRECT_SMALL :
case DTM_TABLE_SMALL :
case DTM_DIRECT_TABLE :
case DTM_TABLE :
retn = TRUE;
break;
}
return retn;
}
boolean DtmTabular( // DETERMINE IF SCOPE TABULAR DESTRUCTION METHOD, SCOPE
FN_CTL* fctl ) // - function control
{
return dtmTabular( fctl->dtor_method );
}
boolean DtmTabularFunc( // DETERMINE IF SCOPE TABULAR DESTRUCTION METHOD, FUNCTION
FN_CTL* fctl ) // - function control
{
return dtmTabular( fctl->func_dtor_method );
}
//***********************************************************************
// Code Generation Support -- general
//***********************************************************************
cg_name CgFetchType( // PERFORM A FETCH
cg_name operand, // - operand to be fetched
cg_type type ) // - type of fetch
{
return CGUnary( O_POINTS, operand, type );
}
cg_name CgFetchPtr( // FETCH A POINTER
cg_name operand ) // - operand to be fetched
{
return CgFetchType( operand, T_POINTER );
}
cg_name CgFetchTemp( // FETCH A TEMPORARY
temp_handle handle, // - handle for temporary
cg_type type ) // - type of temp
{
return CgFetchType( CGTempName( handle, type ), type );
}
cg_name CgSaveAsTemp( // SAVE INTO A TEMPORARY
temp_handle* a_hand, // - addr[ temp handle ]
cg_name expr, // - expression to be saved
cg_type type ) // - and its type
{
temp_handle handle; // - allocated temporary handle
handle = CGTemp( type );
*a_hand = handle;
return CGLVAssign( CGTempName( handle, type ), expr, type );
}
static void addArgument( // ADD AN ARGUMENT
call_handle handle, // - handle for call
cg_name expr, // - expression for argument
cg_type type ) // - argument type
{
CGAddParm( handle, expr, type );
}
cg_name CgSymbol( // PASS SYMBOL TO CODE GENERATOR
SYMBOL sym ) // - symbol
{
return CGFEName( (cg_sym_handle)sym, CgTypeSym( sym ) );
}
cg_name CgOffsetExpr( // MAKE OFFSET EXPRESSION
cg_name expr, // - lhs expression
target_offset_t offset, // - offset
cg_type type ) // - resultant type
{
if( offset == 0 ) {
expr = CGUnary( O_CONVERT, expr, type );
} else {
expr = CGBinary( O_PLUS, expr, CgOffset( offset ), type );
}
return expr;
}
cg_name CgAddrSymbol( // PASS ADDR OF SYMBOL TO CODE GENERATOR
SYMBOL sym ) // - symbol
{
#if 0
return CGFEName( (cg_sym_handle)sym, CgTypePtrSym( sym ) );
#else
return CGFEName( (cg_sym_handle)sym, CgTypeSym( sym ) );
#endif
}
cg_name CgOffset( // PASS ABSOLUTE OFFSET TO CODE GENERATOR
unsigned offset ) // - offset value
{
return CGInteger( offset, CgTypeOffset() );
}
cg_name CgSymbolPlusOffset( // GENERATE SYMBOL + OFFSET
SYMBOL sym, // - symbol
unsigned offset ) // - offset
{
return CgOffsetExpr( CgAddrSymbol( sym ), offset, CgTypePtrSym( sym ) );
}
cg_name CgFetchSymbolAddOffset( // GENERATE RVALUE( SYMBOL ) + OFFSET
SYMBOL sym, // - symbol
unsigned offset ) // - offset
{
return CgOffsetExpr( CgFetchSym( sym ), offset, CgTypeSym( sym ) );
}
cg_type CgReturnType( // GET CG-TYPE FOR RETURN
cg_type type ) // - code-gen type
{
if( CompFlags.returns_promoted && 0 == CgBackInlinedDepth() ) {
type = FEParmType( NULL, NULL, type );
}
return type;
}
cg_name CgFetchSym( // FETCH A SYMBOL
SYMBOL sym ) // - symbol
{
return CgFetchType( CgSymbol( sym ), CgTypeSym( sym ) );
}
cg_name CgMakeDup( // MAKE A DUPLICATE
cg_name *orig, // - original
cg_type cgtype ) // - and its type
{
temp_handle handle; // - dup. handle
cg_name dup; // - duplicated node
dup = CgSaveAsTemp( &handle, *orig, cgtype );
dup = CgFetchType( dup, cgtype );
*orig = CgFetchTemp( handle, cgtype );
// returned cg_name must be emitted before
// any sequence points that use *orig
// (i.e., returned cg_name sets up the duplicate value)
return dup;
}
cg_name CgMakeTwoDups( // MAKE TWO DUPLICATES
cg_name *orig, // - original and destination for first dup
cg_name *second, // - destination for second dup
cg_type cgtype ) // - original type
{
temp_handle handle; // - dup. handle
cg_name dup; // - duplicated node
dup = CgSaveAsTemp( &handle, *orig, cgtype );
dup = CgFetchType( dup, cgtype );
*orig = CgFetchTemp( handle, cgtype );
*second = CgFetchTemp( handle, cgtype );
// returned cg_name must be emitted before
// any sequence points that use *orig or *second
// (i.e., returned cg_name sets up the duplicate value)
return dup;
}
static cg_type prcCgType( // PROCESS A NEW CODE-GEN TYPE
cg_type type ) // - code generation type
{
if( ( type == T_SINGLE )
||( type == TY_DOUBLE ) ) { //***** LATER UPGRADE FOR LONG DBL
CompFlags.float_used = TRUE;
}
return type;
}
cg_type CgGetCgType( // GET CODEGEN TYPE
TYPE type ) // - type
{
TYPE basic; // - basic type
cg_type cgtype; // - codegen type
basic = TypedefModifierRemove( type );
if( basic->id == TYP_CLASS ) {
if( OMR_CLASS_VAL == ObjModelArgument( basic ) ) {
cgtype = prcCgType( CgTypeOutput( type ) );
} else {
cgtype = T_POINTER;
}
} else {
cgtype = prcCgType( CgTypeOutput( type ) );
}
return cgtype;
}
cg_type CgFuncRetnType( // GET CG RETURN TYPE FOR A FUNCTION
SYMBOL func ) // - function
{
TYPE ftype; // - type for function
cg_type cgtype; // - codegen type
ftype = FunctionDeclarationType( func->sym_type );
if( OMR_CLASS_REF == ObjModelFunctionReturn( ftype ) ) {
cgtype = T_POINTER;
} else {
cgtype = prcCgType( CgTypeOutput( ftype->of ) );
}
return cgtype;
}
cg_type CgExprType( // GET EXPRESSION TYPE
TYPE type ) // - C++ type
{
return prcCgType( CgTypeOutput( type ) );
}
void CgAssign( // EMIT AN ASSIGNMENT
cg_name lhs, // - lhs argument
cg_name rhs, // - rhs argument
cg_type type ) // - type for assignment
{
CgDone( CGLVAssign( lhs, rhs, type ), T_POINTER );
}
void CgAssignPtr( // EMIT A POINTER ASSIGNMENT
cg_name lhs, // - lhs argument
cg_name rhs ) // - rhs argument
{
CgAssign( lhs, rhs, T_POINTER );
}
static call_handle initDtorCall( // INITIALIZE DTOR CALL
SYMBOL dtor ) // - DTOR to be called
{
cg_name dtor_name;
call_handle h;
dtor_name = CgSymbol( dtor );
h = CGInitCall( dtor_name, CgFuncRetnType( dtor ), (cg_sym_handle)dtor );
return( h );
}
static void addDtorArgs( // ADD DTOR ARGUMENTS
call_handle handle, // - call handle
SYMBOL dtor, // - destructor
cg_name var, // - destruction address
unsigned cdtor ) // - CDTOR to be used
{
cg_name expr; // - expression for CDTOR
expr = CGInteger( cdtor, TY_UNSIGNED );
switch( PcCallImpl( dtor->sym_type ) ) {
case CALL_IMPL_REV_CPP :
case CALL_IMPL_REV_C :
addArgument( handle, var, T_POINTER );
addArgument( handle, expr, TY_UNSIGNED );
break;
default :
addArgument( handle, expr, TY_UNSIGNED );
addArgument( handle, var, T_POINTER );
break;
}
}
static cg_name finiDtorCall( // COMPLETE DTOR CALL
call_handle handle, // - call handle
unsigned cdtor ) // - cdtor arg to use
{
cg_name n;
CgBackCallGened( handle );
n = CgFetchPtr( CGCall( handle ) );
CallStabCdArgSet( handle, cdtor );
return( n );
}
cg_name CgDestructSymOffset( // CONSTRUCT DTOR CALL FOR SYMBOL+OFFSET
FN_CTL* fctl, // - function control
SYMBOL dtor, // - destructor
SYMBOL sym, // - SYMBOL to be DTOR'ed
target_size_t offset, // - offset from "sym"
unsigned cdtor ) // - CDTOR to be used
{
call_handle handle; // - call handle
SYMBOL trans; // - translated symbol
SYMBOL bound; // - bound reference
target_offset_t bound_off; // - bound offset
boolean inlined; // - TRUE ==> inlined dtor call
handle = initDtorCall( dtor );
inlined = CgBackFuncInlined( dtor );
if( inlined ) {
CallStackPush( dtor, handle, T_POINTER );
IbpAdd( sym, offset, fctl );
IbpDefineIndex( 0 );
}
if( IbpReference( sym, &trans, &bound, &bound_off ) ) {
trans = bound;
offset += bound_off;
}
addDtorArgs( handle, dtor, CgSymbolPlusOffset( trans, offset ), cdtor );
if( inlined ) {
CallStackPop();
}
return finiDtorCall( handle, cdtor );
}
cg_name CgDestructExpr( // CONSTRUCT DTOR CALL FOR EXPRESSION
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?