2002-05-30 04:37:26 +02:00
|
|
|
/* 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
|
|
|
|
|
*/
|
2002-08-12 03:34:58 +02:00
|
|
|
#ifdef HAVE_CVS_IDENT
|
2003-02-16 03:23:14 +01:00
|
|
|
#ident "$Id: veriusertfs.c,v 1.6 2003/02/16 02:23:14 steve Exp $"
|
2002-05-30 04:37:26 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Contains the routines required to implement veriusertfs routines
|
|
|
|
|
* via VPI. This is extremly ugly, so don't look after eating dinner.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
# include <string.h>
|
|
|
|
|
# include <stdlib.h>
|
2002-06-04 03:42:58 +02:00
|
|
|
# include <assert.h>
|
2002-05-30 04:37:26 +02:00
|
|
|
# include "vpi_user.h"
|
|
|
|
|
# include "veriuser.h"
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* local structure used to hold the persistent veriusertfs data
|
2002-05-31 20:21:39 +02:00
|
|
|
* and anything else we decide to put in here, like workarea data.
|
2002-05-30 04:37:26 +02:00
|
|
|
*/
|
|
|
|
|
typedef struct t_pli_data {
|
2002-05-31 20:21:39 +02:00
|
|
|
p_tfcell tf; /* pointer to veriusertfs cell */
|
2002-06-04 03:42:58 +02:00
|
|
|
int paramvc; /* parameter number for misctf */
|
2002-05-30 04:37:26 +02:00
|
|
|
} s_pli_data, *p_pli_data;
|
|
|
|
|
|
|
|
|
|
static int compiletf(char *);
|
|
|
|
|
static int calltf(char *);
|
|
|
|
|
static int callback(p_cb_data);
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Register veriusertfs routines/wrappers.
|
|
|
|
|
*/
|
2003-02-16 03:23:14 +01:00
|
|
|
void veriusertfs_register_table(p_tfcell vtable)
|
2002-05-30 04:37:26 +02:00
|
|
|
{
|
2002-05-31 20:21:39 +02:00
|
|
|
p_tfcell tf;
|
2002-05-30 04:37:26 +02:00
|
|
|
s_vpi_systf_data tf_data;
|
|
|
|
|
p_pli_data data;
|
|
|
|
|
|
2003-02-16 03:23:14 +01:00
|
|
|
for (tf = vtable; tf; tf++) {
|
2002-05-30 04:37:26 +02:00
|
|
|
/* last element */
|
2002-05-31 20:21:39 +02:00
|
|
|
if (tf->type == 0) break;
|
2002-05-30 04:37:26 +02:00
|
|
|
|
2002-06-04 03:42:58 +02:00
|
|
|
/* force forwref true */
|
2002-05-31 20:21:39 +02:00
|
|
|
if (!tf->forwref) {
|
2002-06-04 03:42:58 +02:00
|
|
|
vpi_printf("veriusertfs: %s, forcing forwref = true\n",
|
2002-05-31 20:21:39 +02:00
|
|
|
tf->tfname);
|
2002-05-30 04:37:26 +02:00
|
|
|
}
|
|
|
|
|
|
2002-05-31 20:21:39 +02:00
|
|
|
/* squirrel away veriusertfs in persistent user_data */
|
2002-05-30 04:37:26 +02:00
|
|
|
data = (p_pli_data) calloc(1, sizeof(s_pli_data));
|
2002-06-04 03:42:58 +02:00
|
|
|
assert(data != NULL);
|
2002-05-31 20:21:39 +02:00
|
|
|
data->tf = tf;
|
2002-05-30 04:37:26 +02:00
|
|
|
|
2002-06-04 03:42:58 +02:00
|
|
|
/* build callback structure */
|
2002-05-30 04:37:26 +02:00
|
|
|
(void) memset(&tf_data, 0, sizeof(s_vpi_systf_data));
|
2002-05-31 20:21:39 +02:00
|
|
|
switch (tf->type) {
|
2002-05-30 04:37:26 +02:00
|
|
|
case usertask:
|
|
|
|
|
tf_data.type = vpiSysTask;
|
|
|
|
|
break;
|
|
|
|
|
case userfunction:
|
|
|
|
|
tf_data.type = vpiSysFunc;
|
|
|
|
|
break;
|
|
|
|
|
default:
|
2002-06-04 03:42:58 +02:00
|
|
|
vpi_printf("veriusertfs: %s, unsupported type %d\n",
|
2002-05-31 20:21:39 +02:00
|
|
|
tf->tfname, tf->type);
|
2002-05-30 04:37:26 +02:00
|
|
|
continue;
|
|
|
|
|
break;
|
|
|
|
|
}
|
2003-02-16 03:23:14 +01:00
|
|
|
|
2002-05-31 20:21:39 +02:00
|
|
|
tf_data.tfname = tf->tfname;
|
2002-05-30 04:37:26 +02:00
|
|
|
tf_data.compiletf = compiletf;
|
|
|
|
|
tf_data.calltf = calltf;
|
2002-05-31 20:21:39 +02:00
|
|
|
tf_data.sizetf = tf->sizetf;
|
2002-05-30 04:37:26 +02:00
|
|
|
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;
|
2002-05-31 20:21:39 +02:00
|
|
|
p_tfcell tf;
|
2002-05-30 04:37:26 +02:00
|
|
|
s_cb_data cb_data;
|
2002-06-04 03:42:58 +02:00
|
|
|
vpiHandle call_h, arg_i, arg_h;
|
|
|
|
|
p_pli_data dp;
|
|
|
|
|
int paramvc = 1;
|
|
|
|
|
int rtn;
|
2002-05-30 04:37:26 +02:00
|
|
|
|
|
|
|
|
/* cast back from opaque */
|
|
|
|
|
pli = (p_pli_data)data;
|
2002-05-31 20:21:39 +02:00
|
|
|
tf = pli->tf;
|
2002-05-30 04:37:26 +02:00
|
|
|
|
|
|
|
|
/* 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;
|
|
|
|
|
|
2002-06-04 03:42:58 +02:00
|
|
|
/* register EOS misctf callback */
|
2002-05-30 04:37:26 +02:00
|
|
|
cb_data.reason = cbEndOfSimulation;
|
|
|
|
|
cb_data.obj = call_h;
|
|
|
|
|
vpi_register_cb(&cb_data);
|
|
|
|
|
|
2002-06-04 03:42:58 +02:00
|
|
|
/* register paramvc misctf callback(s) */
|
2002-05-30 04:37:26 +02:00
|
|
|
cb_data.reason = cbValueChange;
|
|
|
|
|
arg_i = vpi_iterate(vpiArgument, call_h);
|
|
|
|
|
if (arg_i != NULL) {
|
|
|
|
|
while ((arg_h = vpi_scan(arg_i)) != NULL) {
|
2002-06-04 03:42:58 +02:00
|
|
|
/* replicate user_data for each instance */
|
|
|
|
|
dp = (p_pli_data)calloc(1, sizeof(s_pli_data));
|
|
|
|
|
assert(dp != NULL);
|
|
|
|
|
memcpy(dp, cb_data.user_data, sizeof(s_pli_data));
|
|
|
|
|
dp->paramvc = paramvc++;
|
|
|
|
|
cb_data.user_data = (char *)dp;
|
2002-05-30 04:37:26 +02:00
|
|
|
cb_data.obj = arg_h;
|
|
|
|
|
vpi_register_cb(&cb_data);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2002-06-04 03:42:58 +02:00
|
|
|
/*
|
|
|
|
|
* Since we are in compiletf, checktf and misctf need to
|
|
|
|
|
* be executed. Check runs first to match other simulators.
|
|
|
|
|
*/
|
|
|
|
|
rtn = (tf->checktf) ? tf->checktf(tf->data, reason_checktf) : 0;
|
2002-06-03 02:08:42 +02:00
|
|
|
if (tf->misctf) tf->misctf(tf->data, reason_endofcompile, 0);
|
2002-05-30 04:37:26 +02:00
|
|
|
|
2002-06-04 03:42:58 +02:00
|
|
|
return rtn;
|
2002-05-30 04:37:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* This function is the wrapper for the veriusertfs calltf routine.
|
|
|
|
|
*/
|
|
|
|
|
static int calltf(char *data)
|
|
|
|
|
{
|
|
|
|
|
p_pli_data pli;
|
2002-05-31 20:21:39 +02:00
|
|
|
p_tfcell tf;
|
2002-05-30 04:37:26 +02:00
|
|
|
|
|
|
|
|
/* cast back from opaque */
|
|
|
|
|
pli = (p_pli_data)data;
|
2002-05-31 20:21:39 +02:00
|
|
|
tf = pli->tf;
|
2002-05-30 04:37:26 +02:00
|
|
|
|
|
|
|
|
/* execute calltf */
|
2002-06-04 03:42:58 +02:00
|
|
|
return (tf->calltf) ? tf->calltf(tf->data, reason_calltf) : 0;
|
2002-05-30 04:37:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* This function is the wrapper for all the misctf callbacks
|
|
|
|
|
*/
|
2002-06-04 03:42:58 +02:00
|
|
|
extern int async_misctf_enable;
|
|
|
|
|
|
|
|
|
|
static int callback(p_cb_data data)
|
2002-05-30 04:37:26 +02:00
|
|
|
{
|
|
|
|
|
p_pli_data pli;
|
2002-05-31 20:21:39 +02:00
|
|
|
p_tfcell tf;
|
2002-05-30 04:37:26 +02:00
|
|
|
int reason;
|
2002-06-04 03:42:58 +02:00
|
|
|
int paramvc = 0;
|
|
|
|
|
|
|
|
|
|
/* not enabled */
|
|
|
|
|
if (data->reason == cbValueChange && !async_misctf_enable) return 0;
|
2002-05-30 04:37:26 +02:00
|
|
|
|
|
|
|
|
/* cast back from opaque */
|
|
|
|
|
pli = (p_pli_data)data->user_data;
|
2002-05-31 20:21:39 +02:00
|
|
|
tf = pli->tf;
|
2002-05-30 04:37:26 +02:00
|
|
|
|
|
|
|
|
switch (data->reason) {
|
|
|
|
|
case cbValueChange:
|
|
|
|
|
reason = reason_paramvc;
|
2002-06-04 03:42:58 +02:00
|
|
|
paramvc = pli->paramvc;
|
2002-05-30 04:37:26 +02:00
|
|
|
break;
|
|
|
|
|
case cbEndOfSimulation:
|
|
|
|
|
reason = reason_finish;
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
abort();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* execute misctf */
|
2002-06-04 03:42:58 +02:00
|
|
|
return (tf->misctf) ? tf->misctf(tf->data, reason, paramvc) : 0;
|
2002-05-30 04:37:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* $Log: veriusertfs.c,v $
|
2003-02-16 03:23:14 +01:00
|
|
|
* Revision 1.6 2003/02/16 02:23:14 steve
|
|
|
|
|
* Change the IV veriusertfs_register to accept table pointers.
|
|
|
|
|
*
|
2002-08-12 03:34:58 +02:00
|
|
|
* Revision 1.5 2002/08/12 01:35:02 steve
|
|
|
|
|
* conditional ident string using autoconfig.
|
|
|
|
|
*
|
2002-06-04 03:42:58 +02:00
|
|
|
* Revision 1.4 2002/06/04 01:42:58 steve
|
|
|
|
|
* Add misctf support to libveriuser
|
|
|
|
|
*
|
2002-06-03 02:08:42 +02:00
|
|
|
* Revision 1.3 2002/06/03 00:08:42 steve
|
|
|
|
|
* Better typing for veriusertfs table.
|
|
|
|
|
*
|
2002-05-31 20:21:39 +02:00
|
|
|
* Revision 1.2 2002/05/31 18:21:39 steve
|
|
|
|
|
* Check for and don't dereference null pointers,
|
|
|
|
|
* Avoid copy of static objects.
|
|
|
|
|
* (mruff)
|
|
|
|
|
*
|
2002-05-30 04:37:26 +02:00
|
|
|
* Revision 1.1 2002/05/30 02:37:26 steve
|
|
|
|
|
* Add the veriusertf_register funciton.
|
|
|
|
|
*
|
|
|
|
|
*/
|