diff --git a/vpi/sys_lxt.c b/vpi/sys_lxt.c index d03b3a31a..f6b4ed644 100644 --- a/vpi/sys_lxt.c +++ b/vpi/sys_lxt.c @@ -17,7 +17,7 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA */ #if !defined(WINNT) && !defined(macintosh) -#ident "$Id: sys_lxt.c,v 1.8 2002/07/15 03:57:30 steve Exp $" +#ident "$Id: sys_lxt.c,v 1.9 2002/07/17 05:13:43 steve Exp $" #endif # include "config.h" @@ -548,7 +548,7 @@ static void scan_item(unsigned depth, vpiHandle item, int skip) /* Value */ vpiNet, vpiReg, - vpiIntegerVar, + vpiVariables, /* Scope */ vpiFunction, vpiModule, @@ -570,6 +570,7 @@ static void scan_item(unsigned depth, vpiHandle item, int skip) case vpiNet: type = "wire"; if(0){ case vpiIntegerVar: + case vpiTimeVar: case vpiReg: type = "reg"; } if (skip) @@ -812,6 +813,10 @@ void sys_lxt_register() /* * $Log: sys_lxt.c,v $ + * Revision 1.9 2002/07/17 05:13:43 steve + * Implementation of vpi_handle_by_name, and + * add the vpiVariables iterator. + * * Revision 1.8 2002/07/15 03:57:30 steve * Fix dangling pointer in pop_scope. * diff --git a/vpi/sys_vcd.c b/vpi/sys_vcd.c index 210520b32..29b683591 100644 --- a/vpi/sys_vcd.c +++ b/vpi/sys_vcd.c @@ -17,7 +17,7 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA */ #if !defined(WINNT) && !defined(macintosh) -#ident "$Id: sys_vcd.c,v 1.34 2002/07/12 17:09:21 steve Exp $" +#ident "$Id: sys_vcd.c,v 1.35 2002/07/17 05:13:43 steve Exp $" #endif # include "config.h" @@ -537,7 +537,7 @@ static void scan_item(unsigned depth, vpiHandle item, int skip) /* Value */ vpiNet, vpiReg, - vpiIntegerVar, + vpiVariables, /* Scope */ vpiFunction, vpiModule, @@ -559,6 +559,7 @@ static void scan_item(unsigned depth, vpiHandle item, int skip) case vpiNet: type = "wire"; if(0){ case vpiIntegerVar: + case vpiTimeVar: case vpiReg: type = "reg"; } if (skip) @@ -800,6 +801,10 @@ void sys_vcd_register() /* * $Log: sys_vcd.c,v $ + * Revision 1.35 2002/07/17 05:13:43 steve + * Implementation of vpi_handle_by_name, and + * add the vpiVariables iterator. + * * Revision 1.34 2002/07/12 17:09:21 steve * Remember to scan IntegerVars. * diff --git a/vpi_user.h b/vpi_user.h index 541846969..92a89f339 100644 --- a/vpi_user.h +++ b/vpi_user.h @@ -19,7 +19,7 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA */ #if !defined(WINNT) && !defined(macintosh) -#ident "$Id: vpi_user.h,v 1.12 2002/06/21 04:59:35 steve Exp $" +#ident "$Id: vpi_user.h,v 1.13 2002/07/17 05:13:43 steve Exp $" #endif @@ -173,6 +173,7 @@ typedef struct t_vpi_value { #define vpiSysTfCall 85 #define vpiArgument 89 #define vpiInternalScope 92 +#define vpiVariables 100 #define vpiCallback 1000 @@ -287,6 +288,7 @@ extern vpiHandle vpi_handle(int type, vpiHandle ref); extern vpiHandle vpi_iterate(int type, vpiHandle ref); extern vpiHandle vpi_scan(vpiHandle iter); extern vpiHandle vpi_handle_by_index(vpiHandle ref, int index); +extern vpiHandle vpi_handle_by_name(char*name, vpiHandle scope); extern void vpi_get_time(vpiHandle obj, s_vpi_time*t); extern int vpi_get(int property, vpiHandle ref); @@ -326,6 +328,10 @@ EXTERN_C_END /* * $Log: vpi_user.h,v $ + * Revision 1.13 2002/07/17 05:13:43 steve + * Implementation of vpi_handle_by_name, and + * add the vpiVariables iterator. + * * Revision 1.12 2002/06/21 04:59:35 steve * Carry integerness throughout the compilation. * diff --git a/vvp/vpi_priv.cc b/vvp/vpi_priv.cc index 73f3b8247..0c6c41f9d 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 */ #if !defined(WINNT) -#ident "$Id: vpi_priv.cc,v 1.19 2002/07/12 02:04:44 steve Exp $" +#ident "$Id: vpi_priv.cc,v 1.20 2002/07/17 05:13:43 steve Exp $" #endif # include "vpi_priv.h" @@ -211,14 +211,14 @@ vpiHandle vpi_iterate(int type, vpiHandle ref) "vpi_register_systf. You can't do that!\n"); return 0; } - + if (ref == 0) return vpi_iterate_global(type); if (ref->vpi_type->iterate_) - return (ref->vpi_type->iterate_)(type, ref); + return (ref->vpi_type->iterate_)(type, ref); else - return 0; + return 0; } vpiHandle vpi_handle_by_index(vpiHandle ref, int idx) @@ -228,6 +228,98 @@ vpiHandle vpi_handle_by_index(vpiHandle ref, int idx) return (ref->vpi_type->index_)(ref, idx); } +static vpiHandle find_name(char *name, vpiHandle handle) +{ + vpiHandle rtn = 0; + struct __vpiScope*ref = (struct __vpiScope*)handle; + + /* check module names */ + if (!strcmp(name, vpi_get_str(vpiName, handle))) + rtn = handle; + + /* brute force search for the name in all objects in this scope */ + for (unsigned i = 0 ; i < ref->nintern ; i += 1) { + char *nm = vpi_get_str(vpiName, ref->intern[i]); + if (!strcmp(name, nm)) { + rtn = ref->intern[i]; + break; + } else if (vpi_get(vpiType, ref->intern[i]) == vpiMemory) { + /* We need to iterate on the words */ + vpiHandle word_i, word_h; + word_i = vpi_iterate(vpiMemoryWord, ref->intern[i]); + while (word_i && (word_h = vpi_scan(word_i))) { + nm = vpi_get_str(vpiName, word_h); + if (!strcmp(name, nm)) { + rtn = word_h; + break; + } + } + } + /* found it yet? */ + if (rtn) break; + } + + return rtn; +} + +static vpiHandle find_scope(char *name, vpiHandle handle, int depth) +{ + vpiHandle iter, hand, rtn = 0; + + iter = !handle ? vpi_iterate(vpiModule, NULL) : + vpi_iterate(vpiInternalScope, handle); + + while (iter && (hand = vpi_scan(iter))) { + char *nm = vpi_get_str(vpiName, hand); + int len = strlen(nm); + char *cp = name + len; /* hier seperator */ + + if (!handle && !strcmp(name, nm)) { + /* root module */ + rtn = hand; + } else if (!strncmp(name, nm, len) && *(cp) == '.') + /* recurse deeper */ + rtn = find_scope(cp+1, hand, depth + 1); + + /* found it yet ? */ + if (rtn) break; + } + + /* matched up to here */ + if (!rtn) rtn = handle; + + return rtn; +} + +vpiHandle vpi_handle_by_name(char *name, vpiHandle scope) +{ + vpiHandle hand; + char *nm, *cp; + int len; + + /* If scope provided, look in cooresponding module; otherwise + * traverse the hierarcy specified in name to find the leaf module + * and try finding it there. + */ + if (scope) + hand = vpi_handle(vpiModule, scope); + else + hand = find_scope(name, NULL, 0); + + if (hand) { + /* remove hierarchical portion of name */ + nm = vpi_get_str(vpiFullName, hand); + len = strlen(nm); + cp = name + len; + if (!strncmp(name, nm, len) && *cp == '.') name = cp + 1; + + /* Ok, time to burn some cycles */ + return find_name(name, hand); + } + + return 0; +} + extern "C" void vpi_vprintf(const char*fmt, va_list ap) { vprintf(fmt, ap); @@ -248,6 +340,10 @@ extern "C" void vpi_sim_vcontrol(int operation, va_list ap) /* * $Log: vpi_priv.cc,v $ + * Revision 1.20 2002/07/17 05:13:43 steve + * Implementation of vpi_handle_by_name, and + * add the vpiVariables iterator. + * * Revision 1.19 2002/07/12 02:04:44 steve * vpi_iterate return null if there is nothing to iterate. * @@ -296,4 +392,3 @@ extern "C" void vpi_sim_vcontrol(int operation, va_list ap) * Revision 1.6 2001/06/21 22:54:12 steve * Support cbValueChange callbacks. */ - diff --git a/vvp/vpi_scope.cc b/vvp/vpi_scope.cc index fc71466f7..dc040e472 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 */ #if !defined(WINNT) -#ident "$Id: vpi_scope.cc,v 1.18 2002/07/14 02:52:05 steve Exp $" +#ident "$Id: vpi_scope.cc,v 1.19 2002/07/17 05:13:43 steve Exp $" #endif # include "compile.h" @@ -97,19 +97,22 @@ static vpiHandle scope_get_handle(int code, vpiHandle obj) return 0; } -/* Handle subclasses for vpiTypes */ -static inline int compare_types(int code, int type) +/* compares vpiType's considering object classes */ +static int compare_types(int code, int type) { - if (code == type || - code == vpiScope && - type == vpiModule || - type == vpiFunction || - type == vpiTask || - type == vpiNamedBegin || - type == vpiNamedFork) - { + if ( code == type + || (code == vpiInternalScope && + (type == vpiModule || + type == vpiFunction || + type == vpiTask || + type == vpiNamedBegin || + type == vpiNamedFork)) + || (code == vpiVariables && + (type == vpiIntegerVar || + type == vpiTimeVar)) + ) return 1; - } else + else return 0; } @@ -152,10 +155,6 @@ static vpiHandle module_iter(int code, vpiHandle obj) switch (code) { case vpiInternalScope: - return module_iter_subset(vpiScope, ref); - - /* Generate and iterator for all the modules contained - in this scope. */ case vpiMemory: case vpiModule: case vpiNamedEvent: @@ -408,6 +407,10 @@ void vpip_attach_to_current_scope(vpiHandle obj) /* * $Log: vpi_scope.cc,v $ + * Revision 1.19 2002/07/17 05:13:43 steve + * Implementation of vpi_handle_by_name, and + * add the vpiVariables iterator. + * * Revision 1.18 2002/07/14 02:52:05 steve * Fix vpiScope iterator. *