brmdump.cpp
来自「开放源码的编译器open watcom 1.6.0版的源代码」· C++ 代码 · 共 1,289 行 · 第 1/3 页
CPP
1,289 行
fprintf( outfile, "Scope: %08X\n", _index );
fprintf( outfile, " Flags: %02X\n", flags );
if( flags == BRI_ST_Function && fn_ptr.fn_name_ptr != NULL ){
buf = fn_ptr.fn_name_ptr->_buf;
fprintf( outfile, " Symbol: %s\n", buf );
if( fn_ptr.fn_type_ptr != NULL ){
fprintf( outfile, " Type: " );
fn_ptr.fn_type_ptr->WriteType();
fprintf( outfile, " (%08X)\n", fn_id.fn_type_index );
}
} else if( flags == BRI_ST_Class && type_ptr != NULL ){
fprintf( outfile, " Type: " );
type_ptr->WriteType();
fprintf( outfile, " (%08X)\n", type_index );
} else {
fprintf( outfile, " Index: %08X\n", type_index );
}
}
void ScopeRec::ReIndex()
/**********************/
{
if( flags == BRI_ST_Function ){
fn_ptr.fn_name_ptr = string_table.Lookup( fn_id.fn_name_index );
fn_ptr.fn_type_ptr = type_list.Lookup( fn_id.fn_type_index );
} else {
type_ptr = type_list.Lookup( type_index );
}
}
void ScopeEndRec::DumpData()
/**************************/
{
fprintf( outfile, "End Scope.\n" );
}
void DefnRec::DumpData()
/**********************/
{
uint_8 * name_buf;
if( symbol_ptr != NULL ){
if( symbol_ptr->name_ptr != NULL ){
name_buf = symbol_ptr->name_ptr->_buf;
} else {
name_buf = (uint_8 *) ANONYMOUS;
}
fprintf( outfile, "Definition: %s (%08X)\n", name_buf, symbol_index );
} else {
fprintf( outfile, "Definition: %08X\n", symbol_index );
}
if( filename_ptr != NULL ){
fprintf( outfile, " Filename: %s\n", filename_ptr->_buf );
} else {
fprintf( outfile, " Filename: %08X\n", filename_id );
}
fprintf( outfile, " Column: %d\n", delta_col );
fprintf( outfile, " Line: %d\n", delta_line );
}
void DefnRec::ReIndex()
/*********************/
{
filename_ptr = string_table.Lookup( filename_id );
symbol_ptr = decl_list.Lookup( symbol_index );
}
void DeltaRec::DumpData()
/***********************/
{
fprintf( outfile, "Delta:\n" );
fprintf( outfile, " DCol: %d\n", delta_col );
fprintf( outfile, " DLine: %d\n", delta_line );
}
void UsageRec::DumpData()
/***********************/
{
uint_8 * name_buf;
fprintf( outfile, "Reference:\n" );
fprintf( outfile, " Flags: %X\n", type );
fprintf( outfile, " DCol: %d\n", delta_col );
fprintf( outfile, " DLine: %d\n", delta_line );
if( type == BRI_RT_TypeOf ){
if( type_ptr != NULL ){
fprintf( outfile, " Target Type: " );
type_ptr->WriteType();
fprintf( outfile, " (%08X)\n", type_index );
} else {
fprintf( outfile, " Target Type: %08X\n", type_index );
}
} else {
if( target_ptr != NULL ){
if( target_ptr->name_ptr != NULL ){
name_buf = target_ptr->name_ptr->_buf;
} else {
name_buf = (uint_8 *) ANONYMOUS;
}
fprintf( outfile, " Target Symbol: %s (%08X)\n",
name_buf, target_index );
} else {
fprintf( outfile, " Target Symbol: %08X\n", target_index );
}
}
}
void UsageRec::ReIndex()
/**********************/
{
if( type == BRI_RT_TypeOf ){
type_ptr = type_list.Lookup( type_index );
} else {
target_ptr = decl_list.Lookup( target_index );
}
}
void GuardRec::DumpData()
/***********************/
{
int i;
fprintf( outfile, "Guard (type %02X):\n", type );
if( string_ptr != NULL ){
fprintf( outfile, " %s\n", string_ptr->_buf );
} else {
fprintf( outfile, " %08X\n", string_id );
}
if( type == BRI_GT_Value || type == BRI_GT_RefValue ||
type == BRI_GT_Declaration ){
fprintf( outfile, " # Parameters: %d\n", num_params );
if( length > 0 ){
fprintf( outfile, " Definition:" );
for( i=0; i<length; i++ ){
fprintf( outfile, " %02X", defn[i] );
}
fputc( '\n', outfile );
}
}
}
void GuardRec::ReIndex()
/**********************/
{
string_ptr = string_table.Lookup( string_id );
}
OrderedList::OrderedList(int delete_entries)
/******************************************/
{
_first = NULL;
_last = NULL;
_current = NULL;
_count = 0;
_del_entries = delete_entries;
}
OrderedList::~OrderedList()
/*************************/
{
Link * current = _first;
Link * prev = NULL;
while( current != NULL ) {
prev = current;
current = current->_next;
if( _del_entries ){
delete prev->_data;
}
delete prev;
}
}
void OrderedList::Append( OrderedData * data )
/********************************************/
{
Link * link = new Link;
link->_next = NULL;
link->_data = data;
if( _last == NULL ){
_first = _last = link;
} else {
_last->_next = link;
_last = link;
}
_count += 1;
}
OrderedData * OrderedList::First()
/********************************/
{
OrderedData * result = NULL;
_current = _first;
if( _current != NULL ){
result = _current->_data;
}
return result;
}
OrderedData * OrderedList::Next()
/*******************************/
{
OrderedData * result = NULL;
if( _current != NULL ){
_current = _current->_next;
if( _current != NULL ){
result = _current->_data;
}
}
return result;
}
template<class T>
HashTable<T>::HashTable()
/************************/
{
_table = new Link *[NUM_BUCKETS];
memset( _table, 0, NUM_BUCKETS*sizeof(Link *));
}
template<class T>
int HashTable<T>::Hash( uint_32 id )
/*********************************/
{
//return ((int) (id << 8)) % NUM_BUCKETS;
uint_32 s = id;
uint_32 c;
uint_32 g;
uint_32 h;
h = 0x4;
c = 0x4;
c += s;
h = ( h << 4 ) + c;
g = h & ~0x0ffffff;
h ^= g;
h ^= g >> (4+4+4+4+4);
g = h & ~0x0fff;
h ^= g;
h ^= g >> (4+4+4);
h ^= h >> (2+4);
return( (int) (h%NUM_BUCKETS) );
}
template<class T>
void HashTable<T>::Insert( T *hashdata )
/**************************************/
{
Link * current;
Link * prev;
Link * link = new Link;
int index = Hash(hashdata->_index);
current = _table[ index ];
prev = NULL;
while( current != NULL && current->_data->_index < hashdata->_index ){
prev = current;
current = current->_next;
}
if( current != NULL ){
link->_next = current;
} else {
link->_next = NULL;
}
if( prev != NULL ){
prev->_next = link;
} else {
_table[ index ] = link;
}
link->_data = hashdata;
}
template<class T>
T * HashTable<T>::Lookup( uint_32 id )
/************************************/
{
int index = Hash( id );
Link * current;
T * result = NULL;
current = _table[ index ];
while( current != NULL && current->_data->_index < id ){
current = current->_next;
}
if( current != NULL && current->_data->_index == id ){
result = current->_data;
}
return result;
}
void DumpHeader()
/***************/
{
fprintf( outfile
, "Watcom browse file v%d.%d\n"
, header.major_ver
, header.minor_ver );
if( header.num_declaration > 0 ){
fprintf( outfile, "Declaration nodes: %2d\n", header.num_declaration);
}
if( header.num_file > 0 ){
fprintf( outfile, "File nodes: %2d\n", header.num_file );
}
if( header.num_scope > 0 ){
fprintf( outfile, "Scope nodes: %2d\n", header.num_scope );
}
if( header.num_definition > 0 ){
fprintf( outfile, "Definition nodes: %2d\n", header.num_definition );
}
if( header.num_delta > 0 ){
fprintf( outfile, "Delta nodes: %2d\n", header.num_delta );
}
if( header.num_usage > 0 ){
fprintf( outfile, "Usage nodes: %2d\n", header.num_usage );
}
if( header.num_string > 0 ){
fprintf( outfile, "String nodes: %2d\n", header.num_string );
}
if( header.num_type > 0 ){
fprintf( outfile, "Type nodes: %2d\n", header.num_type );
}
if( header.num_guard > 0 ){
fprintf( outfile, "Guard nodes: %2d\n", header.num_guard );
}
if( header.num_template > 0 ){
fprintf( outfile, "Template nodes: %2d\n", header.num_template );
}
}
void DumpHeaderFinal()
/********************/
{
OrderedData * current;
current = record_list.First();
while( current != NULL ){
current->ReIndex();
current = record_list.Next();
}
current = record_list.First();
while( current != NULL ){
current->DumpData();
current = record_list.Next();
}
if( header.num_declaration != 0 ){
fprintf( outfile, "The number of declaration nodes was incorrect.\n" );
fprintf( outfile, " It was off by %d.\n", header.num_declaration );
}
if( header.num_file != 0 ){
fprintf( outfile, "The number of file nodes was incorrect.\n" );
fprintf( outfile, " It was off by %d.\n", header.num_file );
}
if( header.num_scope != 0 ){
fprintf( outfile, "The number of scope nodes was incorrect.\n" );
fprintf( outfile, " It was off by %d.\n", header.num_scope );
}
if( header.num_delta != 0 ){
fprintf( outfile, "The number of delta nodes was incorrect.\n" );
fprintf( outfile, " It was off by %d.\n", header.num_delta );
}
if( header.num_definition != 0 ){
fprintf( outfile, "The number of definition nodes was incorrect.\n" );
fprintf( outfile, " It was off by %d.\n", header.num_definition );
}
if( header.num_string != 0 ){
fprintf( outfile, "The number of string nodes was incorrect.\n" );
fprintf( outfile, " It was off by %d.\n", header.num_string );
}
if( header.num_usage != 0 ){
fprintf( outfile, "The number of usage nodes was incorrect.\n" );
fprintf( outfile, " It was off by %d.\n", header.num_usage );
}
if( header.num_type != 0 ){
fprintf( outfile, "The number of type nodes was incorrect.\n" );
fprintf( outfile, " It was off by %d.\n", header.num_type );
}
if( header.num_guard != 0 ){
fprintf( outfile, "The number of guard nodes was incorrect.\n" );
fprintf( outfile, " It was off by %d.\n", header.num_guard );
}
if( header.num_template != 0 ){
fprintf( outfile, "The number of template nodes was incorrect.\n" );
fprintf( outfile, " It was off by %d.\n", header.num_template );
}
if( header.num_pch != 0 ){
fprintf( outfile, "The number of PCH nodes was incorrect.\n" );
fprintf( outfile, " It was off by %d.\n", header.num_pch );
}
}
int ReadDeclaration()
/*******************/
{
static const int result = sizeof(BRI_SymbolID)
+ BRI_SIZE_SYMBOLATTRIBUTES
+ sizeof(BRI_StringID)
+ sizeof(BRI_TypeID);
DeclRec * decl_rec = new DeclRec;
fread( &decl_rec->_index, sizeof(BRI_SymbolID), 1, infile );
fread( &decl_rec->attributes, BRI_SIZE_SYMBOLATTRIBUTES, 1, infile );
fread( &decl_rec->name_id, sizeof(BRI_StringID), 1, infile );
fread( &decl_rec->type_id, sizeof(BRI_TypeID), 1, infile );
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?