2001-03-16 02:44:34 +01:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2001 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
|
|
|
|
|
* 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
|
2007-04-18 03:57:07 +02:00
|
|
|
#ident "$Id: vpi_priv.cc,v 1.54 2007/04/18 01:57:07 steve Exp $"
|
2001-03-16 02:44:34 +01:00
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
# include "vpi_priv.h"
|
2001-03-19 02:55:38 +01:00
|
|
|
# include "schedule.h"
|
2001-03-16 02:44:34 +01:00
|
|
|
# include <stdio.h>
|
|
|
|
|
# include <stdarg.h>
|
2002-07-05 19:14:15 +02:00
|
|
|
# include <string.h>
|
2001-03-16 02:44:34 +01:00
|
|
|
# include <assert.h>
|
2001-09-15 20:27:04 +02:00
|
|
|
#ifdef HAVE_MALLOC_H
|
2001-03-16 02:44:34 +01:00
|
|
|
# include <malloc.h>
|
2001-09-15 20:27:04 +02:00
|
|
|
#endif
|
|
|
|
|
# include <stdlib.h>
|
2003-04-27 06:19:24 +02:00
|
|
|
# include <math.h>
|
2001-03-16 02:44:34 +01:00
|
|
|
|
2002-05-18 04:34:11 +02:00
|
|
|
vpi_mode_t vpi_mode_flag = VPI_MODE_NONE;
|
2003-03-12 03:50:32 +01:00
|
|
|
FILE*vpi_trace = 0;
|
2002-05-18 04:34:11 +02:00
|
|
|
|
2002-07-19 03:57:26 +02:00
|
|
|
static s_vpi_vlog_info vpi_vlog_info;
|
|
|
|
|
static s_vpi_error_info vpip_last_error = { 0, 0, 0, 0, 0, 0, 0 };
|
|
|
|
|
|
2002-07-05 19:14:15 +02:00
|
|
|
/*
|
|
|
|
|
* The vpip_string function creates a constant string from the pass
|
|
|
|
|
* input. This constant string is permanently allocate from an
|
|
|
|
|
* efficient string buffer store.
|
|
|
|
|
*/
|
|
|
|
|
struct vpip_string_chunk {
|
|
|
|
|
struct vpip_string_chunk*next;
|
|
|
|
|
char data[64*1024 - sizeof (struct vpip_string_chunk*)];
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const char *vpip_string(const char*str)
|
|
|
|
|
{
|
|
|
|
|
static vpip_string_chunk first_chunk = {0, {0}};
|
|
|
|
|
static vpip_string_chunk*chunk_list = &first_chunk;
|
|
|
|
|
static unsigned chunk_fill = 0;
|
|
|
|
|
|
|
|
|
|
unsigned len = strlen(str);
|
|
|
|
|
assert( (len+1) <= sizeof chunk_list->data );
|
|
|
|
|
|
|
|
|
|
if ( (len+1) > (sizeof chunk_list->data - chunk_fill) ) {
|
|
|
|
|
vpip_string_chunk*tmp = new vpip_string_chunk;
|
|
|
|
|
tmp->next = chunk_list;
|
|
|
|
|
chunk_list = tmp;
|
|
|
|
|
chunk_fill = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
char*res = chunk_list->data + chunk_fill;
|
|
|
|
|
chunk_fill += len + 1;
|
|
|
|
|
|
|
|
|
|
strcpy(res, str);
|
|
|
|
|
return res;
|
|
|
|
|
}
|
|
|
|
|
|
2003-03-06 05:32:00 +01:00
|
|
|
static unsigned hash_string(const char*text)
|
|
|
|
|
{
|
|
|
|
|
unsigned h = 0;
|
|
|
|
|
|
|
|
|
|
while (*text) {
|
|
|
|
|
h = (h << 4) ^ (h >> 28) ^ *text;
|
|
|
|
|
text += 1;
|
|
|
|
|
}
|
|
|
|
|
return h;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const char* vpip_name_string(const char*text)
|
|
|
|
|
{
|
|
|
|
|
const unsigned HASH_SIZE = 4096;
|
|
|
|
|
static const char*hash_table[HASH_SIZE] = {0};
|
|
|
|
|
|
|
|
|
|
unsigned hash_value = hash_string(text) % HASH_SIZE;
|
|
|
|
|
|
|
|
|
|
/* If we easily find the string in the hash table, then return
|
|
|
|
|
that and be done. */
|
|
|
|
|
if (hash_table[hash_value]
|
|
|
|
|
&& (strcmp(hash_table[hash_value], text) == 0)) {
|
|
|
|
|
return hash_table[hash_value];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* The existing hash entry is not a match. Replace it with the
|
|
|
|
|
newly allocated value, and return the new pointer as the
|
|
|
|
|
result to the add. */
|
|
|
|
|
const char*res = vpip_string(text);
|
|
|
|
|
hash_table[hash_value] = res;
|
|
|
|
|
|
|
|
|
|
return res;
|
|
|
|
|
}
|
2004-02-18 03:51:59 +01:00
|
|
|
PLI_INT32 vpi_chk_error(p_vpi_error_info info)
|
2002-07-19 03:57:26 +02:00
|
|
|
{
|
2002-08-24 07:02:58 +02:00
|
|
|
if (vpip_last_error.state == 0)
|
2002-07-19 03:57:26 +02:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
info->state = vpip_last_error.state;
|
|
|
|
|
info->level = vpip_last_error.level;
|
|
|
|
|
info->message = vpip_last_error.message;
|
|
|
|
|
info->product = vpi_vlog_info.product;
|
|
|
|
|
info->code = "";
|
|
|
|
|
info->file = 0;
|
|
|
|
|
info->line = 0;
|
|
|
|
|
|
|
|
|
|
return info->level;
|
|
|
|
|
}
|
|
|
|
|
|
2001-03-16 02:44:34 +01:00
|
|
|
/*
|
|
|
|
|
* When a task is called, this value is set so that vpi_handle can
|
|
|
|
|
* fathom the vpi_handle(vpiSysTfCall,0) function.
|
|
|
|
|
*/
|
|
|
|
|
struct __vpiSysTaskCall*vpip_cur_task = 0;
|
|
|
|
|
|
2004-02-18 03:51:59 +01:00
|
|
|
PLI_INT32 vpi_free_object(vpiHandle ref)
|
2001-03-16 02:44:34 +01:00
|
|
|
{
|
2003-05-30 06:08:28 +02:00
|
|
|
int rtn;
|
|
|
|
|
|
|
|
|
|
if (vpi_trace) {
|
|
|
|
|
fprintf(vpi_trace, "vpi_free_object(%p)", ref);
|
|
|
|
|
fflush(vpi_trace);
|
|
|
|
|
}
|
|
|
|
|
|
2002-06-02 21:05:50 +02:00
|
|
|
assert(ref);
|
2003-02-02 02:40:24 +01:00
|
|
|
if (ref->vpi_type->vpi_free_object_ == 0)
|
2003-05-30 06:08:28 +02:00
|
|
|
rtn = 1;
|
|
|
|
|
else
|
|
|
|
|
rtn = ref->vpi_type->vpi_free_object_(ref);
|
|
|
|
|
|
|
|
|
|
if (vpi_trace)
|
|
|
|
|
fprintf(vpi_trace, " --> %d\n", rtn);
|
2003-02-02 02:40:24 +01:00
|
|
|
|
2003-05-30 06:08:28 +02:00
|
|
|
return rtn;
|
2001-03-16 02:44:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int vpip_get_global(int property)
|
|
|
|
|
{
|
|
|
|
|
switch (property) {
|
|
|
|
|
|
2001-04-03 05:46:14 +02:00
|
|
|
case vpiTimePrecision:
|
2001-07-01 01:03:16 +02:00
|
|
|
return vpip_get_time_precision();
|
2001-04-03 05:46:14 +02:00
|
|
|
|
2001-03-16 02:44:34 +01:00
|
|
|
default:
|
2001-04-03 05:46:14 +02:00
|
|
|
fprintf(stderr, "vpi error: bad global property: %d\n", property);
|
2001-03-16 02:44:34 +01:00
|
|
|
assert(0);
|
2003-03-12 03:50:32 +01:00
|
|
|
return vpiUndefined;
|
2001-03-16 02:44:34 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2003-03-14 06:02:34 +01:00
|
|
|
static const char* vpi_property_str(PLI_INT32 code)
|
|
|
|
|
{
|
|
|
|
|
static char buf[32];
|
|
|
|
|
switch (code) {
|
|
|
|
|
case vpiConstType:
|
|
|
|
|
return "vpiConstType";
|
|
|
|
|
case vpiName:
|
|
|
|
|
return "vpiName";
|
|
|
|
|
case vpiFullName:
|
|
|
|
|
return "vpiFullName";
|
|
|
|
|
case vpiTimeUnit:
|
|
|
|
|
return "vpiTimeUnit";
|
|
|
|
|
default:
|
|
|
|
|
sprintf(buf, "%d", code);
|
|
|
|
|
}
|
|
|
|
|
return buf;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static const char* vpi_type_values(PLI_INT32 code)
|
|
|
|
|
{
|
|
|
|
|
static char buf[32];
|
|
|
|
|
switch (code) {
|
|
|
|
|
case vpiConstant:
|
|
|
|
|
return "vpiConstant";
|
2007-08-16 06:05:42 +02:00
|
|
|
case vpiIntegerVar:
|
|
|
|
|
return "vpiIntegerVar";
|
|
|
|
|
case vpiFunction:
|
|
|
|
|
return "vpiFunction";
|
2003-03-14 06:02:34 +01:00
|
|
|
case vpiModule:
|
|
|
|
|
return "vpiModule";
|
|
|
|
|
case vpiNet:
|
|
|
|
|
return "vpiNet";
|
2007-08-16 06:05:42 +02:00
|
|
|
case vpiParameter:
|
|
|
|
|
return "vpiParameter";
|
|
|
|
|
case vpiRealVar:
|
|
|
|
|
return "vpiRealVar";
|
2003-03-14 06:02:34 +01:00
|
|
|
case vpiReg:
|
|
|
|
|
return "vpiReg";
|
2007-08-16 06:05:42 +02:00
|
|
|
case vpiTask:
|
|
|
|
|
return "vpiTask";
|
2003-03-14 06:02:34 +01:00
|
|
|
default:
|
|
|
|
|
sprintf(buf, "%d", code);
|
|
|
|
|
}
|
|
|
|
|
return buf;
|
|
|
|
|
}
|
|
|
|
|
|
2004-02-18 03:51:59 +01:00
|
|
|
PLI_INT32 vpi_get(int property, vpiHandle ref)
|
2001-03-16 02:44:34 +01:00
|
|
|
{
|
|
|
|
|
if (ref == 0)
|
|
|
|
|
return vpip_get_global(property);
|
|
|
|
|
|
2002-06-21 06:58:55 +02:00
|
|
|
if (property == vpiType) {
|
2003-03-13 05:34:18 +01:00
|
|
|
if (vpi_trace) {
|
2003-03-14 06:02:34 +01:00
|
|
|
fprintf(vpi_trace, "vpi_get(vpiType, %p) --> %s\n",
|
|
|
|
|
ref, vpi_type_values(ref->vpi_type->type_code));
|
2003-03-13 05:34:18 +01:00
|
|
|
}
|
|
|
|
|
|
2002-06-21 06:58:55 +02:00
|
|
|
struct __vpiSignal*rfp = (struct __vpiSignal*)ref;
|
|
|
|
|
if (ref->vpi_type->type_code == vpiReg && rfp->isint_)
|
|
|
|
|
return vpiIntegerVar;
|
|
|
|
|
else
|
|
|
|
|
return ref->vpi_type->type_code;
|
|
|
|
|
}
|
2001-07-11 04:27:21 +02:00
|
|
|
|
2003-03-14 06:02:34 +01:00
|
|
|
if (ref->vpi_type->vpi_get_ == 0) {
|
|
|
|
|
if (vpi_trace) {
|
|
|
|
|
fprintf(vpi_trace, "vpi_get(%s, %p) --X\n",
|
|
|
|
|
vpi_property_str(property), ref);
|
|
|
|
|
}
|
|
|
|
|
|
2003-03-12 03:50:32 +01:00
|
|
|
return vpiUndefined;
|
2003-03-14 06:02:34 +01:00
|
|
|
}
|
2001-03-16 02:44:34 +01:00
|
|
|
|
2003-03-12 03:50:32 +01:00
|
|
|
int res = (ref->vpi_type->vpi_get_)(property, ref);
|
|
|
|
|
|
|
|
|
|
if (vpi_trace) {
|
2003-03-14 06:02:34 +01:00
|
|
|
fprintf(vpi_trace, "vpi_get(%s, %p) --> %d\n",
|
|
|
|
|
vpi_property_str(property), ref, res);
|
2003-03-12 03:50:32 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return res;
|
2001-03-16 02:44:34 +01:00
|
|
|
}
|
|
|
|
|
|
2004-02-18 18:52:00 +01:00
|
|
|
char* vpi_get_str(PLI_INT32 property, vpiHandle ref)
|
2001-03-16 02:44:34 +01:00
|
|
|
{
|
2002-12-12 00:55:22 +01:00
|
|
|
if (ref == 0) {
|
2003-03-14 06:02:34 +01:00
|
|
|
fprintf(stderr, "vpi error: vpi_get_str(%s, 0) called "
|
|
|
|
|
"with null vpiHandle.\n", vpi_property_str(property));
|
2002-12-12 00:55:22 +01:00
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2007-08-16 06:05:42 +02:00
|
|
|
if (property == vpiType) {
|
|
|
|
|
if (vpi_trace) {
|
|
|
|
|
fprintf(vpi_trace, "vpi_get(vpiType, %p) --> %s\n",
|
|
|
|
|
ref, vpi_type_values(ref->vpi_type->type_code));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
struct __vpiSignal*rfp = (struct __vpiSignal*)ref;
|
|
|
|
|
PLI_INT32 type;
|
|
|
|
|
if (ref->vpi_type->type_code == vpiReg && rfp->isint_)
|
|
|
|
|
type = vpiIntegerVar;
|
|
|
|
|
else
|
|
|
|
|
type = ref->vpi_type->type_code;
|
|
|
|
|
return (char *)vpi_type_values(type);
|
|
|
|
|
}
|
|
|
|
|
|
2003-03-12 03:50:32 +01:00
|
|
|
if (ref->vpi_type->vpi_get_str_ == 0) {
|
|
|
|
|
if (vpi_trace) {
|
2003-03-14 06:02:34 +01:00
|
|
|
fprintf(vpi_trace, "vpi_get_str(%s, %p) --X\n",
|
|
|
|
|
vpi_property_str(property), ref);
|
2003-03-12 03:50:32 +01:00
|
|
|
}
|
2001-03-16 02:44:34 +01:00
|
|
|
return 0;
|
2003-03-12 03:50:32 +01:00
|
|
|
}
|
2001-03-16 02:44:34 +01:00
|
|
|
|
2003-03-12 03:50:32 +01:00
|
|
|
char*res = (char*)(ref->vpi_type->vpi_get_str_)(property, ref);
|
|
|
|
|
|
|
|
|
|
if (vpi_trace) {
|
2003-03-14 06:02:34 +01:00
|
|
|
fprintf(vpi_trace, "vpi_get_str(%s, %p) --> %s\n",
|
|
|
|
|
vpi_property_str(property), ref, res);
|
2003-03-12 03:50:32 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return res;
|
2001-03-16 02:44:34 +01:00
|
|
|
}
|
|
|
|
|
|
2003-05-02 06:29:57 +02:00
|
|
|
int vpip_time_units_from_handle(vpiHandle obj)
|
2003-04-27 06:19:24 +02:00
|
|
|
{
|
|
|
|
|
struct __vpiSysTaskCall*task;
|
|
|
|
|
struct __vpiScope*scope;
|
2003-05-02 06:29:57 +02:00
|
|
|
struct __vpiSignal*signal;
|
2003-04-27 06:19:24 +02:00
|
|
|
|
|
|
|
|
if (obj == 0)
|
|
|
|
|
return vpip_get_time_precision();
|
|
|
|
|
|
|
|
|
|
switch (obj->vpi_type->type_code) {
|
|
|
|
|
case vpiSysTaskCall:
|
|
|
|
|
task = (struct __vpiSysTaskCall*)obj;
|
|
|
|
|
return task->scope->time_units;
|
|
|
|
|
|
|
|
|
|
case vpiModule:
|
|
|
|
|
scope = (struct __vpiScope*)obj;
|
|
|
|
|
return scope->time_units;
|
|
|
|
|
|
2003-05-02 06:29:57 +02:00
|
|
|
case vpiNet:
|
|
|
|
|
case vpiReg:
|
|
|
|
|
signal = (struct __vpiSignal*)obj;
|
|
|
|
|
return signal->scope->time_units;
|
|
|
|
|
|
2003-04-27 06:19:24 +02:00
|
|
|
default:
|
|
|
|
|
fprintf(stderr, "ERROR: vpi_get_time called with object "
|
|
|
|
|
"handle type=%u\n", obj->vpi_type->type_code);
|
|
|
|
|
assert(0);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2001-04-03 05:46:14 +02:00
|
|
|
void vpi_get_time(vpiHandle obj, s_vpi_time*vp)
|
2001-03-16 02:44:34 +01:00
|
|
|
{
|
2003-04-27 06:19:24 +02:00
|
|
|
int units;
|
2003-05-15 03:24:46 +02:00
|
|
|
vvp_time64_t time;
|
2003-04-27 06:19:24 +02:00
|
|
|
|
2002-06-02 21:05:50 +02:00
|
|
|
assert(vp);
|
2001-04-03 05:46:14 +02:00
|
|
|
|
2003-05-15 03:24:46 +02:00
|
|
|
time = schedule_simtime();
|
|
|
|
|
|
2003-04-27 06:19:24 +02:00
|
|
|
switch (vp->type) {
|
|
|
|
|
case vpiSimTime:
|
2003-05-15 03:24:46 +02:00
|
|
|
vp->high = (time >> 32) & 0xffffffff;
|
|
|
|
|
vp->low = time & 0xffffffff;
|
2003-04-27 06:19:24 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case vpiScaledRealTime:
|
2003-05-02 06:29:57 +02:00
|
|
|
units = vpip_time_units_from_handle(obj);
|
2005-12-05 22:19:55 +01:00
|
|
|
vp->real = pow(10.0L, vpip_get_time_precision() - units);
|
2003-05-15 03:24:46 +02:00
|
|
|
vp->real *= time;
|
2003-04-27 06:19:24 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
fprintf(stderr, "vpi_get_time: unknown type: %d\n", vp->type);
|
|
|
|
|
assert(0);
|
|
|
|
|
break;
|
|
|
|
|
}
|
2001-03-16 02:44:34 +01:00
|
|
|
}
|
|
|
|
|
|
2004-02-18 03:51:59 +01:00
|
|
|
PLI_INT32 vpi_get_vlog_info(p_vpi_vlog_info vlog_info_p)
|
2002-01-09 04:15:23 +01:00
|
|
|
{
|
2002-04-07 02:46:21 +02:00
|
|
|
if (vlog_info_p != 0) {
|
|
|
|
|
*vlog_info_p = vpi_vlog_info;
|
|
|
|
|
return 1;
|
|
|
|
|
} else {
|
|
|
|
|
return 0;
|
2002-01-09 04:15:23 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void vpi_set_vlog_info(int argc, char** argv)
|
|
|
|
|
{
|
|
|
|
|
vpi_vlog_info.product = "Icarus Verilog";
|
|
|
|
|
vpi_vlog_info.version = "$Name: $";
|
|
|
|
|
vpi_vlog_info.argc = argc;
|
|
|
|
|
vpi_vlog_info.argv = argv;
|
2003-03-12 03:50:32 +01:00
|
|
|
|
2003-06-25 06:04:19 +02:00
|
|
|
static char trace_buf[1024];
|
|
|
|
|
|
2003-03-13 05:34:18 +01:00
|
|
|
if (const char*path = getenv("VPI_TRACE")) {
|
2003-06-17 18:55:07 +02:00
|
|
|
if (!strcmp(path,"-"))
|
2003-03-13 05:34:18 +01:00
|
|
|
vpi_trace = stdout;
|
2003-06-17 18:55:07 +02:00
|
|
|
else {
|
2003-03-13 05:34:18 +01:00
|
|
|
vpi_trace = fopen(path, "w");
|
2003-06-17 18:55:07 +02:00
|
|
|
if (!vpi_trace) {
|
|
|
|
|
perror(path);
|
|
|
|
|
exit(1);
|
|
|
|
|
}
|
2003-06-25 06:04:19 +02:00
|
|
|
setvbuf(vpi_trace, trace_buf, _IOLBF, sizeof(trace_buf));
|
2003-06-17 18:55:07 +02:00
|
|
|
}
|
2003-03-13 05:34:18 +01:00
|
|
|
}
|
2002-01-09 04:15:23 +01:00
|
|
|
}
|
|
|
|
|
|
2006-03-06 06:43:15 +01:00
|
|
|
/*
|
|
|
|
|
* This is a generic function to convert a vvp_vector4_t value into a
|
|
|
|
|
* vpi_value structure. The format is selected by the format of the
|
|
|
|
|
* value pointer. The width is the real width of the word, in case the
|
|
|
|
|
* word_val width is not accurate.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
static void vec4_get_value_string(const vvp_vector4_t&word_val, unsigned width,
|
|
|
|
|
s_vpi_value*vp);
|
|
|
|
|
|
|
|
|
|
void vpip_vec4_get_value(const vvp_vector4_t&word_val, unsigned width,
|
|
|
|
|
bool signed_flag, s_vpi_value*vp)
|
|
|
|
|
{
|
|
|
|
|
char *rbuf = 0;
|
|
|
|
|
|
|
|
|
|
switch (vp->format) {
|
|
|
|
|
default:
|
|
|
|
|
fprintf(stderr, "internal error: Format %d not implemented\n",
|
|
|
|
|
vp->format);
|
|
|
|
|
assert(0 && "format not implemented");
|
|
|
|
|
|
|
|
|
|
case vpiBinStrVal:
|
|
|
|
|
rbuf = need_result_buf(width+1, RBUF_VAL);
|
|
|
|
|
for (unsigned idx = 0 ; idx < width ; idx += 1) {
|
|
|
|
|
vvp_bit4_t bit = word_val.value(idx);
|
|
|
|
|
rbuf[width-idx-1] = "01xz"[bit];
|
|
|
|
|
}
|
|
|
|
|
rbuf[width] = 0;
|
|
|
|
|
vp->value.str = rbuf;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case vpiOctStrVal: {
|
|
|
|
|
unsigned hwid = (width+2) / 3;
|
|
|
|
|
rbuf = need_result_buf(hwid+1, RBUF_VAL);
|
|
|
|
|
vpip_vec4_to_oct_str(word_val, rbuf, hwid+1, signed_flag);
|
|
|
|
|
vp->value.str = rbuf;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case vpiDecStrVal: {
|
|
|
|
|
rbuf = need_result_buf(width+1, RBUF_VAL);
|
|
|
|
|
vpip_vec4_to_dec_str(word_val, rbuf, width+1, signed_flag);
|
|
|
|
|
vp->value.str = rbuf;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case vpiHexStrVal: {
|
|
|
|
|
unsigned hwid = (width + 3) / 4;
|
|
|
|
|
|
|
|
|
|
rbuf = need_result_buf(hwid+1, RBUF_VAL);
|
|
|
|
|
rbuf[hwid] = 0;
|
|
|
|
|
|
|
|
|
|
vpip_vec4_to_hex_str(word_val, rbuf, hwid+1, signed_flag);
|
|
|
|
|
vp->value.str = rbuf;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2007-04-12 06:45:52 +02:00
|
|
|
case vpiScalarVal: {
|
|
|
|
|
// scalars should be of size 1
|
|
|
|
|
assert(width == 1);
|
|
|
|
|
switch(word_val.value(0)) {
|
|
|
|
|
case BIT4_0:
|
|
|
|
|
vp->value.scalar = vpi0;
|
|
|
|
|
break;
|
|
|
|
|
case BIT4_1:
|
|
|
|
|
vp->value.scalar = vpi1;
|
|
|
|
|
break;
|
|
|
|
|
case BIT4_X:
|
|
|
|
|
vp->value.scalar = vpiX;
|
|
|
|
|
case BIT4_Z:
|
|
|
|
|
vp->value.scalar = vpiZ;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2006-03-06 06:43:15 +01:00
|
|
|
case vpiIntVal: {
|
|
|
|
|
long val = 0;
|
|
|
|
|
vvp_bit4_t pad = BIT4_0;
|
|
|
|
|
if (signed_flag && word_val.size() > 0)
|
|
|
|
|
pad = word_val.value(word_val.size()-1);
|
|
|
|
|
|
2007-03-07 01:38:15 +01:00
|
|
|
for (unsigned idx = 0 ; idx < 8*sizeof(val) ; idx += 1) {
|
2006-03-06 06:43:15 +01:00
|
|
|
vvp_bit4_t val4 = pad;
|
|
|
|
|
if (idx < word_val.size())
|
|
|
|
|
val4 = word_val.value(idx);
|
|
|
|
|
if (val4 == BIT4_1)
|
|
|
|
|
val |= 1L << idx;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
vp->value.integer = val;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case vpiVectorVal: {
|
|
|
|
|
unsigned hwid = (width - 1)/32 + 1;
|
|
|
|
|
|
|
|
|
|
rbuf = need_result_buf(hwid * sizeof(s_vpi_vecval), RBUF_VAL);
|
|
|
|
|
s_vpi_vecval *op = (p_vpi_vecval)rbuf;
|
|
|
|
|
vp->value.vector = op;
|
|
|
|
|
|
|
|
|
|
op->aval = op->bval = 0;
|
|
|
|
|
for (unsigned idx = 0 ; idx < width ; idx += 1) {
|
|
|
|
|
switch (word_val.value(idx)) {
|
|
|
|
|
case BIT4_0:
|
|
|
|
|
op->aval &= ~(1 << idx % 32);
|
|
|
|
|
op->bval &= ~(1 << idx % 32);
|
|
|
|
|
break;
|
|
|
|
|
case BIT4_1:
|
|
|
|
|
op->aval |= (1 << idx % 32);
|
|
|
|
|
op->bval &= ~(1 << idx % 32);
|
|
|
|
|
break;
|
|
|
|
|
case BIT4_X:
|
|
|
|
|
op->aval |= (1 << idx % 32);
|
|
|
|
|
op->bval |= (1 << idx % 32);
|
|
|
|
|
break;
|
|
|
|
|
case BIT4_Z:
|
|
|
|
|
op->aval &= ~(1 << idx % 32);
|
|
|
|
|
op->bval |= (1 << idx % 32);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
if (!((idx+1) % 32) && (idx+1 < width)) {
|
|
|
|
|
op++;
|
|
|
|
|
op->aval = op->bval = 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case vpiStringVal:
|
|
|
|
|
vec4_get_value_string(word_val, width, vp);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case vpiRealVal: {
|
2007-04-18 03:57:07 +02:00
|
|
|
vector4_to_value(word_val, vp->value.real, signed_flag);
|
2006-03-06 06:43:15 +01:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void vec4_get_value_string(const vvp_vector4_t&word_val, unsigned width,
|
|
|
|
|
s_vpi_value*vp)
|
|
|
|
|
{
|
|
|
|
|
unsigned nchar = width / 8;
|
|
|
|
|
unsigned tail = width % 8;
|
|
|
|
|
|
|
|
|
|
char*rbuf = need_result_buf(nchar + 1, RBUF_VAL);
|
|
|
|
|
char*cp = rbuf;
|
|
|
|
|
|
|
|
|
|
if (tail > 0) {
|
|
|
|
|
char char_val = 0;
|
|
|
|
|
for (unsigned idx = width-tail; idx < width ; idx += 1) {
|
|
|
|
|
vvp_bit4_t val = word_val.value(idx);
|
|
|
|
|
if (val == BIT4_1)
|
|
|
|
|
char_val |= 1 << idx;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (char_val != 0)
|
|
|
|
|
*cp++ = char_val;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (unsigned idx = 0 ; idx < nchar ; idx += 1) {
|
|
|
|
|
unsigned bit = (nchar - idx - 1) * 8;
|
|
|
|
|
char char_val = 0;
|
|
|
|
|
for (unsigned bdx = 0 ; bdx < 8 ; bdx += 1) {
|
|
|
|
|
vvp_bit4_t val = word_val.value(bit+bdx);
|
|
|
|
|
if (val == BIT4_1)
|
|
|
|
|
char_val |= 1 << bdx;
|
|
|
|
|
}
|
|
|
|
|
if (char_val != 0)
|
|
|
|
|
*cp++ = char_val;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
*cp = 0;
|
|
|
|
|
vp->value.str = rbuf;
|
|
|
|
|
}
|
|
|
|
|
|
2001-03-16 02:44:34 +01:00
|
|
|
void vpi_get_value(vpiHandle expr, s_vpi_value*vp)
|
|
|
|
|
{
|
2002-06-02 21:05:50 +02:00
|
|
|
assert(expr);
|
|
|
|
|
assert(vp);
|
2001-03-16 02:44:34 +01:00
|
|
|
if (expr->vpi_type->vpi_get_value_) {
|
|
|
|
|
(expr->vpi_type->vpi_get_value_)(expr, vp);
|
2003-03-12 03:50:32 +01:00
|
|
|
|
|
|
|
|
if (vpi_trace) switch (vp->format) {
|
|
|
|
|
case vpiStringVal:
|
2003-06-17 18:55:07 +02:00
|
|
|
fprintf(vpi_trace,"vpi_get_value(%p=<%d>) -> string=\"%s\"\n",
|
2003-03-13 05:34:18 +01:00
|
|
|
expr, expr->vpi_type->type_code, vp->value.str);
|
2003-03-12 03:50:32 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case vpiBinStrVal:
|
2003-03-13 05:34:18 +01:00
|
|
|
fprintf(vpi_trace, "vpi_get_value(<%d>...) -> binstr=%s\n",
|
2003-03-12 03:50:32 +01:00
|
|
|
expr->vpi_type->type_code, vp->value.str);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case vpiIntVal:
|
2003-03-13 05:34:18 +01:00
|
|
|
fprintf(vpi_trace, "vpi_get_value(<%d>...) -> int=%d\n",
|
2003-03-12 03:50:32 +01:00
|
|
|
expr->vpi_type->type_code, vp->value.integer);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
default:
|
2003-03-13 05:34:18 +01:00
|
|
|
fprintf(vpi_trace, "vpi_get_value(<%d>...) -> <%d>=?\n",
|
2003-03-12 03:50:32 +01:00
|
|
|
expr->vpi_type->type_code, vp->format);
|
|
|
|
|
}
|
2001-03-16 02:44:34 +01:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2003-03-12 03:50:32 +01:00
|
|
|
if (vpi_trace) {
|
2003-03-13 05:34:18 +01:00
|
|
|
fprintf(vpi_trace, "vpi_get_value(<%d>...) -> <suppress>\n",
|
2003-03-12 03:50:32 +01:00
|
|
|
expr->vpi_type->type_code);
|
|
|
|
|
}
|
|
|
|
|
|
2001-03-16 02:44:34 +01:00
|
|
|
vp->format = vpiSuppressVal;
|
|
|
|
|
}
|
|
|
|
|
|
2004-05-19 05:26:24 +02:00
|
|
|
struct vpip_put_value_event : vvp_gen_event_s {
|
|
|
|
|
vpiHandle handle;
|
|
|
|
|
s_vpi_value value;
|
2005-06-02 18:02:11 +02:00
|
|
|
virtual void run_run();
|
2005-12-05 22:19:55 +01:00
|
|
|
~vpip_put_value_event() { }
|
2004-05-19 05:26:24 +02:00
|
|
|
};
|
|
|
|
|
|
2005-06-02 18:02:11 +02:00
|
|
|
void vpip_put_value_event::run_run()
|
2004-05-19 05:26:24 +02:00
|
|
|
{
|
2005-06-02 18:02:11 +02:00
|
|
|
handle->vpi_type->vpi_put_value_ (handle, &value);
|
2004-05-19 05:26:24 +02:00
|
|
|
}
|
|
|
|
|
|
2001-03-16 02:44:34 +01:00
|
|
|
vpiHandle vpi_put_value(vpiHandle obj, s_vpi_value*vp,
|
2004-05-19 05:26:24 +02:00
|
|
|
s_vpi_time*when, PLI_INT32 flags)
|
2001-03-16 02:44:34 +01:00
|
|
|
{
|
2002-06-02 21:05:50 +02:00
|
|
|
assert(obj);
|
2004-05-19 05:26:24 +02:00
|
|
|
|
|
|
|
|
if (obj->vpi_type->vpi_put_value_ == 0)
|
2001-03-16 02:44:34 +01:00
|
|
|
return 0;
|
2004-05-19 05:26:24 +02:00
|
|
|
|
|
|
|
|
if (flags != vpiNoDelay) {
|
|
|
|
|
vvp_time64_t dly;
|
|
|
|
|
|
2007-01-31 23:28:55 +01:00
|
|
|
assert(when != 0);
|
|
|
|
|
|
2004-05-19 05:26:24 +02:00
|
|
|
switch (when->type) {
|
|
|
|
|
case vpiScaledRealTime:
|
|
|
|
|
dly = (vvp_time64_t)(when->real *
|
2005-12-05 22:19:55 +01:00
|
|
|
(pow(10.0L,
|
2004-05-19 05:26:24 +02:00
|
|
|
vpip_time_units_from_handle(obj) -
|
|
|
|
|
vpip_get_time_precision())));
|
|
|
|
|
break;
|
|
|
|
|
case vpiSimTime:
|
|
|
|
|
dly = vpip_timestruct_to_time(when);
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
dly = 0;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
vpip_put_value_event*put = new vpip_put_value_event;
|
|
|
|
|
put->handle = obj;
|
|
|
|
|
put->value = *vp;
|
2005-06-09 07:04:45 +02:00
|
|
|
schedule_generic(put, dly, false);
|
2004-05-19 05:26:24 +02:00
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
(obj->vpi_type->vpi_put_value_)(obj, vp);
|
|
|
|
|
|
|
|
|
|
return 0;
|
2001-03-16 02:44:34 +01:00
|
|
|
}
|
|
|
|
|
|
2004-02-18 18:52:00 +01:00
|
|
|
vpiHandle vpi_handle(PLI_INT32 type, vpiHandle ref)
|
2001-03-16 02:44:34 +01:00
|
|
|
{
|
|
|
|
|
if (type == vpiSysTfCall) {
|
|
|
|
|
assert(ref == 0);
|
2003-03-14 06:02:34 +01:00
|
|
|
|
|
|
|
|
if (vpi_trace) {
|
|
|
|
|
fprintf(vpi_trace, "vpi_handle(vpiSysTfCall, 0) "
|
|
|
|
|
"-> %p (%s)\n", &vpip_cur_task->base,
|
|
|
|
|
vpip_cur_task->defn->info.tfname);
|
|
|
|
|
}
|
|
|
|
|
|
2001-03-16 02:44:34 +01:00
|
|
|
return &vpip_cur_task->base;
|
|
|
|
|
}
|
|
|
|
|
|
2003-06-22 06:19:26 +02:00
|
|
|
if (ref == 0) {
|
|
|
|
|
fprintf(stderr, "internal error: vpi_handle(type=%d, ref=0)\n",
|
|
|
|
|
type);
|
|
|
|
|
}
|
2002-06-02 21:05:50 +02:00
|
|
|
assert(ref);
|
2002-07-19 03:12:50 +02:00
|
|
|
|
2003-03-14 06:02:34 +01:00
|
|
|
if (ref->vpi_type->handle_ == 0) {
|
|
|
|
|
|
|
|
|
|
if (vpi_trace) {
|
|
|
|
|
fprintf(vpi_trace, "vpi_handle(%d, %p) -X\n",
|
|
|
|
|
type, ref);
|
|
|
|
|
}
|
|
|
|
|
|
2002-07-19 03:12:50 +02:00
|
|
|
return 0;
|
2003-03-14 06:02:34 +01:00
|
|
|
}
|
2002-07-19 03:12:50 +02:00
|
|
|
|
2001-03-16 02:44:34 +01:00
|
|
|
assert(ref->vpi_type->handle_);
|
2003-03-13 05:34:18 +01:00
|
|
|
vpiHandle res = (ref->vpi_type->handle_)(type, ref);
|
|
|
|
|
|
|
|
|
|
if (vpi_trace) {
|
|
|
|
|
fprintf(vpi_trace, "vpi_handle(%d, %p) -> %p\n",
|
|
|
|
|
type, ref, res);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return res;
|
2001-03-16 02:44:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* This function asks the object to return an iterator for
|
|
|
|
|
* the specified reference. It is up to the iterate_ method to
|
|
|
|
|
* allocate a properly formed iterator.
|
|
|
|
|
*/
|
2002-01-06 01:48:39 +01:00
|
|
|
static vpiHandle vpi_iterate_global(int type)
|
|
|
|
|
{
|
|
|
|
|
switch (type) {
|
|
|
|
|
case vpiModule:
|
|
|
|
|
return vpip_make_root_iterator();
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2004-02-18 18:52:00 +01:00
|
|
|
vpiHandle vpi_iterate(PLI_INT32 type, vpiHandle ref)
|
2001-03-16 02:44:34 +01:00
|
|
|
{
|
2003-06-17 18:55:07 +02:00
|
|
|
vpiHandle rtn = 0;
|
|
|
|
|
|
2002-05-18 04:34:11 +02:00
|
|
|
assert(vpi_mode_flag != VPI_MODE_NONE);
|
|
|
|
|
if (vpi_mode_flag == VPI_MODE_REGISTER) {
|
|
|
|
|
fprintf(stderr, "vpi error: vpi_iterate called during "
|
|
|
|
|
"vpi_register_systf. You can't do that!\n");
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
2002-07-17 07:13:43 +02:00
|
|
|
|
2002-01-06 01:48:39 +01:00
|
|
|
if (ref == 0)
|
2003-06-17 18:55:07 +02:00
|
|
|
rtn = vpi_iterate_global(type);
|
|
|
|
|
else if (ref->vpi_type->iterate_)
|
|
|
|
|
rtn = (ref->vpi_type->iterate_)(type, ref);
|
2003-03-14 06:02:34 +01:00
|
|
|
|
2003-06-17 18:55:07 +02:00
|
|
|
if (vpi_trace) {
|
|
|
|
|
fprintf(vpi_trace, "vpi_iterate(%d, %p) ->%s\n",
|
|
|
|
|
type, ref, rtn ? "" : " (null)");
|
2003-03-14 06:02:34 +01:00
|
|
|
}
|
2003-06-17 18:55:07 +02:00
|
|
|
|
|
|
|
|
return rtn;
|
2001-03-16 02:44:34 +01:00
|
|
|
}
|
|
|
|
|
|
2004-02-18 18:52:00 +01:00
|
|
|
vpiHandle vpi_handle_by_index(vpiHandle ref, PLI_INT32 idx)
|
2001-03-16 02:44:34 +01:00
|
|
|
{
|
2002-06-02 21:05:50 +02:00
|
|
|
assert(ref);
|
2002-07-19 03:12:50 +02:00
|
|
|
|
|
|
|
|
if (ref->vpi_type->index_ == 0)
|
|
|
|
|
return 0;
|
|
|
|
|
|
2001-03-16 02:44:34 +01:00
|
|
|
assert(ref->vpi_type->index_);
|
|
|
|
|
return (ref->vpi_type->index_)(ref, idx);
|
|
|
|
|
}
|
|
|
|
|
|
2003-03-13 05:34:18 +01:00
|
|
|
static vpiHandle find_name(const char *name, vpiHandle handle)
|
2002-07-17 07:13:43 +02:00
|
|
|
{
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2003-03-13 05:34:18 +01:00
|
|
|
static vpiHandle find_scope(const char *name, vpiHandle handle, int depth)
|
2002-07-17 07:13:43 +02:00
|
|
|
{
|
|
|
|
|
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);
|
2003-03-13 05:34:18 +01:00
|
|
|
const char *cp = name + len; /* hier separator */
|
2002-07-17 07:13:43 +02:00
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2003-03-13 05:34:18 +01:00
|
|
|
vpiHandle vpi_handle_by_name(const char *name, vpiHandle scope)
|
2002-07-17 07:13:43 +02:00
|
|
|
{
|
|
|
|
|
vpiHandle hand;
|
2003-03-13 05:34:18 +01:00
|
|
|
const char *nm, *cp;
|
2002-07-17 07:13:43 +02:00
|
|
|
int len;
|
|
|
|
|
|
2003-03-13 05:34:18 +01:00
|
|
|
|
|
|
|
|
if (vpi_trace) {
|
|
|
|
|
fprintf(vpi_trace, "vpi_handle_by_name(%s, %p) -->\n",
|
|
|
|
|
name, scope);
|
|
|
|
|
}
|
|
|
|
|
|
2003-02-10 00:33:26 +01:00
|
|
|
/* If scope provided, look in corresponding module; otherwise
|
|
|
|
|
* traverse the hierarchy specified in name to find the leaf module
|
2002-07-17 07:13:43 +02:00
|
|
|
* and try finding it there.
|
|
|
|
|
*/
|
2007-08-16 01:09:38 +02:00
|
|
|
if (scope) {
|
|
|
|
|
/* Some implementations support either a module or a scope. */
|
|
|
|
|
if (vpi_get(vpiType, scope ) == vpiScope) {
|
|
|
|
|
hand = vpi_handle(vpiModule, scope);
|
|
|
|
|
} else {
|
|
|
|
|
hand = scope;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
2002-07-17 07:13:43 +02:00
|
|
|
hand = find_scope(name, NULL, 0);
|
2007-08-16 01:09:38 +02:00
|
|
|
}
|
2002-07-17 07:13:43 +02:00
|
|
|
|
|
|
|
|
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 */
|
2003-03-13 05:34:18 +01:00
|
|
|
vpiHandle out = find_name(name, hand);
|
|
|
|
|
return out;
|
2002-07-17 07:13:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2007-09-11 00:30:00 +02:00
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
We Increment the tow vpi methods to enable the
|
|
|
|
|
read/write SDF delay values from/into
|
|
|
|
|
the modpath vpiHandle
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
baiscally, they will redirect the generic vpi_interface
|
|
|
|
|
|
|
|
|
|
vpi_get_delay ( .. )
|
|
|
|
|
vpi_put_delay ( .. )
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
to the
|
|
|
|
|
|
|
|
|
|
modpath_get_delay ( .. ) ;
|
|
|
|
|
modpath_put_delay ( .. ) ;
|
|
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void vpi_get_delays(vpiHandle expr, p_vpi_delay delays)
|
|
|
|
|
{
|
|
|
|
|
assert(expr);
|
|
|
|
|
assert(delays);
|
|
|
|
|
|
|
|
|
|
if (expr->vpi_type->vpi_get_delays_)
|
|
|
|
|
{
|
|
|
|
|
(expr->vpi_type->vpi_get_delays_)(expr, delays);
|
|
|
|
|
|
|
|
|
|
if (vpi_trace)
|
|
|
|
|
{
|
|
|
|
|
fprintf(vpi_trace,
|
|
|
|
|
"vpi_get_delays(%s, %p) -->\n", expr, delays);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void vpi_put_delays(vpiHandle expr, p_vpi_delay delays)
|
|
|
|
|
{
|
|
|
|
|
assert(expr );
|
|
|
|
|
assert(delays );
|
|
|
|
|
|
|
|
|
|
if (expr->vpi_type->vpi_put_delays_)
|
|
|
|
|
{
|
|
|
|
|
(expr->vpi_type->vpi_put_delays_)(expr, delays);
|
|
|
|
|
|
|
|
|
|
if (vpi_trace)
|
|
|
|
|
{
|
|
|
|
|
fprintf(vpi_trace,
|
|
|
|
|
"vpi_put_delays(%s, %p) -->\n", expr, delays);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2003-05-15 18:51:08 +02:00
|
|
|
extern "C" PLI_INT32 vpi_vprintf(const char*fmt, va_list ap)
|
2001-03-16 02:44:34 +01:00
|
|
|
{
|
2003-05-15 18:51:08 +02:00
|
|
|
return vpi_mcd_vprintf(1, fmt, ap);
|
2001-03-16 02:44:34 +01:00
|
|
|
}
|
|
|
|
|
|
2003-05-15 18:51:08 +02:00
|
|
|
extern "C" PLI_INT32 vpi_printf(const char *fmt, ...)
|
2003-01-10 04:06:32 +01:00
|
|
|
{
|
|
|
|
|
va_list ap;
|
|
|
|
|
va_start(ap, fmt);
|
2003-05-15 18:51:08 +02:00
|
|
|
int r = vpi_mcd_vprintf(1, fmt, ap);
|
2003-01-10 04:06:32 +01:00
|
|
|
va_end(ap);
|
2003-05-15 18:51:08 +02:00
|
|
|
return r;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
extern "C" PLI_INT32 vpi_flush(void)
|
|
|
|
|
{
|
|
|
|
|
return vpi_mcd_flush(1);
|
2003-01-10 04:06:32 +01:00
|
|
|
}
|
|
|
|
|
|
2001-03-16 02:44:34 +01:00
|
|
|
|
2001-06-12 05:53:10 +02:00
|
|
|
extern "C" void vpi_sim_vcontrol(int operation, va_list ap)
|
2001-03-16 02:44:34 +01:00
|
|
|
{
|
2007-07-20 19:38:50 +02:00
|
|
|
long diag_msg;
|
|
|
|
|
|
2001-03-19 02:55:38 +01:00
|
|
|
switch (operation) {
|
|
|
|
|
case vpiFinish:
|
2007-07-20 19:38:50 +02:00
|
|
|
diag_msg = va_arg(ap, long);
|
|
|
|
|
schedule_finish(diag_msg);
|
2001-03-19 02:55:38 +01:00
|
|
|
break;
|
|
|
|
|
|
2003-02-21 04:40:35 +01:00
|
|
|
case vpiStop:
|
2007-07-20 19:38:50 +02:00
|
|
|
diag_msg = va_arg(ap, long);
|
|
|
|
|
schedule_stop(diag_msg);
|
2003-02-21 04:40:35 +01:00
|
|
|
break;
|
|
|
|
|
|
2001-03-19 02:55:38 +01:00
|
|
|
default:
|
2007-08-23 00:15:32 +02:00
|
|
|
fprintf(stderr, "Unsupported operation %d.\n", operation);
|
2001-03-19 02:55:38 +01:00
|
|
|
assert(0);
|
|
|
|
|
}
|
2001-03-16 02:44:34 +01:00
|
|
|
}
|
|
|
|
|
|
2004-02-18 03:51:59 +01:00
|
|
|
extern "C" void vpi_sim_control(PLI_INT32 operation, ...)
|
2003-01-10 04:06:32 +01:00
|
|
|
{
|
|
|
|
|
va_list ap;
|
|
|
|
|
va_start(ap, operation);
|
|
|
|
|
vpi_sim_vcontrol(operation, ap);
|
|
|
|
|
va_end(ap);
|
|
|
|
|
}
|
|
|
|
|
|
2004-02-18 03:51:59 +01:00
|
|
|
extern "C" void vpi_control(PLI_INT32 operation, ...)
|
2003-01-10 20:02:21 +01:00
|
|
|
{
|
|
|
|
|
va_list ap;
|
|
|
|
|
va_start(ap, operation);
|
|
|
|
|
vpi_sim_vcontrol(operation, ap);
|
|
|
|
|
va_end(ap);
|
|
|
|
|
}
|
|
|
|
|
|