2001-03-20 07:16:23 +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
|
|
|
|
|
*/
|
|
|
|
|
#if !defined(WINNT)
|
2001-03-25 01:35:35 +01:00
|
|
|
#ident "$Id: vpi_signal.cc,v 1.3 2001/03/25 00:35:35 steve Exp $"
|
2001-03-20 07:16:23 +01:00
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* vpiReg handles are handled here. These objects represent vectors of
|
|
|
|
|
* .var objects that can be manipulated by the VPI module.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
# include "vpi_priv.h"
|
2001-03-21 06:13:03 +01:00
|
|
|
# include "functor.h"
|
2001-03-20 07:16:23 +01:00
|
|
|
# include <malloc.h>
|
|
|
|
|
# include <assert.h>
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* implement vpi_get for vpiReg objects.
|
|
|
|
|
*/
|
|
|
|
|
static int signal_get(int code, vpiHandle ref)
|
|
|
|
|
{
|
|
|
|
|
assert((ref->vpi_type->type_code==vpiNet)
|
|
|
|
|
|| (ref->vpi_type->type_code==vpiReg));
|
|
|
|
|
|
|
|
|
|
struct __vpiSignal*rfp = (struct __vpiSignal*)ref;
|
|
|
|
|
|
|
|
|
|
switch (code) {
|
|
|
|
|
|
|
|
|
|
case vpiSigned:
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
case vpiSize:
|
|
|
|
|
if (rfp->msb >= rfp->lsb)
|
|
|
|
|
return rfp->msb - rfp->lsb + 1;
|
|
|
|
|
else
|
|
|
|
|
return rfp->lsb - rfp->msb + 1;
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static char* signal_get_str(int code, vpiHandle ref)
|
|
|
|
|
{
|
|
|
|
|
assert((ref->vpi_type->type_code==vpiNet)
|
|
|
|
|
|| (ref->vpi_type->type_code==vpiReg));
|
|
|
|
|
|
|
|
|
|
struct __vpiSignal*rfp = (struct __vpiSignal*)ref;
|
|
|
|
|
|
|
|
|
|
switch (code) {
|
|
|
|
|
|
|
|
|
|
case vpiFullName:
|
|
|
|
|
return (char*)rfp->name;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2001-03-21 06:13:03 +01:00
|
|
|
static char buf[4096];
|
|
|
|
|
|
2001-03-20 07:16:23 +01:00
|
|
|
/*
|
|
|
|
|
* The get_value method reads the values of the functors and returns
|
|
|
|
|
* the vector to the caller. This causes no side-effect, and reads the
|
|
|
|
|
* variables like a %load would.
|
|
|
|
|
*/
|
|
|
|
|
static void signal_get_value(vpiHandle ref, s_vpi_value*vp)
|
|
|
|
|
{
|
2001-03-21 06:13:03 +01:00
|
|
|
static const char bit_char[4] = { '0', '1', 'x', 'z' };
|
|
|
|
|
|
2001-03-20 07:16:23 +01:00
|
|
|
assert((ref->vpi_type->type_code==vpiNet)
|
|
|
|
|
|| (ref->vpi_type->type_code==vpiReg));
|
|
|
|
|
|
|
|
|
|
struct __vpiSignal*rfp = (struct __vpiSignal*)ref;
|
|
|
|
|
|
2001-03-21 06:13:03 +01:00
|
|
|
unsigned wid = (rfp->msb >= rfp->lsb)
|
|
|
|
|
? (rfp->msb - rfp->lsb + 1)
|
|
|
|
|
: (rfp->lsb - rfp->msb + 1);
|
|
|
|
|
|
|
|
|
|
switch (vp->format) {
|
|
|
|
|
|
|
|
|
|
case vpiBinStrVal:
|
|
|
|
|
for (unsigned idx = 0 ; idx < wid ; idx += 1) {
|
|
|
|
|
vvp_ipoint_t fptr = ipoint_index(rfp->bits, idx);
|
|
|
|
|
functor_t fp = functor_index(fptr);
|
|
|
|
|
buf[wid-idx-1] = bit_char[fp->oval&3];
|
|
|
|
|
}
|
|
|
|
|
buf[wid] = 0;
|
|
|
|
|
vp->value.str = buf;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
/* XXXX Not implemented yet. */
|
|
|
|
|
assert(0);
|
|
|
|
|
}
|
2001-03-20 07:16:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* The put_value method writes the value into the vector, and returns
|
|
|
|
|
* the affected ref. This operation works much like the %set or
|
|
|
|
|
* %assign instructions and causes all the side-effects that the
|
|
|
|
|
* equivilent instruction would cause.
|
|
|
|
|
*/
|
|
|
|
|
static vpiHandle signal_put_value(vpiHandle ref, s_vpi_value*vp,
|
|
|
|
|
p_vpi_time when, int flags)
|
|
|
|
|
{
|
|
|
|
|
assert((ref->vpi_type->type_code==vpiNet)
|
|
|
|
|
|| (ref->vpi_type->type_code==vpiReg));
|
|
|
|
|
|
|
|
|
|
struct __vpiSignal*rfp = (struct __vpiSignal*)ref;
|
|
|
|
|
|
|
|
|
|
/* XXXX Not implemented yet. */
|
|
|
|
|
assert(0);
|
|
|
|
|
|
|
|
|
|
return ref;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static const struct __vpirt vpip_reg_rt = {
|
|
|
|
|
vpiReg,
|
|
|
|
|
signal_get,
|
|
|
|
|
signal_get_str,
|
|
|
|
|
signal_get_value,
|
|
|
|
|
signal_put_value,
|
|
|
|
|
0,
|
|
|
|
|
0
|
|
|
|
|
};
|
|
|
|
|
|
2001-03-25 01:35:35 +01:00
|
|
|
static const struct __vpirt vpip_net_rt = {
|
|
|
|
|
vpiNet,
|
|
|
|
|
signal_get,
|
|
|
|
|
signal_get_str,
|
|
|
|
|
signal_get_value,
|
|
|
|
|
signal_put_value,
|
|
|
|
|
0,
|
|
|
|
|
0
|
|
|
|
|
};
|
|
|
|
|
|
2001-03-20 07:16:23 +01:00
|
|
|
/*
|
|
|
|
|
* Construct a vpiReg object. Give the object specified dimensions,
|
|
|
|
|
* and point to the specified functor for the lsb.
|
|
|
|
|
*/
|
|
|
|
|
vpiHandle vpip_make_reg(char*name, int msb, int lsb, vvp_ipoint_t base)
|
|
|
|
|
{
|
|
|
|
|
struct __vpiSignal*obj = (struct __vpiSignal*)
|
|
|
|
|
malloc(sizeof(struct __vpiSignal));
|
|
|
|
|
obj->base.vpi_type = &vpip_reg_rt;
|
|
|
|
|
obj->name = name;
|
|
|
|
|
obj->msb = msb;
|
|
|
|
|
obj->lsb = lsb;
|
|
|
|
|
obj->bits = base;
|
|
|
|
|
|
|
|
|
|
obj->scope = vpip_peek_current_scope();
|
|
|
|
|
|
|
|
|
|
return &obj->base;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2001-03-25 01:35:35 +01:00
|
|
|
/*
|
|
|
|
|
* Construct a vpiReg object. Give the object specified dimensions,
|
|
|
|
|
* and point to the specified functor for the lsb.
|
|
|
|
|
*/
|
|
|
|
|
vpiHandle vpip_make_net(char*name, int msb, int lsb, vvp_ipoint_t base)
|
|
|
|
|
{
|
|
|
|
|
struct __vpiSignal*obj = (struct __vpiSignal*)
|
|
|
|
|
malloc(sizeof(struct __vpiSignal));
|
|
|
|
|
obj->base.vpi_type = &vpip_net_rt;
|
|
|
|
|
obj->name = name;
|
|
|
|
|
obj->msb = msb;
|
|
|
|
|
obj->lsb = lsb;
|
|
|
|
|
obj->bits = base;
|
|
|
|
|
|
|
|
|
|
obj->scope = vpip_peek_current_scope();
|
|
|
|
|
|
|
|
|
|
return &obj->base;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2001-03-20 07:16:23 +01:00
|
|
|
/*
|
|
|
|
|
* $Log: vpi_signal.cc,v $
|
2001-03-25 01:35:35 +01:00
|
|
|
* Revision 1.3 2001/03/25 00:35:35 steve
|
|
|
|
|
* Add the .net statement.
|
|
|
|
|
*
|
2001-03-21 06:13:03 +01:00
|
|
|
* Revision 1.2 2001/03/21 05:13:03 steve
|
|
|
|
|
* Allow var objects as vpiHandle arguments to %vpi_call.
|
|
|
|
|
*
|
2001-03-20 07:16:23 +01:00
|
|
|
* Revision 1.1 2001/03/20 06:16:24 steve
|
|
|
|
|
* Add support for variable vectors.
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
|