symtable.h File Reference

Contains functions for manipulating a symtable structure. More...

#include "defines.h"

Go to the source code of this file.

Functions

symtablesymtable_create ()
 Creates a new symtable structure.
void symtable_add (const char *sym, vsignal *sig, int msb, int lsb)
 Creates a new symtable entry and adds it to the specified symbol table.
void symtable_set_value (const char *sym, const char *value)
 Sets all matching symtable entries to specified value.
void symtable_assign (const sim_time *time)
 Assigns stored values to all associated signals stored in specified symbol table.
void symtable_dealloc (symtable *symtab)
 Deallocates all symtable entries for specified symbol table.

Detailed Description

Contains functions for manipulating a symtable structure.

Author:
Trevor Williams (phase1geo@gmail.com)
Date:
1/3/2002

Function Documentation

void symtable_add ( const char *  sym,
vsignal sig,
int  msb,
int  lsb 
)

Creates a new symtable entry and adds it to the specified symbol table.

Using the symbol as a unique ID, creates a new symtable element for specified information and places it into the binary tree.

Parameters:
sym VCD symbol for the specified signal
sig Pointer to signal corresponding to the specified symbol
msb Most significant bit of variable to set
lsb Least significant bit of variable to set

References PROFILE, PROFILE_END, symtable_s::sig_head, symtable_add_sym_sig(), symtable_create(), symtable_init(), symtable_s::table, vsignal_s::value, and vcd_symtab_size.

Referenced by db_assign_symbol().

00239   { PROFILE(SYMTABLE_ADD);
00240 
00241   symtable*   curr;  /* Pointer to current symtable entry */
00242   const char* ptr;   /* Pointer to current character in sym */
00243 
00244   assert( vcd_symtab != NULL );
00245   assert( sym[0]     != '\0' );
00246   assert( sig->value != NULL );
00247 
00248   curr = vcd_symtab;
00249   ptr  = sym;
00250 
00251   while( *ptr != '\0' ) {
00252     if( curr->table[(int)*ptr] == NULL ) {
00253       curr->table[(int)*ptr] = symtable_create();
00254     }
00255     curr = curr->table[(int)*ptr];
00256     ptr++;
00257   }
00258 
00259   if( curr->sig_head == NULL ) {
00260     if( msb < lsb ) {
00261       symtable_init( curr, lsb, msb );
00262     } else {
00263       symtable_init( curr, msb, lsb );
00264     }
00265   }
00266 
00267   symtable_add_sym_sig( curr, sig, msb, lsb );
00268 
00269   /* 
00270    Finally increment the number of entries in the root table structure.
00271   */
00272   vcd_symtab_size++;
00273 
00274   PROFILE_END;
00275 
00276 }

void symtable_assign ( const sim_time time  ) 

Assigns stored values to all associated signals stored in specified symbol table.

Exceptions:
anonymous vsignal_vcd_assign

Traverses simulation symentry array, assigning stored string value to the stored signal.

Parameters:
time Pointer to current simulation time structure

References sym_sig_s::lsb, sym_sig_s::msb, sym_sig_s::next, postsim_size, PROFILE, PROFILE_END, sym_sig_s::sig, symtable_s::sig_head, symtable_s::value, and vsignal_vcd_assign().

Referenced by db_do_timestep().

00334   { PROFILE(SYMTABLE_ASSIGN);
00335 
00336   symtable* curr;  /* Pointer to current symtable entry */
00337   sym_sig*  sig;   /* Pointer to current sym_sig in list */
00338   int       i;     /* Loop iterator */
00339 
00340   for( i=0; i<postsim_size; i++ ) {
00341     curr = timestep_tab[i];
00342     sig = curr->sig_head;
00343     while( sig != NULL ) {
00344       vsignal_vcd_assign( sig->sig, curr->value, sig->msb, sig->lsb, time );
00345       sig = sig->next;
00346     }
00347     curr->value[0] = '\0';
00348   }
00349   postsim_size = 0;
00350 
00351   PROFILE_END;
00352 
00353 }

symtable* symtable_create (  ) 

Creates a new symtable structure.

Returns:
Returns a pointer to the newly created symbol table entry.

Creates a new symbol table entry and returns a pointer to the newly created structure.

References malloc_safe, PROFILE, PROFILE_END, symtable_s::sig_head, symtable_s::sig_tail, symtable_s::table, and symtable_s::value.

