2003-01-26 00:48:05 +01:00
|
|
|
/*
|
2008-05-01 00:39:50 +02:00
|
|
|
* Copyright (c) 2003-2008 Stephen Williams (steve@icarus.com)
|
2003-01-26 00:48:05 +01:00
|
|
|
*
|
|
|
|
|
* 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
|
|
|
|
|
*/
|
|
|
|
|
|
2008-01-01 18:45:02 +01:00
|
|
|
# include "compile.h"
|
2003-01-26 00:48:05 +01:00
|
|
|
# include "vpi_priv.h"
|
2003-02-10 06:20:10 +01:00
|
|
|
# include "schedule.h"
|
2003-01-26 00:48:05 +01:00
|
|
|
# include <stdio.h>
|
|
|
|
|
# include <stdlib.h>
|
2003-03-13 05:59:21 +01:00
|
|
|
# include <string.h>
|
2003-01-26 00:48:05 +01:00
|
|
|
#ifdef HAVE_MALLOC_H
|
|
|
|
|
# include <malloc.h>
|
|
|
|
|
#endif
|
|
|
|
|
# include <assert.h>
|
|
|
|
|
|
2007-12-03 18:44:31 +01:00
|
|
|
static int real_var_get(int code, vpiHandle ref)
|
|
|
|
|
{
|
|
|
|
|
assert(ref->vpi_type->type_code == vpiRealVar);
|
|
|
|
|
|
|
|
|
|
struct __vpiRealVar*rfp = (struct __vpiRealVar*)ref;
|
|
|
|
|
|
2008-05-01 00:39:50 +02:00
|
|
|
switch (code) {
|
|
|
|
|
case vpiArray:
|
2007-12-03 18:44:31 +01:00
|
|
|
return rfp->parent != 0;
|
2008-05-01 00:39:50 +02:00
|
|
|
|
|
|
|
|
case vpiSize:
|
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
|
|
case vpiLineNo:
|
|
|
|
|
return 0; // Not implemented for now!
|
2007-12-03 18:44:31 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
2003-01-26 00:48:05 +01:00
|
|
|
|
2003-02-10 06:20:10 +01:00
|
|
|
static char* real_var_get_str(int code, vpiHandle ref)
|
|
|
|
|
{
|
|
|
|
|
assert(ref->vpi_type->type_code == vpiRealVar);
|
|
|
|
|
|
|
|
|
|
struct __vpiRealVar*rfp = (struct __vpiRealVar*)ref;
|
2007-12-19 00:11:50 +01:00
|
|
|
|
2008-01-01 18:45:02 +01:00
|
|
|
if (code == vpiFile) { // Not implemented for now!
|
|
|
|
|
return simple_set_rbuf_str(file_names[0]);
|
|
|
|
|
}
|
|
|
|
|
|
2007-12-19 00:11:50 +01:00
|
|
|
char *nm, *ixs;
|
2007-12-03 20:41:52 +01:00
|
|
|
if (rfp->parent) {
|
|
|
|
|
nm = strdup(vpi_get_str(vpiName, rfp->parent));
|
2007-12-19 00:11:50 +01:00
|
|
|
s_vpi_value vp;
|
2007-12-03 20:41:52 +01:00
|
|
|
vp.format = vpiDecStrVal;
|
|
|
|
|
vpi_get_value(rfp->id.index, &vp);
|
2007-12-19 00:11:50 +01:00
|
|
|
ixs = vp.value.str; /* do I need to strdup() this? */
|
2007-12-03 20:41:52 +01:00
|
|
|
} else {
|
|
|
|
|
nm = strdup(rfp->id.name);
|
2007-12-19 00:11:50 +01:00
|
|
|
ixs = NULL;
|
2003-02-10 06:20:10 +01:00
|
|
|
}
|
|
|
|
|
|
2007-12-19 00:11:50 +01:00
|
|
|
char *rbuf = generic_get_str(code, &rfp->scope->base, nm, ixs);
|
2007-12-03 20:41:52 +01:00
|
|
|
free(nm);
|
2007-12-19 00:11:50 +01:00
|
|
|
return rbuf;
|
2003-02-10 06:20:10 +01:00
|
|
|
}
|
|
|
|
|
|
2007-12-03 18:44:31 +01:00
|
|
|
static vpiHandle real_var_get_handle(int code, vpiHandle ref)
|
|
|
|
|
{
|
|
|
|
|
assert(ref->vpi_type->type_code == vpiRealVar);
|
|
|
|
|
|
|
|
|
|
struct __vpiRealVar*rfp = (struct __vpiRealVar*)ref;
|
|
|
|
|
|
|
|
|
|
switch (code) {
|
|
|
|
|
|
|
|
|
|
case vpiParent:
|
|
|
|
|
return rfp->parent;
|
|
|
|
|
|
|
|
|
|
case vpiIndex:
|
2007-12-03 20:41:52 +01:00
|
|
|
return rfp->parent ? rfp->id.index : 0;
|
2007-12-03 18:44:31 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static vpiHandle real_var_iterate(int code, vpiHandle ref)
|
|
|
|
|
{
|
|
|
|
|
assert(ref->vpi_type->type_code == vpiRealVar);
|
|
|
|
|
|
|
|
|
|
struct __vpiRealVar*rfp = (struct __vpiRealVar*)ref;
|
|
|
|
|
|
|
|
|
|
if (code == vpiIndex) {
|
2007-12-03 20:41:52 +01:00
|
|
|
return rfp->parent ? (rfp->id.index->vpi_type->iterate_)
|
|
|
|
|
(code, rfp->id.index) : 0;
|
2007-12-03 18:44:31 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2003-01-26 00:48:05 +01:00
|
|
|
static void real_var_get_value(vpiHandle ref, s_vpi_value*vp)
|
|
|
|
|
{
|
|
|
|
|
assert(ref->vpi_type->type_code == vpiRealVar);
|
|
|
|
|
|
2005-07-06 06:29:25 +02:00
|
|
|
struct __vpiRealVar*rfp
|
|
|
|
|
= (struct __vpiRealVar*)ref;
|
|
|
|
|
vvp_fun_signal_real*fun
|
|
|
|
|
= dynamic_cast<vvp_fun_signal_real*>(rfp->net->fun);
|
2003-02-04 05:03:40 +01:00
|
|
|
|
2005-07-06 06:29:25 +02:00
|
|
|
fun->get_value(vp);
|
2003-01-26 00:48:05 +01:00
|
|
|
}
|
|
|
|
|
|
2008-03-11 05:54:58 +01:00
|
|
|
static vpiHandle real_var_put_value(vpiHandle ref, p_vpi_value vp, int)
|
2003-01-26 00:48:05 +01:00
|
|
|
{
|
|
|
|
|
assert(ref->vpi_type->type_code == vpiRealVar);
|
|
|
|
|
|
2005-07-06 06:29:25 +02:00
|
|
|
struct __vpiRealVar*rfp
|
|
|
|
|
= (struct __vpiRealVar*)ref;
|
2003-01-26 00:48:05 +01:00
|
|
|
|
2005-07-06 06:29:25 +02:00
|
|
|
vvp_net_ptr_t destination (rfp->net, 0);
|
2003-02-10 06:20:10 +01:00
|
|
|
|
2007-08-23 00:15:32 +02:00
|
|
|
switch (vp->format) {
|
2003-02-10 06:20:10 +01:00
|
|
|
|
2007-08-23 00:15:32 +02:00
|
|
|
case vpiRealVal:
|
|
|
|
|
vvp_send_real(destination, vp->value.real);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case vpiIntVal:
|
|
|
|
|
vvp_send_real(destination, (double)vp->value.integer);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
fprintf(stderr, "Cannot convert type %d to a real value.",
|
|
|
|
|
vp->format);
|
|
|
|
|
assert(0);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
}
|
2003-01-26 00:48:05 +01:00
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static const struct __vpirt vpip_real_var_rt = {
|
|
|
|
|
vpiRealVar,
|
|
|
|
|
|
2007-12-03 18:44:31 +01:00
|
|
|
real_var_get,
|
|
|
|
|
real_var_get_str,
|
|
|
|
|
real_var_get_value,
|
|
|
|
|
real_var_put_value,
|
2003-01-26 00:48:05 +01:00
|
|
|
|
2007-12-03 18:44:31 +01:00
|
|
|
real_var_get_handle,
|
|
|
|
|
real_var_iterate,
|
2003-01-26 00:48:05 +01:00
|
|
|
0,
|
|
|
|
|
|
2003-02-02 02:40:24 +01:00
|
|
|
0
|
2003-01-26 00:48:05 +01:00
|
|
|
};
|
|
|
|
|
|
2003-02-10 06:20:10 +01:00
|
|
|
void vpip_real_value_change(struct __vpiCallback*cbh,
|
|
|
|
|
vpiHandle ref)
|
|
|
|
|
{
|
2005-07-06 06:29:25 +02:00
|
|
|
struct __vpiRealVar*rfp
|
|
|
|
|
= (struct __vpiRealVar*)ref;
|
|
|
|
|
vvp_fun_signal_real*fun
|
|
|
|
|
= dynamic_cast<vvp_fun_signal_real*>(rfp->net->fun);
|
|
|
|
|
|
|
|
|
|
fun->add_vpi_callback(cbh);
|
2003-02-10 06:20:10 +01:00
|
|
|
}
|
|
|
|
|
|
2007-12-03 20:41:52 +01:00
|
|
|
/*
|
|
|
|
|
* Since reals do not currently support arrays none of the array code
|
|
|
|
|
* has been tested! Though it should work since it is a copy of the
|
|
|
|
|
* signal code.
|
|
|
|
|
*/
|
2005-07-06 06:29:25 +02:00
|
|
|
vpiHandle vpip_make_real_var(const char*name, vvp_net_t*net)
|
2003-01-26 00:48:05 +01:00
|
|
|
{
|
|
|
|
|
struct __vpiRealVar*obj = (struct __vpiRealVar*)
|
|
|
|
|
malloc(sizeof(struct __vpiRealVar));
|
|
|
|
|
|
|
|
|
|
obj->base.vpi_type = &vpip_real_var_rt;
|
2007-12-03 18:44:31 +01:00
|
|
|
obj->parent = 0;
|
2008-10-28 01:54:50 +01:00
|
|
|
obj->id.name = name ? vpip_name_string(name) : 0;
|
2005-07-06 06:29:25 +02:00
|
|
|
obj->net = net;
|
2003-01-26 00:48:05 +01:00
|
|
|
|
2007-08-17 00:13:25 +02:00
|
|
|
obj->scope = vpip_peek_current_scope();
|
|
|
|
|
|
2003-01-26 00:48:05 +01:00
|
|
|
return &obj->base;
|
|
|
|
|
}
|