1999-11-07 21:33:30 +01:00
|
|
|
/*
|
2023-02-26 23:05:42 +01:00
|
|
|
* Copyright (c) 1999-2023 Stephen Williams (steve@icarus.com)
|
1999-11-07 21:33:30 +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.
|
1999-11-07 21:33:30 +01:00
|
|
|
*/
|
|
|
|
|
|
2002-08-15 04:12:20 +02:00
|
|
|
# include "sys_priv.h"
|
2009-06-16 22:55:30 +02:00
|
|
|
# include "vcd_priv.h"
|
2001-07-25 05:10:48 +02:00
|
|
|
|
1999-11-07 21:33:30 +01:00
|
|
|
/*
|
2010-06-02 01:48:46 +02:00
|
|
|
* This file contains the implementations of the VCD related functions.
|
1999-11-07 21:33:30 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
# include <stdio.h>
|
|
|
|
|
# include <stdlib.h>
|
|
|
|
|
# include <string.h>
|
|
|
|
|
# include <assert.h>
|
2000-04-08 07:28:39 +02:00
|
|
|
# include <time.h>
|
2010-10-24 00:52:56 +02:00
|
|
|
# include "ivl_alloc.h"
|
2003-02-11 06:21:33 +01:00
|
|
|
|
2009-06-16 22:55:30 +02:00
|
|
|
static FILE *dump_file = NULL;
|
2022-03-11 16:45:46 +01:00
|
|
|
static int dump_no_date = 0;
|
2009-06-16 22:55:30 +02:00
|
|
|
|
2016-09-25 21:43:58 +02:00
|
|
|
static struct t_vpi_time zero_delay = { vpiSimTime, 0, 0, 0.0 };
|
|
|
|
|
|
2022-05-16 03:47:18 +02:00
|
|
|
/*
|
|
|
|
|
* The vcd_list is the list of all the objects that are tracked for
|
|
|
|
|
* dumping. The vcd_checkpoint goes through the list to dump the current
|
|
|
|
|
* values for everything. When the item has a value change, it is added to the
|
|
|
|
|
* vcd_dmp_list for dumping in the current time step.
|
|
|
|
|
*
|
|
|
|
|
* The vcd_const_list is a list of all of the parameters that are being
|
|
|
|
|
* dumped. This list is scanned less often, since parameters do not change
|
|
|
|
|
* values.
|
|
|
|
|
*/
|
2022-05-17 05:47:32 +02:00
|
|
|
DECLARE_VCD_INFO(vcd_info, const char*);
|
2022-05-16 03:47:18 +02:00
|
|
|
static struct vcd_info *vcd_const_list = NULL;
|
2009-06-16 22:55:30 +02:00
|
|
|
static struct vcd_info *vcd_list = NULL;
|
|
|
|
|
static struct vcd_info *vcd_dmp_list = NULL;
|
2022-05-17 05:47:32 +02:00
|
|
|
|
2009-06-16 22:55:30 +02:00
|
|
|
static PLI_UINT64 vcd_cur_time = 0;
|
|
|
|
|
static int dump_is_off = 0;
|
|
|
|
|
static long dump_limit = 0;
|
|
|
|
|
static int dump_is_full = 0;
|
|
|
|
|
static int finish_status = 0;
|
|
|
|
|
|
1999-11-07 21:33:30 +01:00
|
|
|
|
2000-07-26 06:07:59 +02:00
|
|
|
static const char*units_names[] = {
|
|
|
|
|
"s",
|
|
|
|
|
"ms",
|
|
|
|
|
"us",
|
|
|
|
|
"ns",
|
|
|
|
|
"ps",
|
|
|
|
|
"fs"
|
|
|
|
|
};
|
|
|
|
|
|
2001-10-15 03:50:23 +02:00
|
|
|
static char vcdid[8] = "!";
|
|
|
|
|
|
2000-04-08 07:28:39 +02:00
|
|
|
static void gen_new_vcd_id(void)
|
|
|
|
|
{
|
2001-10-15 03:50:23 +02:00
|
|
|
static unsigned value = 0;
|
|
|
|
|
unsigned v = ++value;
|
2003-12-19 02:27:10 +01:00
|
|
|
unsigned int i;
|
2001-10-15 03:50:23 +02:00
|
|
|
|
|
|
|
|
for (i=0; i < sizeof(vcdid)-1; i++) {
|
|
|
|
|
vcdid[i] = (char)((v%94)+33); /* for range 33..126 */
|
|
|
|
|
v /= 94;
|
|
|
|
|
if(!v) {
|
2004-10-04 03:10:51 +02:00
|
|
|
vcdid[i+1] = '\0';
|
2010-11-17 02:21:51 +01:00
|
|
|
return;
|
2001-10-15 03:50:23 +02:00
|
|
|
}
|
|
|
|
|
}
|
2010-11-17 02:21:51 +01:00
|
|
|
// This should never happen since 94**7 is a lot if identifiers!
|
|
|
|
|
assert(0);
|
2000-04-08 07:28:39 +02:00
|
|
|
}
|
|
|
|
|
|
2000-04-09 06:18:16 +02:00
|
|
|
static char *truncate_bitvec(char *s)
|
|
|
|
|
{
|
2013-04-15 20:53:07 +02:00
|
|
|
char r;
|
2000-04-09 06:18:16 +02:00
|
|
|
|
|
|
|
|
r=*s;
|
2007-12-11 01:14:02 +01:00
|
|
|
if(r=='1') return s;
|
|
|
|
|
else s += 1;
|
2004-10-04 03:10:51 +02:00
|
|
|
|
|
|
|
|
for(;;s++) {
|
2013-04-15 20:53:07 +02:00
|
|
|
char l;
|
2000-04-09 06:18:16 +02:00
|
|
|
l=r; r=*s;
|
|
|
|
|
if(!r) return (s-1);
|
2007-12-11 01:14:02 +01:00
|
|
|
if(l!=r) return(((l=='0')&&(r=='1'))?s:s-1);
|
2000-04-09 06:18:16 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2000-01-20 07:04:55 +01:00
|
|
|
static void show_this_item(struct vcd_info*info)
|
|
|
|
|
{
|
|
|
|
|
s_vpi_value value;
|
2009-06-25 19:48:05 +02:00
|
|
|
PLI_INT32 type = vpi_get(vpiType, info->item);
|
2000-01-20 07:04:55 +01:00
|
|
|
|
2009-06-25 19:48:05 +02:00
|
|
|
if (type == vpiRealVar) {
|
2003-02-11 06:21:33 +01:00
|
|
|
value.format = vpiRealVal;
|
|
|
|
|
vpi_get_value(info->item, &value);
|
|
|
|
|
fprintf(dump_file, "r%.16g %s\n", value.value.real, info->ident);
|
2009-06-25 19:48:05 +02:00
|
|
|
} else if (type == vpiNamedEvent) {
|
|
|
|
|
fprintf(dump_file, "1%s\n", info->ident);
|
2022-05-21 19:13:27 +02:00
|
|
|
} else if (type == vpiParameter && vpi_get(vpiConstType, info->item) == vpiRealConst) {
|
|
|
|
|
|
|
|
|
|
value.format = vpiRealVal;
|
|
|
|
|
vpi_get_value(info->item, &value);
|
|
|
|
|
fprintf(dump_file, "r%.16g %s\n", value.value.real, info->ident);
|
2003-02-11 06:21:33 +01:00
|
|
|
} else if (vpi_get(vpiSize, info->item) == 1) {
|
2000-01-20 07:04:55 +01:00
|
|
|
value.format = vpiBinStrVal;
|
|
|
|
|
vpi_get_value(info->item, &value);
|
|
|
|
|
fprintf(dump_file, "%s%s\n", value.value.str, info->ident);
|
|
|
|
|
} else {
|
|
|
|
|
value.format = vpiBinStrVal;
|
|
|
|
|
vpi_get_value(info->item, &value);
|
2007-12-11 01:14:02 +01:00
|
|
|
fprintf(dump_file, "b%s %s\n", truncate_bitvec(value.value.str),
|
2000-04-09 06:18:16 +02:00
|
|
|
info->ident);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2009-06-25 19:48:05 +02:00
|
|
|
/* Dump values for a $dumpoff. */
|
2001-10-14 20:32:06 +02:00
|
|
|
static void show_this_item_x(struct vcd_info*info)
|
|
|
|
|
{
|
2009-06-25 19:48:05 +02:00
|
|
|
PLI_INT32 type = vpi_get(vpiType, info->item);
|
|
|
|
|
|
|
|
|
|
if (type == vpiRealVar) {
|
2003-02-12 06:28:01 +01:00
|
|
|
/* Some tools dump nothing here...? */
|
|
|
|
|
fprintf(dump_file, "rNaN %s\n", info->ident);
|
2009-06-25 19:48:05 +02:00
|
|
|
} else if (type == vpiNamedEvent) {
|
|
|
|
|
/* Do nothing for named events. */
|
2003-02-12 06:28:01 +01:00
|
|
|
} else if (vpi_get(vpiSize, info->item) == 1) {
|
2001-10-14 20:32:06 +02:00
|
|
|
fprintf(dump_file, "x%s\n", info->ident);
|
|
|
|
|
} else {
|
|
|
|
|
fprintf(dump_file, "bx %s\n", info->ident);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2000-04-09 06:18:16 +02:00
|
|
|
/*
|
2007-11-22 03:22:38 +01:00
|
|
|
* managed qsorted list of scope names/variables for duplicates bsearching
|
2000-04-09 06:18:16 +02:00
|
|
|
*/
|
|
|
|
|
|
2014-07-09 18:52:19 +02:00
|
|
|
struct vcd_names_list_s vcd_tab = { 0, 0, 0, 0 };
|
|
|
|
|
struct vcd_names_list_s vcd_var = { 0, 0, 0, 0 };
|
2000-01-20 07:04:55 +01:00
|
|
|
|
2001-10-09 01:33:00 +02:00
|
|
|
|
2003-09-30 03:33:39 +02:00
|
|
|
static PLI_UINT64 dumpvars_time;
|
2008-09-30 03:06:47 +02:00
|
|
|
__inline__ static int dump_header_pending(void)
|
2001-10-09 01:33:00 +02:00
|
|
|
{
|
|
|
|
|
return dumpvars_status != 2;
|
|
|
|
|
}
|
|
|
|
|
|
2001-10-14 20:32:06 +02:00
|
|
|
|
2006-10-30 23:45:36 +01:00
|
|
|
static PLI_INT32 variable_cb_2(p_cb_data cause)
|
1999-11-07 21:33:30 +01:00
|
|
|
{
|
2003-04-27 04:22:27 +02:00
|
|
|
struct vcd_info* info = vcd_dmp_list;
|
2003-09-30 03:33:39 +02:00
|
|
|
PLI_UINT64 now = timerec_to_time64(cause->time);
|
2001-10-09 01:33:00 +02:00
|
|
|
|
1999-11-07 21:33:30 +01:00
|
|
|
if (now != vcd_cur_time) {
|
2003-10-29 04:28:27 +01:00
|
|
|
fprintf(dump_file, "#%" PLI_UINT64_FMT "\n", now);
|
1999-11-07 21:33:30 +01:00
|
|
|
vcd_cur_time = now;
|
|
|
|
|
}
|
|
|
|
|
|
2003-04-27 04:22:27 +02:00
|
|
|
do {
|
|
|
|
|
show_this_item(info);
|
|
|
|
|
info->scheduled = 0;
|
|
|
|
|
} while ((info = info->dmp_next) != 0);
|
|
|
|
|
|
|
|
|
|
vcd_dmp_list = 0;
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2006-10-30 23:45:36 +01:00
|
|
|
static PLI_INT32 variable_cb_1(p_cb_data cause)
|
2003-04-27 04:22:27 +02:00
|
|
|
{
|
|
|
|
|
struct t_cb_data cb;
|
|
|
|
|
struct vcd_info*info = (struct vcd_info*)cause->user_data;
|
|
|
|
|
|
2007-12-11 01:14:02 +01:00
|
|
|
if (dump_is_full) return 0;
|
|
|
|
|
if (dump_is_off) return 0;
|
2003-04-27 04:22:27 +02:00
|
|
|
if (dump_header_pending()) return 0;
|
2007-12-11 01:14:02 +01:00
|
|
|
if (info->scheduled) return 0;
|
2003-04-27 04:22:27 +02:00
|
|
|
|
2007-10-09 06:01:25 +02:00
|
|
|
if ((dump_limit > 0) && (ftell(dump_file) > dump_limit)) {
|
|
|
|
|
dump_is_full = 1;
|
|
|
|
|
vpi_printf("WARNING: Dump file limit (%ld bytes) "
|
|
|
|
|
"exceeded.\n", dump_limit);
|
|
|
|
|
fprintf(dump_file, "$comment Dump file limit (%ld bytes) "
|
|
|
|
|
"exceeded. $end\n", dump_limit);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2003-04-27 04:22:27 +02:00
|
|
|
if (!vcd_dmp_list) {
|
|
|
|
|
cb = *cause;
|
2016-09-25 21:43:58 +02:00
|
|
|
cb.time = &zero_delay;
|
2003-04-27 04:22:27 +02:00
|
|
|
cb.reason = cbReadOnlySynch;
|
|
|
|
|
cb.cb_rtn = variable_cb_2;
|
|
|
|
|
vpi_register_cb(&cb);
|
2004-10-04 03:10:51 +02:00
|
|
|
}
|
2003-04-27 04:22:27 +02:00
|
|
|
|
|
|
|
|
info->scheduled = 1;
|
|
|
|
|
info->dmp_next = vcd_dmp_list;
|
|
|
|
|
vcd_dmp_list = info;
|
1999-11-07 21:33:30 +01:00
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-16 03:47:18 +02:00
|
|
|
/*
|
|
|
|
|
* This is called at the end of the timestep where the $dumpvars task is
|
|
|
|
|
* called. This allows for values to settle for the timestep, so that the
|
|
|
|
|
* checkpoint gets the current values.
|
|
|
|
|
*/
|
2006-10-30 23:45:36 +01:00
|
|
|
static PLI_INT32 dumpvars_cb(p_cb_data cause)
|
2001-09-30 07:18:46 +02:00
|
|
|
{
|
2007-12-11 01:14:02 +01:00
|
|
|
if (dumpvars_status != 1) return 0;
|
2001-10-09 01:33:00 +02:00
|
|
|
|
|
|
|
|
dumpvars_status = 2;
|
|
|
|
|
|
2003-09-30 03:33:39 +02:00
|
|
|
dumpvars_time = timerec_to_time64(cause->time);
|
2001-09-30 07:18:46 +02:00
|
|
|
vcd_cur_time = dumpvars_time;
|
|
|
|
|
|
|
|
|
|
fprintf(dump_file, "$enddefinitions $end\n");
|
|
|
|
|
|
|
|
|
|
if (!dump_is_off) {
|
2022-05-16 03:47:18 +02:00
|
|
|
fprintf(dump_file, "$comment Show the parameter values. $end\n");
|
|
|
|
|
fprintf(dump_file, "$dumpall\n");
|
2022-05-17 05:47:32 +02:00
|
|
|
ITERATE_VCD_INFO(vcd_const_list, vcd_info, next, show_this_item);
|
2022-05-16 03:47:18 +02:00
|
|
|
fprintf(dump_file, "$end\n");
|
|
|
|
|
|
2003-10-29 04:28:27 +01:00
|
|
|
fprintf(dump_file, "#%" PLI_UINT64_FMT "\n", dumpvars_time);
|
2022-05-16 03:47:18 +02:00
|
|
|
|
2001-09-30 07:18:46 +02:00
|
|
|
fprintf(dump_file, "$dumpvars\n");
|
2022-05-17 05:47:32 +02:00
|
|
|
ITERATE_VCD_INFO(vcd_list, vcd_info, next, show_this_item);
|
2001-09-30 07:18:46 +02:00
|
|
|
fprintf(dump_file, "$end\n");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2007-11-09 00:56:10 +01:00
|
|
|
static PLI_INT32 finish_cb(p_cb_data cause)
|
|
|
|
|
{
|
2009-02-03 00:44:50 +01:00
|
|
|
struct vcd_info *cur, *next;
|
2009-01-24 01:04:44 +01:00
|
|
|
|
2007-12-11 01:14:02 +01:00
|
|
|
if (finish_status != 0) return 0;
|
2007-11-09 00:56:10 +01:00
|
|
|
|
|
|
|
|
finish_status = 1;
|
|
|
|
|
|
|
|
|
|
dumpvars_time = timerec_to_time64(cause->time);
|
|
|
|
|
|
|
|
|
|
if (!dump_is_off && !dump_is_full && dumpvars_time != vcd_cur_time) {
|
|
|
|
|
fprintf(dump_file, "#%" PLI_UINT64_FMT "\n", dumpvars_time);
|
|
|
|
|
}
|
|
|
|
|
|
2009-01-29 19:38:22 +01:00
|
|
|
fclose(dump_file);
|
2009-02-03 00:44:50 +01:00
|
|
|
|
|
|
|
|
for (cur = vcd_list ; cur ; cur = next) {
|
|
|
|
|
next = cur->next;
|
2009-02-03 18:19:31 +01:00
|
|
|
free((char *)cur->ident);
|
2009-02-03 00:44:50 +01:00
|
|
|
free(cur);
|
|
|
|
|
}
|
2009-03-18 02:01:25 +01:00
|
|
|
vcd_list = 0;
|
2022-05-16 03:47:18 +02:00
|
|
|
for (cur = vcd_const_list ; cur ; cur = next) {
|
|
|
|
|
next = cur->next;
|
|
|
|
|
free((char *)cur->ident);
|
|
|
|
|
free(cur);
|
|
|
|
|
}
|
|
|
|
|
vcd_const_list = 0;
|
2009-01-24 01:04:44 +01:00
|
|
|
vcd_names_delete(&vcd_tab);
|
|
|
|
|
vcd_names_delete(&vcd_var);
|
|
|
|
|
nexus_ident_delete();
|
2023-02-26 23:05:42 +01:00
|
|
|
vcd_free_dump_path();
|
2009-01-24 01:04:44 +01:00
|
|
|
|
2007-11-09 00:56:10 +01:00
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2008-09-30 03:06:47 +02:00
|
|
|
__inline__ static int install_dumpvars_callback(void)
|
2001-09-30 07:18:46 +02:00
|
|
|
{
|
|
|
|
|
struct t_cb_data cb;
|
|
|
|
|
|
2007-12-11 01:14:02 +01:00
|
|
|
if (dumpvars_status == 1) return 0;
|
2001-09-30 07:18:46 +02:00
|
|
|
|
|
|
|
|
if (dumpvars_status == 2) {
|
2008-06-04 02:12:27 +02:00
|
|
|
vpi_printf("VCD warning: $dumpvars ignored, previously"
|
|
|
|
|
" called at simtime %" PLI_UINT64_FMT "\n",
|
|
|
|
|
dumpvars_time);
|
2001-09-30 07:18:46 +02:00
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
2016-09-25 21:43:58 +02:00
|
|
|
cb.time = &zero_delay;
|
2001-09-30 07:18:46 +02:00
|
|
|
cb.reason = cbReadOnlySynch;
|
|
|
|
|
cb.cb_rtn = dumpvars_cb;
|
|
|
|
|
cb.user_data = 0x0;
|
|
|
|
|
cb.obj = 0x0;
|
|
|
|
|
|
|
|
|
|
vpi_register_cb(&cb);
|
|
|
|
|
|
2007-11-09 00:56:10 +01:00
|
|
|
cb.reason = cbEndOfSimulation;
|
|
|
|
|
cb.cb_rtn = finish_cb;
|
|
|
|
|
|
|
|
|
|
vpi_register_cb(&cb);
|
|
|
|
|
|
2001-09-30 07:18:46 +02:00
|
|
|
dumpvars_status = 1;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2010-10-04 18:31:01 +02:00
|
|
|
static PLI_INT32 sys_dumpoff_calltf(ICARUS_VPI_CONST PLI_BYTE8*name)
|
2001-06-21 06:15:22 +02:00
|
|
|
{
|
2001-10-14 20:32:06 +02:00
|
|
|
s_vpi_time now;
|
2003-09-30 03:33:39 +02:00
|
|
|
PLI_UINT64 now64;
|
2001-10-14 20:32:06 +02:00
|
|
|
|
2014-07-09 23:16:57 +02:00
|
|
|
(void)name; /* Parameter is not used. */
|
|
|
|
|
|
2007-12-11 01:14:02 +01:00
|
|
|
if (dump_is_off) return 0;
|
2001-10-14 20:32:06 +02:00
|
|
|
|
2001-06-21 06:15:22 +02:00
|
|
|
dump_is_off = 1;
|
2001-10-14 20:32:06 +02:00
|
|
|
|
2007-12-11 01:14:02 +01:00
|
|
|
if (dump_file == 0) return 0;
|
|
|
|
|
if (dump_header_pending()) return 0;
|
2001-10-14 20:32:06 +02:00
|
|
|
|
2002-12-21 01:55:57 +01:00
|
|
|
now.type = vpiSimTime;
|
2001-10-14 20:32:06 +02:00
|
|
|
vpi_get_time(0, &now);
|
2003-09-30 03:33:39 +02:00
|
|
|
now64 = timerec_to_time64(&now);
|
|
|
|
|
|
2007-12-11 01:14:02 +01:00
|
|
|
if (now64 > vcd_cur_time) {
|
2003-10-29 04:28:27 +01:00
|
|
|
fprintf(dump_file, "#%" PLI_UINT64_FMT "\n", now64);
|
2007-12-11 01:14:02 +01:00
|
|
|
vcd_cur_time = now64;
|
|
|
|
|
}
|
2001-10-14 20:32:06 +02:00
|
|
|
|
|
|
|
|
fprintf(dump_file, "$dumpoff\n");
|
2022-05-17 05:47:32 +02:00
|
|
|
ITERATE_VCD_INFO(vcd_list, vcd_info, next, show_this_item_x);
|
2001-10-14 20:32:06 +02:00
|
|
|
fprintf(dump_file, "$end\n");
|
|
|
|
|
|
2001-06-21 06:15:22 +02:00
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2010-10-04 18:31:01 +02:00
|
|
|
static PLI_INT32 sys_dumpon_calltf(ICARUS_VPI_CONST PLI_BYTE8*name)
|
2001-06-21 06:15:22 +02:00
|
|
|
{
|
2001-09-30 07:18:46 +02:00
|
|
|
s_vpi_time now;
|
2003-09-30 03:33:39 +02:00
|
|
|
PLI_UINT64 now64;
|
2001-10-14 20:32:06 +02:00
|
|
|
|
2014-07-09 23:16:57 +02:00
|
|
|
(void)name; /* Parameter is not used. */
|
|
|
|
|
|
2007-12-11 01:14:02 +01:00
|
|
|
if (!dump_is_off) return 0;
|
2001-10-14 20:32:06 +02:00
|
|
|
|
2001-06-21 06:15:22 +02:00
|
|
|
dump_is_off = 0;
|
2001-09-30 07:18:46 +02:00
|
|
|
|
2007-12-11 01:14:02 +01:00
|
|
|
if (dump_file == 0) return 0;
|
|
|
|
|
if (dump_header_pending()) return 0;
|
2001-10-09 01:33:00 +02:00
|
|
|
|
2002-12-21 01:55:57 +01:00
|
|
|
now.type = vpiSimTime;
|
2001-09-30 07:18:46 +02:00
|
|
|
vpi_get_time(0, &now);
|
2003-09-30 03:33:39 +02:00
|
|
|
now64 = timerec_to_time64(&now);
|
|
|
|
|
|
2007-12-11 01:14:02 +01:00
|
|
|
if (now64 > vcd_cur_time) {
|
2003-10-29 04:28:27 +01:00
|
|
|
fprintf(dump_file, "#%" PLI_UINT64_FMT "\n", now64);
|
2007-12-11 01:14:02 +01:00
|
|
|
vcd_cur_time = now64;
|
|
|
|
|
}
|
2001-10-14 20:32:06 +02:00
|
|
|
|
|
|
|
|
fprintf(dump_file, "$dumpon\n");
|
2022-05-17 05:47:32 +02:00
|
|
|
ITERATE_VCD_INFO(vcd_list, vcd_info, next, show_this_item);
|
2001-10-14 20:32:06 +02:00
|
|
|
fprintf(dump_file, "$end\n");
|
2001-09-30 07:18:46 +02:00
|
|
|
|
2001-06-21 06:15:22 +02:00
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2010-10-04 18:31:01 +02:00
|
|
|
static PLI_INT32 sys_dumpall_calltf(ICARUS_VPI_CONST PLI_BYTE8*name)
|
1999-11-07 21:33:30 +01:00
|
|
|
{
|
2000-01-20 07:04:55 +01:00
|
|
|
s_vpi_time now;
|
2003-09-30 03:33:39 +02:00
|
|
|
PLI_UINT64 now64;
|
2000-07-31 05:34:31 +02:00
|
|
|
|
2014-07-09 23:16:57 +02:00
|
|
|
(void)name; /* Parameter is not used. */
|
|
|
|
|
|
2007-12-11 01:14:02 +01:00
|
|
|
if (dump_is_off) return 0;
|
|
|
|
|
if (dump_file == 0) return 0;
|
|
|
|
|
if (dump_header_pending()) return 0;
|
2001-10-09 01:33:00 +02:00
|
|
|
|
2002-12-21 01:55:57 +01:00
|
|
|
now.type = vpiSimTime;
|
2000-01-20 07:04:55 +01:00
|
|
|
vpi_get_time(0, &now);
|
2003-09-30 03:33:39 +02:00
|
|
|
now64 = timerec_to_time64(&now);
|
|
|
|
|
|
2007-12-11 01:14:02 +01:00
|
|
|
if (now64 > vcd_cur_time) {
|
2003-10-29 04:28:27 +01:00
|
|
|
fprintf(dump_file, "#%" PLI_UINT64_FMT "\n", now64);
|
2007-12-11 01:14:02 +01:00
|
|
|
vcd_cur_time = now64;
|
|
|
|
|
}
|
2001-10-14 20:32:06 +02:00
|
|
|
|
|
|
|
|
fprintf(dump_file, "$dumpall\n");
|
2022-05-17 05:47:32 +02:00
|
|
|
ITERATE_VCD_INFO(vcd_list, vcd_info, next, show_this_item);
|
2001-10-14 20:32:06 +02:00
|
|
|
fprintf(dump_file, "$end\n");
|
2000-01-20 07:04:55 +01:00
|
|
|
|
1999-11-07 21:33:30 +01:00
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2008-06-04 02:12:27 +02:00
|
|
|
static void open_dumpfile(vpiHandle callh)
|
2001-01-22 21:58:31 +01:00
|
|
|
{
|
2023-02-26 23:05:42 +01:00
|
|
|
char* use_dump_path = vcd_get_dump_path("vcd");
|
2004-02-15 04:17:15 +01:00
|
|
|
|
2023-02-26 23:05:42 +01:00
|
|
|
dump_file = fopen(use_dump_path, "w");
|
2001-01-23 19:50:26 +01:00
|
|
|
|
2001-01-22 21:58:31 +01:00
|
|
|
if (dump_file == 0) {
|
Rework $plusarg routines.
This patch addresses a number of issues:
Rewrote the $test$plusargs and $value$plusargs routines to have
better error/warning messages, to support runtime strings, to
correctly load bit based values (truncating, padding, negative
value), added support for the real formats using strtod() and
added "x/X" as an alias for "h/H" to match the other part of
Icarus.
Rewrite the vpip_{bin,oct,hex}_str_to_vec4 routines to ignore
embedded "_" characters. Add support for a negative value and
set the entire value to 'bx if an invalid digit is found. A
warning is printed for this case.
Rewrite vpip_dec_str_to_vec4 to ignore embedded "_" characters,
to support a single "x" or "z" constant and to return 'bx if an
invalid digit is found. A warning is printed for this case.
It simplifies the system task/functions error/warning messages.
It removes the signed flag for the bin and dec string conversions.
This was not being used (was always false) and the new negative
value support makes this obsolete.
Add support for a real variable to handle Bin, Oct, Dec and Hex
strings. They are converted into a vvp_vector4_t which is then
converted to a real value.
Add support for setting a bit based value using a real value.
Removed an unneeded rfp signal in vpip_make_reg()
2008-11-13 22:28:19 +01:00
|
|
|
vpi_printf("VCD Error: %s:%d: ", vpi_get_str(vpiFile, callh),
|
2008-06-04 02:12:27 +02:00
|
|
|
(int)vpi_get(vpiLineNo, callh));
|
2023-02-26 23:05:42 +01:00
|
|
|
vpi_printf("Unable to open %s for output.\n", use_dump_path);
|
2021-01-21 08:50:06 +01:00
|
|
|
vpip_set_return_value(1);
|
2007-12-11 01:14:02 +01:00
|
|
|
vpi_control(vpiFinish, 1);
|
2023-02-26 23:05:42 +01:00
|
|
|
vcd_free_dump_path();
|
2001-01-22 21:58:31 +01:00
|
|
|
return;
|
|
|
|
|
} else {
|
|
|
|
|
int prec = vpi_get(vpiTimePrecision, 0);
|
|
|
|
|
unsigned scale = 1;
|
|
|
|
|
unsigned udx = 0;
|
|
|
|
|
time_t walltime;
|
|
|
|
|
|
2009-02-25 01:47:46 +01:00
|
|
|
vpi_printf("VCD info: dumpfile %s opened for output.\n",
|
2023-02-26 23:05:42 +01:00
|
|
|
use_dump_path);
|
2004-10-04 03:10:51 +02:00
|
|
|
|
2001-01-22 21:58:31 +01:00
|
|
|
time(&walltime);
|
|
|
|
|
|
|
|
|
|
assert(prec >= -15);
|
|
|
|
|
while (prec < 0) {
|
|
|
|
|
udx += 1;
|
|
|
|
|
prec += 3;
|
|
|
|
|
}
|
|
|
|
|
while (prec > 0) {
|
|
|
|
|
scale *= 10;
|
|
|
|
|
prec -= 1;
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-11 16:45:46 +01:00
|
|
|
if (!dump_no_date) {
|
|
|
|
|
fprintf(dump_file, "$date\n");
|
|
|
|
|
fprintf(dump_file, "\t%s",asctime(localtime(&walltime)));
|
|
|
|
|
fprintf(dump_file, "$end\n");
|
|
|
|
|
}
|
2001-01-22 21:58:31 +01:00
|
|
|
fprintf(dump_file, "$version\n");
|
|
|
|
|
fprintf(dump_file, "\tIcarus Verilog\n");
|
|
|
|
|
fprintf(dump_file, "$end\n");
|
|
|
|
|
fprintf(dump_file, "$timescale\n");
|
|
|
|
|
fprintf(dump_file, "\t%u%s\n", scale, units_names[udx]);
|
|
|
|
|
fprintf(dump_file, "$end\n");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2010-10-04 18:31:01 +02:00
|
|
|
static PLI_INT32 sys_dumpfile_calltf(ICARUS_VPI_CONST PLI_BYTE8*name)
|
1999-11-07 21:33:30 +01:00
|
|
|
{
|
2023-02-26 23:05:42 +01:00
|
|
|
(void) name;
|
|
|
|
|
return sys_dumpfile_common("VCD", "vcd");
|
1999-11-07 21:33:30 +01:00
|
|
|
}
|
|
|
|
|
|
2010-10-04 18:31:01 +02:00
|
|
|
static PLI_INT32 sys_dumpflush_calltf(ICARUS_VPI_CONST PLI_BYTE8*name)
|
2004-02-15 21:46:01 +01:00
|
|
|
{
|
2014-07-09 23:16:57 +02:00
|
|
|
(void)name; /* Parameter is not used. */
|
2007-12-11 01:14:02 +01:00
|
|
|
if (dump_file) fflush(dump_file);
|
2007-10-09 06:01:25 +02:00
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2010-10-04 18:31:01 +02:00
|
|
|
static PLI_INT32 sys_dumplimit_calltf(ICARUS_VPI_CONST PLI_BYTE8 *name)
|
2007-10-09 06:01:25 +02:00
|
|
|
{
|
|
|
|
|
vpiHandle callh = vpi_handle(vpiSysTfCall, 0);
|
|
|
|
|
vpiHandle argv = vpi_iterate(vpiArgument, callh);
|
|
|
|
|
s_vpi_value val;
|
|
|
|
|
|
2014-07-09 23:16:57 +02:00
|
|
|
(void)name; /* Parameter is not used. */
|
|
|
|
|
|
2007-10-09 06:01:25 +02:00
|
|
|
/* Get the value and set the dump limit. */
|
|
|
|
|
val.format = vpiIntVal;
|
2007-12-11 01:14:02 +01:00
|
|
|
vpi_get_value(vpi_scan(argv), &val);
|
2007-10-09 06:01:25 +02:00
|
|
|
dump_limit = val.value.integer;
|
|
|
|
|
|
|
|
|
|
vpi_free_object(argv);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2009-06-25 21:46:46 +02:00
|
|
|
static void scan_item(unsigned depth, vpiHandle item, int skip)
|
1999-11-07 21:33:30 +01:00
|
|
|
{
|
|
|
|
|
struct t_cb_data cb;
|
2001-10-14 20:32:06 +02:00
|
|
|
struct vcd_info* info;
|
1999-11-07 21:33:30 +01:00
|
|
|
|
2010-06-02 01:48:46 +02:00
|
|
|
const char *type;
|
|
|
|
|
const char *name;
|
|
|
|
|
const char *fullname;
|
|
|
|
|
const char *prefix;
|
|
|
|
|
const char *ident;
|
2001-10-14 20:32:06 +02:00
|
|
|
int nexus_id;
|
2009-06-25 19:48:05 +02:00
|
|
|
unsigned size;
|
|
|
|
|
PLI_INT32 item_type;
|
1999-11-07 21:33:30 +01:00
|
|
|
|
2009-06-25 19:48:05 +02:00
|
|
|
/* Get the displayed type for the various $var and $scope types. */
|
|
|
|
|
/* Not all of these are supported now, but they should be in a
|
|
|
|
|
* future development version. */
|
|
|
|
|
item_type = vpi_get(vpiType, item);
|
|
|
|
|
switch (item_type) {
|
|
|
|
|
case vpiNamedEvent: type = "event"; break;
|
2011-09-06 18:23:42 +02:00
|
|
|
case vpiIntVar:
|
2009-06-25 19:48:05 +02:00
|
|
|
case vpiIntegerVar: type = "integer"; break;
|
2022-05-21 19:13:27 +02:00
|
|
|
/* VCD doesn't support real parameters, so lie. */
|
|
|
|
|
case vpiParameter:
|
|
|
|
|
switch (vpi_get(vpiConstType, item)) {
|
|
|
|
|
case vpiRealConst: type = "real"; break;
|
|
|
|
|
default: type = "parameter"; break;
|
|
|
|
|
}
|
|
|
|
|
break;
|
2009-06-25 19:48:05 +02:00
|
|
|
/* Icarus converts realtime to real. */
|
|
|
|
|
case vpiRealVar: type = "real"; break;
|
2008-06-04 02:12:27 +02:00
|
|
|
case vpiMemoryWord:
|
2011-09-06 18:23:42 +02:00
|
|
|
case vpiBitVar:
|
|
|
|
|
case vpiByteVar:
|
|
|
|
|
case vpiShortIntVar:
|
|
|
|
|
case vpiLongIntVar:
|
2009-06-25 19:48:05 +02:00
|
|
|
case vpiReg: type = "reg"; break;
|
|
|
|
|
/* Icarus converts a time to a plain register. */
|
|
|
|
|
case vpiTimeVar: type = "time"; break;
|
|
|
|
|
case vpiNet:
|
|
|
|
|
switch (vpi_get(vpiNetType, item)) {
|
|
|
|
|
case vpiWand: type = "wand"; break;
|
|
|
|
|
case vpiWor: type = "wor"; break;
|
|
|
|
|
case vpiTri: type = "tri"; break;
|
|
|
|
|
case vpiTri0: type = "tri0"; break;
|
|
|
|
|
case vpiTri1: type = "tri1"; break;
|
|
|
|
|
case vpiTriReg: type = "trireg"; break;
|
|
|
|
|
case vpiTriAnd: type = "triand"; break;
|
|
|
|
|
case vpiTriOr: type = "trior"; break;
|
|
|
|
|
case vpiSupply1: type = "supply1"; break;
|
|
|
|
|
case vpiSupply0: type = "supply0"; break;
|
|
|
|
|
default: type = "wire"; break;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case vpiNamedBegin: type = "begin"; break;
|
2013-07-17 19:55:46 +02:00
|
|
|
case vpiGenScope: type = "begin"; break;
|
2009-06-25 19:48:05 +02:00
|
|
|
case vpiNamedFork: type = "fork"; break;
|
|
|
|
|
case vpiFunction: type = "function"; break;
|
|
|
|
|
case vpiModule: type = "module"; break;
|
2020-11-29 21:41:34 +01:00
|
|
|
case vpiPackage: type = "package"; break;
|
2009-06-25 19:48:05 +02:00
|
|
|
case vpiTask: type = "task"; break;
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
vpi_printf("VCD warning: $dumpvars: Unsupported argument "
|
2020-11-29 21:41:34 +01:00
|
|
|
"type (%s).\n", vpi_get_str(vpiType, item));
|
2009-06-25 19:48:05 +02:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Do some special processing/checking on array words. Dumping
|
|
|
|
|
* array words is an Icarus extension. */
|
|
|
|
|
if (item_type == vpiMemoryWord) {
|
|
|
|
|
/* Turn a non-constant array word select into a constant
|
|
|
|
|
* word select. */
|
2009-06-16 22:55:30 +02:00
|
|
|
if (vpi_get(vpiConstantSelect, item) == 0) {
|
2009-04-16 20:57:00 +02:00
|
|
|
vpiHandle array = vpi_handle(vpiParent, item);
|
2010-05-13 03:53:56 +02:00
|
|
|
PLI_INT32 idx = vpi_get(vpiIndex, item);
|
|
|
|
|
item = vpi_handle_by_index(array, idx);
|
2009-06-16 22:55:30 +02:00
|
|
|
}
|
2007-11-22 03:22:38 +01:00
|
|
|
|
2009-04-28 23:57:46 +02:00
|
|
|
/* An array word is implicitly escaped so look for an
|
|
|
|
|
* escaped identifier that this could conflict with. */
|
2009-06-25 19:48:05 +02:00
|
|
|
/* This does not work as expected since we always find at
|
|
|
|
|
* least the array word. We likely need a custom routine. */
|
2009-04-28 23:57:46 +02:00
|
|
|
if (vpi_get(vpiType, item) == vpiMemoryWord &&
|
|
|
|
|
vpi_handle_by_name(vpi_get_str(vpiFullName, item), 0)) {
|
2009-06-25 19:48:05 +02:00
|
|
|
vpi_printf("VCD warning: array word %s will conflict "
|
|
|
|
|
"with an escaped identifier.\n",
|
2009-04-28 23:57:46 +02:00
|
|
|
vpi_get_str(vpiFullName, item));
|
|
|
|
|
}
|
2009-06-25 19:48:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fullname = vpi_get_str(vpiFullName, item);
|
|
|
|
|
|
|
|
|
|
/* Generate the $var or $scope commands. */
|
|
|
|
|
switch (item_type) {
|
|
|
|
|
case vpiNamedEvent:
|
|
|
|
|
case vpiIntegerVar:
|
2011-09-06 18:23:42 +02:00
|
|
|
case vpiBitVar:
|
|
|
|
|
case vpiByteVar:
|
|
|
|
|
case vpiShortIntVar:
|
|
|
|
|
case vpiIntVar:
|
|
|
|
|
case vpiLongIntVar:
|
2009-06-25 19:48:05 +02:00
|
|
|
case vpiRealVar:
|
|
|
|
|
case vpiMemoryWord:
|
|
|
|
|
case vpiReg:
|
|
|
|
|
case vpiTimeVar:
|
|
|
|
|
case vpiNet:
|
|
|
|
|
|
|
|
|
|
/* If we are skipping all signal or this is in an automatic
|
|
|
|
|
* scope then just return. */
|
|
|
|
|
if (skip || vpi_get(vpiAutomatic, item)) return;
|
|
|
|
|
|
2009-06-25 21:46:46 +02:00
|
|
|
/* Skip this signal if it has already been included.
|
|
|
|
|
* This can only happen for implicitly given signals. */
|
|
|
|
|
if (vcd_names_search(&vcd_var, fullname)) return;
|
2004-10-04 03:10:51 +02:00
|
|
|
|
2009-06-25 19:48:05 +02:00
|
|
|
/* Declare the variable in the VCD file. */
|
2001-10-15 03:50:23 +02:00
|
|
|
name = vpi_get_str(vpiName, item);
|
2007-11-20 20:33:06 +01:00
|
|
|
prefix = is_escaped_id(name) ? "\\" : "";
|
2004-10-04 03:10:51 +02:00
|
|
|
|
2009-06-25 19:48:05 +02:00
|
|
|
/* Some signals can have an alias so handle that. */
|
2001-10-14 20:32:06 +02:00
|
|
|
nexus_id = vpi_get(_vpiNexusId, item);
|
2001-10-15 03:50:23 +02:00
|
|
|
|
2009-06-25 19:48:05 +02:00
|
|
|
ident = 0;
|
|
|
|
|
if (nexus_id) ident = find_nexus_ident(nexus_id);
|
2004-10-04 03:10:51 +02:00
|
|
|
|
2001-10-14 20:32:06 +02:00
|
|
|
if (!ident) {
|
|
|
|
|
ident = strdup(vcdid);
|
|
|
|
|
gen_new_vcd_id();
|
2004-10-04 03:10:51 +02:00
|
|
|
|
2007-12-11 01:14:02 +01:00
|
|
|
if (nexus_id) set_nexus_ident(nexus_id, ident);
|
2004-10-04 03:10:51 +02:00
|
|
|
|
2009-06-25 19:48:05 +02:00
|
|
|
/* Add a callback for the signal. */
|
2001-10-14 20:32:06 +02:00
|
|
|
info = malloc(sizeof(*info));
|
1999-11-28 01:56:08 +01:00
|
|
|
|
2001-10-14 20:32:06 +02:00
|
|
|
info->time.type = vpiSimTime;
|
|
|
|
|
info->item = item;
|
|
|
|
|
info->ident = ident;
|
2003-04-27 04:22:27 +02:00
|
|
|
info->scheduled = 0;
|
2001-09-30 07:18:46 +02:00
|
|
|
|
2001-10-14 20:32:06 +02:00
|
|
|
cb.time = &info->time;
|
|
|
|
|
cb.user_data = (char*)info;
|
2001-10-25 06:19:53 +02:00
|
|
|
cb.value = NULL;
|
2001-10-14 20:32:06 +02:00
|
|
|
cb.obj = item;
|
|
|
|
|
cb.reason = cbValueChange;
|
2003-04-27 04:22:27 +02:00
|
|
|
cb.cb_rtn = variable_cb_1;
|
|
|
|
|
|
2009-06-16 22:55:30 +02:00
|
|
|
info->dmp_next = 0;
|
|
|
|
|
info->next = vcd_list;
|
2001-10-14 20:32:06 +02:00
|
|
|
vcd_list = info;
|
2001-09-30 07:18:46 +02:00
|
|
|
|
2001-10-14 20:32:06 +02:00
|
|
|
info->cb = vpi_register_cb(&cb);
|
|
|
|
|
}
|
2004-10-04 03:10:51 +02:00
|
|
|
|
2009-06-25 19:48:05 +02:00
|
|
|
/* Named events do not have a size, but other tools use
|
|
|
|
|
* a size of 1 and some viewers do not accept a width of
|
|
|
|
|
* zero so we will also use a width of one for events. */
|
|
|
|
|
if (item_type == vpiNamedEvent) size = 1;
|
|
|
|
|
else size = vpi_get(vpiSize, item);
|
|
|
|
|
|
2007-11-20 20:33:06 +01:00
|
|
|
fprintf(dump_file, "$var %s %u %s %s%s",
|
2009-06-25 19:48:05 +02:00
|
|
|
type, size, ident, prefix, name);
|
|
|
|
|
|
|
|
|
|
/* Add a range for vectored values. */
|
2010-06-02 01:48:46 +02:00
|
|
|
if (size > 1 || vpi_get(vpiLeftRange, item) != 0) {
|
2009-12-10 21:49:39 +01:00
|
|
|
fprintf(dump_file, " [%i:%i]",
|
|
|
|
|
(int)vpi_get(vpiLeftRange, item),
|
|
|
|
|
(int)vpi_get(vpiRightRange, item));
|
2003-08-23 01:14:26 +02:00
|
|
|
}
|
2003-04-27 04:22:27 +02:00
|
|
|
|
2009-06-25 19:48:05 +02:00
|
|
|
fprintf(dump_file, " $end\n");
|
2003-02-11 06:21:33 +01:00
|
|
|
break;
|
|
|
|
|
|
2022-05-16 03:47:18 +02:00
|
|
|
case vpiParameter:
|
|
|
|
|
|
|
|
|
|
/* If we are skipping all pamaeters then just return. */
|
|
|
|
|
if (skip) return;
|
|
|
|
|
|
|
|
|
|
size = vpi_get(vpiSize, item);
|
|
|
|
|
|
|
|
|
|
/* Declare the parameter in the VCD file. */
|
|
|
|
|
name = vpi_get_str(vpiName, item);
|
|
|
|
|
prefix = is_escaped_id(name) ? "\\" : "";
|
|
|
|
|
|
|
|
|
|
ident = strdup(vcdid);
|
|
|
|
|
gen_new_vcd_id();
|
|
|
|
|
|
|
|
|
|
/* Make an info item to go in the vcd_const_list. */
|
|
|
|
|
info = malloc(sizeof(*info));
|
|
|
|
|
info->item = item;
|
|
|
|
|
info->ident = ident;
|
|
|
|
|
info->scheduled = 0;
|
|
|
|
|
info->dmp_next = 0;
|
|
|
|
|
info->next = vcd_const_list;
|
|
|
|
|
vcd_const_list = info;
|
|
|
|
|
info->cb = NULL;
|
|
|
|
|
|
|
|
|
|
/* Generate the $var record. Now the parameter is declared. */
|
|
|
|
|
fprintf(dump_file, "$var %s %u %s %s%s $end\n",
|
|
|
|
|
type, size, ident, prefix, name);
|
|
|
|
|
break;
|
|
|
|
|
|
2009-06-25 19:48:05 +02:00
|
|
|
case vpiModule:
|
2013-07-17 19:55:46 +02:00
|
|
|
case vpiGenScope:
|
2009-06-25 19:48:05 +02:00
|
|
|
case vpiFunction:
|
2013-07-17 19:55:46 +02:00
|
|
|
case vpiTask:
|
|
|
|
|
case vpiNamedBegin:
|
2009-06-25 19:48:05 +02:00
|
|
|
case vpiNamedFork:
|
2001-10-15 03:50:23 +02:00
|
|
|
|
2001-10-14 20:32:06 +02:00
|
|
|
if (depth > 0) {
|
2013-04-15 20:53:07 +02:00
|
|
|
/* list of types to iterate upon */
|
|
|
|
|
static int types[] = {
|
|
|
|
|
/* Value */
|
|
|
|
|
vpiNamedEvent,
|
|
|
|
|
vpiNet,
|
2022-05-16 03:47:18 +02:00
|
|
|
vpiParameter,
|
2013-04-15 20:53:07 +02:00
|
|
|
vpiReg,
|
|
|
|
|
vpiVariables,
|
|
|
|
|
/* Scope */
|
|
|
|
|
vpiFunction,
|
2013-07-17 19:55:46 +02:00
|
|
|
vpiGenScope,
|
2013-04-15 20:53:07 +02:00
|
|
|
vpiModule,
|
|
|
|
|
vpiNamedBegin,
|
|
|
|
|
vpiNamedFork,
|
|
|
|
|
vpiTask,
|
|
|
|
|
-1
|
|
|
|
|
};
|
|
|
|
|
int i;
|
2009-06-25 19:48:05 +02:00
|
|
|
int nskip = (vcd_names_search(&vcd_tab, fullname) != 0);
|
2001-10-14 20:32:06 +02:00
|
|
|
|
2009-06-25 19:48:05 +02:00
|
|
|
/* We have to always scan the scope because the
|
|
|
|
|
* depth could be different for this call. */
|
|
|
|
|
if (nskip) {
|
|
|
|
|
vpi_printf("VCD warning: ignoring signals in "
|
|
|
|
|
"previously scanned scope %s.\n", fullname);
|
2009-06-25 21:46:46 +02:00
|
|
|
} else {
|
|
|
|
|
vcd_names_add(&vcd_tab, fullname);
|
|
|
|
|
}
|
2001-10-15 03:50:23 +02:00
|
|
|
|
|
|
|
|
name = vpi_get_str(vpiName, item);
|
|
|
|
|
fprintf(dump_file, "$scope %s %s $end\n", type, name);
|
2002-07-12 04:08:10 +02:00
|
|
|
|
|
|
|
|
for (i=0; types[i]>0; i++) {
|
|
|
|
|
vpiHandle hand;
|
2009-06-25 19:48:05 +02:00
|
|
|
vpiHandle argv = vpi_iterate(types[i], item);
|
2002-07-12 04:08:10 +02:00
|
|
|
while (argv && (hand = vpi_scan(argv))) {
|
2009-06-25 21:46:46 +02:00
|
|
|
scan_item(depth-1, hand, nskip);
|
2001-07-16 20:53:16 +02:00
|
|
|
}
|
2000-04-09 06:18:16 +02:00
|
|
|
}
|
2004-10-04 03:10:51 +02:00
|
|
|
|
2009-06-25 19:48:05 +02:00
|
|
|
/* Sort any signals that we added above. */
|
2001-10-15 03:50:23 +02:00
|
|
|
fprintf(dump_file, "$upscope $end\n");
|
1999-11-07 21:33:30 +01:00
|
|
|
}
|
2001-10-14 20:32:06 +02:00
|
|
|
break;
|
2020-11-29 21:41:34 +01:00
|
|
|
|
|
|
|
|
case vpiPackage:
|
|
|
|
|
vpi_printf("VCD warning: $dumpvars: Package (%s) is not dumpable "
|
|
|
|
|
"with VCD.\n", vpi_get_str(vpiFullName, item));
|
|
|
|
|
break;
|
1999-11-07 21:33:30 +01:00
|
|
|
}
|
1999-11-28 01:56:08 +01:00
|
|
|
}
|
|
|
|
|
|
2008-06-04 02:12:27 +02:00
|
|
|
static int draw_scope(vpiHandle item, vpiHandle callh)
|
2001-10-15 03:50:23 +02:00
|
|
|
{
|
|
|
|
|
int depth;
|
2001-10-26 04:29:10 +02:00
|
|
|
const char *name;
|
2010-09-27 20:03:43 +02:00
|
|
|
const char *type;
|
2001-10-15 03:50:23 +02:00
|
|
|
|
|
|
|
|
vpiHandle scope = vpi_handle(vpiScope, item);
|
2007-12-11 01:14:02 +01:00
|
|
|
if (!scope) return 0;
|
2004-10-04 03:10:51 +02:00
|
|
|
|
2008-06-04 02:12:27 +02:00
|
|
|
depth = 1 + draw_scope(scope, callh);
|
2001-10-15 03:50:23 +02:00
|
|
|
name = vpi_get_str(vpiName, scope);
|
|
|
|
|
|
2007-12-15 02:40:55 +01:00
|
|
|
switch (vpi_get(vpiType, scope)) {
|
2001-10-15 03:50:23 +02:00
|
|
|
case vpiNamedBegin: type = "begin"; break;
|
2013-07-17 19:55:46 +02:00
|
|
|
case vpiGenScope: type = "begin"; break;
|
2001-10-15 03:50:23 +02:00
|
|
|
case vpiTask: type = "task"; break;
|
|
|
|
|
case vpiFunction: type = "function"; break;
|
|
|
|
|
case vpiNamedFork: type = "fork"; break;
|
2007-12-15 02:40:55 +01:00
|
|
|
case vpiModule: type = "module"; break;
|
|
|
|
|
default:
|
2009-12-10 21:49:39 +01:00
|
|
|
type = "invalid";
|
Rework $plusarg routines.
This patch addresses a number of issues:
Rewrote the $test$plusargs and $value$plusargs routines to have
better error/warning messages, to support runtime strings, to
correctly load bit based values (truncating, padding, negative
value), added support for the real formats using strtod() and
added "x/X" as an alias for "h/H" to match the other part of
Icarus.
Rewrite the vpip_{bin,oct,hex}_str_to_vec4 routines to ignore
embedded "_" characters. Add support for a negative value and
set the entire value to 'bx if an invalid digit is found. A
warning is printed for this case.
Rewrite vpip_dec_str_to_vec4 to ignore embedded "_" characters,
to support a single "x" or "z" constant and to return 'bx if an
invalid digit is found. A warning is printed for this case.
It simplifies the system task/functions error/warning messages.
It removes the signed flag for the bin and dec string conversions.
This was not being used (was always false) and the new negative
value support makes this obsolete.
Add support for a real variable to handle Bin, Oct, Dec and Hex
strings. They are converted into a vvp_vector4_t which is then
converted to a real value.
Add support for setting a bit based value using a real value.
Removed an unneeded rfp signal in vpip_make_reg()
2008-11-13 22:28:19 +01:00
|
|
|
vpi_printf("VCD Error: %s:%d: $dumpvars: Unsupported scope "
|
2008-06-04 02:12:27 +02:00
|
|
|
"type (%d)\n", vpi_get_str(vpiFile, callh),
|
2009-12-10 21:49:39 +01:00
|
|
|
(int)vpi_get(vpiLineNo, callh),
|
|
|
|
|
(int)vpi_get(vpiType, item));
|
2007-12-15 02:40:55 +01:00
|
|
|
assert(0);
|
2001-10-15 03:50:23 +02:00
|
|
|
}
|
2004-10-04 03:10:51 +02:00
|
|
|
|
2001-10-15 03:50:23 +02:00
|
|
|
fprintf(dump_file, "$scope %s %s $end\n", type, name);
|
|
|
|
|
|
|
|
|
|
return depth;
|
|
|
|
|
}
|
|
|
|
|
|
2010-10-04 18:31:01 +02:00
|
|
|
static PLI_INT32 sys_dumpvars_calltf(ICARUS_VPI_CONST PLI_BYTE8*name)
|
1999-11-28 01:56:08 +01:00
|
|
|
{
|
2007-12-11 01:14:02 +01:00
|
|
|
vpiHandle callh = vpi_handle(vpiSysTfCall, 0);
|
|
|
|
|
vpiHandle argv = vpi_iterate(vpiArgument, callh);
|
|
|
|
|
vpiHandle item;
|
2000-06-03 04:22:15 +02:00
|
|
|
s_vpi_value value;
|
2007-12-11 01:14:02 +01:00
|
|
|
unsigned depth = 0;
|
1999-11-28 01:56:08 +01:00
|
|
|
|
2014-07-09 23:16:57 +02:00
|
|
|
(void)name; /* Parameter is not used. */
|
|
|
|
|
|
2000-07-31 05:34:31 +02:00
|
|
|
if (dump_file == 0) {
|
2008-06-04 02:12:27 +02:00
|
|
|
open_dumpfile(callh);
|
2009-01-13 18:57:12 +01:00
|
|
|
if (dump_file == 0) {
|
2010-04-30 03:21:13 +02:00
|
|
|
if (argv) vpi_free_object(argv);
|
2009-01-13 18:57:12 +01:00
|
|
|
return 0;
|
|
|
|
|
}
|
2001-09-30 07:18:46 +02:00
|
|
|
}
|
|
|
|
|
|
2009-01-13 18:57:12 +01:00
|
|
|
if (install_dumpvars_callback()) {
|
2010-04-30 03:21:13 +02:00
|
|
|
if (argv) vpi_free_object(argv);
|
2009-01-13 18:57:12 +01:00
|
|
|
return 0;
|
|
|
|
|
}
|
2001-10-14 20:32:06 +02:00
|
|
|
|
2007-12-11 01:14:02 +01:00
|
|
|
/* Get the depth if it exists. */
|
|
|
|
|
if (argv) {
|
|
|
|
|
value.format = vpiIntVal;
|
|
|
|
|
vpi_get_value(vpi_scan(argv), &value);
|
|
|
|
|
depth = value.value.integer;
|
|
|
|
|
}
|
|
|
|
|
if (!depth) depth = 10000;
|
2000-06-03 04:22:15 +02:00
|
|
|
|
2021-04-21 10:08:26 +02:00
|
|
|
/* This dumps all the instances in the design if none are given. */
|
2007-12-11 01:14:02 +01:00
|
|
|
if (!argv || !(item = vpi_scan(argv))) {
|
2021-04-21 10:08:26 +02:00
|
|
|
argv = vpi_iterate(vpiInstance, 0x0);
|
|
|
|
|
assert(argv); /* There must be at least one top level instance. */
|
2007-12-11 01:14:02 +01:00
|
|
|
item = vpi_scan(argv);
|
2001-10-14 20:32:06 +02:00
|
|
|
}
|
2000-01-13 05:48:50 +01:00
|
|
|
|
2007-12-11 01:14:02 +01:00
|
|
|
for ( ; item; item = vpi_scan(argv)) {
|
2009-06-25 21:46:46 +02:00
|
|
|
char *scname;
|
|
|
|
|
const char *fullname;
|
2007-11-22 03:22:38 +01:00
|
|
|
int add_var = 0;
|
2008-09-30 03:06:47 +02:00
|
|
|
int dep;
|
2009-09-16 02:09:24 +02:00
|
|
|
PLI_INT32 item_type = vpi_get(vpiType, item);
|
2008-09-04 18:41:51 +02:00
|
|
|
|
2007-11-22 03:22:38 +01:00
|
|
|
/* If this is a signal make sure it has not already
|
|
|
|
|
* been included. */
|
2009-09-16 02:09:24 +02:00
|
|
|
switch (item_type) {
|
2007-11-22 03:22:38 +01:00
|
|
|
case vpiIntegerVar:
|
2011-09-06 18:23:42 +02:00
|
|
|
case vpiBitVar:
|
|
|
|
|
case vpiByteVar:
|
|
|
|
|
case vpiShortIntVar:
|
|
|
|
|
case vpiIntVar:
|
|
|
|
|
case vpiLongIntVar:
|
2008-06-04 02:12:27 +02:00
|
|
|
case vpiMemoryWord:
|
2009-06-25 19:48:05 +02:00
|
|
|
case vpiNamedEvent:
|
2007-11-22 03:22:38 +01:00
|
|
|
case vpiNet:
|
2009-06-25 19:48:05 +02:00
|
|
|
case vpiParameter:
|
2007-11-22 03:22:38 +01:00
|
|
|
case vpiRealVar:
|
|
|
|
|
case vpiReg:
|
|
|
|
|
case vpiTimeVar:
|
2009-06-25 21:46:46 +02:00
|
|
|
/* Warn if the variables scope (which includes the
|
|
|
|
|
* variable) or the variable itself was already
|
2009-09-16 02:09:24 +02:00
|
|
|
* included. A scope does not automatically include
|
|
|
|
|
* memory words so do not check the scope for them. */
|
2009-06-25 21:46:46 +02:00
|
|
|
scname = strdup(vpi_get_str(vpiFullName,
|
|
|
|
|
vpi_handle(vpiScope, item)));
|
|
|
|
|
fullname = vpi_get_str(vpiFullName, item);
|
2010-05-23 23:30:48 +02:00
|
|
|
if (((item_type != vpiMemoryWord) &&
|
2009-09-16 02:09:24 +02:00
|
|
|
vcd_names_search(&vcd_tab, scname)) ||
|
2009-06-25 21:46:46 +02:00
|
|
|
vcd_names_search(&vcd_var, fullname)) {
|
2008-06-04 02:12:27 +02:00
|
|
|
vpi_printf("VCD warning: skipping signal %s, "
|
|
|
|
|
"it was previously included.\n",
|
2009-06-25 21:46:46 +02:00
|
|
|
fullname);
|
2009-08-12 01:35:49 +02:00
|
|
|
free(scname);
|
2007-11-22 03:22:38 +01:00
|
|
|
continue;
|
|
|
|
|
} else {
|
|
|
|
|
add_var = 1;
|
|
|
|
|
}
|
2009-06-25 21:46:46 +02:00
|
|
|
free(scname);
|
2007-11-22 03:22:38 +01:00
|
|
|
}
|
2001-10-15 03:50:23 +02:00
|
|
|
|
2008-09-30 03:06:47 +02:00
|
|
|
dep = draw_scope(item, callh);
|
2001-10-15 03:50:23 +02:00
|
|
|
|
2009-06-25 21:46:46 +02:00
|
|
|
scan_item(depth, item, 0);
|
2010-05-22 23:53:16 +02:00
|
|
|
/* The scope list must be sorted after we scan an item. */
|
|
|
|
|
vcd_names_sort(&vcd_tab);
|
2004-10-04 03:10:51 +02:00
|
|
|
|
2007-12-11 01:14:02 +01:00
|
|
|
while (dep--) fprintf(dump_file, "$upscope $end\n");
|
2007-11-22 03:22:38 +01:00
|
|
|
|
|
|
|
|
/* Add this signal to the variable list so we can verify it
|
|
|
|
|
* is not included twice. This must be done after it has
|
|
|
|
|
* been added */
|
|
|
|
|
if (add_var) {
|
|
|
|
|
vcd_names_add(&vcd_var, vpi_get_str(vpiFullName, item));
|
|
|
|
|
vcd_names_sort(&vcd_var);
|
|
|
|
|
}
|
2001-10-14 20:32:06 +02:00
|
|
|
}
|
1999-11-07 21:33:30 +01:00
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2014-07-08 21:12:54 +02:00
|
|
|
void sys_vcd_register(void)
|
1999-11-07 21:33:30 +01:00
|
|
|
{
|
|
|
|
|
s_vpi_systf_data tf_data;
|
2010-04-12 08:39:08 +02:00
|
|
|
vpiHandle res;
|
2022-03-11 16:45:46 +01:00
|
|
|
int idx;
|
|
|
|
|
struct t_vpi_vlog_info vlog_info;
|
|
|
|
|
|
|
|
|
|
/* Scan the extended arguments */
|
|
|
|
|
vpi_get_vlog_info(&vlog_info);
|
|
|
|
|
|
|
|
|
|
for (idx = 0 ; idx < vlog_info.argc ; idx += 1) {
|
|
|
|
|
if (strcmp(vlog_info.argv[idx],"-no-date") == 0) {
|
|
|
|
|
dump_no_date = 1;
|
|
|
|
|
}
|
|
|
|
|
}
|
1999-11-07 21:33:30 +01:00
|
|
|
|
2007-12-11 01:14:02 +01:00
|
|
|
/* All the compiletf routines are located in vcd_priv.c. */
|
|
|
|
|
|
1999-11-07 21:33:30 +01:00
|
|
|
tf_data.type = vpiSysTask;
|
|
|
|
|
tf_data.tfname = "$dumpall";
|
|
|
|
|
tf_data.calltf = sys_dumpall_calltf;
|
2008-06-04 02:12:27 +02:00
|
|
|
tf_data.compiletf = sys_no_arg_compiletf;
|
1999-11-07 21:33:30 +01:00
|
|
|
tf_data.sizetf = 0;
|
|
|
|
|
tf_data.user_data = "$dumpall";
|
2010-04-12 08:39:08 +02:00
|
|
|
res = vpi_register_systf(&tf_data);
|
|
|
|
|
vpip_make_systf_system_defined(res);
|
1999-11-07 21:33:30 +01:00
|
|
|
|
|
|
|
|
tf_data.type = vpiSysTask;
|
|
|
|
|
tf_data.tfname = "$dumpfile";
|
|
|
|
|
tf_data.calltf = sys_dumpfile_calltf;
|
2008-06-14 05:46:18 +02:00
|
|
|
tf_data.compiletf = sys_one_string_arg_compiletf;
|
1999-11-07 21:33:30 +01:00
|
|
|
tf_data.sizetf = 0;
|
|
|
|
|
tf_data.user_data = "$dumpfile";
|
2010-04-12 08:39:08 +02:00
|
|
|
res = vpi_register_systf(&tf_data);
|
|
|
|
|
vpip_make_systf_system_defined(res);
|
1999-11-07 21:33:30 +01:00
|
|
|
|
2004-02-15 21:46:01 +01:00
|
|
|
tf_data.type = vpiSysTask;
|
|
|
|
|
tf_data.tfname = "$dumpflush";
|
|
|
|
|
tf_data.calltf = sys_dumpflush_calltf;
|
2008-06-04 02:12:27 +02:00
|
|
|
tf_data.compiletf = sys_no_arg_compiletf;
|
2004-02-15 21:46:01 +01:00
|
|
|
tf_data.sizetf = 0;
|
|
|
|
|
tf_data.user_data = "$dumpflush";
|
2010-04-12 08:39:08 +02:00
|
|
|
res = vpi_register_systf(&tf_data);
|
|
|
|
|
vpip_make_systf_system_defined(res);
|
2004-02-15 21:46:01 +01:00
|
|
|
|
2007-10-09 06:01:25 +02:00
|
|
|
tf_data.type = vpiSysTask;
|
|
|
|
|
tf_data.tfname = "$dumplimit";
|
|
|
|
|
tf_data.calltf = sys_dumplimit_calltf;
|
2008-06-06 04:25:19 +02:00
|
|
|
tf_data.compiletf = sys_one_numeric_arg_compiletf;
|
2007-10-09 06:01:25 +02:00
|
|
|
tf_data.sizetf = 0;
|
|
|
|
|
tf_data.user_data = "$dumplimit";
|
2010-04-12 08:39:08 +02:00
|
|
|
res = vpi_register_systf(&tf_data);
|
|
|
|
|
vpip_make_systf_system_defined(res);
|
2007-10-09 06:01:25 +02:00
|
|
|
|
2007-12-11 01:14:02 +01:00
|
|
|
tf_data.type = vpiSysTask;
|
|
|
|
|
tf_data.tfname = "$dumpoff";
|
|
|
|
|
tf_data.calltf = sys_dumpoff_calltf;
|
2008-06-04 02:12:27 +02:00
|
|
|
tf_data.compiletf = sys_no_arg_compiletf;
|
2007-12-11 01:14:02 +01:00
|
|
|
tf_data.sizetf = 0;
|
|
|
|
|
tf_data.user_data = "$dumpoff";
|
2010-04-12 08:39:08 +02:00
|
|
|
res = vpi_register_systf(&tf_data);
|
|
|
|
|
vpip_make_systf_system_defined(res);
|
2007-12-11 01:14:02 +01:00
|
|
|
|
|
|
|
|
tf_data.type = vpiSysTask;
|
|
|
|
|
tf_data.tfname = "$dumpon";
|
|
|
|
|
tf_data.calltf = sys_dumpon_calltf;
|
2008-06-04 02:12:27 +02:00
|
|
|
tf_data.compiletf = sys_no_arg_compiletf;
|
2007-12-11 01:14:02 +01:00
|
|
|
tf_data.sizetf = 0;
|
|
|
|
|
tf_data.user_data = "$dumpon";
|
2010-04-12 08:39:08 +02:00
|
|
|
res = vpi_register_systf(&tf_data);
|
|
|
|
|
vpip_make_systf_system_defined(res);
|
2007-12-11 01:14:02 +01:00
|
|
|
|
1999-11-07 21:33:30 +01:00
|
|
|
tf_data.type = vpiSysTask;
|
|
|
|
|
tf_data.tfname = "$dumpvars";
|
|
|
|
|
tf_data.calltf = sys_dumpvars_calltf;
|
2007-12-11 01:14:02 +01:00
|
|
|
tf_data.compiletf = sys_dumpvars_compiletf;
|
1999-11-07 21:33:30 +01:00
|
|
|
tf_data.sizetf = 0;
|
|
|
|
|
tf_data.user_data = "$dumpvars";
|
2010-04-12 08:39:08 +02:00
|
|
|
res = vpi_register_systf(&tf_data);
|
|
|
|
|
vpip_make_systf_system_defined(res);
|
1999-11-07 21:33:30 +01:00
|
|
|
}
|