2001-03-18 01:37:55 +01:00
|
|
|
/*
|
2003-03-03 02:47:50 +01:00
|
|
|
* Copyright (c) 2001-2003 Stephen Williams (steve@icarus.com)
|
2001-03-18 01:37:55 +01:00
|
|
|
*
|
|
|
|
|
* This source code is free software; you can redistribute it
|
|
|
|
|
* and/or modify it in source code form under the terms of the GNU
|
|
|
|
|
* General Public License as published by the Free Software
|
|
|
|
|
* Foundation; either version 2 of the License, or (at your option)
|
|
|
|
|
* any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
|
|
|
|
|
*/
|
2002-08-12 03:34:58 +02:00
|
|
|
#ifdef HAVE_CVS_IDENT
|
2003-03-06 05:32:00 +01:00
|
|
|
#ident "$Id: vpi_scope.cc,v 1.28 2003/03/06 04:32:00 steve Exp $"
|
2001-03-18 01:37:55 +01:00
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
# include "compile.h"
|
|
|
|
|
# include "vpi_priv.h"
|
|
|
|
|
# include "symbols.h"
|
2002-01-06 18:50:50 +01:00
|
|
|
# include "functor.h"
|
2002-07-05 19:14:15 +02:00
|
|
|
# include "statistics.h"
|
2001-09-15 20:27:04 +02:00
|
|
|
#ifdef HAVE_MALLOC_H
|
2001-03-18 01:37:55 +01:00
|
|
|
# include <malloc.h>
|
2001-09-15 20:27:04 +02:00
|
|
|
#endif
|
2002-07-12 20:23:30 +02:00
|
|
|
# include <string.h>
|
2001-09-15 20:27:04 +02:00
|
|
|
# include <stdlib.h>
|
2001-03-18 01:37:55 +01:00
|
|
|
# include <assert.h>
|
|
|
|
|
|
2002-01-06 01:48:39 +01:00
|
|
|
static vpiHandle *vpip_root_table_ptr = 0;
|
|
|
|
|
static unsigned vpip_root_table_cnt = 0;
|
|
|
|
|
|
|
|
|
|
vpiHandle vpip_make_root_iterator(void)
|
|
|
|
|
{
|
2002-05-18 04:34:11 +02:00
|
|
|
assert(vpip_root_table_ptr);
|
|
|
|
|
assert(vpip_root_table_cnt);
|
2002-05-03 17:44:11 +02:00
|
|
|
return vpip_make_iterator(vpip_root_table_cnt,
|
|
|
|
|
vpip_root_table_ptr, false);
|
2002-01-06 01:48:39 +01:00
|
|
|
}
|
|
|
|
|
|
2003-02-23 07:41:54 +01:00
|
|
|
void vpip_make_root_iterator(struct __vpiHandle**&table, unsigned&ntable)
|
|
|
|
|
{
|
|
|
|
|
table = vpip_root_table_ptr;
|
|
|
|
|
ntable = vpip_root_table_cnt;
|
|
|
|
|
}
|
|
|
|
|
|
2002-12-21 01:55:57 +01:00
|
|
|
static bool handle_is_scope(vpiHandle obj)
|
|
|
|
|
{
|
|
|
|
|
return (obj->vpi_type->type_code == vpiModule)
|
|
|
|
|
|| (obj->vpi_type->type_code == vpiFunction)
|
|
|
|
|
|| (obj->vpi_type->type_code == vpiTask)
|
|
|
|
|
|| (obj->vpi_type->type_code == vpiNamedBegin)
|
|
|
|
|
|| (obj->vpi_type->type_code == vpiNamedFork);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int scope_get(int code, vpiHandle obj)
|
|
|
|
|
{
|
|
|
|
|
struct __vpiScope*ref = (struct __vpiScope*)obj;
|
|
|
|
|
|
|
|
|
|
assert(handle_is_scope(obj));
|
|
|
|
|
|
|
|
|
|
switch (code) {
|
|
|
|
|
case vpiTimeUnit:
|
|
|
|
|
return ref->time_units;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2003-03-03 02:47:50 +01:00
|
|
|
static void construct_scope_fullname(struct __vpiScope*ref, char*buf)
|
|
|
|
|
{
|
|
|
|
|
if (ref->scope) {
|
|
|
|
|
construct_scope_fullname(ref->scope, buf);
|
|
|
|
|
strcat(buf, ".");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
strcat(buf, ref->name);
|
|
|
|
|
}
|
|
|
|
|
|
2001-04-03 05:46:14 +02:00
|
|
|
static char* scope_get_str(int code, vpiHandle obj)
|
|
|
|
|
{
|
|
|
|
|
struct __vpiScope*ref = (struct __vpiScope*)obj;
|
2003-03-03 02:47:50 +01:00
|
|
|
char *rbuf = need_result_buf(strlen(ref->name) + 1, RBUF_STR);
|
2001-04-03 05:46:14 +02:00
|
|
|
|
2002-12-21 01:55:57 +01:00
|
|
|
assert(handle_is_scope(obj));
|
2001-04-03 05:46:14 +02:00
|
|
|
|
|
|
|
|
switch (code) {
|
2003-03-03 02:47:50 +01:00
|
|
|
case vpiFullName: {
|
|
|
|
|
char buf[4096];
|
|
|
|
|
buf[0] = 0;
|
|
|
|
|
construct_scope_fullname(ref, buf);
|
|
|
|
|
rbuf = need_result_buf(strlen(buf) + 1, RBUF_STR);
|
|
|
|
|
strcpy(rbuf, buf);
|
|
|
|
|
return rbuf;
|
|
|
|
|
}
|
2001-10-15 03:49:50 +02:00
|
|
|
|
|
|
|
|
case vpiName:
|
2003-03-03 02:47:50 +01:00
|
|
|
strcpy(rbuf, ref->name);
|
2002-07-12 20:23:30 +02:00
|
|
|
return rbuf;
|
2003-03-03 02:47:50 +01:00
|
|
|
|
2001-04-03 05:46:14 +02:00
|
|
|
default:
|
|
|
|
|
assert(0);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2001-10-15 03:49:50 +02:00
|
|
|
static vpiHandle scope_get_handle(int code, vpiHandle obj)
|
|
|
|
|
{
|
|
|
|
|
assert((obj->vpi_type->type_code == vpiModule)
|
2001-10-15 04:58:27 +02:00
|
|
|
|| (obj->vpi_type->type_code == vpiFunction)
|
|
|
|
|
|| (obj->vpi_type->type_code == vpiTask)
|
2001-10-15 03:49:50 +02:00
|
|
|
|| (obj->vpi_type->type_code == vpiNamedBegin)
|
2001-10-15 04:58:27 +02:00
|
|
|
|| (obj->vpi_type->type_code == vpiNamedFork));
|
2001-10-15 03:49:50 +02:00
|
|
|
|
|
|
|
|
struct __vpiScope*rfp = (struct __vpiScope*)obj;
|
|
|
|
|
|
|
|
|
|
switch (code) {
|
|
|
|
|
|
|
|
|
|
case vpiScope:
|
|
|
|
|
return &rfp->scope->base;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2002-07-17 07:13:43 +02:00
|
|
|
/* compares vpiType's considering object classes */
|
|
|
|
|
static int compare_types(int code, int type)
|
2002-07-14 04:52:05 +02:00
|
|
|
{
|
2002-11-15 23:14:12 +01:00
|
|
|
/* NOTE: The Verilog VPI does not for any object support
|
|
|
|
|
vpiScope as an iterator parameter, so it is used here as a
|
|
|
|
|
means to scan everything in the *current* scope. */
|
|
|
|
|
if (code == vpiScope)
|
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
|
|
if (code == type)
|
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
|
|
if ( code == vpiInternalScope &&
|
2002-07-17 07:13:43 +02:00
|
|
|
(type == vpiModule ||
|
|
|
|
|
type == vpiFunction ||
|
|
|
|
|
type == vpiTask ||
|
|
|
|
|
type == vpiNamedBegin ||
|
2002-11-15 23:14:12 +01:00
|
|
|
type == vpiNamedFork) )
|
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
|
|
if ( code == vpiVariables &&
|
2002-07-17 07:13:43 +02:00
|
|
|
(type == vpiIntegerVar ||
|
2003-02-11 06:20:45 +01:00
|
|
|
type == vpiTimeVar ||
|
|
|
|
|
type == vpiRealVar))
|
2002-11-15 23:14:12 +01:00
|
|
|
return 1;
|
|
|
|
|
|
|
|
|
|
return 0;
|
2002-07-14 04:52:05 +02:00
|
|
|
}
|
|
|
|
|
|
2002-05-10 18:00:57 +02:00
|
|
|
static vpiHandle module_iter_subset(int code, struct __vpiScope*ref)
|
|
|
|
|
{
|
|
|
|
|
unsigned mcnt = 0, ncnt = 0;
|
|
|
|
|
vpiHandle*args;
|
|
|
|
|
|
|
|
|
|
for (unsigned idx = 0 ; idx < ref->nintern ; idx += 1)
|
2002-07-14 04:52:05 +02:00
|
|
|
if (compare_types(code, ref->intern[idx]->vpi_type->type_code))
|
2002-05-10 18:00:57 +02:00
|
|
|
mcnt += 1;
|
|
|
|
|
|
|
|
|
|
if (mcnt == 0)
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
args = (vpiHandle*)calloc(mcnt, sizeof(vpiHandle));
|
|
|
|
|
for (unsigned idx = 0 ; idx < ref->nintern ; idx += 1)
|
2002-07-14 04:52:05 +02:00
|
|
|
if (compare_types(code, ref->intern[idx]->vpi_type->type_code))
|
2002-05-10 18:00:57 +02:00
|
|
|
args[ncnt++] = ref->intern[idx];
|
|
|
|
|
|
|
|
|
|
assert(ncnt == mcnt);
|
|
|
|
|
|
|
|
|
|
return vpip_make_iterator(mcnt, args, true);
|
|
|
|
|
}
|
|
|
|
|
|
2002-05-03 17:44:11 +02:00
|
|
|
/*
|
|
|
|
|
* 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.
|
|
|
|
|
*/
|
2001-04-03 05:46:14 +02:00
|
|
|
static vpiHandle module_iter(int code, vpiHandle obj)
|
|
|
|
|
{
|
|
|
|
|
struct __vpiScope*ref = (struct __vpiScope*)obj;
|
|
|
|
|
assert((obj->vpi_type->type_code == vpiModule)
|
2001-10-15 04:58:27 +02:00
|
|
|
|| (obj->vpi_type->type_code == vpiFunction)
|
2001-04-03 05:46:14 +02:00
|
|
|
|| (obj->vpi_type->type_code == vpiTask)
|
2001-10-15 04:58:27 +02:00
|
|
|
|| (obj->vpi_type->type_code == vpiNamedBegin)
|
|
|
|
|
|| (obj->vpi_type->type_code == vpiNamedFork));
|
2001-04-03 05:46:14 +02:00
|
|
|
|
2002-11-15 23:14:12 +01:00
|
|
|
return module_iter_subset(code, ref);
|
2001-04-03 05:46:14 +02:00
|
|
|
}
|
|
|
|
|
|
2002-01-06 18:50:50 +01:00
|
|
|
/*
|
|
|
|
|
** Keeping track of functor scope. When the scope changes during
|
|
|
|
|
** compilation, we record the current number of functors in a list.
|
|
|
|
|
**
|
|
|
|
|
** Why are we doing this? The SDF annotator needs this for
|
|
|
|
|
** INTERCONNECT delays. The INTERCONNECT delay is specified between
|
|
|
|
|
** a source modules output port and a target module input port, which
|
|
|
|
|
** are connected with a wire. The vpiSignal for both ports point to
|
|
|
|
|
** the same functor output, together with all other ports that may be
|
|
|
|
|
** connected to the same wire. The SDF annotator need to find those
|
|
|
|
|
** functors which are inside the scope of the target module, which
|
|
|
|
|
** are driven by the source functor. And even this is only an
|
2003-02-10 00:33:26 +01:00
|
|
|
** approximation, in case the wire is connected to multiple inputs of
|
2002-01-06 18:50:50 +01:00
|
|
|
** the same module. But those should have the same delays anyway.
|
|
|
|
|
**
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
struct functor_scope_s {
|
|
|
|
|
vpiHandle scope;
|
|
|
|
|
unsigned start;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static struct functor_scope_s * functor_scopes = 0;
|
|
|
|
|
static unsigned n_functor_scopes = 0;
|
|
|
|
|
static unsigned a_functor_scopes = 0;
|
|
|
|
|
|
|
|
|
|
void functor_set_scope(vpiHandle scope)
|
|
|
|
|
{
|
|
|
|
|
unsigned nfun = functor_limit();
|
|
|
|
|
|
|
|
|
|
if (n_functor_scopes) {
|
|
|
|
|
functor_scope_s *last = &functor_scopes[n_functor_scopes - 1];
|
|
|
|
|
|
|
|
|
|
if (last->scope == scope) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (last->start == nfun) {
|
|
|
|
|
last->scope = scope;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
n_functor_scopes += 1;
|
|
|
|
|
if (n_functor_scopes >= a_functor_scopes) {
|
|
|
|
|
a_functor_scopes += 512;
|
|
|
|
|
functor_scopes = (struct functor_scope_s *)
|
|
|
|
|
realloc(functor_scopes,
|
|
|
|
|
a_functor_scopes*sizeof(struct functor_scope_s));
|
|
|
|
|
assert(functor_scopes);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
functor_scope_s *last = &functor_scopes[n_functor_scopes - 1];
|
|
|
|
|
last->start = nfun;
|
|
|
|
|
last->scope = scope;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
2003-02-10 00:33:26 +01:00
|
|
|
** Look up the scope of a functor.
|
2002-01-06 18:50:50 +01:00
|
|
|
**
|
2003-02-10 00:33:26 +01:00
|
|
|
** Cannot use bsearch, since we are not looking for an exact match
|
2002-01-06 18:50:50 +01:00
|
|
|
*/
|
|
|
|
|
vpiHandle ipoint_get_scope(vvp_ipoint_t ipt)
|
|
|
|
|
{
|
|
|
|
|
if (n_functor_scopes == 0)
|
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
|
|
unsigned fidx = ipt/4;
|
|
|
|
|
|
|
|
|
|
unsigned first = 0;
|
|
|
|
|
unsigned last = n_functor_scopes;
|
|
|
|
|
while (first < last) {
|
|
|
|
|
unsigned next = (first+last)/2;
|
|
|
|
|
functor_scope_s *cur = &functor_scopes[next];
|
|
|
|
|
|
|
|
|
|
if (cur->start > fidx)
|
|
|
|
|
last = next;
|
|
|
|
|
else if (next == first)
|
|
|
|
|
break;
|
|
|
|
|
else
|
|
|
|
|
first = next;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
functor_scope_s *cur = &functor_scopes[first];
|
|
|
|
|
return cur->scope;
|
|
|
|
|
}
|
|
|
|
|
|
2001-10-15 04:58:27 +02:00
|
|
|
static const struct __vpirt vpip_scope_module_rt = {
|
2001-04-03 05:46:14 +02:00
|
|
|
vpiModule,
|
2002-12-21 01:55:57 +01:00
|
|
|
scope_get,
|
2001-04-03 05:46:14 +02:00
|
|
|
scope_get_str,
|
|
|
|
|
0,
|
|
|
|
|
0,
|
2001-10-15 03:49:50 +02:00
|
|
|
scope_get_handle,
|
2001-04-03 05:46:14 +02:00
|
|
|
module_iter
|
|
|
|
|
};
|
|
|
|
|
|
2001-10-15 04:58:27 +02:00
|
|
|
static const struct __vpirt vpip_scope_task_rt = {
|
|
|
|
|
vpiTask,
|
2003-02-27 22:54:44 +01:00
|
|
|
scope_get,
|
2001-10-15 04:58:27 +02:00
|
|
|
scope_get_str,
|
|
|
|
|
0,
|
|
|
|
|
0,
|
|
|
|
|
scope_get_handle,
|
|
|
|
|
module_iter
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static const struct __vpirt vpip_scope_function_rt = {
|
|
|
|
|
vpiFunction,
|
2003-02-27 22:54:44 +01:00
|
|
|
scope_get,
|
2001-10-15 04:58:27 +02:00
|
|
|
scope_get_str,
|
|
|
|
|
0,
|
|
|
|
|
0,
|
|
|
|
|
scope_get_handle,
|
|
|
|
|
module_iter
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static const struct __vpirt vpip_scope_begin_rt = {
|
|
|
|
|
vpiNamedBegin,
|
2003-02-27 22:54:44 +01:00
|
|
|
scope_get,
|
2001-10-15 04:58:27 +02:00
|
|
|
scope_get_str,
|
|
|
|
|
0,
|
|
|
|
|
0,
|
|
|
|
|
scope_get_handle,
|
|
|
|
|
module_iter
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static const struct __vpirt vpip_scope_fork_rt = {
|
|
|
|
|
vpiNamedFork,
|
2003-02-27 22:54:44 +01:00
|
|
|
scope_get,
|
2001-10-15 04:58:27 +02:00
|
|
|
scope_get_str,
|
|
|
|
|
0,
|
|
|
|
|
0,
|
|
|
|
|
scope_get_handle,
|
|
|
|
|
module_iter
|
|
|
|
|
};
|
|
|
|
|
|
2002-12-21 01:55:57 +01:00
|
|
|
/*
|
|
|
|
|
* The current_scope is a compile time concept. As the vvp source is
|
|
|
|
|
* compiled, items that have scope are placed in the current
|
|
|
|
|
* scope. The ".scope" directives select the scope that is current.
|
|
|
|
|
*/
|
2001-03-18 01:37:55 +01:00
|
|
|
static struct __vpiScope*current_scope = 0;
|
|
|
|
|
|
|
|
|
|
static void attach_to_scope_(struct __vpiScope*scope, vpiHandle obj)
|
|
|
|
|
{
|
|
|
|
|
assert(scope);
|
|
|
|
|
unsigned idx = scope->nintern++;
|
|
|
|
|
|
|
|
|
|
if (scope->intern == 0)
|
|
|
|
|
scope->intern = (vpiHandle*)
|
|
|
|
|
malloc(sizeof(vpiHandle));
|
|
|
|
|
else
|
|
|
|
|
scope->intern = (vpiHandle*)
|
|
|
|
|
realloc(scope->intern, sizeof(vpiHandle)*scope->nintern);
|
|
|
|
|
|
|
|
|
|
scope->intern[idx] = obj;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* When the compiler encounters a scope declaration, this function
|
|
|
|
|
* creates and initializes a __vpiScope object with the requested name
|
|
|
|
|
* and within the addressed parent. The label is used as a key in the
|
|
|
|
|
* symbol table and the name is used to construct the actual object.
|
|
|
|
|
*/
|
2001-10-15 04:58:27 +02:00
|
|
|
void compile_scope_decl(char*label, char*type, char*name, char*parent)
|
2001-03-18 01:37:55 +01:00
|
|
|
{
|
2001-04-18 06:21:23 +02:00
|
|
|
struct __vpiScope*scope = new struct __vpiScope;
|
2002-07-05 19:14:15 +02:00
|
|
|
count_vpi_scopes += 1;
|
2001-10-15 04:58:27 +02:00
|
|
|
|
|
|
|
|
switch(type[2]) {
|
2002-01-06 18:50:50 +01:00
|
|
|
case 'd': /* type == moDule */
|
2001-11-02 06:43:11 +01:00
|
|
|
scope->base.vpi_type = &vpip_scope_module_rt;
|
|
|
|
|
break;
|
2002-01-06 18:50:50 +01:00
|
|
|
case 'n': /* type == fuNction */
|
2001-11-02 06:43:11 +01:00
|
|
|
scope->base.vpi_type = &vpip_scope_function_rt;
|
|
|
|
|
break;
|
2002-01-06 18:50:50 +01:00
|
|
|
case 's': /* type == taSk */
|
2001-11-02 06:43:11 +01:00
|
|
|
scope->base.vpi_type = &vpip_scope_task_rt;
|
|
|
|
|
break;
|
2002-01-06 18:50:50 +01:00
|
|
|
case 'r': /* type == foRk */
|
2001-11-02 06:43:11 +01:00
|
|
|
scope->base.vpi_type = &vpip_scope_fork_rt;
|
|
|
|
|
break;
|
2002-01-06 18:50:50 +01:00
|
|
|
case 'g': /* type == beGin */
|
2001-11-02 06:43:11 +01:00
|
|
|
scope->base.vpi_type = &vpip_scope_begin_rt;
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
scope->base.vpi_type = &vpip_scope_module_rt;
|
|
|
|
|
assert(0);
|
2001-10-15 04:58:27 +02:00
|
|
|
}
|
|
|
|
|
|
2001-11-02 06:43:11 +01:00
|
|
|
assert(scope->base.vpi_type);
|
|
|
|
|
|
2003-03-06 05:32:00 +01:00
|
|
|
scope->name = vpip_name_string(name);
|
2001-03-18 01:37:55 +01:00
|
|
|
scope->intern = 0;
|
|
|
|
|
scope->nintern = 0;
|
2001-04-18 06:21:23 +02:00
|
|
|
scope->threads = 0;
|
2001-03-18 01:37:55 +01:00
|
|
|
|
|
|
|
|
current_scope = scope;
|
|
|
|
|
|
2001-03-21 06:13:03 +01:00
|
|
|
compile_vpi_symbol(label, &scope->base);
|
2002-07-05 19:14:15 +02:00
|
|
|
|
2001-03-18 01:37:55 +01:00
|
|
|
free(label);
|
2002-07-05 19:14:15 +02:00
|
|
|
free(type);
|
|
|
|
|
free(name);
|
2001-03-18 01:37:55 +01:00
|
|
|
|
|
|
|
|
if (parent) {
|
2001-07-11 06:43:57 +02:00
|
|
|
static vpiHandle obj;
|
|
|
|
|
compile_vpi_lookup(&obj, parent);
|
|
|
|
|
assert(obj);
|
2001-03-21 06:13:03 +01:00
|
|
|
struct __vpiScope*sp = (struct __vpiScope*) obj;
|
2001-03-18 01:37:55 +01:00
|
|
|
attach_to_scope_(sp, &scope->base);
|
2001-10-15 03:49:50 +02:00
|
|
|
scope->scope = (struct __vpiScope*)obj;
|
2002-12-21 01:55:57 +01:00
|
|
|
|
|
|
|
|
/* Inherit time units from the parent scope. */
|
|
|
|
|
scope->time_units = sp->time_units;
|
|
|
|
|
|
2001-10-15 03:49:50 +02:00
|
|
|
} else {
|
|
|
|
|
scope->scope = 0x0;
|
2002-01-06 01:48:39 +01:00
|
|
|
|
|
|
|
|
unsigned cnt = vpip_root_table_cnt + 1;
|
|
|
|
|
vpip_root_table_ptr = (vpiHandle*)
|
|
|
|
|
realloc(vpip_root_table_ptr, cnt * sizeof(vpiHandle));
|
|
|
|
|
vpip_root_table_ptr[vpip_root_table_cnt] = &scope->base;
|
|
|
|
|
vpip_root_table_cnt = cnt;
|
2002-12-21 01:55:57 +01:00
|
|
|
|
|
|
|
|
/* Root scopes inherit time_units from system precision. */
|
|
|
|
|
scope->time_units = vpip_get_time_precision();
|
2001-03-18 01:37:55 +01:00
|
|
|
}
|
2002-01-06 18:50:50 +01:00
|
|
|
|
|
|
|
|
functor_set_scope(¤t_scope->base);
|
2001-03-18 01:37:55 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void compile_scope_recall(char*symbol)
|
|
|
|
|
{
|
2001-07-11 06:43:57 +02:00
|
|
|
compile_vpi_lookup((vpiHandle*)¤t_scope, symbol);
|
|
|
|
|
assert(current_scope);
|
2002-01-06 18:50:50 +01:00
|
|
|
functor_set_scope(¤t_scope->base);
|
2001-03-18 01:37:55 +01:00
|
|
|
}
|
|
|
|
|
|
2002-12-21 01:55:57 +01:00
|
|
|
/*
|
|
|
|
|
* This function handles the ".timescale" directive in the vvp
|
|
|
|
|
* source. It sets in the current scope the specified units value.
|
|
|
|
|
*/
|
|
|
|
|
void compile_timescale(long units)
|
|
|
|
|
{
|
|
|
|
|
assert(current_scope);
|
|
|
|
|
current_scope->time_units = units;
|
|
|
|
|
}
|
|
|
|
|
|
2001-04-18 06:21:23 +02:00
|
|
|
struct __vpiScope* vpip_peek_current_scope(void)
|
2001-03-18 01:37:55 +01:00
|
|
|
{
|
2001-04-18 06:21:23 +02:00
|
|
|
return current_scope;
|
2001-03-18 01:37:55 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void vpip_attach_to_current_scope(vpiHandle obj)
|
|
|
|
|
{
|
|
|
|
|
attach_to_scope_(current_scope, obj);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* $Log: vpi_scope.cc,v $
|
2003-03-06 05:32:00 +01:00
|
|
|
* Revision 1.28 2003/03/06 04:32:00 steve
|
|
|
|
|
* Use hashed name strings for identifiers.
|
|
|
|
|
*
|
2003-03-03 02:47:50 +01:00
|
|
|
* Revision 1.27 2003/03/03 01:47:50 steve
|
|
|
|
|
* .scope directives store only the base names.
|
|
|
|
|
*
|
2003-02-27 22:54:44 +01:00
|
|
|
* Revision 1.26 2003/02/27 21:54:44 steve
|
|
|
|
|
* Add scope type have a vpi_get function.
|
|
|
|
|
*
|
2003-02-23 07:41:54 +01:00
|
|
|
* Revision 1.25 2003/02/23 06:41:54 steve
|
|
|
|
|
* Add to interactive stop mode support for
|
|
|
|
|
* current scope, the ability to scan/traverse
|
|
|
|
|
* scopes, and the ability to call system tasks.
|
|
|
|
|
*
|
2003-02-11 06:20:45 +01:00
|
|
|
* Revision 1.24 2003/02/11 05:20:45 steve
|
|
|
|
|
* Include vpiRealVar objects in vpiVariables scan.
|
|
|
|
|
*
|
2003-02-10 00:33:26 +01:00
|
|
|
* Revision 1.23 2003/02/09 23:33:26 steve
|
|
|
|
|
* Spelling fixes.
|
|
|
|
|
*
|
2002-12-21 01:55:57 +01:00
|
|
|
* Revision 1.22 2002/12/21 00:55:58 steve
|
|
|
|
|
* The $time system task returns the integer time
|
|
|
|
|
* scaled to the local units. Change the internal
|
|
|
|
|
* implementation of vpiSystemTime the $time functions
|
|
|
|
|
* to properly account for this. Also add $simtime
|
|
|
|
|
* to get the simulation time.
|
|
|
|
|
*
|
2002-11-15 23:14:12 +01:00
|
|
|
* Revision 1.21 2002/11/15 22:14:12 steve
|
|
|
|
|
* Add vpiScope iterate on vpiScope objects.
|
|
|
|
|
*
|
2002-08-12 03:34:58 +02:00
|
|
|
* Revision 1.20 2002/08/12 01:35:09 steve
|
|
|
|
|
* conditional ident string using autoconfig.
|
|
|
|
|
*
|
2002-07-17 07:13:43 +02:00
|
|
|
* Revision 1.19 2002/07/17 05:13:43 steve
|
|
|
|
|
* Implementation of vpi_handle_by_name, and
|
|
|
|
|
* add the vpiVariables iterator.
|
|
|
|
|
*
|
2002-07-14 04:52:05 +02:00
|
|
|
* Revision 1.18 2002/07/14 02:52:05 steve
|
|
|
|
|
* Fix vpiScope iterator.
|
|
|
|
|
*
|
2002-07-12 20:23:30 +02:00
|
|
|
* Revision 1.17 2002/07/12 18:23:30 steve
|
|
|
|
|
* Use result buf for event and scope names.
|
|
|
|
|
*
|
2002-07-05 19:14:15 +02:00
|
|
|
* Revision 1.16 2002/07/05 17:14:15 steve
|
|
|
|
|
* Names of vpi objects allocated as vpip_strings.
|
|
|
|
|
*
|
2002-05-18 04:34:11 +02:00
|
|
|
* Revision 1.15 2002/05/18 02:34:11 steve
|
|
|
|
|
* Add vpi support for named events.
|
|
|
|
|
*
|
|
|
|
|
* Add vpi_mode_flag to track the mode of the
|
|
|
|
|
* vpi engine. This is for error checking.
|
2001-03-18 01:37:55 +01:00
|
|
|
*/
|
|
|
|
|
|