Add VCD output and related system tasks.

This commit is contained in:
steve 1999-11-07 20:33:30 +00:00
parent 43ff33cd79
commit 02f8099aa7
6 changed files with 272 additions and 8 deletions

View File

@ -18,7 +18,7 @@
# 59 Temple Place - Suite 330
# Boston, MA 02111-1307, USA
#
#ident "$Id: Makefile.in,v 1.6 1999/10/22 23:58:13 steve Exp $"
#ident "$Id: Makefile.in,v 1.7 1999/11/07 20:33:30 steve Exp $"
#
#
SHELL = /bin/sh
@ -52,7 +52,7 @@ all: system.vpi
$(CC) -Wall $(CPPFLAGS) -I$(srcdir) -MD -c $< -o $*.o
mv $*.d dep
O = sys_table.o sys_display.o sys_finish.o
O = sys_table.o sys_display.o sys_finish.o sys_vcd.o
system.vpi: $O
$(CC) -shared -o $@ $O

View File

@ -17,21 +17,26 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
#if !defined(WINNT)
#ident "$Id: sys_table.c,v 1.1 1999/08/15 01:23:56 steve Exp $"
#ident "$Id: sys_table.c,v 1.2 1999/11/07 20:33:30 steve Exp $"
#endif
extern void sys_finish_register();
extern void sys_display_register();
extern void sys_vcd_register();
void (*vlog_startup_routines[])() = {
sys_finish_register,
sys_display_register,
sys_vcd_register,
0
};
/*
* $Log: sys_table.c,v $
* Revision 1.2 1999/11/07 20:33:30 steve
* Add VCD output and related system tasks.
*
* Revision 1.1 1999/08/15 01:23:56 steve
* Convert vvm to implement system tasks with vpi.
*

219
vpi/sys_vcd.c Normal file
View File

@ -0,0 +1,219 @@
/*
* Copyright (c) 1999 Stephen Williams (steve@icarus.com)
*
* This source code is free software; you can redistribute it
* and/or modify it in source code form under the terms of the GNU
* General Public License as published by the Free Software
* Foundation; either version 2 of the License, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
#if !defined(WINNT)
#ident "$Id: sys_vcd.c,v 1.1 1999/11/07 20:33:30 steve Exp $"
#endif
/*
* This file contains the implementations of the VCD related
* funcitons.
*/
# include <vpi_user.h>
# include <stdio.h>
# include <stdlib.h>
# include <string.h>
# include <assert.h>
static FILE*dump_file = 0;
struct vcd_info {
vpiHandle item;
vpiHandle cb;
struct t_vpi_time time;
char*ident;
struct vcd_info*next;
};
static struct vcd_info*vcd_list = 0;
unsigned long vcd_cur_time = 0;
static int variable_cb(p_cb_data cause)
{
unsigned long now = cause->time->low;
s_vpi_value value;
struct t_cb_data cb;
struct vcd_info*info = (struct vcd_info*)cause->user_data;
/* Reschedule this event so that it happens for the next
trigger on this variable. */
cb = *cause;
vpi_register_cb(&cb);
if (now != vcd_cur_time) {
fprintf(dump_file, "#%lu\n", now);
vcd_cur_time = now;
}
if (vpi_get(vpiSize, info->item) == 1) {
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);
fprintf(dump_file, "b%s %s\n", value.value.str, info->ident);
}
return 0;
}
static int sys_dumpall_calltf(char*name)
{
return 0;
}
static int sys_dumpfile_calltf(char*name)
{
char*path;
vpiHandle sys = vpi_handle(vpiSysTfCall, 0);
vpiHandle argv = vpi_iterate(vpiArgument, sys);
vpiHandle item = vpi_scan(argv);
if (item) {
s_vpi_value value;
if (vpi_get(vpiType, item) != vpiConstant) {
vpi_printf("ERROR: %s parameter must be a constant\n", name);
return 0;
}
if (vpi_get(vpiConstType, item) != vpiStringConst) {
vpi_printf("ERROR: %s parameter must be a constant\n", name);
return 0;
}
value.format = vpiStringVal;
vpi_get_value(item, &value);
path = strdup(value.value.str);
vpi_free_object(argv);
} else {
path = strdup("dumpfile.vcd");
}
assert(dump_file == 0);
dump_file = fopen(path, "w");
if (dump_file == 0) {
vpi_printf("ERROR: Unable to open %s for output.\n", path);
return 0;
}
free(path);
return 0;
}
static int sys_dumpvars_calltf(char*name)
{
struct t_cb_data cb;
struct vcd_info*info;
char ident[64];
unsigned nident = 0;
vpiHandle sys = vpi_handle(vpiSysTfCall, 0);
vpiHandle argv = vpi_iterate(vpiArgument, sys);
vpiHandle item = vpi_scan(argv);
if (item == 0) {
vpi_printf("SORRY: %s requires arguments\n", name);
return 0;
}
assert(dump_file);
cb.reason = cbValueChange;
cb.cb_rtn = variable_cb;
for (item = vpi_scan(argv) ; item ; item = vpi_scan(argv)) {
switch (vpi_get(vpiType, item)) {
case vpiNet:
case vpiReg: {
const char*type = "wire";
if (vpi_get(vpiType, item) == vpiReg)
type = "reg";
sprintf(ident, "<%u", nident++);
info = malloc(sizeof(*info));
info->time.type = vpiSimTime;
cb.time = &info->time;
cb.user_data = (char*)info;
cb.obj = item;
info->item = item;
info->ident = strdup(ident);
info->cb = vpi_register_cb(&cb);
info->next = vcd_list;
vcd_list = info;
fprintf(dump_file, "$var %s %u %s %s $end\n",
type, vpi_get(vpiSize, item), ident,
vpi_get_str(vpiFullName, item));
break;
}
default:
vpi_printf("ERROR: (%s): Unsupported parameter type\n",
name);
}
}
fprintf(dump_file, "$enddefinitions $end\n");
fprintf(dump_file, "#0\n");
return 0;
}
void sys_vcd_register()
{
s_vpi_systf_data tf_data;
tf_data.type = vpiSysTask;
tf_data.tfname = "$dumpall";
tf_data.calltf = sys_dumpall_calltf;
tf_data.compiletf = 0;
tf_data.sizetf = 0;
tf_data.user_data = "$dumpall";
vpi_register_systf(&tf_data);
tf_data.type = vpiSysTask;
tf_data.tfname = "$dumpfile";
tf_data.calltf = sys_dumpfile_calltf;
tf_data.compiletf = 0;
tf_data.sizetf = 0;
tf_data.user_data = "$dumpfile";
vpi_register_systf(&tf_data);
tf_data.type = vpiSysTask;
tf_data.tfname = "$dumpvars";
tf_data.calltf = sys_dumpvars_calltf;
tf_data.compiletf = 0;
tf_data.sizetf = 0;
tf_data.user_data = "$dumpvars";
vpi_register_systf(&tf_data);
}
/*
* $Log: sys_vcd.c,v $
* Revision 1.1 1999/11/07 20:33:30 steve
* Add VCD output and related system tasks.
*
*/

