Add vpiModule iterator to vpiScope objects.

This commit is contained in:
steve 2002-05-03 15:44:11 +00:00
parent d126a414bd
commit fb457128bf
6 changed files with 101 additions and 19 deletions

View File

@ -17,7 +17,7 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
#if !defined(WINNT) && !defined(macintosh)
#ident "$Id: vpi_iter.cc,v 1.2 2001/05/08 23:59:33 steve Exp $"
#ident "$Id: vpi_iter.cc,v 1.3 2002/05/03 15:44:11 steve Exp $"
#endif
/*
@ -28,17 +28,32 @@
# include <stdlib.h>
# include <assert.h>
static int iterator_free_object(vpiHandle ref)
{
struct __vpiIterator*hp = (struct __vpiIterator*)ref;
assert(ref->vpi_type->type_code == vpiIterator);
if (hp->free_args_flag)
free(hp->args);
free(hp);
return 0;
}
static const struct __vpirt vpip_iterator_rt = {
vpiIterator,
0,
0,
0,
0,
0,
0
0, // vpi_get_
0, // vpi_get_str_
0, // vpi_get_value_
0, // vpi_put_value_
0, // handle_
0, // iterate_
0, // index_
&iterator_free_object
};
vpiHandle vpip_make_iterator(unsigned nargs, vpiHandle*args)
vpiHandle vpip_make_iterator(unsigned nargs, vpiHandle*args,
bool free_args_flag)
{
struct __vpiIterator*res = (struct __vpiIterator*)
calloc(1, sizeof(struct __vpiIterator));
@ -47,6 +62,8 @@ vpiHandle vpip_make_iterator(unsigned nargs, vpiHandle*args)
res->nargs = nargs;
res->next = 0;
res->free_args_flag = free_args_flag;
return &(res->base);
}
@ -72,6 +89,9 @@ vpiHandle vpi_scan(vpiHandle ref)
/*
* $Log: vpi_iter.cc,v $
* Revision 1.3 2002/05/03 15:44:11 steve
* Add vpiModule iterator to vpiScope objects.
*
* Revision 1.2 2001/05/08 23:59:33 steve
* Add ivl and vvp.tgt support for memories in
* expressions and l-values. (Stephan Boettcher)

View File

@ -27,7 +27,7 @@
* Picture Elements, Inc., 777 Panoramic Way, Berkeley, CA 94704.
*/
#if !defined(WINNT) && !defined(macintosh)
#ident "$Id: vpi_memory.cc,v 1.5 2002/02/06 04:48:34 steve Exp $"
#ident "$Id: vpi_memory.cc,v 1.6 2002/05/03 15:44:11 steve Exp $"
#endif
# include "vpi_priv.h"
@ -119,6 +119,12 @@ static vpiHandle memory_scan(vpiHandle ref, int)
return &rfp->word.base;
}
static int mem_iter_free_object(vpiHandle ref)
{
free(ref);
return 0;
}
static const struct __vpirt vpip_mem_iter_rt = {
vpiIterator,
0,
@ -128,6 +134,7 @@ static const struct __vpirt vpip_mem_iter_rt = {
0,
0,
memory_scan,
&mem_iter_free_object
};
static vpiHandle memory_iterate(int code, vpiHandle ref)
@ -363,6 +370,9 @@ vpiHandle vpip_make_memory(vvp_memory_t mem)
/*
* $Log: vpi_memory.cc,v $
* Revision 1.6 2002/05/03 15:44:11 steve
* Add vpiModule iterator to vpiScope objects.
*
* Revision 1.5 2002/02/06 04:48:34 steve
* get bin or hex string values of memory words.
*

View File

@ -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.13 2002/04/07 00:46:21 steve Exp $"
#ident "$Id: vpi_priv.cc,v 1.14 2002/05/03 15:44:11 steve Exp $"
#endif
# include "vpi_priv.h"
@ -38,8 +38,8 @@ struct __vpiSysTaskCall*vpip_cur_task = 0;
int vpi_free_object(vpiHandle ref)
{
free(ref);
return 0;
assert(ref->vpi_type->vpi_free_object_);
return ref->vpi_type->vpi_free_object_(ref);
}
static int vpip_get_global(int property)
@ -190,6 +190,9 @@ extern "C" void vpi_sim_vcontrol(int operation, va_list ap)
/*
* $Log: vpi_priv.cc,v $
* Revision 1.14 2002/05/03 15:44:11 steve
* Add vpiModule iterator to vpiScope objects.
*
* Revision 1.13 2002/04/07 00:46:21 steve
* minor cleanup of formatting.
*

View File

@ -19,7 +19,7 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
#if !defined(WINNT)
#ident "$Id: vpi_priv.h,v 1.31 2002/04/20 04:33:23 steve Exp $"
#ident "$Id: vpi_priv.h,v 1.32 2002/05/03 15:44:11 steve Exp $"
#endif
# include "vpi_user.h"
@ -61,20 +61,32 @@ struct __vpirt {
vpiHandle (*handle_)(int, vpiHandle);
vpiHandle (*iterate_)(int, vpiHandle);
vpiHandle (*index_)(vpiHandle, int);
/* This implements the vpi_free_object method. */
int (*vpi_free_object_)(vpiHandle);
};
/*
* The vpiHandle for an iterator has this structure. The definition of
* the methods lives in vpi_iter.c
*
* The args and nargs members point to the array of vpiHandle objects
* that are to be iterated over. The next member is the index of the
* next item to be returned by a vpi_scan.
*
* The free_args_flag member is true if when this iterator object is
* released it must also free the args array.
*/
struct __vpiIterator {
struct __vpiHandle base;
vpiHandle *args;
unsigned nargs;
unsigned next;
bool free_args_flag;
};
extern vpiHandle vpip_make_iterator(unsigned nargs, vpiHandle*args);
extern vpiHandle vpip_make_iterator(unsigned nargs, vpiHandle*args,
bool free_args_flag);
/*
* Scopes are created by .scope statements in the source.
@ -272,6 +284,9 @@ extern unsigned vpip_bits_to_dec_str(const unsigned char *bits,
/*
* $Log: vpi_priv.h,v $
* Revision 1.32 2002/05/03 15:44:11 steve
* Add vpiModule iterator to vpiScope objects.
*
* Revision 1.31 2002/04/20 04:33:23 steve
* Support specified times in cbReadOnlySync, and
* add support for cbReadWriteSync.

View File

@ -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.12 2002/01/06 17:50:50 steve Exp $"
#ident "$Id: vpi_scope.cc,v 1.13 2002/05/03 15:44:11 steve Exp $"
#endif
# include "compile.h"
@ -35,7 +35,8 @@ static unsigned vpip_root_table_cnt = 0;
vpiHandle vpip_make_root_iterator(void)
{
return vpip_make_iterator(vpip_root_table_cnt, vpip_root_table_ptr);
return vpip_make_iterator(vpip_root_table_cnt,
vpip_root_table_ptr, false);
}
static char* scope_get_str(int code, vpiHandle obj)
@ -90,6 +91,12 @@ static vpiHandle scope_get_handle(int code, vpiHandle obj)
return 0;
}
/*
* This function implements the vpi_iterate method for vpiModule and
* similar objects. The vpi_iterate allows the user to iterate over
* things that are contained in the scope object, by generating an
* iterator for the requested set of items.
*/
static vpiHandle module_iter(int code, vpiHandle obj)
{
struct __vpiScope*ref = (struct __vpiScope*)obj;
@ -101,7 +108,28 @@ static vpiHandle module_iter(int code, vpiHandle obj)
switch (code) {
case vpiInternalScope:
return vpip_make_iterator(ref->nintern, ref->intern);
return vpip_make_iterator(ref->nintern, ref->intern, false);
/* Generate and iterator for all the modules contained
in this scope. */
case vpiModule:
{ unsigned mcnt = 0, ncnt = 0;
vpiHandle*args;
for (unsigned idx = 0 ; idx < ref->nintern ; idx += 1)
if (ref->intern[idx]->vpi_type->type_code == vpiModule)
mcnt += 1;
if (mcnt == 0)
return 0;
args = (vpiHandle*)calloc(mcnt, sizeof(vpiHandle));
for (unsigned idx = 0 ; idx < ref->nintern ; idx += 1)
if (ref->intern[idx]->vpi_type->type_code == vpiModule)
args[ncnt++] = ref->intern[idx];
assert(ncnt == mcnt);
return vpip_make_iterator(mcnt, args, true);
}
}
return 0;
}
@ -343,6 +371,9 @@ void vpip_attach_to_current_scope(vpiHandle obj)
/*
* $Log: vpi_scope.cc,v $
* Revision 1.13 2002/05/03 15:44:11 steve
* Add vpiModule iterator to vpiScope objects.
*
* Revision 1.12 2002/01/06 17:50:50 steve
* Support scope for functors. (Stephan Boettcher)
*

View File

@ -17,7 +17,7 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
#if !defined(WINNT)
#ident "$Id: vpi_tasks.cc,v 1.11 2002/04/07 02:34:10 steve Exp $"
#ident "$Id: vpi_tasks.cc,v 1.12 2002/05/03 15:44:11 steve Exp $"
#endif
/*
@ -82,7 +82,7 @@ static vpiHandle systask_iter(int type, vpiHandle ref)
if (rfp->nargs == 0)
return 0;
return vpip_make_iterator(rfp->nargs, rfp->args);
return vpip_make_iterator(rfp->nargs, rfp->args, false);
}
static const struct __vpirt vpip_systask_rt = {
@ -335,6 +335,9 @@ void vpi_register_systf(const struct t_vpi_systf_data*ss)
/*
* $Log: vpi_tasks.cc,v $
* Revision 1.12 2002/05/03 15:44:11 steve
* Add vpiModule iterator to vpiScope objects.
*
* Revision 1.11 2002/04/07 02:34:10 steve
* Set vpip_cur_task while calling compileft
*