Referenced by covered_sim_calltf(), fst_parse(), lxt_parse(), symtable_add(), and vcd_parse().

00211                             { PROFILE(SYMTABLE_CREATE);
00212 
00213   symtable* symtab;  /* Pointer to new symtable entry */
00214   int       i;       /* Loop iterator */
00215 
00216   symtab           = (symtable*)malloc_safe( sizeof( symtable ) );
00217   symtab->sig_head = NULL;
00218   symtab->sig_tail = NULL;
00219   symtab->value    = NULL;
00220   for( i=0; i<256; i++ ) {
00221     symtab->table[i] = NULL;
00222   }
00223 
00224   PROFILE_END;
00225 
00226   return( symtab );
00227 
00228 }

void symtable_dealloc ( symtable symtab  ) 

Deallocates all symtable entries for specified symbol table.

Recursively deallocates all elements of specifies symbol table.

Parameters:
symtab Pointer to root of symtable to clear

References free_safe, sym_sig_s::next, PROFILE, PROFILE_END, symtable_s::sig_head, symtable_s::size, symtable_dealloc(), symtable_s::table, and symtable_s::value.

Referenced by covered_end_of_sim(), fst_parse(), lxt_parse(), symtable_dealloc(), and vcd_parse().

00360   { PROFILE(SYMTABLE_DEALLOC);
00361 
00362   sym_sig* curr;  /* Pointer to current sym_sig in list */
00363   sym_sig* tmp;   /* Temporary pointer to sym_sig */
00364   int      i;     /* Loop iterator */
00365 
00366   if( symtab != NULL ) {
00367 
00368     for( i=0; i<256; i++ ) {
00369       symtable_dealloc( symtab->table[i] );
00370     }
00371 
00372     if( symtab->value != NULL ) {
00373       free_safe( symtab->value, symtab->size );
00374     }
00375 
00376     /* Remove sym_sig list */
00377     curr = symtab->sig_head;
00378     while( curr != NULL ) {
00379       tmp = curr->next;
00380       free_safe( curr, sizeof( sym_sig ) );
00381       curr = tmp;
00382     }
00383 
00384     free_safe( symtab, sizeof( symtable ) );
00385 
00386   }
00387 
00388   PROFILE_END;
00389 
00390 }

void symtable_set_value ( const char *  sym,
const char *  value 
)

Sets all matching symtable entries to specified value.

Performs a binary search of the specified tree to find all matching symtable entries. When the signal is found, the specified value is assigned to the symtable entry.

Parameters:
sym Name of symbol to find in the table
value Value to set symtable entry to when match found

References FALSE, postsim_size, PROFILE, PROFILE_END, symtable_s::size, symtable_s::table, TRUE, and symtable_s::value.

Referenced by db_set_symbol_char(), and db_set_symbol_string().

00285   { PROFILE(SYMTABLE_SET_VALUE);
00286 
00287   symtable*   curr;         /* Pointer to current symtable */
00288   const char* ptr;          /* Pointer to current character in symbol */
00289   bool        set = FALSE;  /* Specifies if this symtable entry has been set this timestep yet */
00290 
00291   assert( vcd_symtab != NULL );
00292   assert( sym[0] != '\0' );
00293 
00294   curr = vcd_symtab;
00295   ptr  = sym;
00296 
00297   while( (curr != NULL) && (*ptr != '\0') ) {
00298     curr = curr->table[(int)*ptr];
00299     ptr++;
00300   }
00301 
00302   if( (curr != NULL) && (curr->value != NULL) ) {
00303 
00304     if( curr->value[0] != '\0' ) {
00305       set = TRUE;
00306     }
00307 
00308     /* printf( "strlen( value ): %d, curr->size: %d\n", strlen( value ), curr->size ); */
00309     assert( strlen( value ) < curr->size );     /* Useful for debugging but not necessary */
00310     strcpy( curr->value, value );
00311 
00312     if( !set ) {
00313 
00314       /* Place in postsim queue */
00315       timestep_tab[postsim_size] = curr;
00316       postsim_size++;
00317    
00318     }
00319 
00320   }
00321 
00322   PROFILE_END;
00323 
00324 }

Generated on Sun Nov 21 00:55:41 2010 for Covered by  doxygen 1.6.3