2003-01-26 00:48:05 +01:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2003 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
|
|
|
|
|
*/
|
|
|
|
|
#ifdef HAVE_CVS_IDENT
|
2005-09-20 20:34:01 +02:00
|
|
|
#ident "$Id: vpi_real.cc,v 1.11 2005/09/20 18:34:02 steve Exp $"
|
2003-01-26 00:48:05 +01:00
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
# 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>
|
|
|
|
|
|
|
|
|
|
|
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-08-17 00:13:25 +02:00
|
|
|
char *bn = strdup(vpi_get_str(vpiFullName, &rfp->scope->base));
|
|
|
|
|
char *rbuf = need_result_buf(strlen(bn)+strlen(rfp->name) + 2,
|
|
|
|
|
RBUF_STR);
|
2003-02-10 06:20:10 +01:00
|
|
|
|
|
|
|
|
switch (code) {
|
|
|
|
|
|
2007-08-17 00:13:25 +02:00
|
|
|
case vpiFullName:
|
|
|
|
|
sprintf(rbuf, "%s.%s", bn, rfp->name);
|
|
|
|
|
free(bn);
|
|
|
|
|
return rbuf;
|
|
|
|
|
|
2003-02-10 06:20:10 +01:00
|
|
|
case vpiName:
|
2003-03-13 05:59:21 +01:00
|
|
|
strcpy(rbuf, rfp->name);
|
2007-08-17 00:13:25 +02:00
|
|
|
free(bn);
|
2003-03-13 05:59:21 +01:00
|
|
|
return rbuf;
|
2003-02-10 06:20:10 +01:00
|
|
|
|
|
|
|
|
default:
|
2007-08-17 00:13:25 +02:00
|
|
|
free(bn);
|
2003-02-10 06:20:10 +01:00
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
2004-05-19 05:26:24 +02:00
|
|
|
static vpiHandle real_var_put_value(vpiHandle ref, p_vpi_value vp)
|
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
|
|
|
|
2005-07-06 06:29:25 +02:00
|
|
|
assert(vp->format == vpiRealVal);
|
|
|
|
|
vvp_send_real(destination, vp->value.real);
|
2003-02-10 06:20:10 +01:00
|
|
|
|
2003-01-26 00:48:05 +01:00
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static const struct __vpirt vpip_real_var_rt = {
|
|
|
|
|
vpiRealVar,
|
|
|
|
|
|
|
|
|
|
0,
|
2003-02-10 06:20:10 +01:00
|
|
|
&real_var_get_str,
|
2003-01-26 00:48:05 +01:00
|
|
|
&real_var_get_value,
|
|
|
|
|
&real_var_put_value,
|
|
|
|
|
|
|
|
|
|
0,
|
|
|
|
|
0,
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
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;
|
2003-03-06 05:32:00 +01:00
|
|
|
obj->name = vpip_name_string(name);
|
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;
|
|
|
|
|
}
|
|
|
|
|
|