dumpblk.c

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

C
581
字号
/****************************************************************************
*
*                            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:  Instruction block/range dump.
*
****************************************************************************/


#include "standard.h"
#include "coderep.h"
#include "opcodes.h"
#include "dump.h"

extern  void            DumpNL(void);
extern  void            DumpPtr(pointer);
extern  void            DumpIns(instruction*);
extern  void            DumpLineNum(instruction*);
extern  void            DumpInt(int);
extern  void            DumpInsList(block*);
extern  void            DumpInstrsOnly(block*);
extern  char            *AskName(pointer,cg_class);
extern  sym_handle      AskForLblSym(label_handle);
extern  void            DumpSymList(name*);
extern  void            Dump8h(unsigned_32);

extern  block   *HeadBlock;
extern  name    *Names[];


static void DumpBlkFlags( block *blk )
/************************************/
{
    if( blk->class & RETURN ) {
        DumpLiteral( "Ret " );
    } else {
        DumpLiteral( "----" );
    }
    if( blk->class & JUMP ) {
        DumpLiteral( "Jmp " );
    } else {
        DumpLiteral( "----" );
    }
    if( blk->class & CONDITIONAL ) {
        DumpLiteral( "Cond " );
    } else {
        DumpLiteral( "-----" );
    }
    if( blk->class & SELECT ) {
        DumpLiteral( "Sel " );
    } else {
        DumpLiteral( "----" );
    }
    if( blk->class & ITERATIONS_KNOWN ) {
        DumpLiteral( "Itr " );
    } else {
        DumpLiteral( "----" );
    }
    if( blk->class & BIG_LABEL ) {
        DumpLiteral( "LBL " );
    } else {
        DumpLiteral( "----" );
    }
    if( blk->class & CALL_LABEL ) {
        DumpLiteral( "LCall " );
    } else {
        DumpLiteral( "------" );
    }
    if( blk->class & LABEL_RETURN ) {
        DumpLiteral( "LRet " );
    } else {
        DumpLiteral( "-----" );
    }
    if( blk->class & RETURNED_TO ) {
        DumpLiteral( "RetTo " );
    } else {
        DumpLiteral( "------" );
    }
    if( blk->class & LOOP_HEADER ) {
        DumpLiteral( "LupHd " );
    } else {
        DumpLiteral( "------" );
    }
    if( blk->class & IN_LOOP ) {
        DumpLiteral( "InLup " );
    } else {
        DumpLiteral( "------" );
    }
    if( blk->class & LOOP_EXIT ) {
        DumpLiteral( "LupEx " );
    } else {
        DumpLiteral( "------" );
    }
    if( blk->class & BLOCK_VISITED ) {
        DumpLiteral( "Vst " );
    } else {
        DumpLiteral( "----" );
    }
    if( blk->class & BLOCK_MARKED ) {
        DumpLiteral( "Mrk " );
    } else {
        DumpLiteral( "----" );
    }
    if( blk->class & UNKNOWN_DESTINATION ) {
        DumpLiteral( "Dst? " );
    } else {
        DumpLiteral( "-----" );
    }
    if( blk->class & MULTIPLE_EXITS ) {
        DumpLiteral( "2Exits " );
    } else {
        DumpLiteral( "-------" );
    }
    DumpNL();
}


extern  void    DumpRefs( name *op )
/**********************************/
{
    block       *blk;
    instruction *ins;
    int         dsize;
    int         i;

    blk = HeadBlock;
    while( blk != NULL ) {
        ins = blk->ins.hd.next;
        while( ins->head.opcode != OP_BLOCK ) {
            dsize = 0;
            i = ins->num_operands;
            while( --i >= 0 ) {
                if( ins->operands[ i ] == op ) {
                    DumpLiteral( "OP(" );
                    DumpInt( i + 1 );
                    DumpLiteral( ") " );
                    dsize += 6;
                } else if( ins->operands[ i ]->n.class == N_INDEXED ) {
                    if( ins->operands[ i ]->i.index == op ) {
                        DumpLiteral( "IX(" );
                        DumpInt( i + 1 );
                        DumpLiteral( ") " );
                        dsize += 6;
                    } else if( ins->operands[ i ]->i.base == op ) {
                        if( ins->operands[ i ]->i.index_flags & X_FAKE_BASE ) {
                            DumpLiteral( "FB(" );
                        } else {
                            DumpLiteral( "BA(" );
                        }
                        DumpInt( i + 1 );
                        DumpLiteral( ") " );
                        dsize += 6;
                    }
                }
            }
            if( ins->result == op ) {
                DumpLiteral( "RES " );
                dsize += 4;
            } else if( ins->result != NULL ) {
                if( ins->result->i.index == op ) {
                    DumpLiteral( "IX(" );
                    DumpInt( i + 1 );
                    DumpLiteral( ") " );
                    dsize += 4;
                } else if( ins->result->i.base == op ) {
                    if( ins->result->i.index_flags & X_FAKE_BASE ) {
                        DumpLiteral( "FB(" );
                    } else {
                        DumpLiteral( "BA(" );
                    }
                    DumpInt( i + 1 );
                    DumpLiteral( ") " );
                    dsize += 4;
                }
            }
            if( dsize ) {
                while( ++dsize < 23 ) {
                    DumpLiteral( " " );
                }
                DumpIns( ins );
            }
            ins = ins->head.next;
        }
        blk = blk->next_block;
    }
}


static  void    DumpBlkLabel( block *b )
/**************************************/
{
    if( b->label != NULL ) {
        DumpLiteral( " L" );
        DumpPtr( b->label );
        DumpLiteral( " " );
        DumpXString( AskName( AskForLblSym( b->label ), CG_FE ) );
        if( b->edge[ 0 ].flags & BLOCK_LABEL_DIES ) {
            DumpLiteral( " label dies" );
        }
    }
}


static  bool    FindBlock( block *b )
/***********************************/
{
    block       *blk;

    blk = HeadBlock;
    for( ;; ) {
        if( blk == NULL ) return( FALSE );
        if( blk == b ) return( TRUE );
        blk = blk->next_block;
    }
}

extern  void    DumpBlkId( block *b )
/***********************************/
{
    DumpLiteral( "Block " );
    DumpInt( b->id );
    DumpLiteral( "(" );
    DumpInt( b->gen_id );
    DumpLiteral( ")" );
}

static  void    DumpInputs( block *b )
/************************************/
{
    int         i;
    block_edge  *edge;

    DumpPtr( b->input_edges );
    DumpLiteral( "           Origins: " );
    if( b->input_edges != NULL ) {
        i = 0;
        edge = b->input_edges;
        for(;;) {
            if( FindBlock( edge->source ) ) {
                DumpBlkId( edge->source );
            } else {
                DumpLiteral( "?" );
            }
            edge = edge->next_source;
            if( edge == NULL ) break;
            DumpLiteral( ", " );
            ++ i;
            if( ( i & 7 ) == 0 ) {
                DumpNL();
                DumpLiteral( "         " );
            }
        }
    }
    DumpNL();
}


extern  void    DumpLBit( local_bit_set *bit )
/********************************************/
{
    _LBitIter( Dump8h, (*bit) );
}


extern  void    DumpGBit( global_bit_set *bit )
/*********************************************/
{
    _GBitIter( Dump8h, (*bit) );
}

⌨️ 快捷键说明

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