Add the veriusertf_register funciton.

This commit is contained in:
steve 2002-05-30 02:37:26 +00:00
parent b9339d3c60
commit b5a1d116fa
3 changed files with 234 additions and 3 deletions

View File

@ -16,7 +16,7 @@
# 59 Temple Place - Suite 330
# Boston, MA 02111-1307, USA
#
#ident "$Id: Makefile.in,v 1.6 2002/05/30 02:12:17 steve Exp $"
#ident "$Id: Makefile.in,v 1.7 2002/05/30 02:37:26 steve Exp $"
#
#
SHELL = /bin/sh
@ -45,7 +45,8 @@ LDFLAGS = @LDFLAGS@
STRIP = @STRIP@
A = a_close.o a_initialize.o a_product_version.o
O = finish.o io_print.o mc_scan_plusargs.o nump.o $A
O = finish.o io_print.o mc_scan_plusargs.o nump.o \
veriusertfs.o $A
all: libveriuser.a

195
libveriuser/veriusertfs.c Normal file
View File

@ -0,0 +1,195 @@
/* vi:sw=6
* Copyright (c) 2002 Michael Ruff (mruff at chiaro.com)
* Michael Runyan (mrunyan at chiaro.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: veriusertfs.c,v 1.1 2002/05/30 02:37:26 steve Exp $"
#endif
/*
* Contains the routines required to implement veriusertfs routines
* via VPI. This is extremly ugly, so don't look after eating dinner.
*/
# include <stdio.h>
# include <string.h>
# include <stdlib.h>
# include "vpi_user.h"
# include "veriuser.h"
/*
* local structure used to hold the persistent veriusertfs data
* and anything else we decice to put it here like workarea data.
*/
typedef struct t_pli_data {
short data; /* veriusertfs data */
int (*checktf)(); /* pointer to checktf routine */
int (*calltf)(); /* pointer to calltf routine */
int (*misctf)(); /* pointer to misctf routine */
} s_pli_data, *p_pli_data;
static int compiletf(char *);
static int calltf(char *);
static int callback(p_cb_data);
/*
* Register veriusertfs routines/wrappers.
*/
void veriusertfs_register()
{
p_tfcell usertf;
s_vpi_systf_data tf_data;
p_pli_data data;
for (usertf = veriusertfs; usertf; usertf++) {
/* last element */
if (usertf->type == 0) break;
/* only forwref true */
if (!usertf->forwref) {
vpi_printf(" skipping %s, forwref != true\n",
usertf->tfname);
continue;
}
/* squirrel away some of veriusertfs in persistent user_data */
data = (p_pli_data) calloc(1, sizeof(s_pli_data));
data->data = usertf->data;
data->checktf = usertf->checktf;
data->calltf = usertf->calltf;
data->misctf = usertf->misctf;
(void) memset(&tf_data, 0, sizeof(s_vpi_systf_data));
switch (usertf->type) {
case usertask:
tf_data.type = vpiSysTask;
break;
case userfunction:
tf_data.type = vpiSysFunc;
break;
default:
vpi_printf(" skipping %s, unsupported type %d\n",
usertf->tfname, usertf->type);
continue;
break;
}
tf_data.tfname = usertf->tfname;
tf_data.compiletf = compiletf;
tf_data.calltf = calltf;
tf_data.sizetf = usertf->sizetf;
tf_data.user_data = (char *)data;
/* register */
vpi_register_systf(&tf_data);
}
return;
}
/*
* This function calls the veriusertfs checktf and sets up all the
* callbacks misctf requires.
*/
static int compiletf(char *data)
{
p_pli_data pli;
vpiHandle call_h, arg_i, arg_h;
s_cb_data cb_data;
/* cast back from opaque */
pli = (p_pli_data)data;
/* get call handle */
call_h = vpi_handle(vpiSysTfCall, NULL);
/* default cb_data */
(void) memset(&cb_data, 0, sizeof(s_cb_data));
cb_data.cb_rtn = callback;
cb_data.user_data = data;
/* register EndOfSim misctf callback */
cb_data.reason = cbEndOfSimulation;
cb_data.obj = call_h;
vpi_register_cb(&cb_data);
#if 0
/* register callbacks on each argument */
cb_data.reason = cbValueChange;
arg_i = vpi_iterate(vpiArgument, call_h);
if (arg_i != NULL) {
while ((arg_h = vpi_scan(arg_i)) != NULL) {
cb_data.obj = arg_h;
vpi_register_cb(&cb_data);
}
}
#endif
/* since we are at compiletf, misctf needs to fire */
pli->misctf(pli->data, reason_endofcompile);
/* similarly run checktf now */
return pli->checktf(pli->data, 0);
}
/*
* This function is the wrapper for the veriusertfs calltf routine.
*/
static int calltf(char *data)
{
p_pli_data pli;
/* cast back from opaque */
pli = (p_pli_data)data;
/* execute calltf */
return pli->calltf(pli->data, 0);
}
/*
* This function is the wrapper for all the misctf callbacks
*/
static int callback (p_cb_data data)
{
p_pli_data pli;
int reason;
/* cast back from opaque */
pli = (p_pli_data)data->user_data;
switch (data->reason) {
case cbValueChange:
reason = reason_paramvc;
break;
case cbEndOfSimulation:
reason = reason_finish;
break;
default:
abort();
}
/* execute misctf */
return pli->misctf(pli->data, reason);
}
/*
* $Log: veriusertfs.c,v $
* Revision 1.1 2002/05/30 02:37:26 steve
* Add the veriusertf_register funciton.
*
*/

View File

@ -19,7 +19,7 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
#if !defined(WINNT) && !defined(macintosh)
#ident "$Id: veriuser.h,v 1.6 2002/05/30 02:12:17 steve Exp $"
#ident "$Id: veriuser.h,v 1.7 2002/05/30 02:37:26 steve Exp $"
#endif
/*
@ -46,6 +46,38 @@
EXTERN_C_START
/*
* structure for veriusertfs array
*/
typedef struct t_tfcell
{
short type; /* usertask|userfunction|userrealfunction */
short data; /* data passed to user routine */
int (*checktf)(); /* pointer to checktf routine */
int (*sizetf)(); /* pointer to sizetf routine */
int (*calltf)(); /* pointer to calltf routine */
int (*misctf)(); /* pointer to misctf routine */
char *tfname; /* name of the system task/function */
int forwref; /* usually set to 1 */
char *tfveritool; /* usually ignored */
char *tferrmessage; /* usually ignored */
char pad[20]; /* Pad of XL */
} s_tfcell, *p_tfcell;
extern s_tfcell veriusertfs[];
extern void veriusertfs_register();
#define usertask 1
#define userfunction 2
#define userrealfunction 3
/* misctf callback reasons */
#define reason_paramvc 7
#define reason_finish 9
#define reason_endofcompile 16
/* Extern functions from the library. */
extern void io_printf (const char *, ...)
__attribute__((format (printf,1,2)));
extern char* mc_scan_plusargs(char*plusarg);
@ -66,6 +98,9 @@ EXTERN_C_END
/*
* $Log: veriuser.h,v $
* Revision 1.7 2002/05/30 02:37:26 steve
* Add the veriusertf_register funciton.
*
* Revision 1.6 2002/05/30 02:12:17 steve
* Add tf_nump from mruff.
*