mrline.cpp
来自「开放源码的编译器open watcom 1.6.0版的源代码」· C++ 代码 · 共 415 行 · 第 1/2 页
CPP
415 行
/****************************************************************************
*
* 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: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE
* DESCRIBE IT HERE!
*
****************************************************************************/
#include <wchash.h>
#include <wchiter.h>
#include <wcvector.h>
#include <wstd.h>
#include <dwarf.h>
#include <string.h>
#include "mroffset.h"
#include "mrline.h"
#include "mrfile.h"
#if INSTRUMENTS
# include "dwmerger.h"
#endif
/*---------------------- MergeFileRelocKey ------------------------*/
unsigned MergeFileRelocKey::hashVal() const
//-----------------------------------------
{
return (uint) mbrFile << ( ( sizeof(uint) - sizeof(uint_8) ) * 8) ^ oldIdx;
}
/*---------------------- MergeFileEntry ------------------------*/
MergeFileEntry::MergeFileEntry()
: name( NULL )
, directoryIdx( 0 )
, modTime( 0 )
, length( 0 )
//---------------------------------
{
}
MergeFileEntry::MergeFileEntry( const MergeFileEntry& other )
//-----------------------------------------------------------
: name( other.name )
, directoryIdx( other.directoryIdx )
, modTime( other.modTime )
, length( other.length )
{
}
bool MergeFileEntry::operator==( const MergeFileEntry& other ) const
//------------------------------------------------------------------
{
return (name == other.name);
}
MergeFileEntry& MergeFileEntry::operator=( const MergeFileEntry& other )
//----------------------------------------------------------------------
{
name.operator= ( other.name );
directoryIdx = other.directoryIdx;
modTime = other.modTime;
length = other.length;
return *this;
}
uint MergeFileEntry::getLen()
//---------------------------
{
return( strlen( name.getString() ) + 1
+ MergeFile::ULEB128Len( directoryIdx )
+ MergeFile::ULEB128Len( modTime )
+ MergeFile::ULEB128Len( length ) );
}
/*---------------------- MergeLineSection ------------------------*/
MergeLineSection::MergeLineSection()
//----------------------------------
{
_directoriesByName = new WCValHashDict<MergeStringHdl,uint_16>(
MergeStringHdl::getHashVal, 20 );
_directoriesReloc = new WCValHashDict<MergeFileRelocKey,uint_16>(
MergeFileRelocKey::getHashVal, 200 );
_directories = new WCValOrderedVector<MergeStringHdl>( 20, 10 );
_filesByName = new WCValHashDict<MergeStringHdl,uint_16>(
MergeStringHdl::getHashVal, 200 );
_filesReloc = new WCValHashDict<MergeFileRelocKey,uint_16>(
MergeFileRelocKey::getHashVal, 500 );
_files = new WCValOrderedVector<MergeFileEntry>( 200, 50 );
}
MergeLineSection::~MergeLineSection()
//-----------------------------------
{
#if INSTRUMENTS
Log.printf( "\nMergeLineSection\n----------------\n" );
Log.printf( "MergeLineSection::_directoriesByName: %u entries, loaded %%%3.2f\n", _directoriesByName->entries(), 100.0 * ((double)_directoriesByName->entries() / (double)_directoriesByName->buckets()) );
Log.printf( "MergeLineSection::_directoriesReloc: %u entries, loaded %%%3.2f\n", _directoriesReloc->entries(), 100.0 * ((double)_directoriesReloc->entries() / (double)_directoriesReloc->buckets()) );
Log.printf( "MergeLineSection::_directories: %u entries\n", _directories->entries() );
Log.printf( "MergeLineSection::_filesByName: %u entries, loaded %%%3.2f\n", _filesByName->entries(), 100.0 * ((double)_filesByName->entries() / (double)_filesByName->buckets()) );
Log.printf( "MergeLineSection::_filesReloc: %u entries, loaded %%%3.2f\n", _filesReloc->entries(), 100.0 * ((double)_filesReloc->entries() / (double)_filesReloc->buckets()) );
Log.printf( "MergeLineSection::_files: %u entries\n", _files->entries() );
#endif
delete _directoriesByName;
delete _directoriesReloc;
delete _directories;
delete _filesByName;
delete _filesReloc;
delete _files;
}
#if 0 // no longer needed -- file by file
void MergeLineSection::mergeLine( WCPtrOrderedVector<MergeFile>& files )
//----------------------------------------------------------------------
{
uint_8 i;
uint_32 * drSizes;
uint_32 totLen = 0;
for( i = 0; i < files.entries(); i += 1 ){
drSizes = files[ i ]->getDRSizes();
scanFile( files[ i ], i, drSizes[ DR_DEBUG_LINE ] );
#if INSTRUMENTS
Log.printf( " File %s - %ld bytes\n", files[i]->getFileName(), drSizes[ DR_DEBUG_LINE ] );
totLen += drSizes[ DR_DEBUG_LINE ];
#endif
}
#if INSTRUMENTS
Log.printf( " %d files, %ld bytes\n", i, totLen );
#endif
_outFile->startWriteSect( DR_DEBUG_LINE );
writePrologue();
_outFile->endWriteSect();
}
#endif
void MergeLineSection::scanFile( MergeFile * file, uint_8 idx )
//-------------------------------------------------------------
{
uint_32 len;
MergeOffset moff( idx, 0 );
len = file->getDRSizes()[ DR_DEBUG_LINE ];
while( moff.offset < len ) {
readLineSect( file, moff );
}
#if INSTRUMENTS
Log.printf( " %s .debug_line - %ld bytes\n", file->getFileName(), len );
#endif
}
void MergeLineSection::readLineSect( MergeFile * file, MergeOffset& moff )
//------------------------------------------------------------------------
{
MergeOffset startOff = moff;// offset of start of line section
uint_16 i;
const char * string;
MergeStringHdl name;
uint_32 lineEnd; // offset of end of compunit's line info
uint_8 opcode; // standard opcode
uint_32 oplen;
uint_32 extopcode;
uint_32 total_length; // length of compunit's line information
uint_16 version;
uint_32 prologue_length; // length of prologue for this compunit
uint_8 op_base; // number of first special opcode
uint_8 * standard_opcode_lengths;
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?