2001-03-18 01:37:55 +01:00
|
|
|
/*
|
2013-01-03 01:59:04 +01:00
|
|
|
* Copyright (c) 2001-2013 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
|
2012-08-29 03:41:23 +02:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2001-03-18 01:37:55 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
# include "compile.h"
|
|
|
|
|
# include "vpi_priv.h"
|
|
|
|
|
# include "symbols.h"
|
2002-07-05 19:14:15 +02:00
|
|
|
# include "statistics.h"
|
2009-01-30 02:23:09 +01:00
|
|
|
# include "config.h"
|
|
|
|
|
#ifdef CHECK_WITH_VALGRIND
|
|
|
|
|
# include "vvp_cleanup.h"
|
|
|
|
|
#endif
|
2010-05-31 22:12:06 +02:00
|
|
|
# include <cstring>
|
|
|
|
|
# include <cstdlib>
|
|
|
|
|
# include <cassert>
|
2010-10-24 00:52:56 +02:00
|
|
|
# include "ivl_alloc.h"
|
2001-03-18 01:37:55 +01:00
|
|
|
|
2012-06-04 21:43:33 +02:00
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
2012-02-12 22:21:30 +01:00
|
|
|
void vpip_make_root_iterator(__vpiHandle**&table, unsigned&ntable)
|
2003-02-23 07:41:54 +01:00
|
|
|
{
|
|
|
|
|
table = vpip_root_table_ptr;
|
|
|
|
|
ntable = vpip_root_table_cnt;
|
|
|
|
|
}
|
|
|
|
|
|
2009-01-30 02:23:09 +01:00
|
|
|
#ifdef CHECK_WITH_VALGRIND
|
2012-10-09 03:52:24 +02:00
|
|
|
void port_delete(__vpiHandle*handle);
|
|
|
|
|
|
2009-01-30 02:23:09 +01:00
|
|
|
static void delete_sub_scopes(struct __vpiScope *scope)
|
|
|
|
|
{
|
|
|
|
|
for (unsigned idx = 0; idx < scope->nintern; idx += 1) {
|
2013-05-01 03:34:33 +02:00
|
|
|
struct __vpiScope*lscope = static_cast<__vpiScope*>
|
|
|
|
|
((scope->intern)[idx]);
|
2012-10-09 03:52:24 +02:00
|
|
|
switch(scope->intern[idx]->get_type_code()) {
|
2009-01-30 02:23:09 +01:00
|
|
|
case vpiFunction:
|
|
|
|
|
case vpiTask:
|
|
|
|
|
contexts_delete(lscope);
|
|
|
|
|
case vpiModule:
|
2013-07-17 19:55:46 +02:00
|
|
|
case vpiGenScope:
|
2009-01-30 02:23:09 +01:00
|
|
|
case vpiNamedBegin:
|
|
|
|
|
case vpiNamedFork:
|
|
|
|
|
delete_sub_scopes(lscope);
|
2010-01-09 19:38:24 +01:00
|
|
|
vthreads_delete(lscope);
|
2009-01-30 02:23:09 +01:00
|
|
|
delete (scope->intern)[idx];
|
|
|
|
|
break;
|
|
|
|
|
case vpiMemory:
|
2009-02-27 21:34:48 +01:00
|
|
|
case vpiNetArray:
|
2009-01-30 02:23:09 +01:00
|
|
|
memory_delete((scope->intern)[idx]);
|
|
|
|
|
break;
|
|
|
|
|
case vpiModPath:
|
|
|
|
|
/* The destination ModPath is cleaned up later. */
|
2012-10-09 03:52:24 +02:00
|
|
|
delete (scope->intern)[idx];
|
2009-01-30 02:23:09 +01:00
|
|
|
break;
|
|
|
|
|
case vpiNamedEvent:
|
|
|
|
|
named_event_delete((scope->intern)[idx]);
|
|
|
|
|
break;
|
|
|
|
|
case vpiNet:
|
|
|
|
|
case vpiReg:
|
2010-10-23 00:12:53 +02:00
|
|
|
case vpiIntegerVar:
|
|
|
|
|
case vpiLongIntVar:
|
|
|
|
|
case vpiShortIntVar:
|
|
|
|
|
case vpiIntVar:
|
|
|
|
|
case vpiByteVar:
|
2011-04-04 19:47:20 +02:00
|
|
|
case vpiBitVar:
|
2009-01-30 02:23:09 +01:00
|
|
|
signal_delete((scope->intern)[idx]);
|
|
|
|
|
break;
|
|
|
|
|
case vpiParameter:
|
|
|
|
|
parameter_delete((scope->intern)[idx]);
|
|
|
|
|
break;
|
|
|
|
|
case vpiRealVar:
|
2009-01-31 03:36:07 +01:00
|
|
|
real_delete((scope->intern)[idx]);
|
2011-10-10 07:20:40 +02:00
|
|
|
break;
|
|
|
|
|
case vpiEnumTypespec:
|
|
|
|
|
enum_delete((scope->intern)[idx]);
|
2009-01-30 02:23:09 +01:00
|
|
|
break;
|
2012-10-09 03:52:24 +02:00
|
|
|
case vpiPort:
|
|
|
|
|
port_delete((scope->intern)[idx]);
|
|
|
|
|
break;
|
|
|
|
|
case vpiStringVar:
|
2012-12-18 20:08:30 +01:00
|
|
|
string_delete((scope->intern)[idx]);
|
|
|
|
|
break;
|
|
|
|
|
case vpiClassVar:
|
|
|
|
|
class_delete((scope->intern)[idx]);
|
|
|
|
|
break;
|
2012-10-09 03:52:24 +02:00
|
|
|
case vpiRegArray:
|
2012-12-18 20:08:30 +01:00
|
|
|
darray_delete((scope->intern)[idx]);
|
2012-10-09 03:52:24 +02:00
|
|
|
break;
|
2009-01-30 02:23:09 +01:00
|
|
|
default:
|
|
|
|
|
fprintf(stderr, "Need support for type: %d\n",
|
2012-10-09 03:52:24 +02:00
|
|
|
scope->intern[idx]->get_type_code());
|
2009-01-30 02:23:09 +01:00
|
|
|
assert(0);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
free(scope->intern);
|
2013-01-03 01:59:04 +01:00
|
|
|
|
|
|
|
|
/* Clean up any class definitions. */
|
|
|
|
|
map<std::string, class_type*>::iterator citer;
|
|
|
|
|
for (citer = scope->classes.begin();
|
|
|
|
|
citer != scope->classes.end(); ++ citer ) {
|
|
|
|
|
class_def_delete(citer->second);
|
|
|
|
|
}
|
2009-01-30 02:23:09 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void root_table_delete(void)
|
|
|
|
|
{
|
|
|
|
|
for (unsigned idx = 0; idx < vpip_root_table_cnt; idx += 1) {
|
2013-05-01 03:34:33 +02:00
|
|
|
struct __vpiScope *scope = static_cast<__vpiScope *>
|
|
|
|
|
(vpip_root_table_ptr[idx]);
|
2009-01-30 02:23:09 +01:00
|
|
|
delete_sub_scopes(scope);
|
2010-01-09 19:38:24 +01:00
|
|
|
vthreads_delete(scope);
|
2009-01-30 02:23:09 +01:00
|
|
|
delete scope;
|
|
|
|
|
}
|
|
|
|
|
free(vpip_root_table_ptr);
|
|
|
|
|
vpip_root_table_ptr = 0;
|
|
|
|
|
vpip_root_table_cnt = 0;
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
2002-12-21 01:55:57 +01:00
|
|
|
static int scope_get(int code, vpiHandle obj)
|
|
|
|
|
{
|
2012-01-19 19:16:39 +01:00
|
|
|
struct __vpiScope*ref = dynamic_cast<__vpiScope*>(obj);
|
|
|
|
|
assert(obj);
|
2002-12-21 01:55:57 +01:00
|
|
|
|
|
|
|
|
switch (code) {
|
2009-05-21 23:41:58 +02:00
|
|
|
case vpiCellInstance:
|
|
|
|
|
return (int) ref->is_cell;
|
|
|
|
|
|
2008-04-30 03:58:25 +02:00
|
|
|
case vpiDefLineNo:
|
|
|
|
|
return ref->def_lineno;
|
|
|
|
|
|
2008-01-01 18:45:02 +01:00
|
|
|
case vpiLineNo:
|
2008-04-30 03:58:25 +02:00
|
|
|
return ref->lineno;
|
2008-01-01 18:45:02 +01:00
|
|
|
|
2002-12-21 01:55:57 +01:00
|
|
|
case vpiTimeUnit:
|
|
|
|
|
return ref->time_units;
|
2007-11-08 18:56:18 +01:00
|
|
|
|
2003-05-27 18:22:10 +02:00
|
|
|
case vpiTimePrecision:
|
2007-09-28 20:21:08 +02:00
|
|
|
return ref->time_precision;
|
2007-11-08 18:56:18 +01:00
|
|
|
|
|
|
|
|
case vpiTopModule:
|
|
|
|
|
return 0x0 == ref->scope;
|
2008-11-09 01:26:55 +01:00
|
|
|
|
|
|
|
|
case vpiAutomatic:
|
|
|
|
|
return (int) ref->is_automatic;
|
2002-12-21 01:55:57 +01:00
|
|
|
}
|
|
|
|
|
|
2011-12-06 04:52:49 +01:00
|
|
|
return vpiUndefined;
|
2002-12-21 01:55:57 +01:00
|
|
|
}
|
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
2007-08-16 06:05:42 +02:00
|
|
|
static const char* scope_get_type(int code)
|
|
|
|
|
{
|
|
|
|
|
switch (code) {
|
|
|
|
|
case vpiModule:
|
|
|
|
|
return "vpiModule";
|
2013-07-17 19:55:46 +02:00
|
|
|
case vpiGenScope:
|
|
|
|
|
return "vpiGenScope";
|
2007-08-16 06:05:42 +02:00
|
|
|
case vpiFunction:
|
|
|
|
|
return "vpiFunction";
|
|
|
|
|
case vpiTask:
|
|
|
|
|
return "vpiTask";
|
|
|
|
|
case vpiNamedBegin:
|
|
|
|
|
return "vpiNamedBegin";
|
|
|
|
|
case vpiNamedFork:
|
|
|
|
|
return "vpiNamedFork";
|
|
|
|
|
default:
|
2011-12-06 04:52:49 +01:00
|
|
|
fprintf(stderr, "VPI error: invalid scope type code %d.\n", code);
|
|
|
|
|
return NULL;
|
2007-08-16 06:05:42 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2001-04-03 05:46:14 +02:00
|
|
|
static char* scope_get_str(int code, vpiHandle obj)
|
|
|
|
|
{
|
2012-01-19 19:16:39 +01:00
|
|
|
struct __vpiScope*ref = dynamic_cast<__vpiScope*>(obj);
|
|
|
|
|
assert(ref);
|
2001-04-03 05:46:14 +02:00
|
|
|
|
2007-12-19 00:11:50 +01:00
|
|
|
char buf[4096]; // XXX is a fixed buffer size really reliable?
|
|
|
|
|
const char *p=0;
|
2001-04-03 05:46:14 +02:00
|
|
|
switch (code) {
|
2008-04-30 03:58:25 +02:00
|
|
|
case vpiDefFile:
|
|
|
|
|
p = file_names[ref->def_file_idx];
|
|
|
|
|
break;
|
|
|
|
|
|
2008-01-01 18:45:02 +01:00
|
|
|
case vpiFile:
|
2008-04-30 03:58:25 +02:00
|
|
|
p = file_names[ref->file_idx];
|
2008-01-01 18:45:02 +01:00
|
|
|
break;
|
|
|
|
|
|
2007-12-19 00:11:50 +01:00
|
|
|
case vpiFullName:
|
|
|
|
|
buf[0] = 0;
|
|
|
|
|
construct_scope_fullname(ref, buf);
|
|
|
|
|
p = buf;
|
|
|
|
|
break;
|
2001-10-15 03:49:50 +02:00
|
|
|
|
|
|
|
|
case vpiName:
|
2007-12-19 00:11:50 +01:00
|
|
|
p = ref->name;
|
|
|
|
|
break;
|
2003-03-03 02:47:50 +01:00
|
|
|
|
2003-05-29 04:21:45 +02:00
|
|
|
case vpiDefName:
|
2007-12-19 00:11:50 +01:00
|
|
|
p = ref->tname;
|
|
|
|
|
break;
|
2003-05-29 04:21:45 +02:00
|
|
|
|
2007-08-16 06:05:42 +02:00
|
|
|
case vpiType:
|
2007-12-19 00:11:50 +01:00
|
|
|
p = scope_get_type(code);
|
|
|
|
|
break;
|
2007-08-16 06:05:42 +02:00
|
|
|
|
2001-04-03 05:46:14 +02:00
|
|
|
default:
|
2011-12-06 04:52:49 +01:00
|
|
|
fprintf(stderr, "VPI error: invalid scope string code %d.\n", code);
|
|
|
|
|
return NULL;
|
2001-04-03 05:46:14 +02:00
|
|
|
}
|
2007-12-19 00:11:50 +01:00
|
|
|
return simple_set_rbuf_str(p);
|
2001-04-03 05:46:14 +02:00
|
|
|
}
|
|
|
|
|
|
2001-10-15 03:49:50 +02:00
|
|
|
static vpiHandle scope_get_handle(int code, vpiHandle obj)
|
|
|
|
|
{
|
2012-01-19 19:16:39 +01:00
|
|
|
struct __vpiScope*rfp = dynamic_cast<__vpiScope*>(obj);
|
|
|
|
|
assert(rfp);
|
2001-10-15 03:49:50 +02:00
|
|
|
|
|
|
|
|
switch (code) {
|
|
|
|
|
|
|
|
|
|
case vpiScope:
|
2012-01-19 19:16:39 +01:00
|
|
|
return rfp->scope;
|
2003-03-14 06:01:22 +01:00
|
|
|
|
|
|
|
|
case vpiModule:
|
2012-01-19 19:16:39 +01:00
|
|
|
return rfp->scope;
|
2001-10-15 03:49:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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 ||
|
2013-07-17 19:55:46 +02:00
|
|
|
type == vpiGenScope ||
|
2002-07-17 07:13:43 +02:00
|
|
|
type == vpiFunction ||
|
|
|
|
|
type == vpiTask ||
|
|
|
|
|
type == vpiNamedBegin ||
|
2002-11-15 23:14:12 +01:00
|
|
|
type == vpiNamedFork) )
|
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
|
|
if ( code == vpiVariables &&
|
2011-09-06 17:58:25 +02:00
|
|
|
(type == vpiIntegerVar ||
|
|
|
|
|
type == vpiBitVar ||
|
|
|
|
|
type == vpiByteVar ||
|
|
|
|
|
type == vpiShortIntVar ||
|
|
|
|
|
type == vpiIntVar ||
|
|
|
|
|
type == vpiLongIntVar ||
|
|
|
|
|
type == vpiTimeVar ||
|
2003-02-11 06:20:45 +01:00
|
|
|
type == vpiRealVar))
|
2008-09-04 18:41:51 +02:00
|
|
|
return 1;
|
2002-11-15 23:14:12 +01:00
|
|
|
|
|
|
|
|
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)
|
2012-01-19 19:16:39 +01:00
|
|
|
if (compare_types(code, ref->intern[idx]->get_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)
|
2012-01-19 19:16:39 +01:00
|
|
|
if (compare_types(code, ref->intern[idx]->get_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)
|
|
|
|
|
{
|
2012-01-19 19:16:39 +01:00
|
|
|
struct __vpiScope*ref = dynamic_cast<__vpiScope*>(obj);
|
|
|
|
|
assert(ref);
|
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
|
|
|
|
2012-01-20 20:39:48 +01:00
|
|
|
int __vpiScope::vpi_get(int code)
|
|
|
|
|
{ return scope_get(code, this); }
|
|
|
|
|
|
|
|
|
|
char*__vpiScope::vpi_get_str(int code)
|
|
|
|
|
{ return scope_get_str(code, this); }
|
|
|
|
|
|
|
|
|
|
vpiHandle __vpiScope::vpi_handle(int code)
|
|
|
|
|
{ return scope_get_handle(code, this); }
|
|
|
|
|
|
|
|
|
|
vpiHandle __vpiScope::vpi_iterate(int code)
|
|
|
|
|
{ return module_iter(code, this); }
|
|
|
|
|
|
2001-04-03 05:46:14 +02:00
|
|
|
|
2012-01-20 00:04:51 +01:00
|
|
|
struct vpiScopeModule : public __vpiScope {
|
2012-01-20 23:15:26 +01:00
|
|
|
inline vpiScopeModule() { }
|
2012-01-20 00:04:51 +01:00
|
|
|
int get_type_code(void) const { return vpiModule; }
|
|
|
|
|
};
|
|
|
|
|
|
2013-02-17 23:42:07 +01:00
|
|
|
struct vpiScopePackage : public __vpiScope {
|
|
|
|
|
inline vpiScopePackage() { }
|
|
|
|
|
int get_type_code(void) const { return vpiPackage; }
|
|
|
|
|
};
|
|
|
|
|
|
2012-01-20 00:04:51 +01:00
|
|
|
struct vpiScopeTask : public __vpiScope {
|
2012-01-20 23:15:26 +01:00
|
|
|
inline vpiScopeTask() { }
|
2012-01-20 00:04:51 +01:00
|
|
|
int get_type_code(void) const { return vpiTask; }
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct vpiScopeFunction : public __vpiScope {
|
2012-01-20 23:15:26 +01:00
|
|
|
inline vpiScopeFunction() { }
|
2012-01-20 00:04:51 +01:00
|
|
|
int get_type_code(void) const { return vpiFunction; }
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct vpiScopeBegin : public __vpiScope {
|
2012-01-20 23:15:26 +01:00
|
|
|
inline vpiScopeBegin() { }
|
2012-01-20 00:04:51 +01:00
|
|
|
int get_type_code(void) const { return vpiNamedBegin; }
|
|
|
|
|
};
|
|
|
|
|
|
2013-07-17 19:55:46 +02:00
|
|
|
struct vpiScopeGenerate : public __vpiScope {
|
|
|
|
|
inline vpiScopeGenerate() { }
|
|
|
|
|
int get_type_code(void) const { return vpiGenScope; }
|
|
|
|
|
};
|
|
|
|
|
|
2012-01-20 00:04:51 +01:00
|
|
|
struct vpiScopeFork : public __vpiScope {
|
2012-01-20 23:15:26 +01:00
|
|
|
inline vpiScopeFork() { }
|
2012-01-20 00:04:51 +01:00
|
|
|
int get_type_code(void) const { return vpiNamedFork; }
|
|
|
|
|
};
|
|
|
|
|
|
2013-03-23 04:07:08 +01:00
|
|
|
struct vpiScopeClass : public __vpiScope {
|
|
|
|
|
inline vpiScopeClass() { }
|
|
|
|
|
int get_type_code(void) const { return vpiClassTypespec; }
|
|
|
|
|
};
|
|
|
|
|
|
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;
|
|
|
|
|
|
2009-09-28 03:29:07 +02:00
|
|
|
void vpip_attach_to_scope(struct __vpiScope*scope, vpiHandle obj)
|
2001-03-18 01:37:55 +01:00
|
|
|
{
|
|
|
|
|
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.
|
|
|
|
|
*/
|
2003-05-29 04:21:45 +02:00
|
|
|
void
|
2009-01-13 18:57:12 +01:00
|
|
|
compile_scope_decl(char*label, char*type, char*name, char*tname,
|
2008-04-30 03:58:25 +02:00
|
|
|
char*parent, long file_idx, long lineno,
|
2009-05-21 23:41:58 +02:00
|
|
|
long def_file_idx, long def_lineno, long is_cell)
|
2001-03-18 01:37:55 +01:00
|
|
|
{
|
2002-07-05 19:14:15 +02:00
|
|
|
count_vpi_scopes += 1;
|
2001-10-15 04:58:27 +02:00
|
|
|
|
2012-01-19 19:16:39 +01:00
|
|
|
char*base_type;
|
|
|
|
|
bool is_automatic;
|
2008-11-09 01:26:55 +01:00
|
|
|
if (strncmp(type,"auto",4) == 0) {
|
2012-01-19 19:16:39 +01:00
|
|
|
is_automatic = true;
|
2008-11-09 01:26:55 +01:00
|
|
|
base_type = &type[4];
|
|
|
|
|
} else {
|
2012-01-19 19:16:39 +01:00
|
|
|
is_automatic = false;
|
2008-11-09 01:26:55 +01:00
|
|
|
base_type = &type[0];
|
|
|
|
|
}
|
|
|
|
|
|
2012-01-19 19:16:39 +01:00
|
|
|
struct __vpiScope*scope;
|
2008-11-09 01:26:55 +01:00
|
|
|
if (strcmp(base_type,"module") == 0) {
|
2012-01-20 00:04:51 +01:00
|
|
|
scope = new vpiScopeModule;
|
2008-11-09 01:26:55 +01:00
|
|
|
} else if (strcmp(base_type,"function") == 0) {
|
2012-01-20 00:04:51 +01:00
|
|
|
scope = new vpiScopeFunction;
|
2008-11-09 01:26:55 +01:00
|
|
|
} else if (strcmp(base_type,"task") == 0) {
|
2012-01-20 00:04:51 +01:00
|
|
|
scope = new vpiScopeTask;
|
2008-11-09 01:26:55 +01:00
|
|
|
} else if (strcmp(base_type,"fork") == 0) {
|
2012-01-20 00:04:51 +01:00
|
|
|
scope = new vpiScopeFork;
|
2008-11-09 01:26:55 +01:00
|
|
|
} else if (strcmp(base_type,"begin") == 0) {
|
2012-01-20 00:04:51 +01:00
|
|
|
scope = new vpiScopeBegin;
|
2008-11-09 01:26:55 +01:00
|
|
|
} else if (strcmp(base_type,"generate") == 0) {
|
2013-07-17 19:55:46 +02:00
|
|
|
scope = new vpiScopeGenerate;
|
2013-02-17 23:42:07 +01:00
|
|
|
} else if (strcmp(base_type,"package") == 0) {
|
|
|
|
|
scope = new vpiScopePackage;
|
2013-03-23 04:07:08 +01:00
|
|
|
} else if (strcmp(base_type,"class") == 0) {
|
|
|
|
|
scope = new vpiScopeClass;
|
2008-09-27 01:54:13 +02:00
|
|
|
} else {
|
2012-01-20 00:04:51 +01:00
|
|
|
scope = new vpiScopeModule;
|
2001-11-02 06:43:11 +01:00
|
|
|
assert(0);
|
2001-10-15 04:58:27 +02:00
|
|
|
}
|
|
|
|
|
|
2003-03-06 05:32:00 +01:00
|
|
|
scope->name = vpip_name_string(name);
|
2009-01-15 18:41:29 +01:00
|
|
|
if (tname) scope->tname = vpip_name_string(tname);
|
|
|
|
|
else scope->tname = vpip_name_string("");
|
2008-04-30 03:58:25 +02:00
|
|
|
scope->file_idx = (unsigned) file_idx;
|
|
|
|
|
scope->lineno = (unsigned) lineno;
|
|
|
|
|
scope->def_file_idx = (unsigned) def_file_idx;
|
|
|
|
|
scope->def_lineno = (unsigned) def_lineno;
|
2012-01-19 19:16:39 +01:00
|
|
|
scope->is_automatic = is_automatic;
|
2001-03-18 01:37:55 +01:00
|
|
|
scope->intern = 0;
|
|
|
|
|
scope->nintern = 0;
|
2008-09-27 01:54:13 +02:00
|
|
|
scope->item = 0;
|
|
|
|
|
scope->nitem = 0;
|
2008-10-28 18:52:39 +01:00
|
|
|
scope->live_contexts = 0;
|
|
|
|
|
scope->free_contexts = 0;
|
2001-03-18 01:37:55 +01:00
|
|
|
|
2012-01-19 19:16:39 +01:00
|
|
|
if (is_cell) scope->is_cell = true;
|
|
|
|
|
else scope->is_cell = false;
|
|
|
|
|
|
2001-03-18 01:37:55 +01:00
|
|
|
current_scope = scope;
|
|
|
|
|
|
2012-01-19 19:16:39 +01:00
|
|
|
compile_vpi_symbol(label, scope);
|
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);
|
2009-01-13 18:57:12 +01:00
|
|
|
delete[] name;
|
|
|
|
|
delete[] tname;
|
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);
|
2012-01-19 19:16:39 +01:00
|
|
|
struct __vpiScope*sp = dynamic_cast<__vpiScope*>(obj);
|
|
|
|
|
vpip_attach_to_scope(sp, scope);
|
|
|
|
|
scope->scope = dynamic_cast<__vpiScope*>(obj);
|
2002-12-21 01:55:57 +01:00
|
|
|
|
2007-09-28 20:21:08 +02:00
|
|
|
/* Inherit time units and precision from the parent scope. */
|
2002-12-21 01:55:57 +01:00
|
|
|
scope->time_units = sp->time_units;
|
2007-09-28 20:21:08 +02:00
|
|
|
scope->time_precision = sp->time_precision;
|
2002-12-21 01:55:57 +01:00
|
|
|
|
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));
|
2012-01-19 19:16:39 +01:00
|
|
|
vpip_root_table_ptr[vpip_root_table_cnt] = scope;
|
2002-01-06 01:48:39 +01:00
|
|
|
vpip_root_table_cnt = cnt;
|
2002-12-21 01:55:57 +01:00
|
|
|
|
2007-09-28 20:21:08 +02:00
|
|
|
/* Root scopes inherit time_units and precision from the
|
|
|
|
|
system precision. */
|
2002-12-21 01:55:57 +01:00
|
|
|
scope->time_units = vpip_get_time_precision();
|
2007-09-28 20:21:08 +02:00
|
|
|
scope->time_precision = vpip_get_time_precision();
|
2001-03-18 01:37:55 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void compile_scope_recall(char*symbol)
|
|
|
|
|
{
|
2010-07-15 02:45:36 +02:00
|
|
|
/* A __vpiScope starts with a __vpiHandle structure so this is
|
|
|
|
|
a safe cast. We need the (void*) to avoid a dereferenced
|
|
|
|
|
type punned pointer warning from some gcc compilers. */
|
|
|
|
|
compile_vpi_lookup((vpiHandle*)(void*)¤t_scope, symbol);
|
2001-07-11 06:43:57 +02:00
|
|
|
assert(current_scope);
|
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.
|
|
|
|
|
*/
|
2007-09-28 20:21:08 +02:00
|
|
|
void compile_timescale(long units, long precision)
|
2002-12-21 01:55:57 +01:00
|
|
|
{
|
|
|
|
|
assert(current_scope);
|
|
|
|
|
current_scope->time_units = units;
|
2007-09-28 20:21:08 +02:00
|
|
|
current_scope->time_precision = precision;
|
2002-12-21 01:55:57 +01:00
|
|
|
}
|
|
|
|
|
|
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)
|
|
|
|
|
{
|
2009-09-28 03:29:07 +02:00
|
|
|
vpip_attach_to_scope(current_scope, obj);
|
2001-03-18 01:37:55 +01:00
|
|
|
}
|
2008-09-27 01:54:13 +02:00
|
|
|
|
2008-10-28 18:52:39 +01:00
|
|
|
struct __vpiScope* vpip_peek_context_scope(void)
|
2008-09-27 01:54:13 +02:00
|
|
|
{
|
2008-10-28 18:52:39 +01:00
|
|
|
struct __vpiScope*scope = current_scope;
|
|
|
|
|
|
|
|
|
|
/* A context is allocated for each automatic task or function.
|
|
|
|
|
Storage for nested scopes (named blocks) is allocated in
|
|
|
|
|
the parent context. */
|
|
|
|
|
while (scope->scope && scope->scope->is_automatic)
|
|
|
|
|
scope = scope->scope;
|
|
|
|
|
|
|
|
|
|
return scope;
|
2008-09-27 01:54:13 +02:00
|
|
|
}
|
2008-10-28 18:52:39 +01:00
|
|
|
|
|
|
|
|
unsigned vpip_add_item_to_context(automatic_hooks_s*item,
|
|
|
|
|
struct __vpiScope*scope)
|
|
|
|
|
{
|
|
|
|
|
assert(scope);
|
|
|
|
|
assert(scope->is_automatic);
|
|
|
|
|
|
|
|
|
|
unsigned idx = scope->nitem++;
|
|
|
|
|
|
|
|
|
|
if (scope->item == 0)
|
|
|
|
|
scope->item = (automatic_hooks_s**)
|
|
|
|
|
malloc(sizeof(automatic_hooks_s*));
|
|
|
|
|
else
|
|
|
|
|
scope->item = (automatic_hooks_s**)
|
|
|
|
|
realloc(scope->item, sizeof(automatic_hooks_s*)*scope->nitem);
|
|
|
|
|
|
|
|
|
|
scope->item[idx] = item;
|
|
|
|
|
|
|
|
|
|
/* Offset the context index by 2 to leave space for the list links. */
|
|
|
|
|
return 2 + idx;
|
|
|
|
|
}
|
2012-06-04 21:43:33 +02:00
|
|
|
|
|
|
|
|
|
2012-10-09 03:52:24 +02:00
|
|
|
class vpiPortInfo : public __vpiHandle {
|
|
|
|
|
public:
|
2012-06-04 21:43:33 +02:00
|
|
|
vpiPortInfo( __vpiScope *parent,
|
|
|
|
|
unsigned index,
|
|
|
|
|
int vpi_direction,
|
|
|
|
|
unsigned width,
|
|
|
|
|
const char *name );
|
2012-10-09 03:52:24 +02:00
|
|
|
~vpiPortInfo();
|
2012-06-04 21:43:33 +02:00
|
|
|
|
|
|
|
|
int get_type_code(void) const { return vpiPort; }
|
|
|
|
|
|
|
|
|
|
int vpi_get(int code);
|
|
|
|
|
char* vpi_get_str(int code);
|
|
|
|
|
vpiHandle vpi_handle(int code);
|
|
|
|
|
|
2012-10-09 03:52:24 +02:00
|
|
|
private:
|
2012-06-04 21:43:33 +02:00
|
|
|
__vpiScope *parent_;
|
|
|
|
|
unsigned index_;
|
|
|
|
|
int direction_;
|
|
|
|
|
unsigned width_;
|
|
|
|
|
const char *name_;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
vpiPortInfo::vpiPortInfo( __vpiScope *parent,
|
|
|
|
|
unsigned index,
|
|
|
|
|
int vpi_direction,
|
|
|
|
|
unsigned width,
|
|
|
|
|
const char *name ) :
|
2012-10-09 03:52:24 +02:00
|
|
|
parent_(parent),
|
|
|
|
|
index_(index),
|
|
|
|
|
direction_(vpi_direction),
|
|
|
|
|
width_(width),
|
|
|
|
|
name_(name)
|
2012-06-04 21:43:33 +02:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2012-10-09 03:52:24 +02:00
|
|
|
vpiPortInfo::~vpiPortInfo()
|
|
|
|
|
{
|
|
|
|
|
delete[] name_;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#ifdef CHECK_WITH_VALGRIND
|
|
|
|
|
void port_delete(__vpiHandle *handle)
|
|
|
|
|
{
|
|
|
|
|
delete dynamic_cast<vpiPortInfo *>(handle);
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
2012-06-04 21:43:33 +02:00
|
|
|
int vpiPortInfo::vpi_get(int code)
|
|
|
|
|
{
|
|
|
|
|
switch( code ) {
|
|
|
|
|
|
|
|
|
|
case vpiDirection :
|
|
|
|
|
return direction_;
|
|
|
|
|
case vpiPortIndex :
|
|
|
|
|
return index_;
|
|
|
|
|
case vpiSize :
|
|
|
|
|
return width_;
|
|
|
|
|
default :
|
|
|
|
|
return vpiUndefined;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
char *vpiPortInfo::vpi_get_str(int code)
|
|
|
|
|
{
|
|
|
|
|
switch( code ) {
|
|
|
|
|
case vpiName :
|
|
|
|
|
return simple_set_rbuf_str(name_);
|
|
|
|
|
default :
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
vpiHandle vpiPortInfo::vpi_handle(int code)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
switch (code) {
|
|
|
|
|
|
|
|
|
|
case vpiParent:
|
|
|
|
|
case vpiScope:
|
|
|
|
|
case vpiModule:
|
|
|
|
|
return parent_;
|
|
|
|
|
default :
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Port info is meta-data to allow vpi queries of the port signature of modules for
|
|
|
|
|
* code-generators etc. There are no actual nets corresponding to instances of module ports
|
|
|
|
|
* as elaboration directly connects nets connected through module ports.
|
|
|
|
|
*/
|
|
|
|
|
void compile_port_info( unsigned index, int vpi_direction, unsigned width, const char *name )
|
|
|
|
|
{
|
|
|
|
|
vpiHandle obj = new vpiPortInfo( vpip_peek_current_scope(),
|
|
|
|
|
index, vpi_direction, width, name );
|
|
|
|
|
vpip_attach_to_current_scope(obj);
|
|
|
|
|
}
|