2003-09-01 06:04:03 +02:00
|
|
|
/*
|
2025-10-13 02:35:15 +02:00
|
|
|
* Copyright (c) 2003-2025 Stephen Williams (steve@icarus.com)
|
2003-09-01 06:04:03 +02: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.
|
2003-09-01 06:04:03 +02:00
|
|
|
*/
|
|
|
|
|
|
2010-05-17 18:38:23 +02:00
|
|
|
/* The sys_priv.h include must be before the lxt2_write.h include! */
|
2003-09-30 03:33:39 +02:00
|
|
|
# include "sys_priv.h"
|
2010-05-17 18:38:23 +02:00
|
|
|
# include "lxt2_write.h"
|
2009-06-16 22:55:30 +02:00
|
|
|
# include "vcd_priv.h"
|
2003-09-01 06:04:03 +02:00
|
|
|
|
|
|
|
|
/*
|
2010-06-02 01:48:46 +02:00
|
|
|
* This file contains the implementations of the LXT2 related functions.
|
2003-09-01 06:04:03 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
# include <stdio.h>
|
|
|
|
|
# include <stdlib.h>
|
|
|
|
|
# include <string.h>
|
|
|
|
|
# include <time.h>
|
|
|
|
|
# include "stringheap.h"
|
2010-01-09 05:20:26 +01:00
|
|
|
# include <assert.h>
|
2010-10-24 00:52:56 +02:00
|
|
|
# include "ivl_alloc.h"
|
2003-09-01 06:04:03 +02:00
|
|
|
|
|
|
|
|
|
2009-06-16 22:55:30 +02:00
|
|
|
static struct lxt2_wr_trace *dump_file = NULL;
|
|
|
|
|
|
2010-01-09 05:20:26 +01:00
|
|
|
static void* lxt2_thread(void*arg);
|
|
|
|
|
|
2016-09-25 21:43:58 +02:00
|
|
|
static struct t_vpi_time zero_delay = { vpiSimTime, 0, 0, 0.0 };
|
|
|
|
|
|
2010-01-10 20:41:51 +01:00
|
|
|
/*
|
|
|
|
|
* Manage a table of all the dump-enabled vcd item. The cells of this
|
|
|
|
|
* table are allocated incrementally, but are released all at once, so
|
|
|
|
|
* we can allocate the items in chunks.
|
|
|
|
|
*/
|
2009-06-16 22:55:30 +02:00
|
|
|
struct vcd_info {
|
|
|
|
|
vpiHandle item;
|
|
|
|
|
vpiHandle cb;
|
|
|
|
|
struct lxt2_wr_symbol *sym;
|
|
|
|
|
struct vcd_info *dmp_next;
|
|
|
|
|
};
|
|
|
|
|
|
2010-01-10 20:41:51 +01:00
|
|
|
struct vcd_info_chunk {
|
|
|
|
|
struct vcd_info_chunk*chunk_next;
|
|
|
|
|
uint16_t chunk_fill;
|
|
|
|
|
struct vcd_info data[0x10000];
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct vcd_info_chunk*info_chunk_list = 0;
|
|
|
|
|
|
2025-10-13 02:35:15 +02:00
|
|
|
static struct vcd_info*new_vcd_info(void)
|
2010-01-10 20:41:51 +01:00
|
|
|
{
|
|
|
|
|
struct vcd_info_chunk*cur_chunk = info_chunk_list;
|
|
|
|
|
if (cur_chunk == 0 || cur_chunk->chunk_fill == 0xffff) {
|
|
|
|
|
struct vcd_info_chunk*tmp = calloc(1, sizeof(struct vcd_info_chunk));
|
|
|
|
|
tmp->chunk_fill = 0;
|
|
|
|
|
tmp->chunk_next = cur_chunk;
|
|
|
|
|
info_chunk_list = cur_chunk = tmp;
|
|
|
|
|
return info_chunk_list->data + 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
cur_chunk->chunk_fill += 1;
|
2010-01-11 00:01:51 +01:00
|
|
|
struct vcd_info*ptr = cur_chunk->data + cur_chunk->chunk_fill;
|
2010-01-10 20:41:51 +01:00
|
|
|
return ptr;
|
|
|
|
|
}
|
|
|
|
|
|
2025-10-13 02:35:15 +02:00
|
|
|
static void functor_all_vcd_info( void (*fun) (struct vcd_info*info) )
|
2010-01-10 20:41:51 +01:00
|
|
|
{
|
|
|
|
|
struct vcd_info_chunk*cur;
|
|
|
|
|
for (cur = info_chunk_list ; cur ; cur = cur->chunk_next) {
|
|
|
|
|
int idx;
|
|
|
|
|
struct vcd_info*ptr;
|
|
|
|
|
for (idx=0, ptr=cur->data ; idx <= cur->chunk_fill ; idx += 1, ptr += 1)
|
|
|
|
|
fun (ptr);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-10-13 02:35:15 +02:00
|
|
|
static void delete_all_vcd_info(void)
|
2010-01-10 20:41:51 +01:00
|
|
|
{
|
|
|
|
|
while (info_chunk_list) {
|
|
|
|
|
struct vcd_info_chunk*tmp = info_chunk_list->chunk_next;
|
|
|
|
|
free(info_chunk_list);
|
|
|
|
|
info_chunk_list = tmp;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Use this pointer to keep a list of vcd_info items that are
|
|
|
|
|
* scheduled to be dumped. Use the VCD_INFO_ENDP value as a trailer
|
|
|
|
|
* pointer instead of 0 so that individual vcd_info objects can tell
|
|
|
|
|
* if they are in the list already, even if they are at the end of the
|
|
|
|
|
* list.
|
|
|
|
|
*/
|
|
|
|
|
# define VCD_INFO_ENDP ((struct vcd_info*)1)
|
|
|
|
|
static struct vcd_info *vcd_dmp_list = VCD_INFO_ENDP;
|
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;
|
|
|
|
|
|
|
|
|
|
|
2003-09-01 06:04:03 +02:00
|
|
|
static enum lxm_optimum_mode_e {
|
|
|
|
|
LXM_NONE = 0,
|
|
|
|
|
LXM_SPACE = 1,
|
|
|
|
|
LXM_SPEED = 2
|
|
|
|
|
} lxm_optimum_mode = LXM_SPEED;
|
|
|
|
|
|
2004-02-06 19:23:30 +01:00
|
|
|
static off_t lxt2_file_size_limit = 0x40000000UL;
|
2003-09-01 06:04:03 +02:00
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* The lxt_scope head and current pointers are used to keep a scope
|
|
|
|
|
* stack that can be accessed from the bottom. The lxt_scope_head
|
|
|
|
|
* points to the first (bottom) item in the stack and
|
|
|
|
|
* lxt_scope_current points to the last (top) item in the stack. The
|
|
|
|
|
* push_scope and pop_scope methods manipulate the stack.
|
|
|
|
|
*/
|
|
|
|
|
struct lxt_scope
|
|
|
|
|
{
|
|
|
|
|
struct lxt_scope *next, *prev;
|
|
|
|
|
char *name;
|
|
|
|
|
int len;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static struct lxt_scope *lxt_scope_head=NULL, *lxt_scope_current=NULL;
|
|
|
|
|
|
|
|
|
|
static void push_scope(const char *name)
|
|
|
|
|
{
|
|
|
|
|
struct lxt_scope *t = (struct lxt_scope *)
|
|
|
|
|
calloc(1, sizeof(struct lxt_scope));
|
|
|
|
|
|
|
|
|
|
t->name = strdup(name);
|
|
|
|
|
t->len = strlen(name);
|
|
|
|
|
|
|
|
|
|
if(!lxt_scope_head) {
|
|
|
|
|
lxt_scope_head = lxt_scope_current = t;
|
|
|
|
|
} else {
|
|
|
|
|
lxt_scope_current->next = t;
|
|
|
|
|
t->prev = lxt_scope_current;
|
|
|
|
|
lxt_scope_current = t;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void pop_scope(void)
|
|
|
|
|
{
|
|
|
|
|
struct lxt_scope *t;
|
|
|
|
|
|
|
|
|
|
assert(lxt_scope_current);
|
|
|
|
|
|
|
|
|
|
t=lxt_scope_current->prev;
|
|
|
|
|
free(lxt_scope_current->name);
|
|
|
|
|
free(lxt_scope_current);
|
|
|
|
|
lxt_scope_current = t;
|
|
|
|
|
if (lxt_scope_current) {
|
|
|
|
|
lxt_scope_current->next = 0;
|
|
|
|
|
} else {
|
|
|
|
|
lxt_scope_head = 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* This function uses the scope stack to generate a hierarchical
|
|
|
|
|
* name. Scan the scope stack from the bottom up to construct the
|
|
|
|
|
* name.
|
|
|
|
|
*/
|
|
|
|
|
static char *create_full_name(const char *name)
|
|
|
|
|
{
|
|
|
|
|
char *n, *n2;
|
|
|
|
|
int len = 0;
|
2007-11-20 20:33:06 +01:00
|
|
|
int is_esc_id = is_escaped_id(name);
|
2003-09-01 06:04:03 +02:00
|
|
|
struct lxt_scope *t = lxt_scope_head;
|
|
|
|
|
|
|
|
|
|
/* Figure out how long the combined string will be. */
|
|
|
|
|
while(t) {
|
|
|
|
|
len+=t->len+1;
|
|
|
|
|
t=t->next;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
len += strlen(name) + 1;
|
2007-11-20 20:33:06 +01:00
|
|
|
if (is_esc_id) len += 1;
|
2003-09-01 06:04:03 +02:00
|
|
|
|
|
|
|
|
/* Allocate a string buffer. */
|
|
|
|
|
n = n2 = malloc(len);
|
|
|
|
|
|
|
|
|
|
t = lxt_scope_head;
|
|
|
|
|
while(t) {
|
|
|
|
|
strcpy(n2, t->name);
|
|
|
|
|
n2 += t->len;
|
|
|
|
|
*n2 = '.';
|
|
|
|
|
n2++;
|
|
|
|
|
t=t->next;
|
|
|
|
|
}
|
|
|
|
|
|
2007-11-20 20:33:06 +01:00
|
|
|
if (is_esc_id) {
|
|
|
|
|
*n2 = '\\';
|
|
|
|
|
n2++;
|
|
|
|
|
}
|
2003-09-01 06:04:03 +02:00
|
|
|
strcpy(n2, name);
|
|
|
|
|
n2 += strlen(n2);
|
|
|
|
|
assert( (n2 - n + 1) == len );
|
|
|
|
|
|
|
|
|
|
return n;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void show_this_item(struct vcd_info*info)
|
|
|
|
|
{
|
|
|
|
|
s_vpi_value value;
|
|
|
|
|
|
2009-02-25 01:47:46 +01:00
|
|
|
if (vpi_get(vpiType, info->item) == vpiRealVar) {
|
2003-09-01 06:04:03 +02:00
|
|
|
value.format = vpiRealVal;
|
|
|
|
|
vpi_get_value(info->item, &value);
|
2010-01-09 05:20:26 +01:00
|
|
|
vcd_work_emit_double(info->sym, value.value.real);
|
2003-09-01 06:04:03 +02:00
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
value.format = vpiBinStrVal;
|
|
|
|
|
vpi_get_value(info->item, &value);
|
2010-01-09 05:20:26 +01:00
|
|
|
vcd_work_emit_bits(info->sym, value.value.str);
|
2003-09-01 06:04:03 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void show_this_item_x(struct vcd_info*info)
|
|
|
|
|
{
|
|
|
|
|
if (vpi_get(vpiType,info->item) == vpiRealVar) {
|
|
|
|
|
/* Should write a NaN here? */
|
|
|
|
|
} else {
|
2010-01-09 05:20:26 +01:00
|
|
|
vcd_work_emit_bits(info->sym, "x");
|
2003-09-01 06:04:03 +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)
|
2003-09-01 06:04:03 +02:00
|
|
|
{
|
|
|
|
|
return dumpvars_status != 2;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* This function writes out all the traced variables, whether they
|
|
|
|
|
* changed or not.
|
|
|
|
|
*/
|
2014-07-09 00:31:34 +02:00
|
|
|
static void vcd_checkpoint(void)
|
2003-09-01 06:04:03 +02:00
|
|
|
{
|
2010-01-10 20:41:51 +01:00
|
|
|
functor_all_vcd_info( show_this_item );
|
2003-09-01 06:04:03 +02:00
|
|
|
}
|
|
|
|
|
|
2014-07-09 00:31:34 +02:00
|
|
|
static void vcd_checkpoint_x(void)
|
2003-09-01 06:04:03 +02:00
|
|
|
{
|
2010-01-10 20:41:51 +01:00
|
|
|
functor_all_vcd_info( show_this_item_x );
|
2003-09-01 06:04:03 +02:00
|
|
|
}
|
|
|
|
|
|
2006-10-30 23:45:36 +01:00
|
|
|
static PLI_INT32 variable_cb_2(p_cb_data cause)
|
2003-09-01 06:04:03 +02:00
|
|
|
{
|
2010-01-10 20:41:51 +01:00
|
|
|
assert(cause->time->type == vpiSimTime);
|
2003-09-30 03:33:39 +02:00
|
|
|
PLI_UINT64 now = timerec_to_time64(cause->time);
|
2004-10-04 03:10:51 +02:00
|
|
|
|
|
|
|
|
if (now != vcd_cur_time) {
|
2010-01-09 05:20:26 +01:00
|
|
|
vcd_work_set_time(now);
|
2003-09-01 06:04:03 +02:00
|
|
|
vcd_cur_time = now;
|
|
|
|
|
}
|
|
|
|
|
|
2010-01-10 20:41:51 +01:00
|
|
|
while (vcd_dmp_list != VCD_INFO_ENDP) {
|
|
|
|
|
struct vcd_info* info = vcd_dmp_list;
|
|
|
|
|
show_this_item(info);
|
|
|
|
|
vcd_dmp_list = info->dmp_next;
|
|
|
|
|
info->dmp_next = 0;
|
|
|
|
|
}
|
2003-09-01 06:04:03 +02:00
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2006-10-30 23:45:36 +01:00
|
|
|
static PLI_INT32 variable_cb_1(p_cb_data cause)
|
2003-09-01 06:04:03 +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-09-01 06:04:03 +02:00
|
|
|
if (dump_header_pending()) return 0;
|
2010-01-10 20:41:51 +01:00
|
|
|
if (info->dmp_next) return 0;
|
2003-09-01 06:04:03 +02:00
|
|
|
|
2007-10-09 06:01:25 +02:00
|
|
|
if ((dump_limit > 0) && (ftell(dump_file->handle) > dump_limit)) {
|
|
|
|
|
dump_is_full = 1;
|
|
|
|
|
vpi_printf("WARNING: Dump file limit (%ld bytes) "
|
|
|
|
|
"exceeded.\n", dump_limit);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2010-01-10 20:41:51 +01:00
|
|
|
if (vcd_dmp_list == VCD_INFO_ENDP) {
|
2003-09-01 06:04:03 +02:00
|
|
|
cb = *cause;
|
2016-09-25 21:43:58 +02:00
|
|
|
cb.time = &zero_delay;
|
2003-09-01 06:04:03 +02:00
|
|
|
cb.reason = cbReadOnlySynch;
|
|
|
|
|
cb.cb_rtn = variable_cb_2;
|
|
|
|
|
vpi_register_cb(&cb);
|
2004-10-04 03:10:51 +02:00
|
|
|
}
|
2003-09-01 06:04:03 +02:00
|
|
|
|
|
|
|
|
info->dmp_next = vcd_dmp_list;
|
|
|
|
|
vcd_dmp_list = info;
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2006-10-30 23:45:36 +01:00
|
|
|
static PLI_INT32 dumpvars_cb(p_cb_data cause)
|
2003-09-01 06:04:03 +02:00
|
|
|
{
|
2007-12-11 01:14:02 +01:00
|
|
|
if (dumpvars_status != 1) return 0;
|
2003-09-01 06:04:03 +02:00
|
|
|
|
|
|
|
|
dumpvars_status = 2;
|
|
|
|
|
|
2003-09-30 03:33:39 +02:00
|
|
|
dumpvars_time = timerec_to_time64(cause->time);
|
2003-09-01 06:04:03 +02:00
|
|
|
vcd_cur_time = dumpvars_time;
|
|
|
|
|
|
|
|
|
|
if (!dump_is_off) {
|
2010-01-09 05:20:26 +01:00
|
|
|
vcd_work_set_time(dumpvars_time);
|
2003-09-01 06:04:03 +02:00
|
|
|
vcd_checkpoint();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2007-11-09 00:56:10 +01:00
|
|
|
static PLI_INT32 finish_cb(p_cb_data cause)
|
|
|
|
|
{
|
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) {
|
2010-01-09 05:20:26 +01:00
|
|
|
vcd_work_set_time(dumpvars_time);
|
2007-11-09 00:56:10 +01:00
|
|
|
}
|
|
|
|
|
|
2010-01-09 05:20:26 +01:00
|
|
|
vcd_work_terminate();
|
2010-01-10 20:41:51 +01:00
|
|
|
delete_all_vcd_info();
|
2009-03-18 02:01:25 +01:00
|
|
|
|
2010-01-09 05:20:26 +01:00
|
|
|
vcd_scope_names_delete();
|
2009-03-18 02:01:25 +01:00
|
|
|
nexus_ident_delete();
|
2023-02-26 23:05:42 +01:00
|
|
|
vcd_free_dump_path();
|
2009-03-18 02:01:25 +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)
|
2003-09-01 06:04:03 +02:00
|
|
|
{
|
|
|
|
|
struct t_cb_data cb;
|
|
|
|
|
|
2007-12-11 01:14:02 +01:00
|
|
|
if (dumpvars_status == 1) return 0;
|
2003-09-01 06:04:03 +02:00
|
|
|
|
|
|
|
|
if (dumpvars_status == 2) {
|
2008-06-04 02:12:27 +02:00
|
|
|
vpi_printf("LXT2 warning: $dumpvars ignored, previously"
|
|
|
|
|
" called at simtime %" PLI_UINT64_FMT "\n",
|
|
|
|
|
dumpvars_time);
|
2003-09-01 06:04:03 +02:00
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
2016-09-25 21:43:58 +02:00
|
|
|
cb.time = &zero_delay;
|
2003-09-01 06:04:03 +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);
|
|
|
|
|
|
2003-09-01 06:04:03 +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)
|
2003-09-01 06:04:03 +02:00
|
|
|
{
|
|
|
|
|
s_vpi_time now;
|
2003-09-30 03:33:39 +02:00
|
|
|
PLI_UINT64 now64;
|
2003-09-01 06:04:03 +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;
|
2003-09-01 06:04:03 +02:00
|
|
|
|
|
|
|
|
dump_is_off = 1;
|
|
|
|
|
|
2007-12-11 01:14:02 +01:00
|
|
|
if (dump_file == 0) return 0;
|
|
|
|
|
if (dump_header_pending()) return 0;
|
2003-09-01 06:04:03 +02:00
|
|
|
|
|
|
|
|
now.type = vpiSimTime;
|
|
|
|
|
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) {
|
2010-01-09 05:20:26 +01:00
|
|
|
vcd_work_set_time(now64);
|
2009-02-25 01:47:46 +01:00
|
|
|
vcd_cur_time = now64;
|
2007-12-11 01:14:02 +01:00
|
|
|
}
|
2003-09-01 06:04:03 +02:00
|
|
|
|
2010-01-09 05:20:26 +01:00
|
|
|
vcd_work_dumpoff();
|
2003-09-01 06:04:03 +02:00
|
|
|
vcd_checkpoint_x();
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2010-10-04 18:31:01 +02:00
|
|
|
static PLI_INT32 sys_dumpon_calltf(ICARUS_VPI_CONST PLI_BYTE8*name)
|
2003-09-01 06:04:03 +02:00
|
|
|
{
|
|
|
|
|
s_vpi_time now;
|
2003-09-30 03:33:39 +02:00
|
|
|
PLI_UINT64 now64;
|
2003-09-01 06:04:03 +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;
|
2003-09-01 06:04:03 +02:00
|
|
|
|
|
|
|
|
dump_is_off = 0;
|
|
|
|
|
|
2007-12-11 01:14:02 +01:00
|
|
|
if (dump_file == 0) return 0;
|
|
|
|
|
if (dump_header_pending()) return 0;
|
2003-09-01 06:04:03 +02:00
|
|
|
|
|
|
|
|
now.type = vpiSimTime;
|
|
|
|
|
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) {
|
2010-01-09 05:20:26 +01:00
|
|
|
vcd_work_set_time(now64);
|
2009-02-25 01:47:46 +01:00
|
|
|
vcd_cur_time = now64;
|
2007-12-11 01:14:02 +01:00
|
|
|
}
|
2003-09-01 06:04:03 +02:00
|
|
|
|
2010-01-09 05:20:26 +01:00
|
|
|
vcd_work_dumpon();
|
2003-09-01 06:04:03 +02:00
|
|
|
vcd_checkpoint();
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2010-10-04 18:31:01 +02:00
|
|
|
static PLI_INT32 sys_dumpall_calltf(ICARUS_VPI_CONST PLI_BYTE8*name)
|
2003-09-01 06:04:03 +02:00
|
|
|
{
|
|
|
|
|
s_vpi_time now;
|
2003-09-30 03:33:39 +02:00
|
|
|
PLI_UINT64 now64;
|
2003-09-01 06:04:03 +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;
|
2003-09-01 06:04:03 +02:00
|
|
|
|
|
|
|
|
now.type = vpiSimTime;
|
|
|
|
|
vpi_get_time(0, &now);
|
2003-09-30 03:33:39 +02:00
|
|
|
now64 = timerec_to_time64(&now);
|
|
|
|
|
|
2009-02-25 01:47:46 +01:00
|
|
|
if (now64 > vcd_cur_time) {
|
2010-01-09 05:20:26 +01:00
|
|
|
vcd_work_set_time(now64);
|
2009-02-25 01:47:46 +01:00
|
|
|
vcd_cur_time = now64;
|
|
|
|
|
}
|
2003-09-01 06:04:03 +02:00
|
|
|
|
|
|
|
|
vcd_checkpoint();
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void *close_dumpfile(void)
|
|
|
|
|
{
|
2010-01-09 05:20:26 +01:00
|
|
|
vcd_work_terminate();
|
2003-09-01 06:04:03 +02:00
|
|
|
lxt2_wr_close(dump_file);
|
2009-06-16 22:55:30 +02:00
|
|
|
dump_file = NULL;
|
|
|
|
|
return NULL;
|
2003-09-01 06:04:03 +02:00
|
|
|
}
|
|
|
|
|
|
2008-06-04 02:12:27 +02:00
|
|
|
static void open_dumpfile(vpiHandle callh)
|
2003-09-01 06:04:03 +02:00
|
|
|
{
|
2009-08-02 19:10:45 +02:00
|
|
|
off_t use_file_size_limit = lxt2_file_size_limit;
|
2023-02-26 23:05:42 +01:00
|
|
|
char* use_dump_path = vcd_get_dump_path("lx2");
|
2007-12-11 01:14:02 +01:00
|
|
|
|
2023-02-26 23:05:42 +01:00
|
|
|
dump_file = lxt2_wr_init(use_dump_path);
|
2003-09-01 06:04:03 +02:00
|
|
|
|
2009-08-02 19:10:45 +02:00
|
|
|
if (getenv("LXT_FILE_SIZE_LIMIT")) {
|
|
|
|
|
const char*limit_string = getenv("LXT_FILE_SIZE_LIMIT");
|
|
|
|
|
char*ep;
|
|
|
|
|
use_file_size_limit = strtoul(limit_string,&ep,0);
|
|
|
|
|
if (use_file_size_limit == 0 || ep[0] != 0) {
|
|
|
|
|
vpi_printf("LXT2 Warning: %s:%d: LXT_FILE_SIZE_LIMIT is invalid: %s\n",
|
|
|
|
|
vpi_get_str(vpiFile, callh),
|
|
|
|
|
(int)vpi_get(vpiLineNo, callh),
|
|
|
|
|
limit_string);
|
|
|
|
|
use_file_size_limit = lxt2_file_size_limit;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2003-09-01 06:04:03 +02: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("LXT2 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();
|
2003-09-01 06:04:03 +02:00
|
|
|
return;
|
|
|
|
|
} else {
|
|
|
|
|
int prec = vpi_get(vpiTimePrecision, 0);
|
|
|
|
|
|
2008-06-04 02:12:27 +02:00
|
|
|
vpi_printf("LXT2 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
|
|
|
|
2003-09-01 06:04:03 +02:00
|
|
|
assert(prec >= -15);
|
|
|
|
|
lxt2_wr_set_timescale(dump_file, prec);
|
|
|
|
|
|
|
|
|
|
lxt2_wr_set_initial_value(dump_file, 'x');
|
|
|
|
|
lxt2_wr_set_compression_depth(dump_file, 4);
|
2003-09-10 19:53:42 +02:00
|
|
|
lxt2_wr_set_partial_on(dump_file, 1);
|
2009-08-02 19:10:45 +02:00
|
|
|
lxt2_wr_set_break_size(dump_file, use_file_size_limit);
|
2003-09-01 06:04:03 +02:00
|
|
|
|
2010-01-09 05:20:26 +01:00
|
|
|
vcd_work_start(lxt2_thread, 0);
|
2003-09-01 06:04:03 +02:00
|
|
|
atexit((void(*)(void))close_dumpfile);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2010-10-04 18:31:01 +02:00
|
|
|
static PLI_INT32 sys_dumpfile_calltf(ICARUS_VPI_CONST PLI_BYTE8*name)
|
2003-09-01 06:04:03 +02:00
|
|
|
{
|
2023-02-26 23:05:42 +01:00
|
|
|
(void)name;
|
|
|
|
|
return sys_dumpfile_common("LXT2", "lx2");
|
2003-09-01 06:04:03 +02:00
|
|
|
}
|
|
|
|
|
|
2004-02-15 21:46:01 +01:00
|
|
|
/*
|
|
|
|
|
* The LXT2 format is a binary format, but a $dumpflush causes what is
|
|
|
|
|
* in the binary file at the moment to be consistent with itself so
|
|
|
|
|
* that the waveforms can be read by another process. LXT2 normally
|
|
|
|
|
* writes checkpoints out, but this makes it happen at a specific
|
|
|
|
|
* time.
|
|
|
|
|
*/
|
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. */
|
2010-01-09 05:20:26 +01:00
|
|
|
if (dump_file) vcd_work_flush();
|
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. */
|
2007-12-11 01:14:02 +01:00
|
|
|
assert(argv);
|
2007-10-09 06:01:25 +02:00
|
|
|
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;
|
|
|
|
|
}
|
2004-02-15 21:46:01 +01:00
|
|
|
|
2003-09-01 06:04:03 +02:00
|
|
|
static void scan_item(unsigned depth, vpiHandle item, int skip)
|
|
|
|
|
{
|
2024-01-07 21:16:49 +01:00
|
|
|
static int dumpable_types[] = {
|
|
|
|
|
/* Value */
|
|
|
|
|
/* vpiNamedEvent, */
|
|
|
|
|
vpiNet,
|
|
|
|
|
/* vpiParameter, */
|
|
|
|
|
vpiReg,
|
|
|
|
|
vpiVariables,
|
|
|
|
|
/* Scope */
|
|
|
|
|
vpiFunction,
|
|
|
|
|
vpiGenScope,
|
|
|
|
|
vpiModule,
|
|
|
|
|
vpiNamedBegin,
|
|
|
|
|
vpiNamedFork,
|
|
|
|
|
vpiTask,
|
|
|
|
|
-1
|
|
|
|
|
};
|
|
|
|
|
|
2003-09-01 06:04:03 +02:00
|
|
|
struct t_cb_data cb;
|
|
|
|
|
struct vcd_info* info;
|
|
|
|
|
|
|
|
|
|
const char* name;
|
|
|
|
|
const char* ident;
|
|
|
|
|
int nexus_id;
|
|
|
|
|
|
|
|
|
|
switch (vpi_get(vpiType, item)) {
|
|
|
|
|
|
2008-06-04 02:12:27 +02:00
|
|
|
case vpiMemoryWord:
|
2009-04-16 20:57:00 +02:00
|
|
|
if (vpi_get(vpiConstantSelect, item) == 0) {
|
|
|
|
|
/* Turn a non-constant array word select into a
|
|
|
|
|
* constant word select. */
|
|
|
|
|
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-04-16 20:57:00 +02:00
|
|
|
}
|
2018-10-06 21:13:31 +02:00
|
|
|
// fallthrough
|
2009-04-16 20:57:00 +02:00
|
|
|
case vpiIntegerVar:
|
2011-09-06 18:23:42 +02:00
|
|
|
case vpiBitVar:
|
|
|
|
|
case vpiByteVar:
|
|
|
|
|
case vpiShortIntVar:
|
|
|
|
|
case vpiIntVar:
|
|
|
|
|
case vpiLongIntVar:
|
2003-09-01 06:04:03 +02:00
|
|
|
case vpiTimeVar:
|
2011-10-19 23:19:57 +02:00
|
|
|
case vpiReg:
|
|
|
|
|
case vpiNet:
|
2003-09-01 06:04:03 +02: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. */
|
|
|
|
|
if (vpi_get(vpiType, item) == vpiMemoryWord &&
|
|
|
|
|
vpi_handle_by_name(vpi_get_str(vpiFullName, item), 0)) {
|
|
|
|
|
vpi_printf("LXT2 warning: dumping array word %s will "
|
|
|
|
|
"conflict with an escaped identifier.\n",
|
|
|
|
|
vpi_get_str(vpiFullName, item));
|
|
|
|
|
}
|
|
|
|
|
|
2008-10-28 18:52:39 +01:00
|
|
|
if (skip || vpi_get(vpiAutomatic, item)) break;
|
2004-10-04 03:10:51 +02:00
|
|
|
|
2003-09-01 06:04:03 +02:00
|
|
|
name = vpi_get_str(vpiName, item);
|
|
|
|
|
nexus_id = vpi_get(_vpiNexusId, item);
|
|
|
|
|
if (nexus_id) {
|
|
|
|
|
ident = find_nexus_ident(nexus_id);
|
|
|
|
|
} else {
|
|
|
|
|
ident = 0;
|
|
|
|
|
}
|
2004-10-04 03:10:51 +02:00
|
|
|
|
2003-09-01 06:04:03 +02:00
|
|
|
if (!ident) {
|
|
|
|
|
char*tmp = create_full_name(name);
|
|
|
|
|
ident = strdup_sh(&name_heap, tmp);
|
|
|
|
|
free(tmp);
|
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);
|
2003-09-01 06:04:03 +02:00
|
|
|
|
2010-01-10 20:41:51 +01:00
|
|
|
info = new_vcd_info();
|
2003-09-01 06:04:03 +02:00
|
|
|
|
2009-06-16 22:55:30 +02:00
|
|
|
info->item = item;
|
|
|
|
|
info->sym = lxt2_wr_symbol_add(dump_file, ident,
|
|
|
|
|
0 /* array rows */,
|
|
|
|
|
vpi_get(vpiLeftRange, item),
|
|
|
|
|
vpi_get(vpiRightRange, item),
|
|
|
|
|
LXT2_WR_SYM_F_BITS);
|
2010-01-10 20:41:51 +01:00
|
|
|
info->dmp_next = 0;
|
2003-09-01 06:04:03 +02:00
|
|
|
|
2010-01-10 20:41:51 +01:00
|
|
|
cb.time = 0;
|
2003-09-01 06:04:03 +02:00
|
|
|
cb.user_data = (char*)info;
|
|
|
|
|
cb.value = NULL;
|
|
|
|
|
cb.obj = item;
|
|
|
|
|
cb.reason = cbValueChange;
|
|
|
|
|
cb.cb_rtn = variable_cb_1;
|
|
|
|
|
|
|
|
|
|
info->cb = vpi_register_cb(&cb);
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
char *n = create_full_name(name);
|
|
|
|
|
lxt2_wr_symbol_alias(dump_file, ident, n,
|
|
|
|
|
vpi_get(vpiSize, item)-1, 0);
|
|
|
|
|
free(n);
|
|
|
|
|
}
|
2004-10-04 03:10:51 +02:00
|
|
|
|
2003-09-01 06:04:03 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case vpiRealVar:
|
|
|
|
|
|
2008-10-28 18:52:39 +01:00
|
|
|
if (skip || vpi_get(vpiAutomatic, item)) break;
|
2003-09-01 06:04:03 +02:00
|
|
|
|
|
|
|
|
name = vpi_get_str(vpiName, item);
|
|
|
|
|
{ char*tmp = create_full_name(name);
|
|
|
|
|
ident = strdup_sh(&name_heap, tmp);
|
|
|
|
|
free(tmp);
|
|
|
|
|
}
|
2010-01-10 20:41:51 +01:00
|
|
|
info = new_vcd_info();
|
2003-09-01 06:04:03 +02:00
|
|
|
|
2009-02-25 01:47:46 +01:00
|
|
|
info->item = item;
|
|
|
|
|
info->sym = lxt2_wr_symbol_add(dump_file, ident,
|
|
|
|
|
0 /* array rows */,
|
|
|
|
|
vpi_get(vpiSize, item)-1,
|
|
|
|
|
0, LXT2_WR_SYM_F_DOUBLE);
|
2010-01-10 20:41:51 +01:00
|
|
|
info->dmp_next = 0;
|
2003-09-01 06:04:03 +02:00
|
|
|
|
2010-01-10 20:41:51 +01:00
|
|
|
cb.time = 0;
|
2003-09-01 06:04:03 +02:00
|
|
|
cb.user_data = (char*)info;
|
|
|
|
|
cb.value = NULL;
|
|
|
|
|
cb.obj = item;
|
|
|
|
|
cb.reason = cbValueChange;
|
|
|
|
|
cb.cb_rtn = variable_cb_1;
|
|
|
|
|
|
|
|
|
|
info->cb = vpi_register_cb(&cb);
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
2011-10-19 23:19:57 +02:00
|
|
|
case vpiModule:
|
2013-07-17 19:55:46 +02:00
|
|
|
case vpiGenScope:
|
2011-10-19 23:19:57 +02:00
|
|
|
case vpiFunction:
|
2013-07-17 19:55:46 +02:00
|
|
|
case vpiTask:
|
|
|
|
|
case vpiNamedBegin:
|
2011-10-19 23:19:57 +02:00
|
|
|
case vpiNamedFork:
|
2003-09-01 06:04:03 +02:00
|
|
|
|
|
|
|
|
if (depth > 0) {
|
2013-04-15 20:53:07 +02:00
|
|
|
const char* fullname = vpi_get_str(vpiFullName, item);
|
|
|
|
|
int i;
|
|
|
|
|
int nskip = vcd_scope_names_test(fullname);
|
2003-09-01 06:04:03 +02:00
|
|
|
|
|
|
|
|
#if 0
|
2008-06-04 02:12:27 +02:00
|
|
|
vpi_printf("LXT2 info: scanning scope %s, %u levels\n",
|
|
|
|
|
fullname, depth);
|
2003-09-01 06:04:03 +02:00
|
|
|
#endif
|
2004-10-04 03:10:51 +02:00
|
|
|
|
2013-04-15 20:53:07 +02:00
|
|
|
if (nskip) {
|
|
|
|
|
vpi_printf("LXT2 warning: ignoring signals in "
|
|
|
|
|
"previously scanned scope %s\n", fullname);
|
|
|
|
|
} else {
|
2010-01-09 05:20:26 +01:00
|
|
|
vcd_scope_names_add(fullname);
|
2013-04-15 20:53:07 +02:00
|
|
|
}
|
2003-09-01 06:04:03 +02:00
|
|
|
|
|
|
|
|
name = vpi_get_str(vpiName, item);
|
|
|
|
|
|
2011-10-19 23:19:57 +02:00
|
|
|
push_scope(name);
|
2004-10-04 03:10:51 +02:00
|
|
|
|
2024-01-07 21:16:49 +01:00
|
|
|
for (i=0; dumpable_types[i]>0; i++) {
|
2003-09-01 06:04:03 +02:00
|
|
|
vpiHandle hand;
|
2024-01-07 21:16:49 +01:00
|
|
|
vpiHandle argv = vpi_iterate(dumpable_types[i], item);
|
2003-09-01 06:04:03 +02:00
|
|
|
while (argv && (hand = vpi_scan(argv))) {
|
|
|
|
|
scan_item(depth-1, hand, nskip);
|
|
|
|
|
}
|
|
|
|
|
}
|
2004-10-04 03:10:51 +02:00
|
|
|
|
2003-09-01 06:04:03 +02:00
|
|
|
pop_scope();
|
|
|
|
|
}
|
|
|
|
|
break;
|
2004-10-04 03:10:51 +02:00
|
|
|
|
2020-11-29 21:41:34 +01:00
|
|
|
case vpiPackage:
|
2024-01-07 21:16:49 +01:00
|
|
|
// Don't print a warning for empty packages.
|
|
|
|
|
if (vcd_instance_contains_dumpable_items(dumpable_types, item))
|
|
|
|
|
vpi_printf("LXT2 warning: $dumpvars: Package (%s) is not dumpable "
|
|
|
|
|
"with LXT2.\n", vpi_get_str(vpiFullName, item));
|
2020-11-29 21:41:34 +01:00
|
|
|
break;
|
|
|
|
|
|
2003-09-01 06:04:03 +02:00
|
|
|
default:
|
2008-06-04 02:12:27 +02:00
|
|
|
vpi_printf("LXT2 warning: $dumpvars: Unsupported parameter "
|
2020-11-29 21:41:34 +01:00
|
|
|
"type (%s).\n", vpi_get_str(vpiType, item));
|
2003-09-01 06:04:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int draw_scope(vpiHandle item)
|
|
|
|
|
{
|
|
|
|
|
int depth;
|
|
|
|
|
const char *name;
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
2003-09-01 06:04:03 +02:00
|
|
|
depth = 1 + draw_scope(scope);
|
|
|
|
|
name = vpi_get_str(vpiName, scope);
|
|
|
|
|
|
2007-12-11 01:14:02 +01:00
|
|
|
push_scope(name);
|
2003-09-01 06:04:03 +02:00
|
|
|
|
|
|
|
|
return depth;
|
|
|
|
|
}
|
|
|
|
|
|
2010-10-04 18:31:01 +02:00
|
|
|
static PLI_INT32 sys_dumpvars_calltf(ICARUS_VPI_CONST PLI_BYTE8*name)
|
2003-09-01 06:04:03 +02:00
|
|
|
{
|
2007-12-11 01:14:02 +01:00
|
|
|
vpiHandle callh = vpi_handle(vpiSysTfCall, 0);
|
|
|
|
|
vpiHandle argv = vpi_iterate(vpiArgument, callh);
|
|
|
|
|
vpiHandle item;
|
2003-09-01 06:04:03 +02:00
|
|
|
s_vpi_value value;
|
2007-12-11 01:14:02 +01:00
|
|
|
unsigned depth = 0;
|
2003-09-01 06:04:03 +02:00
|
|
|
|
2014-07-09 23:16:57 +02:00
|
|
|
(void)name; /* Parameter is not used. */
|
|
|
|
|
|
2003-09-01 06:04:03 +02:00
|
|
|
if (dump_file == 0) {
|
2008-06-04 02:12:27 +02:00
|
|
|
open_dumpfile(callh);
|
2009-02-25 01:47:46 +01:00
|
|
|
if (dump_file == 0) {
|
2010-04-30 03:21:13 +02:00
|
|
|
if (argv) vpi_free_object(argv);
|
2009-02-25 01:47:46 +01:00
|
|
|
return 0;
|
|
|
|
|
}
|
2003-09-01 06:04:03 +02:00
|
|
|
}
|
|
|
|
|
|
2009-02-25 01:47:46 +01:00
|
|
|
if (install_dumpvars_callback()) {
|
2010-04-30 03:21:13 +02:00
|
|
|
if (argv) vpi_free_object(argv);
|
2009-02-25 01:47:46 +01:00
|
|
|
return 0;
|
|
|
|
|
}
|
2003-09-01 06:04:03 +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;
|
2003-09-01 06:04:03 +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);
|
2003-09-01 06:04:03 +02:00
|
|
|
}
|
|
|
|
|
|
2007-12-11 01:14:02 +01:00
|
|
|
for ( ; item; item = vpi_scan(argv)) {
|
2003-09-01 06:04:03 +02:00
|
|
|
|
|
|
|
|
int dep = draw_scope(item);
|
|
|
|
|
|
|
|
|
|
scan_item(depth, item, 0);
|
2004-10-04 03:10:51 +02:00
|
|
|
|
2007-12-11 01:14:02 +01:00
|
|
|
while (dep--) pop_scope();
|
2003-09-01 06:04:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Most effective compression. */
|
2003-09-26 23:23:08 +02:00
|
|
|
if (lxm_optimum_mode == LXM_SPACE) {
|
2003-09-01 06:04:03 +02:00
|
|
|
lxt2_wr_set_compression_depth(dump_file, 9);
|
2003-09-26 23:23:08 +02:00
|
|
|
lxt2_wr_set_partial_off(dump_file);
|
|
|
|
|
}
|
2003-09-01 06:04:03 +02:00
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2010-01-09 05:20:26 +01:00
|
|
|
static void* lxt2_thread(void*arg)
|
|
|
|
|
{
|
2010-01-09 06:46:32 +01:00
|
|
|
/* Keep track of the current time, and only call the set_time
|
|
|
|
|
function when the time changes. */
|
|
|
|
|
uint64_t cur_time = 0;
|
2010-01-09 05:20:26 +01:00
|
|
|
int run_flag = 1;
|
2014-07-09 23:16:57 +02:00
|
|
|
|
|
|
|
|
(void)arg; /* Parameter is not used. */
|
|
|
|
|
|
2010-01-09 05:20:26 +01:00
|
|
|
while (run_flag) {
|
|
|
|
|
struct vcd_work_item_s*cell = vcd_work_thread_peek();
|
|
|
|
|
|
2010-01-09 06:46:32 +01:00
|
|
|
if (cell->time != cur_time) {
|
|
|
|
|
cur_time = cell->time;
|
|
|
|
|
lxt2_wr_set_time64(dump_file, cur_time);
|
|
|
|
|
}
|
|
|
|
|
|
2010-01-09 05:20:26 +01:00
|
|
|
switch (cell->type) {
|
|
|
|
|
case WT_NONE:
|
|
|
|
|
break;
|
|
|
|
|
case WT_FLUSH:
|
|
|
|
|
lxt2_wr_flush(dump_file);
|
|
|
|
|
break;
|
|
|
|
|
case WT_DUMPON:
|
|
|
|
|
lxt2_wr_set_dumpon(dump_file);
|
|
|
|
|
break;
|
|
|
|
|
case WT_DUMPOFF:
|
|
|
|
|
lxt2_wr_set_dumpoff(dump_file);
|
|
|
|
|
break;
|
|
|
|
|
case WT_EMIT_DOUBLE:
|
|
|
|
|
lxt2_wr_emit_value_double(dump_file, cell->sym_.lxt2,
|
|
|
|
|
0, cell->op_.val_double);
|
2010-01-09 06:46:32 +01:00
|
|
|
break;
|
2010-01-09 05:20:26 +01:00
|
|
|
case WT_EMIT_BITS:
|
|
|
|
|
lxt2_wr_emit_value_bit_string(dump_file, cell->sym_.lxt2,
|
|
|
|
|
0, cell->op_.val_char);
|
|
|
|
|
break;
|
|
|
|
|
case WT_TERMINATE:
|
|
|
|
|
run_flag = 0;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
vcd_work_thread_pop();
|
|
|
|
|
}
|
2010-01-09 06:46:32 +01:00
|
|
|
|
2010-01-09 05:20:26 +01:00
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2014-07-09 00:31:34 +02:00
|
|
|
void sys_lxt2_register(void)
|
2003-09-01 06:04:03 +02:00
|
|
|
{
|
|
|
|
|
int idx;
|
|
|
|
|
struct t_vpi_vlog_info vlog_info;
|
|
|
|
|
s_vpi_systf_data tf_data;
|
2010-04-12 08:39:08 +02:00
|
|
|
vpiHandle res;
|
2003-09-01 06:04:03 +02:00
|
|
|
|
2010-05-23 20:28:27 +02:00
|
|
|
/* Scan the extended arguments, looking for lxt2 optimization flags. */
|
2003-09-01 06:04:03 +02:00
|
|
|
vpi_get_vlog_info(&vlog_info);
|
|
|
|
|
|
2010-05-23 20:28:27 +02:00
|
|
|
/* The "speed" option is not used in this dumper. */
|
2003-09-01 06:04:03 +02:00
|
|
|
for (idx = 0 ; idx < vlog_info.argc ; idx += 1) {
|
2010-05-21 03:06:17 +02:00
|
|
|
if (strcmp(vlog_info.argv[idx],"-lxt2-space") == 0) {
|
2003-09-01 06:04:03 +02:00
|
|
|
lxm_optimum_mode = LXM_SPACE;
|
|
|
|
|
|
2010-05-21 03:06:17 +02:00
|
|
|
} else if (strcmp(vlog_info.argv[idx],"-lxt2-speed") == 0) {
|
|
|
|
|
lxm_optimum_mode = LXM_SPEED;
|
|
|
|
|
|
|
|
|
|
} else if (strcmp(vlog_info.argv[idx],"-lx2-space") == 0) {
|
|
|
|
|
lxm_optimum_mode = LXM_SPACE;
|
|
|
|
|
|
|
|
|
|
} else if (strcmp(vlog_info.argv[idx],"-lx2-speed") == 0) {
|
2003-09-01 06:04:03 +02:00
|
|
|
lxm_optimum_mode = LXM_SPEED;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2007-12-11 01:14:02 +01:00
|
|
|
/* All the compiletf routines are located in vcd_priv.c. */
|
|
|
|
|
|
2003-09-01 06:04:03 +02: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;
|
2003-09-01 06:04:03 +02: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);
|
2003-09-01 06:04:03 +02: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;
|
2003-09-01 06:04:03 +02: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);
|
2003-09-01 06:04:03 +02: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
|
|
|
|
2003-09-01 06:04:03 +02: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;
|
2003-09-01 06:04:03 +02: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);
|
2003-09-01 06:04:03 +02:00
|
|
|
}
|