dumpblk.c

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

C
581
字号


static  void    DumpDataFlo( block *b )
/*************************************/
{
    if( b->dataflow != NULL ) {
        DumpLiteral( "IN   " );
        DumpGBit( &b->dataflow->in );
        DumpLiteral( " OUT  " );
        DumpGBit( &b->dataflow->out );
        DumpNL();
        DumpLiteral( "DEF  " );
        DumpGBit( &b->dataflow->def );
        DumpLiteral( " USE  " );
        DumpGBit( &b->dataflow->use );
        DumpNL();
        DumpLiteral( "LOAD " );
        DumpGBit( &b->dataflow->need_load );
        DumpLiteral( " STOR " );
        DumpGBit( &b->dataflow->need_store );
        DumpNL();
    }
}


static  void    DumpGotos( block *b, bool all )
/*********************************************/
{
    int         i;

    DumpPtr( &b->edge[ 0 ] );
    DumpLiteral( "           Destinations: " );
    if( b->targets > 0 ) {
        if( ( b->edge[ 0 ].flags & DEST_LABEL_DIES ) && all ) {
            DumpLiteral( "(kills) " );
        }
        if( b->edge[ 0 ].flags & DEST_IS_BLOCK ) {
            DumpBlkId( b->edge[ 0 ].destination );
        } else {
            DumpLiteral( "L" );
            DumpPtr( b->edge[ 0 ].destination );
        }
        i = 0;
        while( ++i < b->targets ) {
            DumpLiteral( ", " );
            if( ( b->edge[ i ].flags & DEST_LABEL_DIES ) && all ) {
                DumpLiteral( "(kills) " );
            }
            if( b->edge[ i ].flags & DEST_IS_BLOCK ) {
                DumpBlkId( b->edge[ i ].destination );
            } else {
                DumpLiteral( "L" );
                DumpPtr( b->edge[ i ].destination );
            }
        }
    }
    DumpNL();
}


extern  void    DumpLoops( void )
/*******************************/
{
    block       *blk;

    blk = HeadBlock;
    while( blk != NULL ) {
        DumpBlkId( blk );
        if( blk->class & LOOP_HEADER ) {
            DumpLiteral( " Is loop header." );
        } else {
            DumpLiteral( "                " );
        }
        if( blk->loop_head != NULL ) {
            DumpLiteral( " Has loop header " );
            DumpBlkId( blk->loop_head );
        }
        DumpNL();
        blk = blk->next_block;
    }
}


extern  void    DumpFlowGraph( block *blk )
/*****************************************/
{
    interval_def        *head;
    interval_def        *curr;
    int                 i;

    DumpLiteral( "Interval graph" );
    DumpNL();
    head = blk->u.interval;
    while( head->parent != NULL ) {
        head = head->parent;
    }
    curr = head;
    for(;;) {
        if( curr->level == 0 ) {
            DumpBlkId( curr->first_block );
            DumpLiteral( " loop depth " );
            DumpInt( curr->first_block->depth );
            DumpNL();
            for(;;) {
                if( curr->next_sub_int != NULL ) break;
                if( curr == head ) break;
                curr = curr->parent;
            }
            i = head->level;
            while( i > curr->level ) {
                DumpLiteral( "|     " );
                -- i;
            }
            if( i > 0 ) {
                for(;;) {
                    DumpLiteral( "End   " );
                    if( -- i == 0 ) break;
                }
                DumpNL();
                i = head->level;
                while( i > curr->level ) {
                    DumpLiteral( "|     " );
                    -- i;
                }
            }
            if( curr == head ) break;
            curr = curr->next_sub_int;
        } else {
            DumpLiteral( "Start " );
            curr = curr->sub_int;
        }
    }
    DumpNL();
}


