Use hashed name strings for identifiers.

This commit is contained in:
steve 2003-03-06 04:32:00 +00:00
parent 22d392a75c
commit ef47ea31fa
6 changed files with 70 additions and 10 deletions

View File

@ -17,7 +17,7 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
#ifdef HAVE_CVS_IDENT
#ident "$Id: vpi_event.cc,v 1.6 2003/02/02 01:40:24 steve Exp $"
#ident "$Id: vpi_event.cc,v 1.7 2003/03/06 04:32:00 steve Exp $"
#endif
# include "vpi_priv.h"
@ -92,7 +92,7 @@ vpiHandle vpip_make_named_event(const char*name)
malloc(sizeof(struct __vpiNamedEvent));
obj->base.vpi_type = &vpip_named_event_rt;
obj->name = vpip_string(name);
obj->name = vpip_name_string(name);
obj->scope = vpip_peek_current_scope();
obj->callbacks = 0;
@ -115,6 +115,9 @@ void vpip_run_named_event_callbacks(vpiHandle ref)
/*
* $Log: vpi_event.cc,v $
* Revision 1.7 2003/03/06 04:32:00 steve
* Use hashed name strings for identifiers.
*
* Revision 1.6 2003/02/02 01:40:24 steve
* Five vpi_free_object a default behavior.
*

View File

@ -17,7 +17,7 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
#ifdef HAVE_CVS_IDENT
#ident "$Id: vpi_priv.cc,v 1.31 2003/02/21 03:40:35 steve Exp $"
#ident "$Id: vpi_priv.cc,v 1.32 2003/03/06 04:32:00 steve Exp $"
#endif
# include "vpi_priv.h"
@ -69,6 +69,39 @@ const char *vpip_string(const char*str)
return res;
}
static unsigned hash_string(const char*text)
{
unsigned h = 0;
while (*text) {
h = (h << 4) ^ (h >> 28) ^ *text;
text += 1;
}
return h;
}
const char* vpip_name_string(const char*text)
{
const unsigned HASH_SIZE = 4096;
static const char*hash_table[HASH_SIZE] = {0};
unsigned hash_value = hash_string(text) % HASH_SIZE;
/* If we easily find the string in the hash table, then return
that and be done. */
if (hash_table[hash_value]
&& (strcmp(hash_table[hash_value], text) == 0)) {
return hash_table[hash_value];
}
/* The existing hash entry is not a match. Replace it with the
newly allocated value, and return the new pointer as the
result to the add. */
const char*res = vpip_string(text);
hash_table[hash_value] = res;
return res;
}
int vpi_chk_error(p_vpi_error_info info)
{
if (vpip_last_error.state == 0)
@ -399,6 +432,9 @@ extern "C" void vpi_control(int operation, ...)
/*
* $Log: vpi_priv.cc,v $
* Revision 1.32 2003/03/06 04:32:00 steve
* Use hashed name strings for identifiers.
*
* Revision 1.31 2003/02/21 03:40:35 steve
* Add vpiStop and interactive mode.
*

View File

@ -19,7 +19,7 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
#ifdef HAVE_CVS_IDENT
#ident "$Id: vpi_priv.h,v 1.50 2003/02/24 06:35:45 steve Exp $"
#ident "$Id: vpi_priv.h,v 1.51 2003/03/06 04:32:00 steve Exp $"
#endif
# include "vpi_user.h"
@ -354,7 +354,16 @@ extern void vpip_set_time_precision(int pres);
extern void vpip_time_to_timestruct(struct t_vpi_time*ts, vvp_time64_t ti);
extern vvp_time64_t vpip_timestruct_to_time(const struct t_vpi_time*ts);
/*
* These functions are used mostly as compile time to strings into
* permallocated memory. The vpip_string function is the most general,
* it allocates a fresh string no matter what. The vpip_name_string
* allocates a string and keeps a pointer in the hash, and tries to
* reuse it if it can. This us useful for handle names, which may be
* reused in different scopes.
*/
extern const char* vpip_string(const char*str);
extern const char* vpip_name_string(const char*str);
/*
** Functions defined in vpi_scope.cc, to keep track of functor scope.
@ -403,6 +412,9 @@ extern char *need_result_buf(unsigned cnt, vpi_rbuf_t type);
/*
* $Log: vpi_priv.h,v $
* Revision 1.51 2003/03/06 04:32:00 steve
* Use hashed name strings for identifiers.
*
* Revision 1.50 2003/02/24 06:35:45 steve
* Interactive task calls take string arguments.
*

View File

@ -17,7 +17,7 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
#ifdef HAVE_CVS_IDENT
#ident "$Id: vpi_real.cc,v 1.6 2003/02/28 21:20:34 steve Exp $"
#ident "$Id: vpi_real.cc,v 1.7 2003/03/06 04:32:00 steve Exp $"
#endif
# include "vpi_priv.h"
@ -169,7 +169,7 @@ vpiHandle vpip_make_real_var(const char*name)
malloc(sizeof(struct __vpiRealVar));
obj->base.vpi_type = &vpip_real_var_rt;
obj->name = vpip_string(name);
obj->name = vpip_name_string(name);
obj->value = 0.0;
obj->cb = 0;
@ -178,6 +178,9 @@ vpiHandle vpip_make_real_var(const char*name)
/*
* $Log: vpi_real.cc,v $
* Revision 1.7 2003/03/06 04:32:00 steve
* Use hashed name strings for identifiers.
*
* Revision 1.6 2003/02/28 21:20:34 steve
* Allow read of realvar as int.
*

View File

@ -17,7 +17,7 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
#ifdef HAVE_CVS_IDENT
#ident "$Id: vpi_scope.cc,v 1.27 2003/03/03 01:47:50 steve Exp $"
#ident "$Id: vpi_scope.cc,v 1.28 2003/03/06 04:32:00 steve Exp $"
#endif
# include "compile.h"
@ -390,7 +390,7 @@ void compile_scope_decl(char*label, char*type, char*name, char*parent)
assert(scope->base.vpi_type);
scope->name = vpip_string(name);
scope->name = vpip_name_string(name);
scope->intern = 0;
scope->nintern = 0;
scope->threads = 0;
@ -460,6 +460,9 @@ void vpip_attach_to_current_scope(vpiHandle obj)
/*
* $Log: vpi_scope.cc,v $
* Revision 1.28 2003/03/06 04:32:00 steve
* Use hashed name strings for identifiers.
*
* Revision 1.27 2003/03/03 01:47:50 steve
* .scope directives store only the base names.
*

View File

@ -17,7 +17,7 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
#ifdef HAVE_CVS_IDENT
#ident "$Id: vpi_signal.cc,v 1.53 2003/02/16 23:40:05 steve Exp $"
#ident "$Id: vpi_signal.cc,v 1.54 2003/03/06 04:32:00 steve Exp $"
#endif
/*
@ -761,7 +761,7 @@ vpiHandle vpip_make_net(const char*name, int msb, int lsb,
{
struct __vpiSignal*obj = allocate_vpiSignal();
obj->base.vpi_type = &vpip_net_rt;
obj->name = vpip_string(name);
obj->name = vpip_name_string(name);
obj->msb = msb;
obj->lsb = lsb;
obj->signed_flag = signed_flag? 1 : 0;
@ -779,6 +779,9 @@ vpiHandle vpip_make_net(const char*name, int msb, int lsb,
/*
* $Log: vpi_signal.cc,v $
* Revision 1.54 2003/03/06 04:32:00 steve
* Use hashed name strings for identifiers.
*
* Revision 1.53 2003/02/16 23:40:05 steve
* Permanent allocate vpiSignals more efficiently.
*