View File

@ -19,7 +19,7 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
#if !defined(WINNT)
#ident "$Id: vpi_user.h,v 1.5 1999/11/07 02:25:08 steve Exp $"
#ident "$Id: vpi_user.h,v 1.6 1999/11/07 20:33:30 steve Exp $"
#endif
#ifdef __cplusplus
@ -109,6 +109,7 @@ typedef struct t_vpi_value {
#define vpiType 1
#define vpiName 2
#define vpiFullName 3
#define vpiSize 4
#define vpiConstType 43
# define vpiDecConst 1
# define vpiRealConst 2
@ -204,6 +205,9 @@ extern void (*vlog_startup_routines[])();
/*
* $Log: vpi_user.h,v $
* Revision 1.6 1999/11/07 20:33:30 steve
* Add VCD output and related system tasks.
*
* Revision 1.5 1999/11/07 02:25:08 steve
* Add the $monitor implementation.
*

View File

@ -17,7 +17,7 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
#if !defined(WINNT)
#ident "$Id: vpi_callback.c,v 1.3 1999/10/29 03:37:22 steve Exp $"
#ident "$Id: vpi_callback.c,v 1.4 1999/11/07 20:33:30 steve Exp $"
#endif
# include "vpi_priv.h"
@ -40,8 +40,22 @@ static struct __vpirt vpip_callback_rt = {
*/
static void vpip_call_callback(void*cp)
{
unsigned long now;
struct __vpiCallback*rfp = (struct __vpiCallback*)cp;
assert(rfp->base.vpi_type->type_code == vpiCallback);
switch (rfp->cb_data.time->type) {
case vpiSuppressTime:
case vpiScaledRealTime: // XXXX not supported
break;
case vpiSimTime:
now = ((struct __vpiTimeVar*)vpip_sim_time())->time;
rfp->cb_data.time->low = now;
rfp->cb_data.time->high = 0;
break;
}
rfp->cb_data.cb_rtn(&rfp->cb_data);
free(rfp);
}
@ -155,6 +169,9 @@ int vpi_remove_cb(vpiHandle ref)
/*
* $Log: vpi_callback.c,v $
* Revision 1.4 1999/11/07 20:33:30 steve
* Add VCD output and related system tasks.
*
* Revision 1.3 1999/10/29 03:37:22 steve
* Support vpiValueChance callbacks.
*

View File

@ -17,13 +17,29 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
#if !defined(WINNT)
#ident "$Id: vpi_signal.c,v 1.4 1999/11/07 02:25:08 steve Exp $"
#ident "$Id: vpi_signal.c,v 1.5 1999/11/07 20:33:30 steve Exp $"
#endif
# include "vpi_priv.h"
# include <assert.h>
static int signal_get(int code, vpiHandle ref)
{
struct __vpiSignal*rfp = (struct __vpiSignal*)ref;
assert((ref->vpi_type->type_code==vpiNet)
|| (ref->vpi_type->type_code==vpiReg));
switch (code) {
case vpiSize:
return rfp->nbits;
default:
return 0;
}
}
static char* signal_get_str(int code, vpiHandle ref)
{
struct __vpiSignal*rfp = (struct __vpiSignal*)ref;
@ -51,7 +67,7 @@ static void signal_get_value(vpiHandle ref, s_vpi_value*vp)
static const struct __vpirt vpip_net_rt = {
vpiNet,
0,
signal_get,
signal_get_str,
signal_get_value,
0,
@ -68,7 +84,7 @@ vpiHandle vpip_make_net(struct __vpiSignal*ref, const char*name)
static const struct __vpirt vpip_reg_rt = {
vpiReg,
0,
signal_get,
signal_get_str,
signal_get_value,
0,
@ -85,6 +101,9 @@ vpiHandle vpip_make_reg(struct __vpiSignal*ref, const char*name)
/*
* $Log: vpi_signal.c,v $
* Revision 1.5 1999/11/07 20:33:30 steve
* Add VCD output and related system tasks.
*
* Revision 1.4 1999/11/07 02:25:08 steve
* Add the $monitor implementation.
*