extern  void    DumpSymTab( void )
/********************************/
{
    int         class;

    class = N_CONSTANT;
    for( ;; ) {
        if( Names[ class ] != NULL ) {
            DumpNL();
            switch( class ) {
            case N_CONSTANT:
                DumpLiteral( "Constants" );
                break;
            case N_MEMORY:
                DumpLiteral( "Memory" );
                break;
            case N_TEMP:
                DumpLiteral( "Temporaries" );
                break;
            case N_REGISTER:
                DumpLiteral( "Registers" );
                break;
            case N_INDEXED:
                DumpLiteral( "Indexed" );
                break;
            }
            DumpSymList( Names[ class ] );
            DumpNL();
        }
        if( ++ class > N_INDEXED ) break;
    }
}

extern  void    DumpEdge( block_num i, block_edge *edge )
/*******************************************************/
{
    DumpLiteral( "\n\tEdge " );
    DumpInt( i );
    DumpLiteral( "(" );
    DumpPtr( edge );
    DumpLiteral( ")\n\t\tDestination:\t" );
    DumpPtr( edge->destination );
    DumpLiteral( "\n\t\tSource:\t" );
    DumpPtr( edge->source );
    DumpLiteral( "\n\t\tNext Source:\t" );
    DumpPtr( edge->next_source );
    DumpLiteral( "\n\t\tFlags:\t" );
    DumpInt( edge->flags );
    DumpNL();
}

extern  void    DumpEdges( block *b )
/***********************************/
{
    block_edge  *edge;
    block_num   i;

    DumpBlkId( b );
    for( i = 0; i < b->targets; i++ ) {
        edge = &b->edge[ i ];
        DumpEdge( i, edge );
    }
}

extern  void    DumpInputEdges( block *b )
/****************************************/
{
    block_edge  *edge;
    block_num   i;

    i = 0;
    for( edge = b->input_edges; edge != NULL; edge = edge->next_source ) {
        DumpEdge( i++, edge );
    }
}

static  void    DumpBlkI( void )
/******************************/
{
    block       *blk;

    blk = HeadBlock;
    while( blk != NULL ) {
        DumpBlkFlags( blk );
        DumpLineNum( (instruction *)&blk->ins );
        DumpPtr( blk );
        DumpLiteral( " " );
        DumpBlkId( blk );
        if( blk->label != NULL ) {
            DumpLiteral( " L:" );
            DumpPtr( blk->label );
        }
        DumpNL();
        if( !_DBitEmpty( blk->dom.id ) ) {
            DumpLiteral( "DOM: id  = " );
            _DBitIter( Dump8h, blk->dom.id );
            DumpNL();
            DumpLiteral( "DOM: dom = " );
            _DBitIter( Dump8h, blk->dom.dominator );
            DumpNL();
            DumpLiteral( "DOM: post= " );
            _DBitIter( Dump8h, blk->dom.post_dominator );
            DumpNL();
        }
        DumpInputs( blk );
        DumpInstrsOnly( blk );
        DumpGotos( blk, FALSE );
        blk = blk->next_block;
    }
}


extern  void    DumpRange(int first,int last)
/*******************************************/
{
    first=first;last=last;
    DumpBlkI();
}

extern  void    DumpABlk( block *b )
/**********************************/
{
    DumpPtr( b );
    DumpLiteral( " " );
    DumpBlkId( b );
    DumpBlkLabel( b );
    DumpLiteral( " Depth " );
    DumpInt( b->depth );
    DumpNL();
    DumpBlkFlags( b );
    DumpInputs( b );
    DumpDataFlo( b );
    DumpInsList( b );
    DumpGotos( b, TRUE );
    DumpNL();
}

extern  void    DumpBlock( block *b )
/***********************************/
{
    while( b != NULL ) {
        DumpABlk( b );
        b = b->next_block;
    }
    DumpLiteral( "-------------------------------" );
    DumpNL();
}

extern  void    DumpBlk( void )
/*****************************/
{
    DumpBlock( HeadBlock );
}

⌨️ 快捷键说明

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