rsp2elfu.cxx 3.31 KB
#include <iostream.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <symconst.h>

#include "rsp2elf.h"

extern symbol * symTable;

int source::containsAddr( unsigned long addr )
{
	range * rp = rangeList;

	while ( rp )
	{
		if ( rp->inrange( addr ) )
			return 1;
		rp = rp->next;
	}
	return 0;
}

void source::newRange( unsigned long addr, int sourceLine )
{
	range * rp = rangeList;
	unsigned long loc = addr;

	while ( rp )
	{
		if ( loc == (rp->endOfRange() + 1) )
		{
			rp->extend( sourceLine );
			return;
		}
		rp = rp->next;
	}

	// Could not find a range to extend, add a new one

	rp = new range( addr, sourceLine );
	if ( rangeList == 0 )	/* no ranges yet */
		rangeList = rp;
	else
        	rangeLast->next = rp;
	rangeLast = rp;
}

void source::PrintProcs( void )
{
	proc * pro = procList;

	while ( pro )
	{
		pro->print();
		pro = pro->next;
	}
}

void source::PrintSymbols( void )
{
	symbol * sym = symList;

	if ( sym == 0 )
		cout << "  File had no orphan symbols" << endl;
	else while ( sym )
	{
		sym->print();
		sym = sym->pnext;
	}
}

void source::AddProc( proc * p ) 
{
	if ( procList )	/* new proc for file */
		procLast->next = p;
	else
		procList = p;
	procLast = p;
	++procCount;
}

void source::AddLine( line * l ) 
{
        if ( lineList == 0 )	/* first line for this file */
		lineList = l;
	else
		lineLast->next = l;
	lineLast = l;
	++lineCount;
}

void source::AddSymbol( symbol * sym ) 
{
	if ( symList )
		symLast->pnext = sym;
	else
		symList = sym;
	symLast = sym;
	++labelCount; 
}

void source::MakeProcForFile( void )
{
	proc * newProc = new proc;
	char c, * s, *d, *procName = (char *) malloc( strlen( fileName ) + 2 );

	if ( !procName )
		nospace();
	d = procName;
	*d++ = '_';
	s = fileName;
	while ( c = *s++ )
		if ( isalnum( c ) )
			*d++ = c;
		else
			*d++ = '_';
	newProc->callMe( procName );	// copies it
	newProc->newlow( rangeList->lowAddr, lineList->LineIs() );
	newProc->newhigh( rangeLast->highAddr, lineLast );
	newProc->InheritLines( lineList, lineLast );
	newProc->InheritLabels( symList, symLast );
	symList = symLast = 0;
	lineList = lineLast = 0;
	labelCount = 0;
	lineCount = 0;
	AddProc( newProc );	// should be only one
	NewSymbol( procName, rangeList->lowAddr, stProc );
}

void proc::print( void ) {
	symbol * s = symList;
	line * l = lineList;

	cout << " PROC " << procName << " range " << hex <<
		lowAddr << ":" << highAddr << " lines " << dec <<
		lowLine << ":" << highLine << " aux " << auxEntry << endl;
	if ( !s )
		cout << "(Proc had no symbols)" << endl;
	else
	while ( s )
	{
		s->print();
		s = s->pnext;
	}
	if ( !l )
		cout << " (Proc had no lines)" << endl;
	else
	{
		cout << "  LINES ";
		while ( l )
		{
			l->print();
			l = l->next;
		}
		cout << endl;
	}	
}

int proc::contains( unsigned long addr ) 
{
        if ( addr >= lowAddr && addr <= highAddr )
		return 1;
	return 0; 
}

void proc::AddLine( line * l ) 
{
        if ( lineList == 0 )	/* first line for this proc */
		lineList = l;
	else
		lineLast->next = l;
	lineLast = l;
	++lineCount;
}

void proc::AsgSymIndex( int index )
{
	symbol * sym = symTable;

	while ( sym )
	{
		if ( !strcmp( procName, sym->NameIs() ) )	// found it
		{
			sym->AsgSymIndex( index );
			return;
		}
		sym = sym->next;
	}
}

int range::inrange( unsigned long addr ) 
{
	if ( addr >= lowAddr && addr <= highAddr )
		return 1;
	return 0;
}