diff --git a/vvp/vpi_event.cc b/vvp/vpi_event.cc index 9b218ea24..15274f56c 100644 --- a/vvp/vpi_event.cc +++ b/vvp/vpi_event.cc @@ -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. * diff --git a/vvp/vpi_priv.cc b/vvp/vpi_priv.cc index 165d0e20b..4f157bf40 100644 --- a/vvp/vpi_priv.cc +++ b/vvp/vpi_priv.cc @@ -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. * diff --git a/vvp/vpi_priv.h b/vvp/vpi_priv.h index 0271433c3..18049474a 100644 --- a/vvp/vpi_priv.h +++ b/vvp/vpi_priv.h @@ -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. * diff --git a/vvp/vpi_real.cc b/vvp/vpi_real.cc index 7fe4f1737..8612d47cf 100644 --- a/vvp/vpi_real.cc +++ b/vvp/vpi_real.cc @@ -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. * diff --git a/vvp/vpi_scope.cc b/vvp/vpi_scope.cc index bdf92090b..e07a61185 100644 --- a/vvp/vpi_scope.cc +++ b/vvp/vpi_scope.cc @@ -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. * diff --git a/vvp/vpi_signal.cc b/vvp/vpi_signal.cc index 01d8cff07..6646c8dcd 100644 --- a/vvp/vpi_signal.cc +++ b/vvp/vpi_signal.cc @@ -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. *