2001-03-16 02:44:34 +01:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2001 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
|
|
|
|
|
*/
|
2002-08-12 03:34:58 +02:00
|
|
|
#ifdef HAVE_CVS_IDENT
|
2006-09-23 00:33:00 +02:00
|
|
|
#ident "$Id: vpi_tasks.cc,v 1.33 2006/09/22 22:33:00 steve Exp $"
|
2001-03-16 02:44:34 +01:00
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* This file keeps the table of system/task definitions. This table is
|
|
|
|
|
* built up before the input source file is parsed, and is used by the
|
|
|
|
|
* compiler when %vpi_call statements are encountered.
|
|
|
|
|
*/
|
2001-05-20 02:46:12 +02:00
|
|
|
# include "vpi_priv.h"
|
|
|
|
|
# include "vthread.h"
|
2001-03-16 02:44:34 +01:00
|
|
|
# include <stdio.h>
|
2001-09-15 20:27:04 +02:00
|
|
|
#ifdef HAVE_MALLOC_H
|
2001-03-16 02:44:34 +01:00
|
|
|
# include <malloc.h>
|
2001-09-15 20:27:04 +02:00
|
|
|
#endif
|
|
|
|
|
# include <stdlib.h>
|
2001-03-16 02:44:34 +01:00
|
|
|
# include <string.h>
|
|
|
|
|
# include <assert.h>
|
|
|
|
|
|
2001-06-25 05:12:06 +02:00
|
|
|
static const struct __vpirt vpip_systask_def_rt = {
|
|
|
|
|
vpiSysTask,
|
|
|
|
|
0,
|
|
|
|
|
0,
|
|
|
|
|
0,
|
|
|
|
|
0,
|
|
|
|
|
0,
|
|
|
|
|
0
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static const struct __vpirt vpip_sysfunc_def_rt = {
|
|
|
|
|
vpiSysFunc,
|
|
|
|
|
0,
|
|
|
|
|
0,
|
|
|
|
|
0,
|
|
|
|
|
0,
|
|
|
|
|
0,
|
|
|
|
|
0
|
|
|
|
|
};
|
|
|
|
|
|
2001-03-16 02:44:34 +01:00
|
|
|
static vpiHandle systask_handle(int type, vpiHandle ref)
|
|
|
|
|
{
|
2001-03-18 01:37:55 +01:00
|
|
|
struct __vpiSysTaskCall*rfp = (struct __vpiSysTaskCall*)ref;
|
|
|
|
|
assert((ref->vpi_type->type_code == vpiSysTaskCall)
|
|
|
|
|
|| (ref->vpi_type->type_code == vpiSysFuncCall));
|
|
|
|
|
|
|
|
|
|
switch (type) {
|
|
|
|
|
case vpiScope:
|
2001-04-18 06:21:23 +02:00
|
|
|
return &rfp->scope->base;
|
2001-03-18 01:37:55 +01:00
|
|
|
default:
|
|
|
|
|
return 0;
|
|
|
|
|
};
|
2001-03-16 02:44:34 +01:00
|
|
|
}
|
|
|
|
|
|
2004-02-18 03:51:59 +01:00
|
|
|
static int systask_get(int type, vpiHandle ref)
|
2003-03-14 06:00:44 +01:00
|
|
|
{
|
|
|
|
|
struct __vpiSysTaskCall*rfp = (struct __vpiSysTaskCall*)ref;
|
|
|
|
|
|
|
|
|
|
assert((ref->vpi_type->type_code == vpiSysTaskCall)
|
|
|
|
|
|| (ref->vpi_type->type_code == vpiSysFuncCall));
|
|
|
|
|
|
|
|
|
|
switch (type) {
|
|
|
|
|
case vpiTimeUnit:
|
|
|
|
|
return rfp->scope->time_units;
|
|
|
|
|
default:
|
|
|
|
|
return vpiUndefined;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2003-03-03 04:27:35 +01:00
|
|
|
/*
|
|
|
|
|
* the get_str function only needs to support vpiName
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
static char *systask_get_str(int type, vpiHandle ref)
|
|
|
|
|
{
|
|
|
|
|
struct __vpiSysTaskCall*rfp = (struct __vpiSysTaskCall*)ref;
|
|
|
|
|
|
|
|
|
|
assert((ref->vpi_type->type_code == vpiSysTaskCall)
|
|
|
|
|
|| (ref->vpi_type->type_code == vpiSysFuncCall));
|
|
|
|
|
|
2003-12-07 21:05:56 +01:00
|
|
|
const char *bn = rfp->defn->info.tfname;
|
2003-03-03 04:27:35 +01:00
|
|
|
char *rbuf = need_result_buf(strlen(bn) + 1, RBUF_STR);
|
|
|
|
|
|
|
|
|
|
switch (type) {
|
|
|
|
|
|
|
|
|
|
case vpiName:
|
|
|
|
|
strcpy(rbuf,bn);
|
|
|
|
|
return rbuf;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2001-03-16 02:44:34 +01:00
|
|
|
/*
|
|
|
|
|
* the iter function only supports getting an iterator of the
|
|
|
|
|
* arguments. This works equally well for tasks and functions.
|
|
|
|
|
*/
|
|
|
|
|
static vpiHandle systask_iter(int type, vpiHandle ref)
|
|
|
|
|
{
|
|
|
|
|
struct __vpiSysTaskCall*rfp = (struct __vpiSysTaskCall*)ref;
|
|
|
|
|
assert((ref->vpi_type->type_code == vpiSysTaskCall)
|
|
|
|
|
|| (ref->vpi_type->type_code == vpiSysFuncCall));
|
|
|
|
|
|
|
|
|
|
if (rfp->nargs == 0)
|
|
|
|
|
return 0;
|
|
|
|
|
|
2002-05-03 17:44:11 +02:00
|
|
|
return vpip_make_iterator(rfp->nargs, rfp->args, false);
|
2001-03-16 02:44:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static const struct __vpirt vpip_systask_rt = {
|
|
|
|
|
vpiSysTaskCall,
|
2003-03-14 06:00:44 +01:00
|
|
|
systask_get,
|
2003-03-03 04:27:35 +01:00
|
|
|
systask_get_str,
|
2001-03-16 02:44:34 +01:00
|
|
|
0,
|
|
|
|
|
0,
|
|
|
|
|
systask_handle,
|
|
|
|
|
systask_iter
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* A value *can* be put to a vpiSysFuncCall object. This is how the
|
|
|
|
|
* return value is set. The value that is given should be converted to
|
2001-05-20 02:46:12 +02:00
|
|
|
* bits and set into the thread space bits that were selected at
|
|
|
|
|
* compile time.
|
2001-03-16 02:44:34 +01:00
|
|
|
*/
|
2004-05-19 05:26:24 +02:00
|
|
|
static vpiHandle sysfunc_put_value(vpiHandle ref, p_vpi_value vp)
|
2001-03-16 02:44:34 +01:00
|
|
|
{
|
2001-05-20 02:46:12 +02:00
|
|
|
assert(ref->vpi_type->type_code == vpiSysFuncCall);
|
|
|
|
|
|
|
|
|
|
struct __vpiSysTaskCall*rfp = (struct __vpiSysTaskCall*)ref;
|
|
|
|
|
|
|
|
|
|
assert(rfp->vbit >= 4);
|
|
|
|
|
|
|
|
|
|
switch (vp->format) {
|
2004-10-04 03:10:51 +02:00
|
|
|
|
2001-05-20 02:46:12 +02:00
|
|
|
case vpiIntVal: {
|
|
|
|
|
long val = vp->value.integer;
|
2003-01-27 01:14:37 +01:00
|
|
|
for (int idx = 0 ; idx < rfp->vwid ; idx += 1) {
|
2001-05-20 02:46:12 +02:00
|
|
|
vthread_put_bit(vpip_current_vthread,
|
2005-08-29 04:38:50 +02:00
|
|
|
rfp->vbit+idx, (val&1)? BIT4_1 :BIT4_0);
|
2001-05-20 02:46:12 +02:00
|
|
|
val >>= 1;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2003-06-18 02:54:28 +02:00
|
|
|
case vpiTimeVal:
|
|
|
|
|
for (int idx = 0 ; idx < rfp->vwid ; idx += 1) {
|
|
|
|
|
PLI_INT32 word;
|
|
|
|
|
if (idx >= 32)
|
|
|
|
|
word = vp->value.time->high;
|
|
|
|
|
else
|
|
|
|
|
word = vp->value.time->low;
|
|
|
|
|
|
|
|
|
|
word >>= idx % 32;
|
|
|
|
|
|
|
|
|
|
vthread_put_bit(vpip_current_vthread,
|
2005-08-29 04:38:50 +02:00
|
|
|
rfp->vbit+idx, (word&1)? BIT4_1 :BIT4_0);
|
2003-06-18 02:54:28 +02:00
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
2001-05-20 02:46:12 +02:00
|
|
|
case vpiScalarVal:
|
|
|
|
|
switch (vp->value.scalar) {
|
|
|
|
|
case vpi0:
|
2005-08-29 04:38:50 +02:00
|
|
|
vthread_put_bit(vpip_current_vthread, rfp->vbit, BIT4_0);
|
2001-05-20 02:46:12 +02:00
|
|
|
break;
|
|
|
|
|
case vpi1:
|
2005-08-29 04:38:50 +02:00
|
|
|
vthread_put_bit(vpip_current_vthread, rfp->vbit, BIT4_1);
|
2001-05-20 02:46:12 +02:00
|
|
|
break;
|
|
|
|
|
case vpiX:
|
2005-08-29 04:38:50 +02:00
|
|
|
vthread_put_bit(vpip_current_vthread, rfp->vbit, BIT4_X);
|
2001-05-20 02:46:12 +02:00
|
|
|
break;
|
|
|
|
|
case vpiZ:
|
2005-08-29 04:38:50 +02:00
|
|
|
vthread_put_bit(vpip_current_vthread, rfp->vbit, BIT4_Z);
|
2001-05-20 02:46:12 +02:00
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
assert(0);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
2003-03-07 03:44:14 +01:00
|
|
|
case vpiVectorVal:
|
|
|
|
|
|
2003-03-13 06:07:10 +01:00
|
|
|
for (unsigned wdx = 0 ; wdx < (unsigned)rfp->vwid ; wdx += 32) {
|
2003-03-07 03:44:14 +01:00
|
|
|
unsigned word = wdx / 32;
|
|
|
|
|
unsigned long aval = vp->value.vector[word].aval;
|
|
|
|
|
unsigned long bval = vp->value.vector[word].bval;
|
|
|
|
|
|
2003-03-13 06:07:10 +01:00
|
|
|
for (unsigned idx = 0 ; (wdx+idx) < (unsigned)rfp->vwid ;
|
|
|
|
|
idx += 1)
|
|
|
|
|
{
|
2003-03-07 03:44:14 +01:00
|
|
|
int bit = (aval&1) | ((bval<<1)&2);
|
2005-08-29 04:38:50 +02:00
|
|
|
vvp_bit4_t bit4;
|
2003-03-07 03:44:14 +01:00
|
|
|
|
|
|
|
|
switch (bit) {
|
|
|
|
|
case 0:
|
2005-08-29 04:38:50 +02:00
|
|
|
bit4 = BIT4_0;
|
2003-03-07 03:44:14 +01:00
|
|
|
break;
|
|
|
|
|
case 1:
|
2005-08-29 04:38:50 +02:00
|
|
|
bit4 = BIT4_1;
|
2003-03-07 03:44:14 +01:00
|
|
|
break;
|
|
|
|
|
case 2:
|
2005-08-29 04:38:50 +02:00
|
|
|
bit4 = BIT4_Z;
|
2003-03-07 03:44:14 +01:00
|
|
|
break;
|
|
|
|
|
case 3:
|
2005-08-29 04:38:50 +02:00
|
|
|
bit4 = BIT4_X;
|
2003-03-07 03:44:14 +01:00
|
|
|
break;
|
2005-09-20 20:34:01 +02:00
|
|
|
default:
|
|
|
|
|
assert(0);
|
2003-03-07 03:44:14 +01:00
|
|
|
}
|
|
|
|
|
vthread_put_bit(vpip_current_vthread,
|
2005-08-29 04:38:50 +02:00
|
|
|
rfp->vbit+wdx+idx, bit4);
|
2003-03-07 03:44:14 +01:00
|
|
|
|
|
|
|
|
aval >>= 1;
|
|
|
|
|
bval >>= 1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
break;
|
2001-05-20 02:46:12 +02:00
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
assert(0);
|
|
|
|
|
}
|
|
|
|
|
|
2001-03-16 02:44:34 +01:00
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2004-05-19 05:26:24 +02:00
|
|
|
static vpiHandle sysfunc_put_real_value(vpiHandle ref, p_vpi_value vp)
|
2003-01-27 01:14:37 +01:00
|
|
|
{
|
|
|
|
|
assert(ref->vpi_type->type_code == vpiSysFuncCall);
|
|
|
|
|
|
|
|
|
|
struct __vpiSysTaskCall*rfp = (struct __vpiSysTaskCall*)ref;
|
|
|
|
|
|
|
|
|
|
/* Make sure this is a real valued function. */
|
|
|
|
|
assert(rfp->vwid == -vpiRealConst);
|
|
|
|
|
|
|
|
|
|
double val = 0.0;
|
|
|
|
|
|
|
|
|
|
switch (vp->format) {
|
|
|
|
|
|
|
|
|
|
case vpiRealVal:
|
|
|
|
|
val = vp->value.real;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
assert(0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
vthread_put_real(vpip_current_vthread, rfp->vbit, val);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2006-06-18 06:15:50 +02:00
|
|
|
static vpiHandle sysfunc_put_4net_value(vpiHandle ref, p_vpi_value vp)
|
|
|
|
|
{
|
|
|
|
|
assert(ref->vpi_type->type_code == vpiSysFuncCall);
|
|
|
|
|
|
|
|
|
|
struct __vpiSysTaskCall*rfp = (struct __vpiSysTaskCall*)ref;
|
|
|
|
|
|
|
|
|
|
unsigned vwid = (unsigned) rfp->vwid;
|
|
|
|
|
vvp_vector4_t val (vwid);
|
|
|
|
|
|
|
|
|
|
switch (vp->format) {
|
|
|
|
|
|
|
|
|
|
case vpiIntVal: {
|
|
|
|
|
long tmp = vp->value.integer;
|
|
|
|
|
for (unsigned idx = 0 ; idx < vwid ; idx += 1) {
|
|
|
|
|
val.set_bit(idx, (tmp&1)? BIT4_1 : BIT4_0);
|
|
|
|
|
tmp >>= 1;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case vpiVectorVal:
|
|
|
|
|
|
|
|
|
|
for (unsigned wdx = 0 ; wdx < vwid ; wdx += 32) {
|
|
|
|
|
unsigned word = wdx / 32;
|
|
|
|
|
unsigned long aval = vp->value.vector[word].aval;
|
|
|
|
|
unsigned long bval = vp->value.vector[word].bval;
|
|
|
|
|
|
|
|
|
|
for (unsigned idx = 0 ; (wdx+idx) < vwid ; idx += 1) {
|
|
|
|
|
int bit = (aval&1) | ((bval<<1)&2);
|
|
|
|
|
vvp_bit4_t bit4;
|
|
|
|
|
|
|
|
|
|
switch (bit) {
|
|
|
|
|
case 0:
|
|
|
|
|
bit4 = BIT4_0;
|
|
|
|
|
break;
|
|
|
|
|
case 1:
|
|
|
|
|
bit4 = BIT4_1;
|
|
|
|
|
break;
|
|
|
|
|
case 2:
|
|
|
|
|
bit4 = BIT4_Z;
|
|
|
|
|
break;
|
|
|
|
|
case 3:
|
|
|
|
|
bit4 = BIT4_X;
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
assert(0);
|
|
|
|
|
}
|
|
|
|
|
val.set_bit(wdx+idx, bit4);
|
|
|
|
|
|
|
|
|
|
aval >>= 1;
|
|
|
|
|
bval >>= 1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
fprintf(stderr, "XXXX format=%d, vwid=%u\n", vp->format, rfp->vwid);
|
|
|
|
|
assert(0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
vvp_send_vec4(rfp->fnet->out, val);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static vpiHandle sysfunc_put_rnet_value(vpiHandle ref, p_vpi_value vp)
|
|
|
|
|
{
|
|
|
|
|
assert(ref->vpi_type->type_code == vpiSysFuncCall);
|
|
|
|
|
|
|
|
|
|
struct __vpiSysTaskCall*rfp = (struct __vpiSysTaskCall*)ref;
|
|
|
|
|
double val;
|
|
|
|
|
|
|
|
|
|
switch (vp->format) {
|
|
|
|
|
|
|
|
|
|
case vpiRealVal:
|
|
|
|
|
val = vp->value.real;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
assert(0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
vvp_send_real(rfp->fnet->out, val);
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2001-05-20 02:46:12 +02:00
|
|
|
|
2001-03-16 02:44:34 +01:00
|
|
|
static const struct __vpirt vpip_sysfunc_rt = {
|
|
|
|
|
vpiSysFuncCall,
|
|
|
|
|
0,
|
2003-03-03 04:27:35 +01:00
|
|
|
systask_get_str,
|
2001-03-16 02:44:34 +01:00
|
|
|
0,
|
|
|
|
|
sysfunc_put_value,
|
2002-12-21 01:55:57 +01:00
|
|
|
systask_handle,
|
2001-03-16 02:44:34 +01:00
|
|
|
systask_iter
|
|
|
|
|
};
|
|
|
|
|
|
2003-01-27 01:14:37 +01:00
|
|
|
static const struct __vpirt vpip_sysfunc_real_rt = {
|
|
|
|
|
vpiSysFuncCall,
|
|
|
|
|
0,
|
2003-03-03 04:27:35 +01:00
|
|
|
systask_get_str,
|
2003-01-27 01:14:37 +01:00
|
|
|
0,
|
|
|
|
|
sysfunc_put_real_value,
|
|
|
|
|
systask_handle,
|
|
|
|
|
systask_iter
|
|
|
|
|
};
|
|
|
|
|
|
2006-06-18 06:15:50 +02:00
|
|
|
static const struct __vpirt vpip_sysfunc_4net_rt = {
|
|
|
|
|
vpiSysFuncCall,
|
|
|
|
|
0,
|
|
|
|
|
systask_get_str,
|
|
|
|
|
0,
|
|
|
|
|
sysfunc_put_4net_value,
|
|
|
|
|
systask_handle,
|
|
|
|
|
systask_iter
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static const struct __vpirt vpip_sysfunc_rnet_rt = {
|
|
|
|
|
vpiSysFuncCall,
|
|
|
|
|
0,
|
|
|
|
|
systask_get_str,
|
|
|
|
|
0,
|
|
|
|
|
sysfunc_put_rnet_value,
|
|
|
|
|
systask_handle,
|
|
|
|
|
systask_iter
|
|
|
|
|
};
|
|
|
|
|
|
2001-03-16 02:44:34 +01:00
|
|
|
/* **** Manipulate the internal datastructures. **** */
|
|
|
|
|
|
|
|
|
|
static struct __vpiUserSystf**def_table = 0;
|
|
|
|
|
static unsigned def_count = 0;
|
|
|
|
|
|
|
|
|
|
static struct __vpiUserSystf* allocate_def(void)
|
|
|
|
|
{
|
|
|
|
|
if (def_table == 0) {
|
|
|
|
|
def_table = (struct __vpiUserSystf**)
|
|
|
|
|
malloc(sizeof (struct __vpiUserSystf*));
|
|
|
|
|
|
|
|
|
|
def_table[0] = (struct __vpiUserSystf*)
|
|
|
|
|
calloc(1, sizeof(struct __vpiUserSystf));
|
|
|
|
|
|
|
|
|
|
def_count = 1;
|
|
|
|
|
return def_table[0];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
def_table = (struct __vpiUserSystf**)
|
|
|
|
|
realloc(def_table, (def_count+1)*sizeof (struct __vpiUserSystf*));
|
|
|
|
|
|
|
|
|
|
def_table[def_count] = (struct __vpiUserSystf*)
|
|
|
|
|
calloc(1, sizeof(struct __vpiUserSystf));
|
|
|
|
|
|
|
|
|
|
return def_table[def_count++];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-06-18 06:15:50 +02:00
|
|
|
struct __vpiUserSystf* vpip_find_systf(const char*name)
|
2001-03-16 02:44:34 +01:00
|
|
|
{
|
|
|
|
|
for (unsigned idx = 0 ; idx < def_count ; idx += 1)
|
|
|
|
|
if (strcmp(def_table[idx]->info.tfname, name) == 0)
|
|
|
|
|
return def_table[idx];
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* A vpi_call is actually built up into a vpiSysTaskCall VPI object
|
|
|
|
|
* that refers back to the vpiUserSystf VPI object that is the
|
|
|
|
|
* definition. So this function is called by the compiler when a
|
|
|
|
|
* %vpi_call statement is encountered. Create here a vpiHandle that
|
|
|
|
|
* describes the call, and return it. The %vpi_call instruction will
|
|
|
|
|
* store this handle for when it is executed.
|
2004-06-30 05:00:36 +02:00
|
|
|
*
|
|
|
|
|
* If this is called to make a function, then the vwid will be a
|
|
|
|
|
* non-zero value that represents the width or type of the result. The
|
|
|
|
|
* vbit is also a non-zero value, the address in thread space of the result.
|
2001-03-16 02:44:34 +01:00
|
|
|
*/
|
2003-01-27 01:14:37 +01:00
|
|
|
vpiHandle vpip_build_vpi_call(const char*name, unsigned vbit, int vwid,
|
2006-06-18 06:15:50 +02:00
|
|
|
class vvp_net_t*fnet,
|
2001-05-20 02:46:12 +02:00
|
|
|
unsigned argc, vpiHandle*argv)
|
2001-03-16 02:44:34 +01:00
|
|
|
{
|
2001-05-20 02:46:12 +02:00
|
|
|
struct __vpiUserSystf*defn = vpip_find_systf(name);
|
|
|
|
|
if (defn == 0) {
|
2001-03-22 23:38:13 +01:00
|
|
|
fprintf(stderr, "%s: This task not defined "
|
|
|
|
|
"by any modules. I cannot compile it.\n", name);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2001-05-20 02:46:12 +02:00
|
|
|
switch (defn->info.type) {
|
|
|
|
|
case vpiSysTask:
|
2006-06-18 06:15:50 +02:00
|
|
|
if (vwid != 0 || fnet != 0) {
|
2001-08-03 08:50:44 +02:00
|
|
|
fprintf(stderr, "%s: This is a system Task, "
|
|
|
|
|
"you cannot call it as a Function\n", name);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
2001-05-20 02:46:12 +02:00
|
|
|
assert(vbit == 0);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case vpiSysFunc:
|
2006-06-18 06:15:50 +02:00
|
|
|
if (vwid == 0 && fnet == 0) {
|
2001-08-03 08:50:44 +02:00
|
|
|
fprintf(stderr, "%s: This is a system Function, "
|
|
|
|
|
"you cannot call it as a Task\n", name);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
2001-05-20 02:46:12 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
assert(0);
|
2001-08-03 08:50:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
struct __vpiSysTaskCall*obj = new struct __vpiSysTaskCall;
|
2001-05-20 02:46:12 +02:00
|
|
|
|
2001-08-03 08:50:44 +02:00
|
|
|
switch (defn->info.type) {
|
|
|
|
|
case vpiSysTask:
|
|
|
|
|
obj->base.vpi_type = &vpip_systask_rt;
|
|
|
|
|
break;
|
2004-10-04 03:10:51 +02:00
|
|
|
|
2001-08-03 08:50:44 +02:00
|
|
|
case vpiSysFunc:
|
2006-06-18 06:15:50 +02:00
|
|
|
if (fnet && vwid == -vpiRealConst) {
|
|
|
|
|
obj->base.vpi_type = &vpip_sysfunc_rnet_rt;
|
2003-01-27 01:14:37 +01:00
|
|
|
|
2006-06-18 06:15:50 +02:00
|
|
|
} else if (fnet && vwid > 0) {
|
|
|
|
|
obj->base.vpi_type = &vpip_sysfunc_4net_rt;
|
2003-01-27 01:14:37 +01:00
|
|
|
|
2006-06-18 06:15:50 +02:00
|
|
|
} else if (vwid == -vpiRealConst) {
|
2003-01-27 01:14:37 +01:00
|
|
|
obj->base.vpi_type = &vpip_sysfunc_real_rt;
|
|
|
|
|
|
2006-06-18 06:15:50 +02:00
|
|
|
} else if (vwid > 0) {
|
2003-01-27 01:14:37 +01:00
|
|
|
obj->base.vpi_type = &vpip_sysfunc_rt;
|
2006-06-18 06:15:50 +02:00
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
assert(0);
|
2003-01-27 01:14:37 +01:00
|
|
|
}
|
2001-08-03 08:50:44 +02:00
|
|
|
break;
|
2001-05-20 02:46:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
obj->scope = vpip_peek_current_scope();
|
|
|
|
|
obj->defn = defn;
|
|
|
|
|
obj->nargs = argc;
|
|
|
|
|
obj->args = argv;
|
2001-08-03 08:50:44 +02:00
|
|
|
obj->vbit = vbit;
|
|
|
|
|
obj->vwid = vwid;
|
2006-06-18 06:15:50 +02:00
|
|
|
obj->fnet = fnet;
|
2003-01-09 05:09:44 +01:00
|
|
|
obj->userdata = 0;
|
2001-05-20 02:46:12 +02:00
|
|
|
|
2001-03-16 02:44:34 +01:00
|
|
|
/* If there is a compiletf function, call it here. */
|
2002-04-07 04:34:10 +02:00
|
|
|
if (obj->defn->info.compiletf) {
|
2002-05-18 04:34:11 +02:00
|
|
|
|
|
|
|
|
assert(vpi_mode_flag == VPI_MODE_NONE);
|
|
|
|
|
vpi_mode_flag = VPI_MODE_COMPILETF;
|
2002-04-07 04:34:10 +02:00
|
|
|
vpip_cur_task = obj;
|
2001-03-16 02:44:34 +01:00
|
|
|
obj->defn->info.compiletf (obj->defn->info.user_data);
|
2002-04-07 04:34:10 +02:00
|
|
|
vpip_cur_task = 0;
|
2002-05-18 04:34:11 +02:00
|
|
|
vpi_mode_flag = VPI_MODE_NONE;
|
2002-04-07 04:34:10 +02:00
|
|
|
}
|
2001-03-16 02:44:34 +01:00
|
|
|
|
|
|
|
|
return &obj->base;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* This function is used by the %vpi_call instruction to actually
|
|
|
|
|
* place the call to the system task/function. For now, only support
|
|
|
|
|
* calls to system tasks.
|
|
|
|
|
*/
|
2001-05-10 02:26:53 +02:00
|
|
|
|
|
|
|
|
vthread_t vpip_current_vthread;
|
|
|
|
|
|
|
|
|
|
void vpip_execute_vpi_call(vthread_t thr, vpiHandle ref)
|
2001-03-16 02:44:34 +01:00
|
|
|
{
|
2001-05-10 02:26:53 +02:00
|
|
|
vpip_current_vthread = thr;
|
|
|
|
|
|
2001-05-20 02:46:12 +02:00
|
|
|
assert((ref->vpi_type->type_code == vpiSysTaskCall)
|
|
|
|
|
|| (ref->vpi_type->type_code == vpiSysFuncCall));
|
2001-03-16 02:44:34 +01:00
|
|
|
|
|
|
|
|
vpip_cur_task = (struct __vpiSysTaskCall*)ref;
|
|
|
|
|
|
2002-05-18 04:34:11 +02:00
|
|
|
if (vpip_cur_task->defn->info.calltf) {
|
|
|
|
|
assert(vpi_mode_flag == VPI_MODE_NONE);
|
|
|
|
|
vpi_mode_flag = VPI_MODE_CALLTF;
|
2002-05-09 05:34:31 +02:00
|
|
|
vpip_cur_task->defn->info.calltf(vpip_cur_task->defn->info.user_data);
|
2002-05-18 04:34:11 +02:00
|
|
|
vpi_mode_flag = VPI_MODE_NONE;
|
|
|
|
|
}
|
2001-03-16 02:44:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* This is the entry function that a VPI module uses to hook a new
|
|
|
|
|
* task/function into the simulator. The function creates a new
|
|
|
|
|
* __vpi_userSystf to represent the definition for the calls that come
|
|
|
|
|
* to pass later.
|
|
|
|
|
*/
|
|
|
|
|
void vpi_register_systf(const struct t_vpi_systf_data*ss)
|
|
|
|
|
{
|
|
|
|
|
struct __vpiUserSystf*cur = allocate_def();
|
2002-06-02 21:05:50 +02:00
|
|
|
assert(ss);
|
2001-06-25 05:12:06 +02:00
|
|
|
switch (ss->type) {
|
|
|
|
|
case vpiSysTask:
|
|
|
|
|
cur->base.vpi_type = &vpip_systask_def_rt;
|
|
|
|
|
break;
|
|
|
|
|
case vpiSysFunc:
|
|
|
|
|
cur->base.vpi_type = &vpip_sysfunc_def_rt;
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
assert(0);
|
|
|
|
|
}
|
|
|
|
|
|
2001-03-16 02:44:34 +01:00
|
|
|
cur->info = *ss;
|
|
|
|
|
cur->info.tfname = strdup(ss->tfname);
|
|
|
|
|
}
|
|
|
|
|
|
2004-02-18 03:51:59 +01:00
|
|
|
PLI_INT32 vpi_put_userdata(vpiHandle ref, void*data)
|
2003-01-09 05:09:44 +01:00
|
|
|
{
|
2006-09-23 00:33:00 +02:00
|
|
|
if (ref->vpi_type->type_code != vpiSysTaskCall
|
|
|
|
|
&& ref->vpi_type->type_code != vpiSysFuncCall)
|
|
|
|
|
return 0;
|
|
|
|
|
|
2003-01-09 05:09:44 +01:00
|
|
|
struct __vpiSysTaskCall*rfp = (struct __vpiSysTaskCall*)ref;
|
|
|
|
|
|
|
|
|
|
rfp->userdata = data;
|
2006-09-23 00:33:00 +02:00
|
|
|
return 1;
|
2003-01-09 05:09:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void* vpi_get_userdata(vpiHandle ref)
|
|
|
|
|
{
|
|
|
|
|
struct __vpiSysTaskCall*rfp = (struct __vpiSysTaskCall*)ref;
|
|
|
|
|
assert((ref->vpi_type->type_code == vpiSysTaskCall)
|
|
|
|
|
|| (ref->vpi_type->type_code == vpiSysFuncCall));
|
|
|
|
|
|
|
|
|
|
return rfp->userdata;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2001-03-16 02:44:34 +01:00
|
|
|
/*
|
|
|
|
|
* $Log: vpi_tasks.cc,v $
|
2006-09-23 00:33:00 +02:00
|
|
|
* Revision 1.33 2006/09/22 22:33:00 steve
|
|
|
|
|
* Correct return code for vpi_put_userdata.
|
|
|
|
|
*
|
2006-06-18 06:15:50 +02:00
|
|
|
* Revision 1.32 2006/06/18 04:15:50 steve
|
|
|
|
|
* Add support for system functions in continuous assignments.
|
|
|
|
|
*
|
2005-09-20 20:34:01 +02:00
|
|
|
* Revision 1.31 2005/09/20 18:34:02 steve
|
|
|
|
|
* Clean up compiler warnings.
|
|
|
|
|
*
|
2005-08-29 04:38:50 +02:00
|
|
|
* Revision 1.30 2005/08/29 02:38:50 steve
|
|
|
|
|
* Eliminate int to vvp_bit4_t casts.
|
|
|
|
|
*
|
2004-10-04 03:10:51 +02:00
|
|
|
* Revision 1.29 2004/10/04 01:10:59 steve
|
|
|
|
|
* Clean up spurious trailing white space.
|
|
|
|
|
*
|
2004-06-30 05:00:36 +02:00
|
|
|
* Revision 1.28 2004/06/30 03:00:36 steve
|
|
|
|
|
* Some explination of vpi_func arguments.
|
|
|
|
|
*
|
2004-05-19 05:26:24 +02:00
|
|
|
* Revision 1.27 2004/05/19 03:30:46 steve
|
|
|
|
|
* Support delayed/non-blocking assignment to reals and others.
|
|
|
|
|
*
|
2004-02-18 03:51:59 +01:00
|
|
|
* Revision 1.26 2004/02/18 02:51:59 steve
|
|
|
|
|
* Fix type mismatches of various VPI functions.
|
|
|
|
|
*
|
2003-12-07 21:05:56 +01:00
|
|
|
* Revision 1.25 2003/12/07 20:05:56 steve
|
|
|
|
|
* Ducument lxt2 access.
|
|
|
|
|
*
|
2003-06-18 02:54:28 +02:00
|
|
|
* Revision 1.24 2003/06/18 00:54:28 steve
|
|
|
|
|
* Account for all 64 bits in results of $time.
|
|
|
|
|
*
|
2003-03-14 06:00:44 +01:00
|
|
|
* Revision 1.23 2003/03/14 05:00:44 steve
|
|
|
|
|
* Support vpi_get of vpiTimeUnit.
|
|
|
|
|
*
|
2003-03-13 06:07:10 +01:00
|
|
|
* Revision 1.22 2003/03/13 05:07:10 steve
|
|
|
|
|
* signed/unsigned warnings.
|
|
|
|
|
*
|
2003-03-07 03:44:14 +01:00
|
|
|
* Revision 1.21 2003/03/07 02:44:14 steve
|
|
|
|
|
* Support vector put of function return values.
|
|
|
|
|
*
|
2003-03-03 04:27:35 +01:00
|
|
|
* Revision 1.20 2003/03/03 03:27:35 steve
|
|
|
|
|
* Support vpiName for system task/function calls.
|
|
|
|
|
*
|
2003-01-27 01:14:37 +01:00
|
|
|
* Revision 1.19 2003/01/27 00:14:37 steve
|
|
|
|
|
* Support in various contexts the $realtime
|
|
|
|
|
* system task.
|
|
|
|
|
*
|
2003-01-09 05:09:44 +01:00
|
|
|
* Revision 1.18 2003/01/09 04:09:44 steve
|
|
|
|
|
* Add vpi_put_userdata
|
|
|
|
|
*
|
2002-12-21 01:55:57 +01:00
|
|
|
* Revision 1.17 2002/12/21 00:55:58 steve
|
|
|
|
|
* The $time system task returns the integer time
|
|
|
|
|
* scaled to the local units. Change the internal
|
|
|
|
|
* implementation of vpiSystemTime the $time functions
|
|
|
|
|
* to properly account for this. Also add $simtime
|
|
|
|
|
* to get the simulation time.
|
|
|
|
|
*
|
2002-08-12 03:34:58 +02:00
|
|
|
* Revision 1.16 2002/08/12 01:35:09 steve
|
|
|
|
|
* conditional ident string using autoconfig.
|
|
|
|
|
*
|
2002-06-02 21:05:50 +02:00
|
|
|
* Revision 1.15 2002/06/02 19:05:50 steve
|
|
|
|
|
* Check for null pointers from users.
|
|
|
|
|
*
|
2002-05-18 04:34:11 +02:00
|
|
|
* Revision 1.14 2002/05/18 02:34:11 steve
|
|
|
|
|
* Add vpi support for named events.
|
|
|
|
|
*
|
|
|
|
|
* Add vpi_mode_flag to track the mode of the
|
|
|
|
|
* vpi engine. This is for error checking.
|
|
|
|
|
*
|
2002-05-09 05:34:31 +02:00
|
|
|
* Revision 1.13 2002/05/09 03:34:31 steve
|
|
|
|
|
* Handle null time and calltf pointers.
|
|
|
|
|
*
|
2002-05-03 17:44:11 +02:00
|
|
|
* Revision 1.12 2002/05/03 15:44:11 steve
|
|
|
|
|
* Add vpiModule iterator to vpiScope objects.
|
|
|
|
|
*
|
2002-04-07 04:34:10 +02:00
|
|
|
* Revision 1.11 2002/04/07 02:34:10 steve
|
|
|
|
|
* Set vpip_cur_task while calling compileft
|
|
|
|
|
*
|
2001-09-15 20:27:04 +02:00
|
|
|
* Revision 1.10 2001/09/15 18:27:05 steve
|
|
|
|
|
* Make configure detect malloc.h
|
|
|
|
|
*
|
2001-08-03 08:50:44 +02:00
|
|
|
* Revision 1.9 2001/08/03 06:50:44 steve
|
|
|
|
|
* Detect system function used as a task.
|
|
|
|
|
*
|
2001-06-25 05:12:06 +02:00
|
|
|
* Revision 1.8 2001/06/25 03:12:06 steve
|
|
|
|
|
* Give task/function definitions a vpi type object.
|
|
|
|
|
*
|
2001-05-20 02:46:12 +02:00
|
|
|
* Revision 1.7 2001/05/20 00:46:12 steve
|
|
|
|
|
* Add support for system function calls.
|
|
|
|
|
*
|
2001-05-10 02:26:53 +02:00
|
|
|
* Revision 1.6 2001/05/10 00:26:53 steve
|
|
|
|
|
* VVP support for memories in expressions,
|
|
|
|
|
* including general support for thread bit
|
|
|
|
|
* vectors as system task parameters.
|
|
|
|
|
* (Stephan Boettcher)
|
|
|
|
|
*
|
2001-04-18 06:21:23 +02:00
|
|
|
* Revision 1.5 2001/04/18 04:21:23 steve
|
|
|
|
|
* Put threads into scopes.
|
|
|
|
|
*
|
2001-03-22 23:38:13 +01:00
|
|
|
* Revision 1.4 2001/03/22 22:38:14 steve
|
|
|
|
|
* Detect undefined system tasks at compile time.
|
|
|
|
|
*
|
2001-03-18 05:35:18 +01:00
|
|
|
* Revision 1.3 2001/03/18 04:35:18 steve
|
|
|
|
|
* Add support for string constants to VPI.
|
|
|
|
|
*
|
2001-03-18 01:37:55 +01:00
|
|
|
* Revision 1.2 2001/03/18 00:37:55 steve
|
|
|
|
|
* Add support for vpi scopes.
|
|
|
|
|
*
|
2001-03-16 02:44:34 +01:00
|
|
|
* Revision 1.1 2001/03/16 01:44:34 steve
|
|
|
|
|
* Add structures for VPI support, and all the %vpi_call
|
|
|
|
|
* instruction. Get linking of VPI modules to work.
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
|