Add missing vpiModule handle code.

Most named objects should have a vpiModule handle to get a handle
to the enclosing module. This patch adds code to get this for all
the elements that I could find that needed it.

It also adds a three more names to vpi_get_str(vpiType, ...) and
fixes a problem in the vpiLeftRange for PV signals.
This commit is contained in:
Cary R 2009-01-16 11:09:48 -08:00 committed by Stephen Williams
parent 6f9ddea07f
commit 3e2c828778
8 changed files with 56 additions and 14 deletions

View File

@ -387,6 +387,9 @@ static vpiHandle vpi_array_get_handle(int code, vpiHandle ref)
case vpiScope:
return &obj->scope->base;
case vpiModule:
return vpip_module(obj->scope);
}
return 0;
@ -529,6 +532,9 @@ static vpiHandle vpi_array_var_word_get_handle(int code, vpiHandle ref)
case vpiScope:
return &parent->scope->base;
case vpiModule:
return vpip_module(parent->scope);
}
return 0;
@ -720,6 +726,9 @@ static vpiHandle vpi_array_vthr_A_get_handle(int code, vpiHandle ref)
case vpiScope:
return &parent->scope->base;
case vpiModule:
return vpip_module(parent->scope);
}
return 0;

View File

@ -291,6 +291,9 @@ static vpiHandle string_param_handle(int code, vpiHandle obj)
case vpiScope:
return &rfp->scope->base;
case vpiModule:
return vpip_module(rfp->scope);
default:
return 0;
}
@ -492,6 +495,9 @@ static vpiHandle binary_param_handle(int code, vpiHandle obj)
case vpiScope:
return &rfp->scope->base;
case vpiModule:
return vpip_module(rfp->scope);
default:
return 0;
}
@ -745,6 +751,9 @@ static vpiHandle real_param_handle(int code, vpiHandle obj)
case vpiScope:
return &rfp->scope->base;
case vpiModule:
return vpip_module(rfp->scope);
default:
return 0;
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2002-2007 Stephen Williams (steve@icarus.com)
* Copyright (c) 2002-2009 Stephen Williams (steve@icarus.com)
*
* This source code is free software; you can redistribute it
* and/or modify it in source code form under the terms of the GNU
@ -61,9 +61,11 @@ static vpiHandle named_event_get_handle(int code, vpiHandle ref)
struct __vpiNamedEvent*obj = (struct __vpiNamedEvent*)ref;
switch (code) {
case vpiScope:
return &obj->scope->base;
case vpiModule:
return vpip_module(obj->scope);
}
return 0;

View File

@ -66,6 +66,15 @@ struct __vpiScope* vpip_scope(__vpiRealVar*sig)
return sig->within.scope;
}
vpiHandle vpip_module(struct __vpiScope*scope)
{
while(scope && scope->base.vpi_type->type_code != vpiModule) {
scope = scope->scope;
}
assert(scope);
return &scope->base;
}
const char *vpip_string(const char*str)
{
static vpip_string_chunk first_chunk = {0, {0}};
@ -218,6 +227,12 @@ static const char* vpi_type_values(PLI_INT32 code)
return "vpiMemoryWord";
case vpiModule:
return "vpiModule";
case vpiNamedBegin:
return "vpiNamedBegin";
case vpiNamedEvent:
return "vpiNamedEvent";
case vpiNamedFork:
return "vpiNamedFork";
case vpiNet:
return "vpiNet";
case vpiParameter:

View File

@ -595,4 +595,7 @@ extern char *need_result_buf(unsigned cnt, vpi_rbuf_t type);
extern char *simple_set_rbuf_str(const char *s1);
extern char *generic_get_str(int code, vpiHandle ref, const char *name, const char *index);
/* A routine to find the enclosing module. */
extern vpiHandle vpip_module(struct __vpiScope*scope);
#endif

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2003-2008 Stephen Williams (steve@icarus.com)
* Copyright (c) 2003-2009 Stephen Williams (steve@icarus.com)
*
* This source code is free software; you can redistribute it
* and/or modify it in source code form under the terms of the GNU
@ -103,6 +103,9 @@ static vpiHandle real_var_get_handle(int code, vpiHandle ref)
case vpiScope:
return &(vpip_scope(rfp)->base);
case vpiModule:
return vpip_module(vpip_scope(rfp));
}
return 0;

View File

@ -596,13 +596,7 @@ static vpiHandle signal_get_handle(int code, vpiHandle ref)
return &(vpip_scope(rfp)->base);
case vpiModule:
{ struct __vpiScope*scope = vpip_scope(rfp);
while (scope && scope->base.vpi_type->type_code != vpiModule)
scope = scope->scope;
assert(scope);
return &scope->base;
}
return vpip_module(vpip_scope(rfp));
}
return 0;
@ -977,7 +971,7 @@ static int PV_get(int code, vpiHandle ref)
return rfp->sbase == 0 && rfp->twid == 0;
case vpiLeftRange:
rval += rfp->width;
rval += rfp->width - 1;
case vpiRightRange:
rval += vpi_get(vpiRightRange, rfp->parent) + PV_get_base(rfp);
return rval;
@ -1129,10 +1123,11 @@ static vpiHandle PV_get_handle(int code, vpiHandle ref)
struct __vpiPV*rfp = (struct __vpiPV*)ref;
switch (code) {
case vpiParent:
return rfp->parent;
break;
case vpiModule:
return vpi_handle(vpiModule, rfp->parent);
}
return 0;

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2001-2008 Stephen Williams (steve@icarus.com)
* Copyright (c) 2001-2009 Stephen Williams (steve@icarus.com)
*
* This source code is free software; you can redistribute it
* and/or modify it in source code form under the terms of the GNU
@ -62,6 +62,7 @@ static vpiHandle systask_handle(int type, vpiHandle ref)
switch (type) {
case vpiScope:
return &rfp->scope->base;
default:
return 0;
};
@ -75,8 +76,13 @@ static int systask_get(int type, vpiHandle ref)
|| (ref->vpi_type->type_code == vpiSysFuncCall));
switch (type) {
/* This is not the correct way to get this information, but
* some of the code that implements the acc and tf routines
* use this method so we will keep it in for now. */
case vpiTimeUnit:
return rfp->scope->time_units;
case vpiTimePrecision:
return rfp->scope->time_precision;
case vpiLineNo:
return rfp->lineno;