|
|
DataMuseum.dkPresents historical artifacts from the history of: DKUUG/EUUG Conference tapes |
This is an automatic "excavation" of a thematic subset of
See our Wiki for more about DKUUG/EUUG Conference tapes Excavated with: AutoArchaeologist - Free & Open Source Software. |
top - metrics - downloadIndex: T l
Length: 4077 (0xfed)
Types: TextFile
Names: »labeltab.c«
└─⟦9ae75bfbd⟧ Bits:30007242 EUUGD3: Starter Kit
└─⟦3f75c1919⟧ »EurOpenD3/utils/decomp.tar.Z«
└─⟦510c4d5ee⟧
└─⟦this⟧ »decomp/labeltab.c«
/*
* Module: labeltab.c
*
* Author: J. Reuter
*
* This file contains the code and data structures to manage
* 'labels'. Two types of labels exist--global and local.
*
* Global labels are function entry points. Access is through:
* glb_add - add a global label entry
* glb_first - get pointer to first global label entry
* glb_next - get pointer to next global label entry
*
* Local labels are destinations of jumps, branches, and case branches.
* A new list is build for each function, with llb_purge() destroying
* the list between processing of functions. Access is through:
* llb_add - add a local label entry
* llb_first - get pointer to first local label entry
* llb_next - get pointer to next local label entry
* llb_purge - destroy local label list
*/
#include "defs.h"
#include "labeltab.h"
/*
* The glb structure is used to build a list of global 'labels'
* (function entry points). It is kept in increasing address order.
*/
private struct glb glb_head = {-1, 0, 0, 0}; /* list head */
private struct glb *glb_cur; /* pointer to 'current' entry */
/*
* glb_add adds an entry to the global label table.
* The entries are kept sorted by increasing 'address'.
* Parameters:
* l_address - the label address
* sym - the symbol table entry number
* local - global (0) or local (1) status (locals are 'static functions')
*/
glb_add( l_address, sym, local )
register address l_address;
register int sym;
register int local;
{
register struct glb *m, *p, *prev_p;
/*
* starting with the list head, search down the chain until we find
* the appropriate place to insert the entry.
*/
p = &glb_head;
do {
prev_p = p;
p = p->next;
} while ( p != NULL && p->l_address <= l_address );
/*
* Now insert the entry between 'prev_p' and 'p'. If the entry
* already exists (prev_p->l_address = l_address) do nothing.
*/
if ( prev_p->l_address != l_address ) {
m = (struct glb *) malloc( sizeof( struct glb ) );
if ( m == NULL ) {
fprintf( stderr, "Out of memory\n" );
exit( 1 );
}
m->l_address = l_address;
m->sym_num = sym;
m->local = local;
prev_p->next = m;
m->next = p;
}
}
/*
* glb_first returns a pointer to the first entry in the global label table
*/
struct glb *glb_first()
{
glb_cur = glb_head.next;
return glb_cur;
}
/*
* glb_next returns a pointer to the next entry in the global label table
*/
struct glb *
glb_next()
{
if ( glb_cur != NULL )
glb_cur = glb_cur->next;
return glb_cur;
}
/*
* The llb structure is used to build a list of local 'labels'.
* These include branch, jump, and case destinations.
*/
private struct llb llb_head = {-1, 0, 0}; /* list head */
private struct llb *llb_cur; /* pointer to list */
/*
* llb_add adds an entry to the local label table.
* The entries are kept sorted by increasing 'address'.
* Parameters:
* l_address - the label address
* caselab - set to indicate the target of a case label
*/
llb_add( l_address, caselab )
register address l_address;
register int caselab;
{
register struct llb *m, *p, *prev_p;
p = &llb_head;
do {
prev_p = p;
p = p->next;
} while ( p != NULL && p->l_address <= l_address );
if ( prev_p->l_address != l_address ) {
m = (struct llb *) malloc( sizeof( struct llb ) );
if ( m == NULL ) {
fprintf( stderr, "Out of memory\n" );
exit( 1 );
}
m->l_address = l_address;
m->caselab = caselab;
prev_p->next = m;
m->next = p;
}
}
/*
* llb_first returns a pointer to the first entry in the local label table
*/
struct llb *
llb_first()
{
llb_cur = llb_head.next;
return llb_cur;
}
/*
* llb_next returns a pointer to the next entry in the local label table
*/
struct llb *
llb_next()
{
if ( llb_cur != NULL )
llb_cur = llb_cur->next;
return llb_cur;
}
/*
* llb_purge removes all entries from the local label table
*/
llb_purge()
{
register struct llb *p, *np;
p = llb_head.next;
while ( p != NULL ) {
np = p->next;
free( p );
p = np;
}
llb_head.next = NULL;
}