2001-03-16 02:44:34 +01:00
|
|
|
/*
|
2025-07-08 22:14:49 +02:00
|
|
|
* Copyright (c) 2008-2025 Stephen Williams (steve@icarus.com)
|
2023-08-17 16:09:20 +02:00
|
|
|
* Copyright (c) 2023 Leo Moser (leo.moser@pm.me)
|
2001-03-16 02:44:34 +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-16 02:44:34 +01:00
|
|
|
*/
|
|
|
|
|
|
2010-01-03 03:22:15 +01:00
|
|
|
# include "version_base.h"
|
2001-03-16 02:44:34 +01:00
|
|
|
# include "vpi_priv.h"
|
2001-03-19 02:55:38 +01:00
|
|
|
# include "schedule.h"
|
2023-07-19 15:02:20 +02:00
|
|
|
# include "logic.h"
|
2023-08-30 09:50:00 +02:00
|
|
|
# include "part.h"
|
2023-12-24 00:37:27 +01:00
|
|
|
# include "concat.h"
|
2013-12-05 01:23:30 +01:00
|
|
|
#ifdef CHECK_WITH_VALGRIND
|
|
|
|
|
# include "vvp_cleanup.h"
|
|
|
|
|
#endif
|
2014-04-14 01:25:30 +02:00
|
|
|
# include <vector>
|
2010-05-31 22:12:06 +02:00
|
|
|
# include <cstdio>
|
|
|
|
|
# include <cstdarg>
|
|
|
|
|
# include <cstring>
|
|
|
|
|
# include <cassert>
|
|
|
|
|
# include <cstdlib>
|
|
|
|
|
# include <cmath>
|
2010-11-23 04:41:00 +01:00
|
|
|
# include <iostream>
|
2001-03-16 02:44:34 +01:00
|
|
|
|
2014-04-14 01:25:30 +02:00
|
|
|
using namespace std;
|
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 };
|
|
|
|
|
|
2022-02-26 20:12:50 +01:00
|
|
|
const char* direction_as_string(int dir)
|
|
|
|
|
{
|
|
|
|
|
switch (dir) {
|
|
|
|
|
case vpiInput:
|
|
|
|
|
return "input";
|
|
|
|
|
case vpiOutput:
|
|
|
|
|
return "output";
|
|
|
|
|
case vpiInout:
|
|
|
|
|
return "inout";
|
|
|
|
|
case vpiMixedIO:
|
|
|
|
|
return "mixed io";
|
|
|
|
|
case vpiNoDirection:
|
|
|
|
|
return "no direction";
|
|
|
|
|
default:
|
|
|
|
|
return "INVALID-DIRECTION";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-01-20 20:39:48 +01:00
|
|
|
__vpiHandle::~__vpiHandle()
|
|
|
|
|
{ }
|
|
|
|
|
|
|
|
|
|
int __vpiHandle::vpi_get(int)
|
|
|
|
|
{ return vpiUndefined; }
|
|
|
|
|
|
|
|
|
|
char* __vpiHandle::vpi_get_str(int)
|
|
|
|
|
{ return 0; }
|
|
|
|
|
|
|
|
|
|
void __vpiHandle::vpi_get_value(p_vpi_value)
|
|
|
|
|
{ }
|
|
|
|
|
|
|
|
|
|
vpiHandle __vpiHandle::vpi_put_value(p_vpi_value, int)
|
|
|
|
|
{ return 0; }
|
|
|
|
|
|
|
|
|
|
vpiHandle __vpiHandle::vpi_handle(int)
|
|
|
|
|
{ return 0; }
|
|
|
|
|
|
|
|
|
|
vpiHandle __vpiHandle::vpi_iterate(int)
|
|
|
|
|
{ return 0; }
|
|
|
|
|
|
|
|
|
|
vpiHandle __vpiHandle::vpi_index(int)
|
|
|
|
|
{ return 0; }
|
|
|
|
|
|
|
|
|
|
void __vpiHandle::vpi_get_delays(p_vpi_delay)
|
|
|
|
|
{ }
|
|
|
|
|
|
|
|
|
|
void __vpiHandle::vpi_put_delays(p_vpi_delay)
|
|
|
|
|
{ }
|
|
|
|
|
|
2012-11-17 04:13:06 +01:00
|
|
|
__vpiBaseVar::__vpiBaseVar(__vpiScope*scope, const char*name, vvp_net_t*net)
|
|
|
|
|
: scope_(scope), name_(name), net_(net)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2013-12-05 01:23:30 +01:00
|
|
|
#ifdef CHECK_WITH_VALGRIND
|
|
|
|
|
__vpiBaseVar::~__vpiBaseVar()
|
|
|
|
|
{
|
|
|
|
|
vvp_net_delete(net_);
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
2012-01-21 20:59:49 +01:00
|
|
|
/*
|
|
|
|
|
* The default behavior for the vpi_free_object to an object is to
|
|
|
|
|
* suppress the actual operation. This is because handles are
|
|
|
|
|
* generally allocated semi-permanently within vvp context. Dynamic
|
|
|
|
|
* objects will override the free_object_fun method to return an
|
|
|
|
|
* appropriately effective function.
|
|
|
|
|
*/
|
|
|
|
|
static int suppress_free(vpiHandle)
|
|
|
|
|
{ return 1; }
|
2012-01-20 23:15:26 +01:00
|
|
|
__vpiHandle::free_object_fun_t __vpiHandle::free_object_fun(void)
|
2012-01-21 20:59:49 +01:00
|
|
|
{ return &suppress_free; }
|
2012-01-20 20:39:48 +01:00
|
|
|
|
2002-07-05 19:14:15 +02:00
|
|
|
/*
|
|
|
|
|
* The vpip_string function creates a constant string from the pass
|
2008-04-30 17:44:37 +02:00
|
|
|
* input. This constant string is permanently allocated from an
|
2002-07-05 19:14:15 +02:00
|
|
|
* efficient string buffer store.
|
|
|
|
|
*/
|
|
|
|
|
struct vpip_string_chunk {
|
|
|
|
|
struct vpip_string_chunk*next;
|
|
|
|
|
char data[64*1024 - sizeof (struct vpip_string_chunk*)];
|
|
|
|
|
};
|
|
|
|
|
|
2007-11-07 03:15:08 +01:00
|
|
|
unsigned vpip_size(__vpiSignal *sig)
|
|
|
|
|
{
|
2014-06-20 00:39:24 +02:00
|
|
|
return abs(sig->msb.get_value() - sig->lsb.get_value()) + 1;
|
2007-11-07 03:15:08 +01:00
|
|
|
}
|
|
|
|
|
|
2015-12-27 20:37:10 +01:00
|
|
|
__vpiScope* vpip_scope(__vpiSignal*sig)
|
2008-06-15 01:17:25 +02:00
|
|
|
{
|
|
|
|
|
if (sig->is_netarray)
|
2021-01-02 22:52:25 +01:00
|
|
|
return static_cast<__vpiScope*>(vpi_handle(vpiScope,
|
|
|
|
|
sig->within.parent));
|
2008-06-15 01:17:25 +02:00
|
|
|
else
|
|
|
|
|
return sig->within.scope;
|
|
|
|
|
}
|
|
|
|
|
|
2015-12-27 20:37:10 +01:00
|
|
|
__vpiScope* vpip_scope(__vpiRealVar*sig)
|
2008-10-29 02:52:32 +01:00
|
|
|
{
|
|
|
|
|
if (sig->is_netarray)
|
2021-01-02 22:52:25 +01:00
|
|
|
return static_cast<__vpiScope*>(vpi_handle(vpiScope,
|
|
|
|
|
sig->within.parent));
|
2008-10-29 02:52:32 +01:00
|
|
|
else
|
|
|
|
|
return sig->within.scope;
|
|
|
|
|
}
|
|
|
|
|
|
2015-12-27 20:37:10 +01:00
|
|
|
vpiHandle vpip_module(__vpiScope*scope)
|
2009-01-16 20:09:48 +01:00
|
|
|
{
|
2012-01-19 19:16:39 +01:00
|
|
|
while(scope && scope->get_type_code() != vpiModule) {
|
2009-01-16 20:09:48 +01:00
|
|
|
scope = scope->scope;
|
|
|
|
|
}
|
|
|
|
|
assert(scope);
|
2012-01-19 19:16:39 +01:00
|
|
|
return scope;
|
2009-01-16 20:09:48 +01:00
|
|
|
}
|
|
|
|
|
|
2002-07-05 19:14:15 +02:00
|
|
|
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) {
|
2015-10-02 18:42:36 +02:00
|
|
|
h = (h << 4) ^ (h >> 28) ^ (unsigned)*text;
|
2003-03-06 05:32:00 +01:00
|
|
|
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;
|
|
|
|
|
}
|
2010-04-11 23:28:45 +02:00
|
|
|
|
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;
|
2008-04-30 17:44:37 +02:00
|
|
|
info->code = (char *) "";
|
2002-07-19 03:57:26 +02:00
|
|
|
info->file = 0;
|
|
|
|
|
info->line = 0;
|
|
|
|
|
|
|
|
|
|
return info->level;
|
|
|
|
|
}
|
|
|
|
|
|
2010-04-11 23:28:45 +02:00
|
|
|
PLI_INT32 vpi_compare_objects(vpiHandle obj1, vpiHandle obj2)
|
|
|
|
|
{
|
2010-04-12 08:39:08 +02:00
|
|
|
assert(obj1);
|
|
|
|
|
assert(obj2);
|
|
|
|
|
|
|
|
|
|
// Does this actually work for all cases?
|
|
|
|
|
if (obj1 != obj2) return 0;
|
|
|
|
|
else return 1;
|
2010-04-11 23:28:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Copy the internal information to the data structure. Do not free or
|
|
|
|
|
* change the tfname/user_data since they are a pointer to the real
|
|
|
|
|
* string/data values. We also support passing a task or function handle
|
|
|
|
|
* instead of just a handle to a vpiUserSystf.
|
|
|
|
|
*/
|
|
|
|
|
void vpi_get_systf_info(vpiHandle ref, p_vpi_systf_data data)
|
|
|
|
|
{
|
2012-01-19 19:16:39 +01:00
|
|
|
struct __vpiUserSystf* rfp = dynamic_cast<__vpiUserSystf*>(ref);
|
|
|
|
|
if (rfp == 0) {
|
|
|
|
|
struct __vpiSysTaskCall*call = dynamic_cast<__vpiSysTaskCall*>(ref);
|
|
|
|
|
assert(call);
|
2010-04-12 18:59:45 +02:00
|
|
|
rfp = call->defn;
|
2010-04-11 23:28:45 +02:00
|
|
|
}
|
2012-01-19 19:16:39 +01:00
|
|
|
|
2010-04-12 08:39:08 +02:00
|
|
|
/* Assert that vpiUserDefn is true! */
|
|
|
|
|
assert(rfp->is_user_defn);
|
2010-04-11 23:28:45 +02:00
|
|
|
|
|
|
|
|
data->type = rfp->info.type;
|
|
|
|
|
data->sysfunctype = rfp->info.sysfunctype;
|
|
|
|
|
data->tfname = rfp->info.tfname;
|
|
|
|
|
data->calltf = rfp->info.calltf;
|
|
|
|
|
data->compiletf = rfp->info.compiletf;
|
|
|
|
|
data->sizetf = rfp->info.sizetf;
|
|
|
|
|
data->user_data = rfp->info.user_data;
|
|
|
|
|
}
|
|
|
|
|
|
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);
|
2012-01-20 23:15:26 +01:00
|
|
|
__vpiHandle::free_object_fun_t fun = ref->free_object_fun();
|
2012-01-21 20:59:49 +01:00
|
|
|
rtn = fun (ref);
|
2003-05-30 06:08:28 +02:00
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
2023-09-04 15:20:31 +02:00
|
|
|
PLI_INT32 vpi_release_handle(vpiHandle ref)
|
|
|
|
|
{
|
|
|
|
|
// Since SystemVerilog vpi_free_object() has been
|
|
|
|
|
// renamed vpi_release_handle(), and thus
|
|
|
|
|
// vpi_free_object() has been deprecated.
|
|
|
|
|
return vpi_free_object(ref);
|
|
|
|
|
}
|
|
|
|
|
|
2001-03-16 02:44:34 +01:00
|
|
|
static int vpip_get_global(int property)
|
|
|
|
|
{
|
|
|
|
|
switch (property) {
|
|
|
|
|
|
2007-09-28 20:21:08 +02:00
|
|
|
case vpiTimeUnit:
|
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";
|
2007-09-28 20:21:08 +02:00
|
|
|
case vpiTimePrecision:
|
|
|
|
|
return "vpiTimePrecision";
|
2009-10-29 19:16:26 +01:00
|
|
|
case vpiSize:
|
|
|
|
|
return "vpiSize";
|
2003-03-14 06:02:34 +01:00
|
|
|
default:
|
2022-12-18 01:29:03 +01:00
|
|
|
snprintf(buf, sizeof(buf), "%d", (int)code);
|
2003-03-14 06:02:34 +01:00
|
|
|
}
|
|
|
|
|
return buf;
|
|
|
|
|
}
|
|
|
|
|
|
2022-02-26 20:12:50 +01:00
|
|
|
const char* vpi_type_as_string(PLI_INT32 code)
|
2003-03-14 06:02:34 +01:00
|
|
|
{
|
|
|
|
|
static char buf[32];
|
|
|
|
|
switch (code) {
|
2015-01-15 04:06:55 +01:00
|
|
|
case vpiArrayType:
|
|
|
|
|
return "vpiArrayType";
|
2011-09-05 23:40:31 +02:00
|
|
|
case vpiBitVar:
|
|
|
|
|
return "vpiBitVar";
|
2010-10-08 03:01:11 +02:00
|
|
|
case vpiByteVar:
|
|
|
|
|
return "vpiByteVar";
|
2015-01-15 04:06:55 +01:00
|
|
|
case vpiClassVar:
|
|
|
|
|
return "vpiClassVar";
|
2003-03-14 06:02:34 +01:00
|
|
|
case vpiConstant:
|
|
|
|
|
return "vpiConstant";
|
2011-10-11 22:33:05 +02:00
|
|
|
case vpiEnumTypespec:
|
|
|
|
|
return "vpiEnumTypespec";
|
2008-06-04 02:12:27 +02:00
|
|
|
case vpiFunction:
|
|
|
|
|
return "vpiFunction";
|
2013-07-17 19:55:46 +02:00
|
|
|
case vpiGenScope:
|
|
|
|
|
return "vpiGenScope";
|
2010-10-08 03:01:11 +02:00
|
|
|
case vpiIntVar:
|
|
|
|
|
return "vpiIntVar";
|
2007-08-16 06:05:42 +02:00
|
|
|
case vpiIntegerVar:
|
|
|
|
|
return "vpiIntegerVar";
|
2007-11-30 00:27:36 +01:00
|
|
|
case vpiIterator:
|
|
|
|
|
return "vpiIterator";
|
2010-10-08 03:01:11 +02:00
|
|
|
case vpiLongIntVar:
|
|
|
|
|
return "vpiLongIntVar";
|
2007-11-30 00:27:36 +01:00
|
|
|
case vpiMemory:
|
|
|
|
|
return "vpiMemory";
|
2008-06-04 02:12:27 +02:00
|
|
|
case vpiMemoryWord:
|
|
|
|
|
return "vpiMemoryWord";
|
2003-03-14 06:02:34 +01:00
|
|
|
case vpiModule:
|
|
|
|
|
return "vpiModule";
|
2009-01-16 20:09:48 +01:00
|
|
|
case vpiNamedBegin:
|
|
|
|
|
return "vpiNamedBegin";
|
|
|
|
|
case vpiNamedEvent:
|
|
|
|
|
return "vpiNamedEvent";
|
|
|
|
|
case vpiNamedFork:
|
|
|
|
|
return "vpiNamedFork";
|
2015-01-15 04:06:55 +01:00
|
|
|
case vpiPackage:
|
|
|
|
|
return "vpiPackage";
|
2012-06-04 21:43:33 +02:00
|
|
|
case vpiPathTerm:
|
|
|
|
|
return "vpiPathTerm";
|
|
|
|
|
case vpiPort:
|
|
|
|
|
return "vpiPort";
|
2003-03-14 06:02:34 +01:00
|
|
|
case vpiNet:
|
|
|
|
|
return "vpiNet";
|
2009-02-27 21:34:48 +01:00
|
|
|
case vpiNetArray:
|
|
|
|
|
return "vpiNetArray";
|
2020-05-31 09:24:32 +02:00
|
|
|
case vpiNetBit:
|
|
|
|
|
return "vpiNetBit";
|
2007-08-16 06:05:42 +02:00
|
|
|
case vpiParameter:
|
|
|
|
|
return "vpiParameter";
|
2008-06-04 02:12:27 +02:00
|
|
|
case vpiPartSelect:
|
|
|
|
|
return "vpiPartSelect";
|
2007-08-16 06:05:42 +02:00
|
|
|
case vpiRealVar:
|
|
|
|
|
return "vpiRealVar";
|
2003-03-14 06:02:34 +01:00
|
|
|
case vpiReg:
|
|
|
|
|
return "vpiReg";
|
2020-05-31 09:24:32 +02:00
|
|
|
case vpiRegBit:
|
|
|
|
|
return "vpiRegBit";
|
2010-10-08 03:01:11 +02:00
|
|
|
case vpiShortIntVar:
|
|
|
|
|
return "vpiShortIntVar";
|
2015-01-15 04:06:55 +01:00
|
|
|
case vpiStringVar:
|
|
|
|
|
return "vpiStringVar";
|
2009-01-15 19:43:46 +01:00
|
|
|
case vpiSysFuncCall:
|
|
|
|
|
return "vpiSysFuncCall";
|
|
|
|
|
case vpiSysTaskCall:
|
|
|
|
|
return "vpiSysTaskCall";
|
2007-08-16 06:05:42 +02:00
|
|
|
case vpiTask:
|
|
|
|
|
return "vpiTask";
|
2008-06-04 02:12:27 +02:00
|
|
|
case vpiTimeVar:
|
|
|
|
|
return "vpiTimeVar";
|
2010-04-11 23:28:45 +02:00
|
|
|
case vpiUserSystf:
|
|
|
|
|
return "vpiUserSystf";
|
2003-03-14 06:02:34 +01:00
|
|
|
default:
|
2022-12-18 01:29:03 +01:00
|
|
|
snprintf(buf, sizeof(buf), "%d", (int)code);
|
2003-03-14 06:02:34 +01:00
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
2010-03-14 07:16:27 +01:00
|
|
|
/* We don't care what the ref is there is only one delay selection. */
|
|
|
|
|
if (property == _vpiDelaySelection) return vpip_delay_selection;
|
|
|
|
|
|
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",
|
2022-02-26 20:12:50 +01:00
|
|
|
ref, vpi_type_as_string(ref->get_type_code()));
|
2003-03-13 05:34:18 +01:00
|
|
|
}
|
|
|
|
|
|
2012-01-19 19:16:39 +01:00
|
|
|
if (ref->get_type_code() == vpiMemory && is_net_array(ref))
|
2009-02-27 21:34:48 +01:00
|
|
|
return vpiNetArray;
|
2002-06-21 06:58:55 +02:00
|
|
|
else
|
2012-01-19 19:16:39 +01:00
|
|
|
return ref->get_type_code();
|
2002-06-21 06:58:55 +02:00
|
|
|
}
|
2001-07-11 04:27:21 +02:00
|
|
|
|
2012-01-19 19:16:39 +01:00
|
|
|
int res = ref->vpi_get(property);
|
2003-03-12 03:50:32 +01:00
|
|
|
|
|
|
|
|
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
|
|
|
{
|
2010-03-14 07:16:27 +01:00
|
|
|
/* We don't care what the ref is there is only one delay selection. */
|
|
|
|
|
if (property == _vpiDelaySelection) {
|
|
|
|
|
switch (vpip_delay_selection) {
|
|
|
|
|
case _vpiDelaySelMinimum:
|
|
|
|
|
return simple_set_rbuf_str("MINIMUM");
|
|
|
|
|
case _vpiDelaySelTypical:
|
|
|
|
|
return simple_set_rbuf_str("TYPICAL");
|
|
|
|
|
case _vpiDelaySelMaximum:
|
|
|
|
|
return simple_set_rbuf_str("MAXIMUM");
|
|
|
|
|
default:
|
|
|
|
|
assert(0);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
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",
|
2022-02-26 20:12:50 +01:00
|
|
|
ref, vpi_type_as_string(ref->get_type_code()));
|
2007-08-16 06:05:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
PLI_INT32 type;
|
2012-01-19 19:16:39 +01:00
|
|
|
if (ref->get_type_code() == vpiMemory && is_net_array(ref))
|
2009-02-27 21:34:48 +01:00
|
|
|
type = vpiNetArray;
|
2007-08-16 06:05:42 +02:00
|
|
|
else
|
2012-01-19 19:16:39 +01:00
|
|
|
type = ref->get_type_code();
|
2022-02-26 20:12:50 +01:00
|
|
|
return (char *)vpi_type_as_string(type);
|
2007-08-16 06:05:42 +02:00
|
|
|
}
|
|
|
|
|
|
2012-01-19 19:16:39 +01:00
|
|
|
char*res = ref->vpi_get_str(property);
|
2003-03-12 03:50:32 +01:00
|
|
|
|
|
|
|
|
if (vpi_trace) {
|
2003-03-14 06:02:34 +01:00
|
|
|
fprintf(vpi_trace, "vpi_get_str(%s, %p) --> %s\n",
|
2012-01-19 19:16:39 +01:00
|
|
|
vpi_property_str(property), ref, res? res : "<NULL>");
|
2003-03-12 03:50:32 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return res;
|
2001-03-16 02:44:34 +01:00
|
|
|
}
|
|
|
|
|
|
2024-02-07 00:35:05 +01:00
|
|
|
__vpiScope*vpip_timescale_scope_from_handle(vpiHandle obj)
|
2003-04-27 06:19:24 +02:00
|
|
|
{
|
|
|
|
|
struct __vpiSysTaskCall*task;
|
2003-05-02 06:29:57 +02:00
|
|
|
struct __vpiSignal*signal;
|
2024-02-06 00:21:45 +01:00
|
|
|
struct __vpiRealVar*real;
|
2017-06-20 06:25:07 +02:00
|
|
|
__vpiNamedEvent*event;
|
2003-04-27 06:19:24 +02:00
|
|
|
|
2012-01-19 19:16:39 +01:00
|
|
|
switch (obj->get_type_code()) {
|
2003-04-27 06:19:24 +02:00
|
|
|
case vpiSysTaskCall:
|
2012-01-19 19:16:39 +01:00
|
|
|
task = dynamic_cast<__vpiSysTaskCall*>(obj);
|
2024-02-06 00:21:45 +01:00
|
|
|
return task->scope;
|
2003-04-27 06:19:24 +02:00
|
|
|
|
|
|
|
|
case vpiModule:
|
2024-02-06 00:21:45 +01:00
|
|
|
return dynamic_cast<__vpiScope*>(obj);
|
2003-04-27 06:19:24 +02:00
|
|
|
|
2003-05-02 06:29:57 +02:00
|
|
|
case vpiNet:
|
|
|
|
|
case vpiReg:
|
2024-02-06 00:21:45 +01:00
|
|
|
case vpiIntegerVar:
|
|
|
|
|
case vpiBitVar:
|
|
|
|
|
case vpiByteVar:
|
|
|
|
|
case vpiShortIntVar:
|
|
|
|
|
case vpiIntVar:
|
|
|
|
|
case vpiLongIntVar:
|
2012-01-19 19:16:39 +01:00
|
|
|
signal = dynamic_cast<__vpiSignal*>(obj);
|
2024-02-06 00:21:45 +01:00
|
|
|
return vpip_scope(signal);
|
|
|
|
|
|
|
|
|
|
case vpiRealVar:
|
|
|
|
|
real = dynamic_cast<__vpiRealVar*>(obj);
|
|
|
|
|
return vpip_scope(real);
|
2003-05-02 06:29:57 +02:00
|
|
|
|
2017-06-15 09:47:29 +02:00
|
|
|
case vpiNamedEvent:
|
|
|
|
|
event = dynamic_cast<__vpiNamedEvent*>(obj);
|
2024-02-06 00:21:45 +01:00
|
|
|
return event->get_scope();
|
|
|
|
|
|
|
|
|
|
case vpiMemory:
|
|
|
|
|
case vpiMemoryWord:
|
|
|
|
|
case vpiPartSelect:
|
|
|
|
|
return dynamic_cast<__vpiScope*>(obj->vpi_handle(vpiScope));
|
2017-06-15 09:47:29 +02:00
|
|
|
|
2003-04-27 06:19:24 +02:00
|
|
|
default:
|
2024-02-06 00:21:45 +01:00
|
|
|
fprintf(stderr, "ERROR: vpip_scope_from_handle called with "
|
2021-06-18 07:44:48 +02:00
|
|
|
"object handle type=%d\n", obj->get_type_code());
|
2007-09-28 20:21:08 +02:00
|
|
|
assert(0);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-02-06 00:21:45 +01:00
|
|
|
int vpip_time_units_from_handle(vpiHandle obj)
|
2007-09-28 20:21:08 +02:00
|
|
|
{
|
|
|
|
|
if (obj == 0)
|
|
|
|
|
return vpip_get_time_precision();
|
|
|
|
|
|
2024-02-06 00:21:45 +01:00
|
|
|
__vpiScope*scope = vpip_timescale_scope_from_handle(obj);
|
|
|
|
|
if (scope == 0)
|
|
|
|
|
return vpip_get_time_precision();
|
2007-09-28 20:21:08 +02:00
|
|
|
|
2024-02-06 00:21:45 +01:00
|
|
|
return scope->time_units;
|
|
|
|
|
}
|
2007-09-28 20:21:08 +02:00
|
|
|
|
2024-02-06 00:21:45 +01:00
|
|
|
int vpip_time_precision_from_handle(vpiHandle obj)
|
|
|
|
|
{
|
|
|
|
|
if (obj == 0)
|
|
|
|
|
return vpip_get_time_precision();
|
2007-09-28 20:21:08 +02:00
|
|
|
|
2024-02-06 00:21:45 +01:00
|
|
|
__vpiScope*scope = vpip_timescale_scope_from_handle(obj);
|
|
|
|
|
if (scope == 0)
|
|
|
|
|
return vpip_get_time_precision();
|
|
|
|
|
|
|
|
|
|
return scope->time_precision;
|
2003-04-27 06:19:24 +02:00
|
|
|
}
|
|
|
|
|
|
2024-02-05 23:12:33 +01:00
|
|
|
double vpip_scaled_time_from_handle(vvp_time64_t time, vpiHandle obj)
|
|
|
|
|
{
|
|
|
|
|
int scale = vpip_get_time_precision() -
|
|
|
|
|
vpip_time_units_from_handle(obj);
|
|
|
|
|
if (scale >= 0)
|
|
|
|
|
return (double)time * pow(10.0, scale);
|
|
|
|
|
else
|
|
|
|
|
return (double)time / pow(10.0, -scale);
|
|
|
|
|
}
|
|
|
|
|
|
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-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:
|
2024-02-05 23:12:33 +01:00
|
|
|
vp->real = vpip_scaled_time_from_handle(time, obj);
|
2003-04-27 06:19:24 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
default:
|
2009-12-10 21:53:58 +01:00
|
|
|
fprintf(stderr, "vpi_get_time: unknown type: %d\n", (int)vp->type);
|
2003-04-27 06:19:24 +02:00
|
|
|
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)
|
|
|
|
|
{
|
2008-01-04 21:25:16 +01:00
|
|
|
static char icarus_product[] = "Icarus Verilog";
|
2010-01-03 03:22:15 +01:00
|
|
|
static char icarus_version[] = VERSION;
|
2008-01-04 21:25:16 +01:00
|
|
|
vpi_vlog_info.product = icarus_product;
|
|
|
|
|
vpi_vlog_info.version = icarus_version;
|
2002-01-09 04:15:23 +01:00
|
|
|
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];
|
2012-06-04 21:43:33 +02: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
|
|
|
}
|
|
|
|
|
|
2009-03-28 03:12:11 +01:00
|
|
|
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;
|
|
|
|
|
|
2014-06-10 07:21:51 +02:00
|
|
|
char*rbuf = (char *) need_result_buf(nchar + 1, RBUF_VAL);
|
2009-03-28 03:12:11 +01:00
|
|
|
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;
|
2023-01-03 00:33:51 +01:00
|
|
|
else if (cp != rbuf)
|
|
|
|
|
*cp++ = ' ';
|
2009-03-28 03:12:11 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
}
|
2023-01-03 00:33:51 +01:00
|
|
|
// Ignore leading null-bytes and replace other null-bytes with space.
|
|
|
|
|
// The LRM is not entirely clear on how null bytes should be handled.
|
|
|
|
|
// This is the implementation chosen for iverilog.
|
2009-03-28 03:12:11 +01:00
|
|
|
if (char_val != 0)
|
|
|
|
|
*cp++ = char_val;
|
2023-01-03 00:33:51 +01:00
|
|
|
else if (cp != rbuf)
|
|
|
|
|
*cp++ = ' ';
|
2009-03-28 03:12:11 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
*cp = 0;
|
|
|
|
|
vp->value.str = rbuf;
|
|
|
|
|
}
|
|
|
|
|
|
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.
|
|
|
|
|
*/
|
|
|
|
|
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:
|
2009-03-28 03:12:11 +01:00
|
|
|
fprintf(stderr, "sorry: Format %d not implemented for "
|
2009-12-10 21:53:58 +01:00
|
|
|
"getting vector values.\n", (int)vp->format);
|
2009-03-28 03:12:11 +01:00
|
|
|
assert(0);
|
2008-08-16 04:28:11 +02:00
|
|
|
|
2008-08-13 19:29:44 +02:00
|
|
|
case vpiSuppressVal:
|
|
|
|
|
break;
|
|
|
|
|
|
2006-03-06 06:43:15 +01:00
|
|
|
case vpiBinStrVal:
|
2014-06-10 07:21:51 +02:00
|
|
|
rbuf = (char *) need_result_buf(width+1, RBUF_VAL);
|
2006-03-06 06:43:15 +01:00
|
|
|
for (unsigned idx = 0 ; idx < width ; idx += 1) {
|
|
|
|
|
vvp_bit4_t bit = word_val.value(idx);
|
2008-04-23 20:16:24 +02:00
|
|
|
rbuf[width-idx-1] = vvp_bit4_to_ascii(bit);
|
2006-03-06 06:43:15 +01:00
|
|
|
}
|
|
|
|
|
rbuf[width] = 0;
|
|
|
|
|
vp->value.str = rbuf;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case vpiOctStrVal: {
|
2010-10-11 06:52:26 +02:00
|
|
|
unsigned hwid = ((width+2) / 3) + 1;
|
2014-06-10 07:21:51 +02:00
|
|
|
rbuf = (char *) need_result_buf(hwid, RBUF_VAL);
|
2010-10-11 06:52:26 +02:00
|
|
|
vpip_vec4_to_oct_str(word_val, rbuf, hwid);
|
2006-03-06 06:43:15 +01:00
|
|
|
vp->value.str = rbuf;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case vpiDecStrVal: {
|
2010-10-11 06:52:26 +02:00
|
|
|
// HERE need a better estimate.
|
2014-06-10 07:21:51 +02:00
|
|
|
rbuf = (char *) need_result_buf(width+1, RBUF_VAL);
|
2006-03-06 06:43:15 +01:00
|
|
|
vpip_vec4_to_dec_str(word_val, rbuf, width+1, signed_flag);
|
|
|
|
|
vp->value.str = rbuf;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case vpiHexStrVal: {
|
2010-10-11 06:52:26 +02:00
|
|
|
unsigned hwid = ((width + 3) / 4) + 1;
|
2014-06-10 07:21:51 +02:00
|
|
|
rbuf = (char *) need_result_buf(hwid, RBUF_VAL);
|
2010-10-11 06:52:26 +02:00
|
|
|
vpip_vec4_to_hex_str(word_val, rbuf, hwid);
|
2006-03-06 06:43:15 +01:00
|
|
|
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;
|
2008-08-13 19:29:44 +02:00
|
|
|
break;
|
2007-04-12 06:45:52 +02:00
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2009-03-28 03:12:11 +01:00
|
|
|
case vpiObjTypeVal:
|
|
|
|
|
// Use the following case to actually set the value!
|
|
|
|
|
vp->format = vpiVectorVal;
|
2018-10-06 21:13:31 +02:00
|
|
|
// fallthrough
|
2006-03-06 06:43:15 +01:00
|
|
|
case vpiVectorVal: {
|
2012-04-01 21:27:28 +02:00
|
|
|
unsigned hwid = (width + 31)/32;
|
2006-03-06 06:43:15 +01:00
|
|
|
|
2014-06-10 19:58:38 +02:00
|
|
|
s_vpi_vecval *op = (p_vpi_vecval)
|
|
|
|
|
need_result_buf(hwid * sizeof(s_vpi_vecval), RBUF_VAL);
|
2006-03-06 06:43:15 +01:00
|
|
|
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:
|
2009-03-28 03:12:11 +01:00
|
|
|
vec4_get_value_string(word_val, width, vp);
|
|
|
|
|
break;
|
2006-03-06 06:43:15 +01:00
|
|
|
|
2009-03-28 03:12:11 +01:00
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2010-11-22 02:24:46 +01:00
|
|
|
void vpip_vec2_get_value(const vvp_vector2_t&word_val, unsigned width,
|
|
|
|
|
bool signed_flag, s_vpi_value*vp)
|
|
|
|
|
{
|
|
|
|
|
switch (vp->format) {
|
|
|
|
|
default:
|
|
|
|
|
fprintf(stderr, "sorry: Format %d not implemented for "
|
|
|
|
|
"getting vector2 values.\n", (int)vp->format);
|
|
|
|
|
assert(0);
|
|
|
|
|
|
|
|
|
|
case vpiSuppressVal:
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case vpiObjTypeVal:
|
|
|
|
|
vp->format = vpiIntVal;
|
2018-10-06 21:13:31 +02:00
|
|
|
// fallthrough
|
2010-11-22 02:24:46 +01:00
|
|
|
case vpiIntVal:
|
2010-11-23 04:41:00 +01:00
|
|
|
vector2_to_value(word_val, vp->value.integer, signed_flag);
|
2010-11-22 02:24:46 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case vpiVectorVal: {
|
2012-04-01 21:27:28 +02:00
|
|
|
unsigned hwid = (width + 31)/32;
|
2010-11-22 02:24:46 +01:00
|
|
|
|
2014-06-10 19:58:38 +02:00
|
|
|
s_vpi_vecval *op = (p_vpi_vecval)
|
|
|
|
|
need_result_buf(hwid * sizeof(s_vpi_vecval), RBUF_VAL);
|
2010-11-22 02:24:46 +01:00
|
|
|
vp->value.vector = op;
|
|
|
|
|
|
|
|
|
|
op->aval = op->bval = 0;
|
|
|
|
|
for (unsigned idx = 0 ; idx < width ; idx += 1) {
|
|
|
|
|
if (word_val.value(idx)) {
|
|
|
|
|
op->aval |= (1 << idx % 32);
|
|
|
|
|
op->bval &= ~(1 << idx % 32);
|
|
|
|
|
} else {
|
|
|
|
|
op->aval &= ~(1 << idx % 32);
|
|
|
|
|
op->bval &= ~(1 << idx % 32);
|
|
|
|
|
}
|
|
|
|
|
if (!((idx+1) % 32) && (idx+1 < width)) {
|
|
|
|
|
op++;
|
|
|
|
|
op->aval = op->bval = 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2009-03-28 03:12:11 +01:00
|
|
|
/*
|
|
|
|
|
* Convert a real value to the appropriate integer.
|
|
|
|
|
*/
|
|
|
|
|
static PLI_INT32 get_real_as_int(double real)
|
2006-03-06 06:43:15 +01:00
|
|
|
{
|
2009-03-28 03:12:11 +01:00
|
|
|
double rtn;
|
2006-03-06 06:43:15 +01:00
|
|
|
|
2009-03-28 03:12:11 +01:00
|
|
|
/* We would normally want to return 'bx for a NaN or
|
|
|
|
|
* +/- infinity, but for an integer the standard says
|
|
|
|
|
* to convert 'bx to 0, so we just return 0. */
|
|
|
|
|
if (real != real || (real && (real == 0.5*real))) {
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
2006-03-06 06:43:15 +01:00
|
|
|
|
2009-03-28 03:12:11 +01:00
|
|
|
/* Round away from zero. */
|
|
|
|
|
if (real >= 0.0) {
|
|
|
|
|
rtn = floor(real);
|
|
|
|
|
if (real >= (rtn + 0.5)) rtn += 1.0;
|
|
|
|
|
} else {
|
|
|
|
|
rtn = ceil(real);
|
|
|
|
|
if (real <= (rtn - 0.5)) rtn -= 1.0;
|
|
|
|
|
}
|
2006-03-06 06:43:15 +01:00
|
|
|
|
2009-03-28 03:12:11 +01:00
|
|
|
return (PLI_INT32) rtn;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* This is a generic function to convert a double value into a
|
|
|
|
|
* vpi_value structure. The format is selected by the format of the
|
|
|
|
|
* value pointer.
|
|
|
|
|
*/
|
|
|
|
|
void vpip_real_get_value(double real, s_vpi_value*vp)
|
|
|
|
|
{
|
|
|
|
|
char *rbuf = 0;
|
|
|
|
|
|
|
|
|
|
switch (vp->format) {
|
|
|
|
|
default:
|
|
|
|
|
fprintf(stderr, "sorry: Format %d not implemented for "
|
2009-12-10 21:53:58 +01:00
|
|
|
"getting real values.\n", (int)vp->format);
|
2009-03-28 03:12:11 +01:00
|
|
|
assert(0);
|
|
|
|
|
|
|
|
|
|
case vpiSuppressVal:
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case vpiObjTypeVal:
|
|
|
|
|
// Use the following case to actually set the value!
|
|
|
|
|
vp->format = vpiRealVal;
|
2018-10-06 21:13:31 +02:00
|
|
|
// fallthrough
|
2009-03-28 03:12:11 +01:00
|
|
|
case vpiRealVal:
|
|
|
|
|
vp->value.real = real;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case vpiIntVal:
|
|
|
|
|
vp->value.integer = get_real_as_int(real);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case vpiDecStrVal:
|
2014-06-10 07:21:51 +02:00
|
|
|
rbuf = (char *) need_result_buf(1025, RBUF_VAL);
|
2009-03-28 03:12:11 +01:00
|
|
|
vpip_vec4_to_dec_str(vvp_vector4_t(1024, real), rbuf, 1025, true);
|
|
|
|
|
vp->value.str = rbuf;
|
|
|
|
|
break;
|
2006-03-06 06:43:15 +01:00
|
|
|
}
|
2009-03-28 03:12:11 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
double real_from_vpi_value(s_vpi_value*vp)
|
|
|
|
|
{
|
|
|
|
|
vvp_vector4_t vec4(1024);
|
|
|
|
|
double result;
|
|
|
|
|
bool is_signed = false;
|
|
|
|
|
|
|
|
|
|
switch (vp->format) {
|
|
|
|
|
default:
|
|
|
|
|
fprintf(stderr, "sorry: Format %d not implemented for "
|
2009-12-10 21:53:58 +01:00
|
|
|
"putting real values.\n", (int)vp->format);
|
2009-03-28 03:12:11 +01:00
|
|
|
assert(0);
|
|
|
|
|
|
|
|
|
|
case vpiRealVal:
|
|
|
|
|
result = vp->value.real;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case vpiIntVal:
|
|
|
|
|
result = (double) vp->value.integer;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case vpiBinStrVal:
|
|
|
|
|
vpip_bin_str_to_vec4(vec4, vp->value.str);
|
|
|
|
|
if (vp->value.str[0] == '-') is_signed = true;
|
|
|
|
|
vector4_to_value(vec4, result, is_signed);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case vpiOctStrVal:
|
|
|
|
|
vpip_oct_str_to_vec4(vec4, vp->value.str);
|
|
|
|
|
if (vp->value.str[0] == '-') is_signed = true;
|
|
|
|
|
vector4_to_value(vec4, result, is_signed);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case vpiDecStrVal:
|
|
|
|
|
vpip_dec_str_to_vec4(vec4, vp->value.str);
|
|
|
|
|
if (vp->value.str[0] == '-') is_signed = true;
|
|
|
|
|
vector4_to_value(vec4, result, is_signed);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case vpiHexStrVal:
|
|
|
|
|
vpip_hex_str_to_vec4(vec4, vp->value.str);
|
|
|
|
|
if (vp->value.str[0] == '-') is_signed = true;
|
|
|
|
|
vector4_to_value(vec4, result, is_signed);
|
|
|
|
|
break;
|
2006-03-06 06:43:15 +01:00
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2009-03-28 03:12:11 +01:00
|
|
|
return result;
|
2006-03-06 06:43:15 +01:00
|
|
|
}
|
|
|
|
|
|
2013-01-06 00:57:58 +01:00
|
|
|
void vpip_string_get_value(const string&val, s_vpi_value*vp)
|
|
|
|
|
{
|
|
|
|
|
char *rbuf = 0;
|
|
|
|
|
|
|
|
|
|
switch (vp->format) {
|
|
|
|
|
default:
|
|
|
|
|
fprintf(stderr, "sorry: Format %d not implemented for "
|
|
|
|
|
"getting string values.\n", (int)vp->format);
|
|
|
|
|
assert(0);
|
|
|
|
|
|
|
|
|
|
case vpiSuppressVal:
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case vpiObjTypeVal:
|
|
|
|
|
// Use the following case to actually set the value!
|
|
|
|
|
vp->format = vpiStringVal;
|
2018-10-06 21:13:31 +02:00
|
|
|
// fallthrough
|
2013-01-06 00:57:58 +01:00
|
|
|
case vpiStringVal:
|
2014-06-10 07:21:51 +02:00
|
|
|
rbuf = (char *) need_result_buf(val.size() + 1, RBUF_VAL);
|
2013-01-06 00:57:58 +01:00
|
|
|
strcpy(rbuf, val.c_str());
|
|
|
|
|
vp->value.str = rbuf;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
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);
|
2003-03-12 03:50:32 +01:00
|
|
|
|
2012-06-18 03:22:50 +02:00
|
|
|
// Never bother with suppressed values. All the derived
|
|
|
|
|
// classes can ignore this type.
|
|
|
|
|
if (vp->format == vpiSuppressVal)
|
|
|
|
|
return;
|
|
|
|
|
|
2012-01-19 19:16:39 +01:00
|
|
|
expr->vpi_get_value(vp);
|
|
|
|
|
|
|
|
|
|
if (vpi_trace) switch (vp->format) {
|
2003-03-12 03:50:32 +01:00
|
|
|
case vpiStringVal:
|
2003-06-17 18:55:07 +02:00
|
|
|
fprintf(vpi_trace,"vpi_get_value(%p=<%d>) -> string=\"%s\"\n",
|
2012-01-19 19:16:39 +01:00
|
|
|
expr, expr->get_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",
|
2012-01-19 19:16:39 +01:00
|
|
|
expr->get_type_code(), vp->value.str);
|
2003-03-12 03:50:32 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case vpiIntVal:
|
2003-03-13 05:34:18 +01:00
|
|
|
fprintf(vpi_trace, "vpi_get_value(<%d>...) -> int=%d\n",
|
2012-01-19 19:16:39 +01:00
|
|
|
expr->get_type_code(), (int)vp->value.integer);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case vpiSuppressVal:
|
|
|
|
|
fprintf(vpi_trace, "vpi_get_value(<%d>...) -> <suppress>\n",
|
|
|
|
|
expr->get_type_code());
|
2003-03-12 03:50:32 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
default:
|
2003-03-13 05:34:18 +01:00
|
|
|
fprintf(vpi_trace, "vpi_get_value(<%d>...) -> <%d>=?\n",
|
2012-01-19 19:16:39 +01:00
|
|
|
expr->get_type_code(), (int)vp->format);
|
2003-03-12 03:50:32 +01:00
|
|
|
}
|
2001-03-16 02:44:34 +01:00
|
|
|
}
|
|
|
|
|
|
2004-05-19 05:26:24 +02:00
|
|
|
struct vpip_put_value_event : vvp_gen_event_s {
|
|
|
|
|
vpiHandle handle;
|
|
|
|
|
s_vpi_value value;
|
2008-03-11 05:54:58 +01:00
|
|
|
int flags;
|
2005-06-02 18:02:11 +02:00
|
|
|
virtual void run_run();
|
2008-02-16 00:05:39 +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
|
|
|
{
|
2012-01-19 19:16:39 +01:00
|
|
|
handle->vpi_put_value(&value, flags);
|
2008-11-19 23:39:59 +01:00
|
|
|
switch (value.format) {
|
|
|
|
|
/* Free the copied string. */
|
|
|
|
|
case vpiBinStrVal:
|
|
|
|
|
case vpiOctStrVal:
|
|
|
|
|
case vpiDecStrVal:
|
|
|
|
|
case vpiHexStrVal:
|
|
|
|
|
case vpiStringVal:
|
|
|
|
|
free(value.value.str);
|
|
|
|
|
break;
|
2012-04-01 21:27:28 +02:00
|
|
|
/* Free the copied time structure. */
|
2008-11-19 23:39:59 +01:00
|
|
|
case vpiTimeVal:
|
2012-04-01 21:27:28 +02:00
|
|
|
free(value.value.time);
|
|
|
|
|
break;
|
|
|
|
|
/* Free the copied vector structure. */
|
2008-11-19 23:39:59 +01:00
|
|
|
case vpiVectorVal:
|
2012-04-01 21:27:28 +02:00
|
|
|
free(value.value.vector);
|
|
|
|
|
break;
|
|
|
|
|
/* Free the copied strength structure. */
|
2008-11-19 23:39:59 +01:00
|
|
|
case vpiStrengthVal:
|
2012-04-01 21:27:28 +02:00
|
|
|
free(value.value.strength);
|
|
|
|
|
break;
|
|
|
|
|
/* Everything else is static in the structure. */
|
2008-11-19 23:39:59 +01:00
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
2004-05-19 05:26:24 +02:00
|
|
|
}
|
|
|
|
|
|
2012-04-01 21:27:28 +02:00
|
|
|
/* Make a copy of a pointer to a time structure. */
|
2022-12-28 08:59:39 +01:00
|
|
|
static t_vpi_time *timedup(const t_vpi_time *val)
|
2012-04-01 21:27:28 +02:00
|
|
|
{
|
|
|
|
|
t_vpi_time *rtn;
|
2013-05-01 03:34:33 +02:00
|
|
|
rtn = static_cast<t_vpi_time *> (malloc(sizeof(t_vpi_time)));
|
2012-04-01 21:27:28 +02:00
|
|
|
*rtn = *val;
|
|
|
|
|
return rtn;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Make a copy of a pointer to a vector value structure. */
|
|
|
|
|
static t_vpi_vecval *vectordup(t_vpi_vecval *val, PLI_INT32 size)
|
|
|
|
|
{
|
|
|
|
|
unsigned num_bytes;
|
|
|
|
|
t_vpi_vecval *rtn;
|
|
|
|
|
assert(size > 0);
|
|
|
|
|
num_bytes = ((size + 31)/32)*sizeof(t_vpi_vecval);
|
2013-05-01 03:34:33 +02:00
|
|
|
rtn = static_cast<t_vpi_vecval *> (malloc(num_bytes));
|
2012-04-01 21:27:28 +02:00
|
|
|
memcpy(rtn, val, num_bytes);
|
|
|
|
|
return rtn;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Make a copy of a pointer to a strength structure. */
|
2022-12-28 08:59:39 +01:00
|
|
|
static t_vpi_strengthval *strengthdup(const t_vpi_strengthval *val)
|
2012-04-01 21:27:28 +02:00
|
|
|
{
|
|
|
|
|
t_vpi_strengthval *rtn;
|
2013-05-01 03:34:33 +02:00
|
|
|
rtn = static_cast<t_vpi_strengthval *>
|
|
|
|
|
(malloc(sizeof(t_vpi_strengthval)));
|
2012-04-01 21:27:28 +02:00
|
|
|
*rtn = *val;
|
|
|
|
|
return rtn;
|
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
|
2008-03-11 05:54:58 +01:00
|
|
|
flags &= ~vpiReturnEvent;
|
|
|
|
|
|
|
|
|
|
if (flags!=vpiNoDelay && flags!=vpiForceFlag && flags!=vpiReleaseFlag) {
|
2004-05-19 05:26:24 +02:00
|
|
|
vvp_time64_t dly;
|
2011-10-31 07:29:02 +01:00
|
|
|
int scale;
|
2004-05-19 05:26:24 +02:00
|
|
|
|
2016-06-09 22:27:20 +02:00
|
|
|
if (vpi_get(vpiAutomatic, obj)) {
|
|
|
|
|
fprintf(stderr, "VPI error: cannot put a value with "
|
|
|
|
|
"a delay on automatically allocated "
|
|
|
|
|
"variable '%s'.\n",
|
|
|
|
|
vpi_get_str(vpiName, obj));
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
2008-11-09 01:26:55 +01:00
|
|
|
|
2007-01-31 23:28:55 +01:00
|
|
|
assert(when != 0);
|
|
|
|
|
|
2008-09-04 18:41:51 +02:00
|
|
|
switch (when->type) {
|
|
|
|
|
case vpiScaledRealTime:
|
2011-10-31 07:29:02 +01:00
|
|
|
scale = vpip_time_units_from_handle(obj) -
|
|
|
|
|
vpip_get_time_precision();
|
|
|
|
|
if (scale >= 0) {
|
|
|
|
|
dly = (vvp_time64_t)(when->real * pow(10.0, scale));
|
|
|
|
|
} else {
|
|
|
|
|
dly = (vvp_time64_t)(when->real / pow(10.0, -scale));
|
|
|
|
|
}
|
2008-09-04 18:41:51 +02:00
|
|
|
break;
|
|
|
|
|
case vpiSimTime:
|
2004-05-19 05:26:24 +02:00
|
|
|
dly = vpip_timestruct_to_time(when);
|
2008-09-04 18:41:51 +02:00
|
|
|
break;
|
|
|
|
|
default:
|
2004-05-19 05:26:24 +02:00
|
|
|
dly = 0;
|
|
|
|
|
break;
|
2008-09-04 18:41:51 +02:00
|
|
|
}
|
2004-05-19 05:26:24 +02:00
|
|
|
|
2016-06-09 22:27:20 +02:00
|
|
|
if ((dly == 0) && schedule_at_rosync()) {
|
|
|
|
|
fprintf(stderr, "VPI error: attempted to put a value to "
|
|
|
|
|
"variable '%s' during a read-only synch "
|
|
|
|
|
"callback.\n", vpi_get_str(vpiName, obj));
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2004-05-19 05:26:24 +02:00
|
|
|
vpip_put_value_event*put = new vpip_put_value_event;
|
|
|
|
|
put->handle = obj;
|
2017-06-15 10:11:11 +02:00
|
|
|
if (dynamic_cast<__vpiNamedEvent*>(obj)) {
|
|
|
|
|
put->value.format = vpiIntVal;
|
|
|
|
|
put->value.value.integer = 0;
|
|
|
|
|
} else {
|
2017-06-15 09:47:29 +02:00
|
|
|
assert(vp);
|
|
|
|
|
put->value = *vp;
|
|
|
|
|
}
|
2012-04-01 21:27:28 +02:00
|
|
|
/* Since this is a scheduled put event we must copy any pointer
|
|
|
|
|
* data to keep it available until the event is actually run. */
|
2008-11-19 23:39:59 +01:00
|
|
|
switch (put->value.format) {
|
2012-04-01 21:27:28 +02:00
|
|
|
/* Copy the string items. */
|
2008-11-19 23:39:59 +01:00
|
|
|
case vpiBinStrVal:
|
|
|
|
|
case vpiOctStrVal:
|
|
|
|
|
case vpiDecStrVal:
|
|
|
|
|
case vpiHexStrVal:
|
|
|
|
|
case vpiStringVal:
|
|
|
|
|
put->value.value.str = strdup(put->value.value.str);
|
|
|
|
|
break;
|
2012-04-01 21:27:28 +02:00
|
|
|
/* Copy a time pointer item. */
|
2008-11-19 23:39:59 +01:00
|
|
|
case vpiTimeVal:
|
2012-04-01 21:27:28 +02:00
|
|
|
put->value.value.time = timedup(put->value.value.time);
|
|
|
|
|
break;
|
|
|
|
|
/* Copy a vector pointer item. */
|
2008-11-19 23:39:59 +01:00
|
|
|
case vpiVectorVal:
|
2012-04-01 21:27:28 +02:00
|
|
|
put->value.value.vector = vectordup(put->value.value.vector,
|
|
|
|
|
vpi_get(vpiSize, obj));
|
|
|
|
|
break;
|
|
|
|
|
/* Copy a strength pointer item. */
|
2008-11-19 23:39:59 +01:00
|
|
|
case vpiStrengthVal:
|
2012-04-01 21:27:28 +02:00
|
|
|
put->value.value.strength =
|
|
|
|
|
strengthdup(put->value.value.strength);
|
|
|
|
|
break;
|
|
|
|
|
/* Everything thing else is already in the structure. */
|
2008-11-19 23:39:59 +01:00
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
2008-03-11 05:54:58 +01:00
|
|
|
put->flags = flags;
|
2009-01-15 05:15:50 +01:00
|
|
|
schedule_generic(put, dly, false, true, true);
|
2004-05-19 05:26:24 +02:00
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2016-06-09 22:27:20 +02:00
|
|
|
if (schedule_at_rosync()) {
|
|
|
|
|
fprintf(stderr, "VPI error: attempted to put a value to "
|
|
|
|
|
"variable '%s' during a read-only synch "
|
|
|
|
|
"callback.\n", vpi_get_str(vpiName, obj));
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2012-01-19 19:16:39 +01:00
|
|
|
obj->vpi_put_value(vp, flags);
|
2004-05-19 05:26:24 +02:00
|
|
|
|
|
|
|
|
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
|
|
|
{
|
2014-06-19 23:50:37 +02:00
|
|
|
vpiHandle res = 0;
|
2003-03-14 06:02:34 +01:00
|
|
|
|
2014-06-19 23:50:37 +02:00
|
|
|
if (ref == 0) {
|
|
|
|
|
// A few types can apply to a nil handle. These are ways
|
|
|
|
|
// that the current function can get started finding things.
|
|
|
|
|
switch (type) {
|
|
|
|
|
|
|
|
|
|
case vpiScope:
|
|
|
|
|
// The IEEE1364-2005 doesn't seem to allow this,
|
|
|
|
|
// but some users seem to think it's handy, so
|
|
|
|
|
// return the scope that contains this SysTfCall.
|
|
|
|
|
assert(vpip_cur_task);
|
|
|
|
|
res = vpip_cur_task->vpi_handle(vpiScope);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case vpiSysTfCall:
|
|
|
|
|
// This is how VPI users get a first handle into
|
|
|
|
|
// the system. This is the handle of the system
|
|
|
|
|
// task/function call currently being executed.
|
|
|
|
|
if (vpi_trace) {
|
|
|
|
|
fprintf(vpi_trace, "vpi_handle(vpiSysTfCall, 0) "
|
|
|
|
|
"-> %p (%s)\n", vpip_cur_task,
|
|
|
|
|
vpip_cur_task->defn->info.tfname);
|
|
|
|
|
}
|
|
|
|
|
return vpip_cur_task;
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
fprintf(stderr, "VPI error: vpi_handle(type=%d, ref=0).\n",
|
|
|
|
|
(int)type);
|
|
|
|
|
res = 0;
|
|
|
|
|
break;
|
2003-03-14 06:02:34 +01:00
|
|
|
}
|
|
|
|
|
|
2014-06-19 23:50:37 +02:00
|
|
|
} else {
|
2001-03-16 02:44:34 +01:00
|
|
|
|
2014-06-19 23:50:37 +02:00
|
|
|
if (type == vpiSysTfCall) {
|
|
|
|
|
fprintf(stderr, "VPI error: vpi_handle(vpiSysTfCall, "
|
|
|
|
|
"ref!=0).\n");
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
res = ref->vpi_handle(type);
|
2003-06-22 06:19:26 +02:00
|
|
|
}
|
2002-07-19 03:12:50 +02:00
|
|
|
|
2003-03-13 05:34:18 +01:00
|
|
|
|
|
|
|
|
if (vpi_trace) {
|
2014-06-19 23:50:37 +02:00
|
|
|
fprintf(vpi_trace, "vpi_handle(vpiScope, ref=%p) "
|
|
|
|
|
"-> %p\n", vpip_cur_task, ref);
|
2003-03-13 05:34:18 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return res;
|
2001-03-16 02:44:34 +01:00
|
|
|
}
|
|
|
|
|
|
2011-10-11 22:33:05 +02:00
|
|
|
static vpiHandle vpip_make_udp_iterator()
|
|
|
|
|
{
|
|
|
|
|
// HERE: Add support for iterating over UDP definitions.
|
|
|
|
|
// See 26.6.16 (page 400 in 1364-2005).
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
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) {
|
2021-04-21 10:01:50 +02:00
|
|
|
case vpiInstance:
|
|
|
|
|
// fallthrough
|
2002-01-06 01:48:39 +01:00
|
|
|
case vpiModule:
|
2021-04-18 10:47:21 +02:00
|
|
|
// fallthrough
|
2021-04-21 10:01:50 +02:00
|
|
|
case vpiProgram:
|
|
|
|
|
// fallthrough
|
|
|
|
|
case vpiInterface:
|
|
|
|
|
// fallthrough
|
2021-04-18 10:47:21 +02:00
|
|
|
case vpiPackage:
|
|
|
|
|
return vpip_make_root_iterator(type);
|
2002-01-06 01:48:39 +01:00
|
|
|
|
2011-10-11 22:33:05 +02:00
|
|
|
case vpiUdpDefn:
|
|
|
|
|
return vpip_make_udp_iterator();
|
|
|
|
|
|
2010-04-12 08:39:08 +02:00
|
|
|
case vpiUserSystf:
|
|
|
|
|
return vpip_make_systf_iterator();
|
2002-01-06 01:48:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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);
|
2012-01-19 19:16:39 +01:00
|
|
|
else
|
|
|
|
|
rtn = ref->vpi_iterate(type);
|
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",
|
2009-12-10 21:53:58 +01:00
|
|
|
(int)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);
|
2012-01-19 19:16:39 +01:00
|
|
|
return ref->vpi_index(idx);
|
2001-03-16 02:44:34 +01:00
|
|
|
}
|
|
|
|
|
|
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;
|
2015-12-27 20:37:10 +01:00
|
|
|
__vpiScope*ref = dynamic_cast<__vpiScope*>(handle);
|
2002-07-17 07:13:43 +02:00
|
|
|
|
|
|
|
|
/* 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 */
|
2015-12-24 02:38:13 +01:00
|
|
|
for (unsigned i = 0 ; i < ref->intern.size() ; i += 1) {
|
2013-12-07 03:22:52 +01:00
|
|
|
/* The standard says that since a port does not have a full
|
|
|
|
|
* name it cannot be found by name. Because of this we need
|
|
|
|
|
* to skip ports here so the correct handle can be located. */
|
|
|
|
|
if (vpi_get(vpiType, ref->intern[i]) == vpiPort) continue;
|
2002-07-17 07:13:43 +02:00
|
|
|
char *nm = vpi_get_str(vpiName, ref->intern[i]);
|
2019-03-23 18:21:40 +01:00
|
|
|
if (nm && !strcmp(name, nm)) {
|
2002-07-17 07:13:43 +02:00
|
|
|
rtn = ref->intern[i];
|
|
|
|
|
break;
|
2009-06-17 00:14:02 +02:00
|
|
|
} else if (vpi_get(vpiType, ref->intern[i]) == vpiMemory ||
|
|
|
|
|
vpi_get(vpiType, ref->intern[i]) == vpiNetArray) {
|
2002-07-17 07:13:43 +02:00
|
|
|
/* 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);
|
2019-03-23 18:21:40 +01:00
|
|
|
if (nm && !strcmp(name, nm)) {
|
2002-07-17 07:13:43 +02:00
|
|
|
rtn = word_h;
|
2015-01-09 01:12:31 +01:00
|
|
|
vpi_free_object(word_i);
|
2002-07-17 07:13:43 +02:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
/* found it yet? */
|
|
|
|
|
if (rtn) break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return rtn;
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-03 04:45:40 +02:00
|
|
|
// Find the end of the escaped identifier or simple identifier
|
|
|
|
|
static char * find_rest(char *name)
|
|
|
|
|
{
|
|
|
|
|
char *rest;
|
|
|
|
|
if (*name == '\\') {
|
|
|
|
|
rest = strchr(name, ' ');
|
|
|
|
|
if (rest) {
|
|
|
|
|
*rest++ = 0; // The space is not part of the string
|
|
|
|
|
// There should be a '.' after the escaped ID if there is
|
|
|
|
|
// anything more. If it is missing add it to avoid a crash
|
|
|
|
|
if ((*rest != '.') && (*rest != 0)) {
|
|
|
|
|
*--rest = '.';
|
|
|
|
|
fprintf(stderr, "ERROR: Malformed scope string: \"%s\"", name);
|
|
|
|
|
}
|
|
|
|
|
if (*rest == 0) {
|
|
|
|
|
rest = 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
rest = strchr(name, '.');
|
|
|
|
|
}
|
|
|
|
|
return rest;
|
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
{
|
|
|
|
|
|
2014-04-14 01:25:30 +02:00
|
|
|
vpiHandle iter = handle==0
|
|
|
|
|
? vpi_iterate(vpiModule, NULL)
|
|
|
|
|
: vpi_iterate(vpiInternalScope, handle);
|
2002-07-17 07:13:43 +02:00
|
|
|
|
2014-04-14 01:25:30 +02:00
|
|
|
vector<char> name_buf (strlen(name)+1);
|
|
|
|
|
strcpy(&name_buf[0], name);
|
|
|
|
|
char*nm_first = &name_buf[0];
|
2020-05-03 04:45:40 +02:00
|
|
|
char*nm_rest = find_rest(nm_first);
|
|
|
|
|
if (*nm_first == '\\') ++nm_first;
|
2014-04-14 01:25:30 +02:00
|
|
|
if (nm_rest) {
|
|
|
|
|
*nm_rest++ = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
vpiHandle rtn = 0;
|
|
|
|
|
vpiHandle hand;
|
2002-07-17 07:13:43 +02:00
|
|
|
while (iter && (hand = vpi_scan(iter))) {
|
|
|
|
|
char *nm = vpi_get_str(vpiName, hand);
|
|
|
|
|
|
2014-04-14 01:25:30 +02:00
|
|
|
if (strcmp(nm_first,nm)==0) {
|
|
|
|
|
if (nm_rest)
|
|
|
|
|
rtn=find_scope(nm_rest, hand, depth+1);
|
|
|
|
|
else
|
|
|
|
|
rtn = hand;
|
|
|
|
|
}
|
2002-07-17 07:13:43 +02:00
|
|
|
|
|
|
|
|
/* found it yet ? */
|
2009-01-13 23:28:30 +01:00
|
|
|
if (rtn) {
|
|
|
|
|
vpi_free_object(iter);
|
|
|
|
|
break;
|
|
|
|
|
}
|
2002-07-17 07:13:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return rtn;
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-03 04:45:40 +02:00
|
|
|
// Find the end of the first escaped identifier or simple identifier
|
|
|
|
|
static char * find_next(char *name)
|
|
|
|
|
{
|
|
|
|
|
char *next;
|
|
|
|
|
if (*name == '\\') {
|
|
|
|
|
next = strchr(name, ' ');
|
|
|
|
|
if (next && *++next == 0) next = 0;
|
|
|
|
|
} else {
|
|
|
|
|
next = strchr(name, '.');
|
|
|
|
|
}
|
|
|
|
|
return next;
|
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
if (vpi_trace) {
|
|
|
|
|
fprintf(vpi_trace, "vpi_handle_by_name(%s, %p) -->\n",
|
|
|
|
|
name, scope);
|
|
|
|
|
}
|
|
|
|
|
|
2014-04-14 01:25:30 +02:00
|
|
|
// Chop the name into path and base. For example, if the name
|
|
|
|
|
// is "a.b.c", then nm_path becomes "a.b" and nm_base becomes
|
|
|
|
|
// "c". If the name is "c" then nm_path is nil and nm_base is "c".
|
|
|
|
|
vector<char> name_buf (strlen(name)+1);
|
|
|
|
|
strcpy(&name_buf[0], name);
|
|
|
|
|
char*nm_path = &name_buf[0];
|
2020-05-03 04:45:40 +02:00
|
|
|
char*nm_base;
|
|
|
|
|
|
|
|
|
|
// Check to see if we have an escaped identifier and if so search
|
|
|
|
|
// the long way because a '.' could be in the escaped name.
|
|
|
|
|
if (strchr(nm_path, '\\')) {
|
|
|
|
|
char *next;
|
2014-04-14 01:25:30 +02:00
|
|
|
nm_base = nm_path;
|
2020-05-03 04:45:40 +02:00
|
|
|
while ((next = find_next(nm_base))) {
|
|
|
|
|
nm_base = ++next;
|
|
|
|
|
}
|
|
|
|
|
if (nm_path == nm_base) {
|
|
|
|
|
nm_path = 0;
|
|
|
|
|
} else {
|
|
|
|
|
*(nm_base-1) = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// If there is no escaped identifier then just look for the last '.'
|
|
|
|
|
} else {
|
|
|
|
|
nm_base = strrchr(nm_path, '.');
|
|
|
|
|
if (nm_base) {
|
|
|
|
|
*nm_base++ = 0;
|
|
|
|
|
} else {
|
|
|
|
|
nm_base = nm_path;
|
|
|
|
|
nm_path = 0;
|
|
|
|
|
}
|
2014-04-14 01:25:30 +02:00
|
|
|
}
|
|
|
|
|
|
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. */
|
2008-05-15 19:36:43 +02:00
|
|
|
switch (vpi_get(vpiType, scope)) {
|
|
|
|
|
case vpiScope:
|
2007-08-16 01:09:38 +02:00
|
|
|
hand = vpi_handle(vpiModule, scope);
|
2008-05-15 19:36:43 +02:00
|
|
|
break;
|
|
|
|
|
case vpiModule:
|
2007-08-16 01:09:38 +02:00
|
|
|
hand = scope;
|
2008-05-15 19:36:43 +02:00
|
|
|
break;
|
|
|
|
|
default:
|
2014-04-14 01:25:30 +02:00
|
|
|
if (vpi_trace) {
|
|
|
|
|
fprintf(vpi_trace, "vpi_handle_by_name: "
|
|
|
|
|
"Scope is not a vpiScope or vpiModule\n");
|
|
|
|
|
}
|
2008-05-15 19:36:43 +02:00
|
|
|
// Use vpi_chk_error() here when it is implemented.
|
|
|
|
|
return 0;
|
2007-08-16 01:09:38 +02:00
|
|
|
}
|
2014-04-14 01:25:30 +02:00
|
|
|
|
|
|
|
|
} else if (nm_path) {
|
|
|
|
|
// The name has a path, and no other scope handle was
|
|
|
|
|
// passed in. That suggests we are looking for "a.b.c"
|
|
|
|
|
// in the root scope. So convert "a.b" to a scope and
|
|
|
|
|
// start there to look for "c".
|
|
|
|
|
hand = find_scope(nm_path, NULL, 0);
|
|
|
|
|
nm_path = 0;
|
|
|
|
|
|
2007-08-16 01:09:38 +02:00
|
|
|
} else {
|
2014-04-14 01:25:30 +02:00
|
|
|
// Special case: scope==<nil>, meaning we are looking in
|
|
|
|
|
// the root, and there is no path to the name, i.e. the
|
|
|
|
|
// string is "c" instead of "top.c". Try to find "c" as
|
|
|
|
|
// a scope and return that.
|
|
|
|
|
hand = find_scope(nm_base, NULL, 0);
|
2007-08-16 01:09:38 +02:00
|
|
|
}
|
2002-07-17 07:13:43 +02:00
|
|
|
|
2014-04-14 01:25:30 +02:00
|
|
|
if (hand == 0) {
|
|
|
|
|
if (vpi_trace) {
|
|
|
|
|
fprintf(vpi_trace, "vpi_handle_by_name: "
|
|
|
|
|
"Scope does not exist. Giving up.\n");
|
|
|
|
|
}
|
2002-07-17 07:13:43 +02:00
|
|
|
|
2014-04-14 01:25:30 +02:00
|
|
|
return 0;
|
2002-07-17 07:13:43 +02:00
|
|
|
}
|
|
|
|
|
|
2014-04-14 01:25:30 +02:00
|
|
|
// If there is a path part, then use it to find the
|
|
|
|
|
// scope. For example, if the full name is a.b.c, then
|
|
|
|
|
// the nm_path string is a.b and we search for that
|
|
|
|
|
// scope. If we find it, then set hand to that scope.
|
|
|
|
|
if (nm_path) {
|
|
|
|
|
vpiHandle tmp = find_scope(nm_path, hand, 0);
|
|
|
|
|
while (tmp == 0 && hand != 0) {
|
|
|
|
|
hand = vpi_handle(vpiScope, hand);
|
|
|
|
|
tmp = find_scope(nm_path, hand, 0);
|
|
|
|
|
}
|
|
|
|
|
hand = tmp;
|
|
|
|
|
}
|
|
|
|
|
|
2023-11-07 00:48:23 +01:00
|
|
|
// find_name() expects escaped identifiers to be stripped
|
|
|
|
|
if (*nm_base == '\\') {
|
|
|
|
|
// Skip the \ at the beginning
|
|
|
|
|
++nm_base;
|
|
|
|
|
|
|
|
|
|
// Drop the space at the end if it exists
|
|
|
|
|
char *next;
|
|
|
|
|
if ((next = strchr(nm_base, ' '))) {
|
|
|
|
|
*next = 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-04-14 01:25:30 +02:00
|
|
|
// Now we have the correct scope, look for the item.
|
|
|
|
|
vpiHandle out = find_name(nm_base, hand);
|
|
|
|
|
|
|
|
|
|
if (vpi_trace) {
|
|
|
|
|
fprintf(vpi_trace, "vpi_handle_by_name: DONE\n");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return out;
|
2002-07-17 07:13:43 +02:00
|
|
|
}
|
|
|
|
|
|
2023-08-30 09:50:00 +02:00
|
|
|
// Check if net2 is connected to current_net through a net of vvp_fun_concat8s
|
|
|
|
|
bool check_connected_to_concat8(vvp_net_t* current_net, vvp_net_t* net2)
|
|
|
|
|
{
|
|
|
|
|
if (!dynamic_cast<vvp_fun_concat8*>(current_net->fun)) return false;
|
|
|
|
|
|
|
|
|
|
vvp_net_ptr_t cur = current_net->out_;
|
|
|
|
|
|
|
|
|
|
// For everything connected
|
|
|
|
|
while (cur.ptr()) {
|
|
|
|
|
// Check if it's a concat8
|
|
|
|
|
if (dynamic_cast<vvp_fun_concat8*>(cur.ptr()->fun)) {
|
|
|
|
|
// Pass on the return value if found
|
|
|
|
|
if (check_connected_to_concat8(cur.ptr(), net2)) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// net2 is connected
|
|
|
|
|
if (cur.ptr() == net2) {
|
2023-09-04 15:20:31 +02:00
|
|
|
return true;
|
2023-08-30 09:50:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Next net in linked list
|
|
|
|
|
cur = cur.ptr()->port[cur.port()];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// net2 is not connected to this concat8
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2023-07-19 15:02:20 +02:00
|
|
|
// Used to get intermodpath for two ports
|
|
|
|
|
vpiHandle vpi_handle_multi(PLI_INT32 type,
|
|
|
|
|
vpiHandle ref1,
|
|
|
|
|
vpiHandle ref2)
|
|
|
|
|
{
|
|
|
|
|
if (vpi_trace) {
|
2023-08-17 16:09:20 +02:00
|
|
|
fprintf(vpi_trace, "vpi_handle_multi(%d, %p, %p) -->\n",
|
|
|
|
|
type, ref1, ref2);
|
2023-07-19 15:02:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (type != vpiInterModPath) {
|
2023-08-17 16:09:20 +02:00
|
|
|
fprintf(stderr, "sorry: vpi_handle_multi currently supports"
|
|
|
|
|
"only vpiInterModPath\n");
|
|
|
|
|
return nullptr;
|
2023-07-19 15:02:20 +02:00
|
|
|
}
|
|
|
|
|
|
2023-09-04 11:31:35 +02:00
|
|
|
// Indicates whether port1 refers to a single bit
|
|
|
|
|
bool port1_has_index = false;
|
|
|
|
|
int port1_bit_index = 0;
|
2023-08-30 09:50:00 +02:00
|
|
|
vpiPortBitInfo* port1_bit = dynamic_cast<vpiPortBitInfo*>(ref1);
|
|
|
|
|
|
|
|
|
|
if (port1_bit) {
|
|
|
|
|
// Get the bit index
|
2023-09-04 11:31:35 +02:00
|
|
|
port1_has_index = true;
|
2023-08-30 09:50:00 +02:00
|
|
|
port1_bit_index = vpi_get(vpiBit, port1_bit);
|
|
|
|
|
// Update the ref1 to point to the base port
|
|
|
|
|
ref1 = vpi_handle(vpiParent, port1_bit);
|
|
|
|
|
}
|
|
|
|
|
|
2023-09-04 11:31:35 +02:00
|
|
|
// Indicates whether port2 refers to a single bit
|
|
|
|
|
bool port2_has_index = false;
|
|
|
|
|
int port2_bit_index = 0;
|
2023-08-30 09:50:00 +02:00
|
|
|
vpiPortBitInfo* port2_bit = dynamic_cast<vpiPortBitInfo*>(ref2);
|
|
|
|
|
|
|
|
|
|
if (port2_bit) {
|
|
|
|
|
// Get the bit index
|
2023-09-04 11:31:35 +02:00
|
|
|
port2_has_index = true;
|
2023-08-30 09:50:00 +02:00
|
|
|
port2_bit_index = vpi_get(vpiBit, port2_bit);
|
|
|
|
|
// Update the ref1 to point to the base port
|
|
|
|
|
ref2 = vpi_handle(vpiParent, port2_bit);
|
|
|
|
|
}
|
|
|
|
|
|
2023-07-19 15:02:20 +02:00
|
|
|
vpiPortInfo* port1 = dynamic_cast<vpiPortInfo*>(ref1);
|
|
|
|
|
|
|
|
|
|
if (!port1) {
|
2023-08-17 16:09:20 +02:00
|
|
|
fprintf(stderr, "sorry: second argument of vpi_handle_multi"
|
|
|
|
|
"must be a vpiPort\n");
|
|
|
|
|
return nullptr;
|
2023-07-19 15:02:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
vpiPortInfo* port2 = dynamic_cast<vpiPortInfo*>(ref2);
|
|
|
|
|
|
|
|
|
|
if (!port2) {
|
2023-08-17 16:09:20 +02:00
|
|
|
fprintf(stderr, "sorry: third argument of vpi_handle_multi"
|
|
|
|
|
"must be a vpiPort\n");
|
|
|
|
|
return nullptr;
|
2023-07-19 15:02:20 +02:00
|
|
|
}
|
|
|
|
|
|
2023-09-04 14:07:48 +02:00
|
|
|
// Get the names of both ports
|
|
|
|
|
std::string port1_name(vpi_get_str(vpiName, ref1));
|
|
|
|
|
std::string port2_name(vpi_get_str(vpiName, ref2));
|
2023-09-04 09:12:38 +02:00
|
|
|
|
2023-08-17 16:09:20 +02:00
|
|
|
// If both ports are vpiOutput, we have to reassign the __vpiSignal from port1
|
|
|
|
|
// to port2 because otherwise the non-delayed version of the signal is dumped
|
|
|
|
|
// even tho the intermodpath is correctly inserted
|
2023-08-17 10:18:56 +02:00
|
|
|
__vpiSignal* output_signal = nullptr;
|
|
|
|
|
|
2023-08-17 16:09:20 +02:00
|
|
|
if (port1->get_direction() == vpiOutput && port2->get_direction() == vpiOutput) {
|
|
|
|
|
vpiHandle scope_port2 = vpi_handle(vpiScope, ref2);
|
|
|
|
|
assert(scope_port2);
|
2023-08-17 10:18:56 +02:00
|
|
|
|
|
|
|
|
// Iterate over nets in the scope of port2
|
2023-08-17 16:09:20 +02:00
|
|
|
vpiHandle net_i = vpi_iterate(vpiNet, scope_port2) ;
|
|
|
|
|
vpiHandle net;
|
2023-08-17 10:18:56 +02:00
|
|
|
|
2023-08-17 16:09:20 +02:00
|
|
|
while ((net = vpi_scan(net_i)) != NULL) {
|
|
|
|
|
std::string net_name(vpi_get_str(vpiName, net));
|
2023-08-17 10:18:56 +02:00
|
|
|
|
2023-08-17 16:09:20 +02:00
|
|
|
// Compare whether the net matches with the port name
|
|
|
|
|
if (net_name == port2_name) {
|
|
|
|
|
output_signal = dynamic_cast<__vpiSignal*>(net);
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-07-25 13:14:49 +02:00
|
|
|
}
|
|
|
|
|
|
2023-08-08 11:42:15 +02:00
|
|
|
vvp_net_t* net1 = port1->get_port();
|
|
|
|
|
vvp_net_t* net2 = port2->get_port();
|
2023-07-19 15:02:20 +02:00
|
|
|
|
2023-08-17 16:09:20 +02:00
|
|
|
if (net1 == nullptr || net2 == nullptr) {
|
|
|
|
|
fprintf(stderr, "Error: Could not find net. "
|
|
|
|
|
"Did you run iverilog with '-ginterconnect'?\n");
|
|
|
|
|
return nullptr;
|
2023-07-19 15:02:20 +02:00
|
|
|
}
|
|
|
|
|
|
2023-08-17 16:09:20 +02:00
|
|
|
if (net1 == net2) {
|
|
|
|
|
fprintf(stderr, "Error: Net for both ports is the same. "
|
|
|
|
|
"Did you pass the same port twice?\n");
|
|
|
|
|
return nullptr;
|
2023-08-17 10:18:56 +02:00
|
|
|
}
|
|
|
|
|
|
2023-08-17 16:09:20 +02:00
|
|
|
if (!dynamic_cast<vvp_fun_buft*>(net1->fun)) {
|
|
|
|
|
fprintf(stderr, "Error: functor of net1 must be"
|
|
|
|
|
"vvp_fun_buft\n");
|
|
|
|
|
return nullptr;
|
2023-07-19 15:02:20 +02:00
|
|
|
}
|
|
|
|
|
|
2023-08-17 16:09:20 +02:00
|
|
|
if (!dynamic_cast<vvp_fun_buft*>(net2->fun)) {
|
|
|
|
|
fprintf(stderr, "Error: functor of net2 must be"
|
|
|
|
|
"vvp_fun_buft\n");
|
|
|
|
|
return nullptr;
|
2023-08-08 11:42:15 +02:00
|
|
|
}
|
2023-07-19 15:02:20 +02:00
|
|
|
|
2023-08-30 09:50:00 +02:00
|
|
|
// If port1 is actually a port bit, we have to get to the correct vvp_fun_part
|
|
|
|
|
// after which we insert the intermodpath delay
|
2023-09-04 11:31:35 +02:00
|
|
|
if (port1_has_index) {
|
2023-08-30 09:50:00 +02:00
|
|
|
vvp_net_ptr_t* net1_ptr = &net1->out_;
|
|
|
|
|
|
|
|
|
|
// Search for part selects connected to port1
|
|
|
|
|
vvp_net_t* current_net = net1_ptr->ptr();
|
|
|
|
|
|
|
|
|
|
while (current_net) {
|
|
|
|
|
if (!current_net) break; // End of list
|
|
|
|
|
|
|
|
|
|
vvp_fun_part* part = dynamic_cast<vvp_fun_part*>(current_net->fun);
|
|
|
|
|
|
|
|
|
|
// Its a part select!
|
|
|
|
|
if (part) {
|
|
|
|
|
// Is it the correct part select?
|
|
|
|
|
if (part->get_base() == (unsigned)port1_bit_index) {
|
|
|
|
|
assert(part->get_wid() == 1);
|
|
|
|
|
net1 = current_net; // Replace net1 as this is our new start point
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
current_net = current_net->port[0].ptr(); // BUFT has only one input, index 0
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-08-17 16:09:20 +02:00
|
|
|
// Iterate over all nodes connected to port1
|
2023-08-17 10:18:56 +02:00
|
|
|
vvp_net_ptr_t cur = net1->out_;
|
|
|
|
|
vvp_net_ptr_t prev = vvp_net_ptr_t(nullptr, 0);
|
2023-07-19 15:02:20 +02:00
|
|
|
|
2023-08-17 16:09:20 +02:00
|
|
|
while (cur.ptr()) {
|
2023-08-30 09:50:00 +02:00
|
|
|
// Either port2 is directly connected to port1
|
|
|
|
|
// Or in the second case port2 is indirectly connected
|
|
|
|
|
// to port1 through a net of concat8s
|
2023-09-04 11:31:35 +02:00
|
|
|
if ( (!port2_has_index && cur.ptr() == net2) ||
|
|
|
|
|
( port2_has_index && check_connected_to_concat8(cur.ptr(), net2))) {
|
2023-08-17 16:09:20 +02:00
|
|
|
vvp_net_t*new_net = new vvp_net_t;
|
|
|
|
|
|
|
|
|
|
// Create new node with intermodpath and connect port2 to it
|
|
|
|
|
int width = 1; // TODO
|
|
|
|
|
vvp_fun_intermodpath*obj = new vvp_fun_intermodpath(new_net, width);
|
|
|
|
|
new_net->fun = obj;
|
|
|
|
|
new_net->out_ = cur;
|
|
|
|
|
|
|
|
|
|
// Port2 is in the middle of the list
|
|
|
|
|
// Insert intermodpath before port2 and keep everything else intact
|
|
|
|
|
if (prev.ptr()) {
|
|
|
|
|
prev.ptr()->port[prev.port()] = vvp_net_ptr_t(new_net, 0); // Point to port 0 of vvp_fun_intermodpath
|
|
|
|
|
new_net->port[0] = cur.ptr()->port[cur.port()]; // Connect the next net in list
|
|
|
|
|
cur.ptr()->port[cur.port()] = vvp_net_ptr_t(nullptr, 0); // Only port2 is connected to intermodpath
|
|
|
|
|
// Port2 is first in list
|
|
|
|
|
// Insert intermodpath before port2 and keep everything else intact
|
|
|
|
|
} else {
|
|
|
|
|
net1->out_ = vvp_net_ptr_t(new_net, 0); // Point to port 0 of vvp_fun_intermodpath
|
|
|
|
|
new_net->port[0] = cur.ptr()->port[cur.port()]; // Connect the next net in list
|
|
|
|
|
cur.ptr()->port[cur.port()] = vvp_net_ptr_t(nullptr, 0); // Only port2 is connected to intermodpath
|
|
|
|
|
}
|
2023-07-19 15:02:20 +02:00
|
|
|
|
2023-08-30 09:50:00 +02:00
|
|
|
// If both ports are vpiOutput and port2 is not a vector,
|
|
|
|
|
// we have to reassign the __vpiSignal so that the delayed
|
|
|
|
|
// values get dumped
|
2023-09-04 11:31:35 +02:00
|
|
|
if (output_signal && !port2_has_index) {
|
2023-08-17 16:09:20 +02:00
|
|
|
net2->fil = net1->fil;
|
|
|
|
|
net1->fil = nullptr;
|
|
|
|
|
output_signal->node = net2;
|
|
|
|
|
}
|
2023-07-19 15:02:20 +02:00
|
|
|
|
2023-08-17 16:09:20 +02:00
|
|
|
// Create the VPI intermodpath object
|
|
|
|
|
__vpiInterModPath* intermodpath = vpip_make_intermodpath(new_net, port1, port2);
|
|
|
|
|
intermodpath->intermodpath = obj;
|
2023-07-19 15:02:20 +02:00
|
|
|
|
2023-08-17 16:09:20 +02:00
|
|
|
// Finally done, return the intermodpath object
|
|
|
|
|
return intermodpath;
|
|
|
|
|
}
|
2023-07-19 15:02:20 +02:00
|
|
|
|
2023-08-17 16:09:20 +02:00
|
|
|
prev = cur;
|
|
|
|
|
cur = cur.ptr()->port[cur.port()]; // Next net in linked list
|
2023-07-19 15:02:20 +02:00
|
|
|
}
|
2023-07-25 13:14:49 +02:00
|
|
|
|
2023-09-04 11:31:35 +02:00
|
|
|
fprintf(stderr, "VPI error: Could not insert intermodpath!\n");
|
|
|
|
|
fprintf(stderr, "\tport1 = %s, port1_has_index = %d, port1_bit_index = %d\n", port1_name.c_str(), port1_has_index, port1_bit_index);
|
|
|
|
|
fprintf(stderr, "\tport2 = %s, port2_has_index = %d, port2_bit_index = %d\n", port2_name.c_str(), port2_has_index, port2_bit_index);
|
2023-07-19 15:02:20 +02:00
|
|
|
return nullptr;
|
|
|
|
|
}
|
2007-09-11 00:30:00 +02:00
|
|
|
|
|
|
|
|
/*
|
2008-09-04 18:41:51 +02:00
|
|
|
We increment the two vpi methods to enable the
|
2007-12-18 02:42:09 +01:00
|
|
|
read/write of SDF delay values from/into
|
2007-09-11 00:30:00 +02:00
|
|
|
the modpath vpiHandle
|
2008-09-04 18:41:51 +02:00
|
|
|
|
2007-09-11 00:30:00 +02:00
|
|
|
|
2008-06-12 19:04:29 +02:00
|
|
|
basically, they will redirect the generic vpi_interface
|
2008-09-04 18:41:51 +02:00
|
|
|
|
|
|
|
|
vpi_get_delay ( .. )
|
2007-09-11 00:30:00 +02:00
|
|
|
vpi_put_delay ( .. )
|
2008-09-04 18:41:51 +02:00
|
|
|
|
|
|
|
|
|
2007-09-11 00:30:00 +02:00
|
|
|
to the
|
2008-09-04 18:41:51 +02:00
|
|
|
|
|
|
|
|
modpath_get_delay ( .. ) ;
|
2007-09-11 00:30:00 +02:00
|
|
|
modpath_put_delay ( .. ) ;
|
2008-09-04 18:41:51 +02:00
|
|
|
|
2007-09-11 00:30:00 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void vpi_get_delays(vpiHandle expr, p_vpi_delay delays)
|
|
|
|
|
{
|
|
|
|
|
assert(expr);
|
|
|
|
|
assert(delays);
|
2008-09-04 18:41:51 +02:00
|
|
|
|
2012-01-19 19:16:39 +01:00
|
|
|
expr->vpi_get_delays(delays);
|
2008-09-04 18:41:51 +02:00
|
|
|
|
2012-01-19 19:16:39 +01:00
|
|
|
if (vpi_trace) {
|
|
|
|
|
fprintf(vpi_trace,
|
|
|
|
|
"vpi_get_delays(%p, %p) -->\n", expr, delays);
|
|
|
|
|
}
|
2007-09-11 00:30:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void vpi_put_delays(vpiHandle expr, p_vpi_delay delays)
|
|
|
|
|
{
|
|
|
|
|
assert(expr );
|
|
|
|
|
assert(delays );
|
2008-09-04 18:41:51 +02:00
|
|
|
|
2012-01-19 19:16:39 +01:00
|
|
|
expr->vpi_put_delays(delays);
|
2008-09-04 18:41:51 +02:00
|
|
|
|
2012-01-19 19:16:39 +01:00
|
|
|
if (vpi_trace) {
|
|
|
|
|
fprintf(vpi_trace,
|
|
|
|
|
"vpi_put_delays(%p, %p) -->\n", expr, delays);
|
|
|
|
|
}
|
2007-09-11 00:30:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
2025-07-08 22:14:49 +02:00
|
|
|
extern "C" PLI_INT32 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:
|
2009-10-29 19:16:26 +01:00
|
|
|
case __ivl_legacy_vpiFinish:
|
2025-07-08 22:14:49 +02:00
|
|
|
diag_msg = va_arg(ap, PLI_INT32);
|
2007-07-20 19:38:50 +02:00
|
|
|
schedule_finish(diag_msg);
|
2001-03-19 02:55:38 +01:00
|
|
|
break;
|
|
|
|
|
|
2003-02-21 04:40:35 +01:00
|
|
|
case vpiStop:
|
2009-10-29 19:16:26 +01:00
|
|
|
case __ivl_legacy_vpiStop:
|
2025-07-08 22:14:49 +02:00
|
|
|
diag_msg = va_arg(ap, PLI_INT32);
|
2007-07-20 19:38:50 +02:00
|
|
|
schedule_stop(diag_msg);
|
2003-02-21 04:40:35 +01:00
|
|
|
break;
|
|
|
|
|
|
2001-03-19 02:55:38 +01:00
|
|
|
default:
|
2025-07-08 22:14:49 +02:00
|
|
|
fprintf(stderr, "Unsupported VPI control operation %d.\n", operation);
|
|
|
|
|
return 0;
|
2001-03-19 02:55:38 +01:00
|
|
|
}
|
2025-07-08 22:14:49 +02:00
|
|
|
return 1;
|
2001-03-16 02:44:34 +01:00
|
|
|
}
|
|
|
|
|
|
2025-07-08 22:14:49 +02:00
|
|
|
extern "C" PLI_INT32 vpi_sim_control(PLI_INT32 operation, ...)
|
2003-01-10 04:06:32 +01:00
|
|
|
{
|
|
|
|
|
va_list ap;
|
|
|
|
|
va_start(ap, operation);
|
2025-07-08 22:14:49 +02:00
|
|
|
int r = vpi_sim_vcontrol(operation, ap);
|
2003-01-10 04:06:32 +01:00
|
|
|
va_end(ap);
|
2025-07-08 22:14:49 +02:00
|
|
|
return r;
|
2003-01-10 04:06:32 +01:00
|
|
|
}
|
|
|
|
|
|
2025-07-08 22:14:49 +02:00
|
|
|
extern "C" PLI_INT32 vpi_control(PLI_INT32 operation, ...)
|
2003-01-10 20:02:21 +01:00
|
|
|
{
|
|
|
|
|
va_list ap;
|
|
|
|
|
va_start(ap, operation);
|
2025-07-08 22:14:49 +02:00
|
|
|
int r = vpi_sim_vcontrol(operation, ap);
|
2003-01-10 20:02:21 +01:00
|
|
|
va_end(ap);
|
2025-07-08 22:14:49 +02:00
|
|
|
return r;
|
2003-01-10 20:02:21 +01:00
|
|
|
}
|
2008-08-16 04:28:11 +02:00
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* This routine calculated the return value for $clog2.
|
|
|
|
|
* It is easier to do it here vs trying to to use the VPI interface.
|
|
|
|
|
*/
|
|
|
|
|
extern "C" s_vpi_vecval vpip_calc_clog2(vpiHandle arg)
|
|
|
|
|
{
|
|
|
|
|
s_vpi_vecval rtn;
|
|
|
|
|
s_vpi_value val;
|
|
|
|
|
vvp_vector4_t vec4;
|
|
|
|
|
bool is_neg = false; // At this point only a real can be negative.
|
|
|
|
|
|
|
|
|
|
/* Get the value as a vvp_vector4_t. */
|
|
|
|
|
val.format = vpiObjTypeVal;
|
|
|
|
|
vpi_get_value(arg, &val);
|
|
|
|
|
if (val.format == vpiRealVal) {
|
|
|
|
|
vpi_get_value(arg, &val);
|
|
|
|
|
/* All double values can be represented in 1024 bits. */
|
|
|
|
|
vec4 = vvp_vector4_t(1024, val.value.real);
|
|
|
|
|
if (val.value.real < 0) is_neg = true;
|
|
|
|
|
} else {
|
|
|
|
|
val.format = vpiVectorVal;
|
|
|
|
|
vpi_get_value(arg, &val);
|
|
|
|
|
unsigned wid = vpi_get(vpiSize, arg);
|
|
|
|
|
vec4 = vvp_vector4_t(wid, BIT4_0);
|
|
|
|
|
for (unsigned idx=0; idx < wid; idx += 1) {
|
|
|
|
|
PLI_INT32 aval = val.value.vector[idx/32].aval;
|
|
|
|
|
PLI_INT32 bval = val.value.vector[idx/32].bval;
|
|
|
|
|
aval >>= idx % 32;
|
|
|
|
|
bval >>= idx % 32;
|
|
|
|
|
int bitmask = (aval&1) | ((bval<<1)&2);
|
|
|
|
|
vvp_bit4_t bit = scalar_to_bit4(bitmask);
|
|
|
|
|
vec4.set_bit(idx, bit);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (vec4.has_xz()) {
|
|
|
|
|
rtn.aval = rtn.bval = 0xFFFFFFFFU; /* Set to 'bx. */
|
|
|
|
|
return rtn;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
vvp_vector2_t vec2(vec4);
|
|
|
|
|
|
|
|
|
|
if (is_neg) vec2.trim_neg(); /* This is a special trim! */
|
|
|
|
|
else vec2.trim(); /* This makes less work shifting. */
|
|
|
|
|
|
|
|
|
|
/* Calculate the clog2 result. */
|
|
|
|
|
PLI_INT32 res = 0;
|
|
|
|
|
if (!vec2.is_zero()) {
|
|
|
|
|
vec2 -= vvp_vector2_t(1, vec2.size());
|
|
|
|
|
while(!vec2.is_zero()) {
|
|
|
|
|
res += 1;
|
|
|
|
|
vec2 >>= 1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
rtn.aval = res;
|
|
|
|
|
rtn.bval = 0;
|
|
|
|
|
return rtn;
|
|
|
|
|
}
|
2012-07-10 23:33:17 +02:00
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* This routine provides the information needed to implement $countdrivers.
|
|
|
|
|
* It is done here for performance reasons - interrogating the drivers
|
|
|
|
|
* individually via the VPI interface would be much slower.
|
|
|
|
|
*/
|
|
|
|
|
extern "C" void vpip_count_drivers(vpiHandle ref, unsigned idx,
|
|
|
|
|
unsigned counts[4])
|
|
|
|
|
{
|
|
|
|
|
struct __vpiSignal*rfp = dynamic_cast<__vpiSignal*>(ref);
|
|
|
|
|
assert(rfp);
|
|
|
|
|
rfp->node->count_drivers(idx, counts);
|
|
|
|
|
}
|
2019-10-22 17:00:13 +02:00
|
|
|
|
2020-05-10 15:06:53 +02:00
|
|
|
#if defined(__MINGW32__) || defined (__CYGWIN__)
|
2019-10-22 17:00:13 +02:00
|
|
|
vpip_routines_s vpi_routines = {
|
|
|
|
|
.register_cb = vpi_register_cb,
|
|
|
|
|
.remove_cb = vpi_remove_cb,
|
|
|
|
|
.register_systf = vpi_register_systf,
|
|
|
|
|
.get_systf_info = vpi_get_systf_info,
|
|
|
|
|
.handle_by_name = vpi_handle_by_name,
|
|
|
|
|
.handle_by_index = vpi_handle_by_index,
|
2023-07-19 15:02:20 +02:00
|
|
|
.handle_multi = vpi_handle_multi,
|
2019-10-22 17:00:13 +02:00
|
|
|
.handle = vpi_handle,
|
|
|
|
|
.iterate = vpi_iterate,
|
|
|
|
|
.scan = vpi_scan,
|
|
|
|
|
.get = vpi_get,
|
|
|
|
|
.get_str = vpi_get_str,
|
|
|
|
|
.get_delays = vpi_get_delays,
|
|
|
|
|
.put_delays = vpi_put_delays,
|
|
|
|
|
.get_value = vpi_get_value,
|
|
|
|
|
.put_value = vpi_put_value,
|
|
|
|
|
.get_time = vpi_get_time,
|
|
|
|
|
.get_userdata = vpi_get_userdata,
|
|
|
|
|
.put_userdata = vpi_put_userdata,
|
|
|
|
|
.mcd_open = vpi_mcd_open,
|
|
|
|
|
.mcd_close = vpi_mcd_close,
|
|
|
|
|
.mcd_flush = vpi_mcd_flush,
|
|
|
|
|
.mcd_name = vpi_mcd_name,
|
|
|
|
|
.mcd_vprintf = vpi_mcd_vprintf,
|
|
|
|
|
.flush = vpi_flush,
|
|
|
|
|
.vprintf = vpi_vprintf,
|
|
|
|
|
.chk_error = vpi_chk_error,
|
|
|
|
|
.compare_objects = vpi_compare_objects,
|
|
|
|
|
.free_object = vpi_free_object,
|
2023-09-04 15:20:31 +02:00
|
|
|
.release_handle = vpi_release_handle,
|
2019-10-22 17:00:13 +02:00
|
|
|
.get_vlog_info = vpi_get_vlog_info,
|
2019-10-27 10:06:55 +01:00
|
|
|
.vcontrol = vpi_sim_vcontrol,
|
2019-10-22 17:00:13 +02:00
|
|
|
.fopen = vpi_fopen,
|
|
|
|
|
.get_file = vpi_get_file,
|
|
|
|
|
.calc_clog2 = vpip_calc_clog2,
|
|
|
|
|
.count_drivers = vpip_count_drivers,
|
|
|
|
|
.format_strength = vpip_format_strength,
|
|
|
|
|
.make_systf_system_defined = vpip_make_systf_system_defined,
|
|
|
|
|
.mcd_rawwrite = vpip_mcd_rawwrite,
|
|
|
|
|
.set_return_value = vpip_set_return_value,
|
|
|
|
|
};
|
2019-10-25 11:07:57 +02:00
|
|
|
#endif
|