2001-03-18 05:35:18 +01:00
|
|
|
/*
|
2012-01-20 00:04:51 +01:00
|
|
|
* Copyright (c) 2001-2012 Stephen Williams (steve@icarus.com)
|
2001-03-18 05:35:18 +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
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
# include "vpi_priv.h"
|
2008-01-01 18:45:02 +01:00
|
|
|
# include "compile.h"
|
2009-01-30 02:23:09 +01:00
|
|
|
# include "config.h"
|
|
|
|
|
#ifdef CHECK_WITH_VALGRIND
|
|
|
|
|
# include "vvp_cleanup.h"
|
|
|
|
|
#endif
|
2010-05-31 22:12:06 +02:00
|
|
|
# include <cstdio>
|
|
|
|
|
# include <cstdlib>
|
|
|
|
|
# include <cstring>
|
|
|
|
|
# include <cassert>
|
2010-10-24 00:52:56 +02:00
|
|
|
# include "ivl_alloc.h"
|
2001-03-18 05:35:18 +01:00
|
|
|
|
|
|
|
|
static int string_get(int code, vpiHandle ref)
|
|
|
|
|
{
|
2002-01-25 04:24:19 +01:00
|
|
|
struct __vpiStringConst*rfp;
|
2001-03-18 05:35:18 +01:00
|
|
|
|
|
|
|
|
switch (code) {
|
2002-01-25 04:24:19 +01:00
|
|
|
case vpiSize:
|
2012-01-19 19:16:39 +01:00
|
|
|
rfp = dynamic_cast<__vpiStringConst*>(ref);
|
|
|
|
|
return strlen(rfp->value)*8;
|
2002-01-25 04:24:19 +01:00
|
|
|
|
|
|
|
|
case vpiSigned:
|
|
|
|
|
return 0;
|
|
|
|
|
|
2001-03-18 05:35:18 +01:00
|
|
|
case vpiConstType:
|
2002-01-25 04:24:19 +01:00
|
|
|
return vpiStringConst;
|
2001-03-18 05:35:18 +01:00
|
|
|
|
2008-11-09 01:26:55 +01:00
|
|
|
case vpiAutomatic:
|
|
|
|
|
return 0;
|
|
|
|
|
|
2009-01-30 02:23:09 +01:00
|
|
|
#ifdef CHECK_WITH_VALGRIND
|
|
|
|
|
case _vpiFromThr:
|
|
|
|
|
return _vpiNoThr;
|
|
|
|
|
#endif
|
|
|
|
|
|
2001-03-18 05:35:18 +01:00
|
|
|
default:
|
2002-01-25 04:24:19 +01:00
|
|
|
fprintf(stderr, "vvp error: get %d not supported "
|
|
|
|
|
"by vpiStringConst\n", code);
|
|
|
|
|
assert(0);
|
|
|
|
|
return 0;
|
2001-03-18 05:35:18 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void string_value(vpiHandle ref, p_vpi_value vp)
|
|
|
|
|
{
|
2002-01-25 04:24:19 +01:00
|
|
|
unsigned uint_value;
|
2007-08-14 00:56:02 +02:00
|
|
|
p_vpi_vecval vecp;
|
2012-01-19 19:16:39 +01:00
|
|
|
struct __vpiStringConst*rfp = dynamic_cast<__vpiStringConst*>(ref);
|
2003-03-13 05:59:21 +01:00
|
|
|
int size = strlen(rfp->value);
|
|
|
|
|
char*rbuf = 0;
|
|
|
|
|
char*cp;
|
|
|
|
|
|
2001-03-18 05:35:18 +01:00
|
|
|
switch (vp->format) {
|
|
|
|
|
case vpiObjTypeVal:
|
2003-03-14 06:02:13 +01:00
|
|
|
/* String parameters by default have vpiStringVal values. */
|
|
|
|
|
vp->format = vpiStringVal;
|
|
|
|
|
|
2001-03-18 05:35:18 +01:00
|
|
|
case vpiStringVal:
|
2003-03-18 00:47:25 +01:00
|
|
|
rbuf = need_result_buf(size + 1, RBUF_VAL);
|
|
|
|
|
strcpy(rbuf, (char*)rfp->value);
|
|
|
|
|
vp->value.str = rbuf;
|
2001-03-18 05:35:18 +01:00
|
|
|
break;
|
|
|
|
|
|
2002-01-25 04:24:19 +01:00
|
|
|
case vpiDecStrVal:
|
|
|
|
|
if (size > 4){
|
|
|
|
|
// We only support standard integers. Ignore other bytes...
|
2004-10-04 03:10:51 +02:00
|
|
|
size = 4;
|
2002-01-25 04:24:19 +01:00
|
|
|
fprintf(stderr, "Warning (vpi_const.cc): %%d on constant strings only looks "
|
|
|
|
|
"at first 4 bytes!\n");
|
|
|
|
|
}
|
2003-03-13 05:59:21 +01:00
|
|
|
rbuf = need_result_buf(size + 1, RBUF_VAL);
|
2002-01-25 04:24:19 +01:00
|
|
|
uint_value = 0;
|
|
|
|
|
for(int i=0; i<size;i ++){
|
|
|
|
|
uint_value <<=8;
|
|
|
|
|
uint_value += (unsigned char)(rfp->value[i]);
|
|
|
|
|
}
|
2003-03-13 05:59:21 +01:00
|
|
|
sprintf(rbuf, "%u", uint_value);
|
|
|
|
|
vp->value.str = rbuf;
|
2002-01-25 04:24:19 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case vpiBinStrVal:
|
2003-03-13 05:59:21 +01:00
|
|
|
rbuf = need_result_buf(8 * size + 1, RBUF_VAL);
|
|
|
|
|
cp = rbuf;
|
2002-01-25 04:24:19 +01:00
|
|
|
for(int i=0; i<size;i ++){
|
|
|
|
|
for(int bit=7;bit>=0; bit--){
|
|
|
|
|
*cp++ = "01"[ (rfp->value[i]>>bit)&1 ];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
*cp = 0;
|
2003-03-13 05:59:21 +01:00
|
|
|
vp->value.str = rbuf;
|
2002-01-25 04:24:19 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case vpiHexStrVal:
|
2003-03-13 05:59:21 +01:00
|
|
|
rbuf = need_result_buf(2 * size + 1, RBUF_VAL);
|
|
|
|
|
cp = rbuf;
|
2002-01-25 04:24:19 +01:00
|
|
|
for(int i=0; i<size;i++){
|
|
|
|
|
for(int nibble=1;nibble>=0; nibble--){
|
|
|
|
|
*cp++ = "0123456789abcdef"[ (rfp->value[i]>>(nibble*4))&15 ];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
*cp = 0;
|
2003-03-13 05:59:21 +01:00
|
|
|
vp->value.str = rbuf;
|
2002-01-25 04:24:19 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case vpiOctStrVal:
|
|
|
|
|
fprintf(stderr, "ERROR (vpi_const.cc): %%o display of constant strings not yet implemented\n");
|
|
|
|
|
assert(0);
|
|
|
|
|
break;
|
|
|
|
|
|
2007-07-24 03:59:02 +02:00
|
|
|
case vpiIntVal:
|
|
|
|
|
vp->value.integer = 0;
|
|
|
|
|
for(int i=0; i<size;i ++){
|
|
|
|
|
for(int bit=7;bit>=0; bit--){
|
|
|
|
|
vp->value.integer <<= 1;
|
|
|
|
|
vp->value.integer += (rfp->value[i]>>bit)&1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
2007-08-14 00:56:02 +02:00
|
|
|
case vpiVectorVal:
|
2009-01-14 22:03:15 +01:00
|
|
|
vp->value.vector = (p_vpi_vecval)
|
|
|
|
|
need_result_buf((size+3)/4*
|
|
|
|
|
sizeof(s_vpi_vecval),
|
|
|
|
|
RBUF_VAL);
|
2007-08-14 00:56:02 +02:00
|
|
|
uint_value = 0;
|
|
|
|
|
vecp = vp->value.vector;
|
2009-01-14 22:03:15 +01:00
|
|
|
vecp->aval = vecp->bval = 0;
|
2007-08-14 00:56:02 +02:00
|
|
|
for(int i=0; i<size;i ++){
|
|
|
|
|
vecp->aval |= rfp->value[i] << uint_value*8;
|
|
|
|
|
uint_value += 1;
|
|
|
|
|
if (uint_value > 3) {
|
|
|
|
|
uint_value = 0;
|
|
|
|
|
vecp += 1;
|
2009-01-14 22:03:15 +01:00
|
|
|
vecp->aval = vecp->bval = 0;
|
2007-08-14 00:56:02 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
2001-03-18 05:35:18 +01:00
|
|
|
default:
|
2009-12-10 21:53:58 +01:00
|
|
|
fprintf(stderr, "ERROR (vpi_const.cc): vp->format: %d\n",
|
|
|
|
|
(int)vp->format);
|
2002-01-25 04:24:19 +01:00
|
|
|
assert(0);
|
|
|
|
|
|
2001-03-18 05:35:18 +01:00
|
|
|
vp->format = vpiSuppressVal;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-01-19 19:16:39 +01:00
|
|
|
inline __vpiStringConst::__vpiStringConst()
|
2012-01-20 23:15:26 +01:00
|
|
|
{ }
|
2012-01-19 19:16:39 +01:00
|
|
|
|
2012-01-20 00:04:51 +01:00
|
|
|
int __vpiStringConst::get_type_code(void) const
|
|
|
|
|
{ return vpiConstant; }
|
|
|
|
|
|
2012-01-20 20:39:48 +01:00
|
|
|
int __vpiStringConst::vpi_get(int code)
|
|
|
|
|
{ return string_get(code, this); }
|
|
|
|
|
|
|
|
|
|
char*__vpiStringConst::vpi_get_str(int)
|
|
|
|
|
{ return 0; }
|
|
|
|
|
|
|
|
|
|
void __vpiStringConst::vpi_get_value(p_vpi_value val)
|
|
|
|
|
{ string_value(this, val); }
|
|
|
|
|
|
|
|
|
|
vpiHandle __vpiStringConst::vpi_put_value(p_vpi_value, int)
|
|
|
|
|
{ return 0; }
|
|
|
|
|
|
|
|
|
|
vpiHandle __vpiStringConst::vpi_handle(int)
|
|
|
|
|
{ return 0; }
|
|
|
|
|
|
|
|
|
|
vpiHandle __vpiStringConst::vpi_iterate(int)
|
|
|
|
|
{ return 0; }
|
|
|
|
|
|
|
|
|
|
vpiHandle __vpiStringConst::vpi_index(int)
|
|
|
|
|
{ return 0; }
|
|
|
|
|
|
|
|
|
|
void __vpiStringConst::vpi_get_delays(p_vpi_delay)
|
|
|
|
|
{ }
|
|
|
|
|
|
|
|
|
|
void __vpiStringConst::vpi_put_delays(p_vpi_delay)
|
|
|
|
|
{ }
|
|
|
|
|
|
2012-01-19 19:16:39 +01:00
|
|
|
struct __vpiStringConstTEMP : public __vpiStringConst {
|
|
|
|
|
__vpiStringConstTEMP();
|
2012-01-20 23:15:26 +01:00
|
|
|
free_object_fun_t free_object_fun(void);
|
2012-01-19 19:16:39 +01:00
|
|
|
};
|
2001-03-18 05:35:18 +01:00
|
|
|
|
2003-02-24 07:35:45 +01:00
|
|
|
static int free_temp_string(vpiHandle obj)
|
|
|
|
|
{
|
2012-01-19 19:16:39 +01:00
|
|
|
struct __vpiStringConstTEMP*rfp = dynamic_cast<__vpiStringConstTEMP*>(obj);
|
2003-02-24 07:35:45 +01:00
|
|
|
|
2009-01-30 02:23:09 +01:00
|
|
|
delete [] rfp->value;
|
2003-02-24 07:35:45 +01:00
|
|
|
free(rfp);
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2012-01-19 19:16:39 +01:00
|
|
|
inline __vpiStringConstTEMP::__vpiStringConstTEMP()
|
2012-01-20 23:15:26 +01:00
|
|
|
{ }
|
|
|
|
|
__vpiHandle::free_object_fun_t __vpiStringConstTEMP::free_object_fun(void)
|
|
|
|
|
{ return &free_temp_string; }
|
2012-01-19 19:16:39 +01:00
|
|
|
|
2007-06-29 03:07:22 +02:00
|
|
|
/*
|
|
|
|
|
* Strings are described at the level of the vvp source as a string
|
|
|
|
|
* with literal characters or octal escapes. No other escapes are
|
|
|
|
|
* included, they are processed already by the compiler that generated
|
|
|
|
|
* the vvp source.
|
|
|
|
|
*/
|
2007-02-26 00:08:24 +01:00
|
|
|
static void vpip_process_string(struct __vpiStringConst*obj)
|
|
|
|
|
{
|
|
|
|
|
char*chr = obj->value;
|
|
|
|
|
char*dp = obj->value;
|
|
|
|
|
|
|
|
|
|
while (*chr) {
|
|
|
|
|
char next_char = *chr;
|
|
|
|
|
|
|
|
|
|
/* Process octal escapes that I might find. */
|
|
|
|
|
if (*chr == '\\') {
|
|
|
|
|
for (int idx = 1 ; idx <= 3 ; idx += 1) {
|
|
|
|
|
assert(chr[idx] != 0);
|
|
|
|
|
assert(chr[idx] < '8');
|
|
|
|
|
assert(chr[idx] >= '0');
|
|
|
|
|
next_char = next_char*8 + chr[idx] - '0';
|
|
|
|
|
}
|
|
|
|
|
chr += 3;
|
|
|
|
|
}
|
|
|
|
|
*dp++ = next_char;
|
|
|
|
|
chr += 1;
|
|
|
|
|
}
|
|
|
|
|
*dp = 0;
|
|
|
|
|
obj->value_len = dp - obj->value;
|
|
|
|
|
}
|
2001-03-18 05:35:18 +01:00
|
|
|
|
2003-02-24 07:35:45 +01:00
|
|
|
vpiHandle vpip_make_string_const(char*text, bool persistent_flag)
|
2001-03-18 05:35:18 +01:00
|
|
|
{
|
|
|
|
|
struct __vpiStringConst*obj;
|
|
|
|
|
|
2012-01-19 19:16:39 +01:00
|
|
|
obj = persistent_flag? new __vpiStringConst : new __vpiStringConstTEMP;
|
2001-03-18 05:35:18 +01:00
|
|
|
obj->value = text;
|
2007-02-26 00:08:24 +01:00
|
|
|
obj->value_len = 0;
|
|
|
|
|
vpip_process_string(obj);
|
2001-03-18 05:35:18 +01:00
|
|
|
|
2012-01-19 19:16:39 +01:00
|
|
|
return obj;
|
2001-03-18 05:35:18 +01:00
|
|
|
}
|
|
|
|
|
|
2004-10-04 03:10:51 +02:00
|
|
|
|
2003-03-11 00:37:07 +01:00
|
|
|
struct __vpiStringParam : public __vpiStringConst {
|
2012-01-19 19:16:39 +01:00
|
|
|
__vpiStringParam();
|
2012-01-20 00:04:51 +01:00
|
|
|
int get_type_code(void) const;
|
2012-01-20 20:39:48 +01:00
|
|
|
int vpi_get(int code);
|
|
|
|
|
char*vpi_get_str(int code);
|
|
|
|
|
vpiHandle vpi_handle(int code);
|
2012-01-20 00:04:51 +01:00
|
|
|
|
2003-03-11 00:37:07 +01:00
|
|
|
const char*basename;
|
2003-03-14 06:02:13 +01:00
|
|
|
struct __vpiScope* scope;
|
2008-05-06 04:46:30 +02:00
|
|
|
unsigned file_idx;
|
|
|
|
|
unsigned lineno;
|
2003-03-11 00:37:07 +01:00
|
|
|
};
|
|
|
|
|
|
2008-05-06 04:46:30 +02:00
|
|
|
static int string_param_get(int code, vpiHandle ref)
|
|
|
|
|
{
|
2012-01-19 19:16:39 +01:00
|
|
|
struct __vpiStringParam*rfp = dynamic_cast<__vpiStringParam*>(ref);
|
|
|
|
|
assert(ref);
|
2008-05-06 04:46:30 +02:00
|
|
|
|
|
|
|
|
if (code == vpiLineNo) {
|
|
|
|
|
return rfp->lineno;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return string_get(code, ref);
|
|
|
|
|
}
|
|
|
|
|
|
2003-03-11 00:37:07 +01:00
|
|
|
static char* string_param_get_str(int code, vpiHandle obj)
|
|
|
|
|
{
|
2012-01-19 19:16:39 +01:00
|
|
|
struct __vpiStringParam*rfp = dynamic_cast<__vpiStringParam*>(obj);
|
|
|
|
|
assert(rfp);
|
2003-03-11 00:37:07 +01:00
|
|
|
|
2008-05-06 04:46:30 +02:00
|
|
|
if (code == vpiFile) {
|
|
|
|
|
return simple_set_rbuf_str(file_names[rfp->file_idx]);
|
2008-01-01 18:45:02 +01:00
|
|
|
}
|
2008-05-06 04:46:30 +02:00
|
|
|
|
2012-01-19 19:16:39 +01:00
|
|
|
return generic_get_str(code, rfp->scope, rfp->basename, NULL);
|
2003-03-14 06:02:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static vpiHandle string_param_handle(int code, vpiHandle obj)
|
|
|
|
|
{
|
2012-01-19 19:16:39 +01:00
|
|
|
struct __vpiStringParam*rfp = dynamic_cast<__vpiStringParam*>(obj);
|
|
|
|
|
assert(rfp);
|
2003-03-14 06:02:13 +01:00
|
|
|
|
|
|
|
|
switch (code) {
|
|
|
|
|
case vpiScope:
|
2012-01-19 19:16:39 +01:00
|
|
|
return rfp->scope;
|
2003-03-14 06:02:13 +01:00
|
|
|
|
2009-01-16 20:09:48 +01:00
|
|
|
case vpiModule:
|
|
|
|
|
return vpip_module(rfp->scope);
|
|
|
|
|
|
2003-03-11 00:37:07 +01:00
|
|
|
default:
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2012-01-19 19:16:39 +01:00
|
|
|
inline __vpiStringParam::__vpiStringParam()
|
2012-01-20 23:15:26 +01:00
|
|
|
{ }
|
2012-01-19 19:16:39 +01:00
|
|
|
|
2012-01-20 00:04:51 +01:00
|
|
|
int __vpiStringParam::get_type_code(void) const
|
|
|
|
|
{ return vpiParameter; }
|
2003-03-11 00:37:07 +01:00
|
|
|
|
2012-01-20 20:39:48 +01:00
|
|
|
int __vpiStringParam::vpi_get(int code)
|
|
|
|
|
{ return string_param_get(code, this); }
|
|
|
|
|
|
|
|
|
|
char*__vpiStringParam::vpi_get_str(int code)
|
|
|
|
|
{ return string_param_get_str(code, this); }
|
|
|
|
|
|
|
|
|
|
vpiHandle __vpiStringParam::vpi_handle(int code)
|
|
|
|
|
{ return string_param_handle(code, this); }
|
|
|
|
|
|
2008-05-06 04:46:30 +02:00
|
|
|
vpiHandle vpip_make_string_param(char*name, char*text,
|
|
|
|
|
long file_idx, long lineno)
|
2003-03-11 00:37:07 +01:00
|
|
|
{
|
2012-01-19 19:16:39 +01:00
|
|
|
struct __vpiStringParam*obj = new __vpiStringParam;
|
2003-03-11 00:37:07 +01:00
|
|
|
obj->value = text;
|
2007-02-26 00:08:24 +01:00
|
|
|
obj->value_len = 0;
|
2003-03-11 00:37:07 +01:00
|
|
|
obj->basename = name;
|
2003-03-14 06:02:13 +01:00
|
|
|
obj->scope = vpip_peek_current_scope();
|
2008-05-06 04:46:30 +02:00
|
|
|
obj->file_idx = (unsigned) file_idx;
|
|
|
|
|
obj->lineno = (unsigned) lineno;
|
2003-03-11 00:37:07 +01:00
|
|
|
|
2007-02-26 00:08:24 +01:00
|
|
|
vpip_process_string(obj);
|
|
|
|
|
|
2012-01-19 19:16:39 +01:00
|
|
|
return obj;
|
2003-03-11 00:37:07 +01:00
|
|
|
}
|
2001-03-18 05:35:18 +01:00
|
|
|
|
2001-04-02 02:24:30 +02:00
|
|
|
static int binary_get(int code, vpiHandle ref)
|
|
|
|
|
{
|
2012-01-19 19:16:39 +01:00
|
|
|
struct __vpiBinaryConst*rfp = dynamic_cast<__vpiBinaryConst*>(ref);
|
2001-04-02 02:24:30 +02:00
|
|
|
|
|
|
|
|
switch (code) {
|
|
|
|
|
case vpiConstType:
|
|
|
|
|
return vpiBinaryConst;
|
|
|
|
|
|
2008-01-01 18:45:02 +01:00
|
|
|
case vpiLineNo:
|
|
|
|
|
return 0; // Not implemented for now!
|
|
|
|
|
|
2002-04-14 05:53:20 +02:00
|
|
|
case vpiSigned:
|
|
|
|
|
return rfp->signed_flag? 1 : 0;
|
2002-01-15 04:21:18 +01:00
|
|
|
|
|
|
|
|
case vpiSize:
|
2006-03-06 06:43:15 +01:00
|
|
|
return rfp->bits.size();
|
2002-01-15 04:21:18 +01:00
|
|
|
|
2008-11-09 01:26:55 +01:00
|
|
|
case vpiAutomatic:
|
|
|
|
|
return 0;
|
|
|
|
|
|
2009-01-30 02:23:09 +01:00
|
|
|
#ifdef CHECK_WITH_VALGRIND
|
|
|
|
|
case _vpiFromThr:
|
|
|
|
|
return _vpiNoThr;
|
|
|
|
|
#endif
|
|
|
|
|
|
2001-04-02 02:24:30 +02:00
|
|
|
default:
|
2002-01-15 04:21:18 +01:00
|
|
|
fprintf(stderr, "vvp error: get %d not supported "
|
|
|
|
|
"by vpiBinaryConst\n", code);
|
2001-04-02 02:24:30 +02:00
|
|
|
assert(0);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2003-05-29 05:46:21 +02:00
|
|
|
|
2001-04-02 02:24:30 +02:00
|
|
|
static void binary_value(vpiHandle ref, p_vpi_value vp)
|
|
|
|
|
{
|
2012-01-19 19:16:39 +01:00
|
|
|
struct __vpiBinaryConst*rfp = dynamic_cast<__vpiBinaryConst*>(ref);
|
2003-03-13 05:59:21 +01:00
|
|
|
|
2001-04-02 02:24:30 +02:00
|
|
|
switch (vp->format) {
|
|
|
|
|
|
2001-04-04 06:33:08 +02:00
|
|
|
case vpiObjTypeVal:
|
2006-03-06 06:43:15 +01:00
|
|
|
case vpiBinStrVal:
|
|
|
|
|
case vpiDecStrVal:
|
|
|
|
|
case vpiOctStrVal:
|
|
|
|
|
case vpiHexStrVal:
|
2007-04-12 06:45:52 +02:00
|
|
|
case vpiScalarVal:
|
2006-03-06 06:43:15 +01:00
|
|
|
case vpiIntVal:
|
|
|
|
|
case vpiVectorVal:
|
2002-04-28 01:26:24 +02:00
|
|
|
case vpiStringVal:
|
2006-03-06 06:43:15 +01:00
|
|
|
case vpiRealVal:
|
|
|
|
|
vpip_vec4_get_value(rfp->bits, rfp->bits.size(),
|
|
|
|
|
rfp->signed_flag, vp);
|
2002-04-28 01:26:24 +02:00
|
|
|
break;
|
|
|
|
|
|
2001-04-02 02:24:30 +02:00
|
|
|
default:
|
2001-04-04 06:33:08 +02:00
|
|
|
fprintf(stderr, "vvp error: format %d not supported "
|
2009-12-10 21:53:58 +01:00
|
|
|
"by vpiBinaryConst\n", (int)vp->format);
|
2001-04-02 02:24:30 +02:00
|
|
|
vp->format = vpiSuppressVal;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2012-01-19 19:16:39 +01:00
|
|
|
inline __vpiBinaryConst::__vpiBinaryConst()
|
2012-01-20 23:15:26 +01:00
|
|
|
{ }
|
2012-01-19 19:16:39 +01:00
|
|
|
|
2012-01-20 00:04:51 +01:00
|
|
|
int __vpiBinaryConst::get_type_code(void) const
|
|
|
|
|
{ return vpiConstant; }
|
|
|
|
|
|
2012-01-20 20:39:48 +01:00
|
|
|
int __vpiBinaryConst::vpi_get(int code)
|
|
|
|
|
{ return binary_get(code, this); }
|
|
|
|
|
|
|
|
|
|
char* __vpiBinaryConst::vpi_get_str(int)
|
|
|
|
|
{ return 0; }
|
|
|
|
|
|
|
|
|
|
void __vpiBinaryConst::vpi_get_value(p_vpi_value val)
|
|
|
|
|
{ binary_value(this, val); }
|
|
|
|
|
|
|
|
|
|
vpiHandle __vpiBinaryConst::vpi_put_value(p_vpi_value, int)
|
|
|
|
|
{ return 0; }
|
|
|
|
|
|
|
|
|
|
vpiHandle __vpiBinaryConst::vpi_handle(int)
|
|
|
|
|
{ return 0; }
|
|
|
|
|
|
|
|
|
|
vpiHandle __vpiBinaryConst::vpi_iterate(int)
|
|
|
|
|
{ return 0; }
|
|
|
|
|
|
|
|
|
|
vpiHandle __vpiBinaryConst::vpi_index(int)
|
|
|
|
|
{ return 0; }
|
|
|
|
|
|
|
|
|
|
void __vpiBinaryConst::vpi_get_delays(p_vpi_delay)
|
|
|
|
|
{ }
|
|
|
|
|
|
|
|
|
|
void __vpiBinaryConst::vpi_put_delays(p_vpi_delay)
|
|
|
|
|
{ }
|
|
|
|
|
|
2002-04-14 05:53:20 +02:00
|
|
|
/*
|
|
|
|
|
* Make a VPI constant from a vector string. The string is normally a
|
|
|
|
|
* ASCII string, with each letter a 4-value bit. The first character
|
|
|
|
|
* may be an 's' if the vector is signed.
|
|
|
|
|
*/
|
2007-04-12 06:25:58 +02:00
|
|
|
vpiHandle vpip_make_binary_const(unsigned wid, const char*bits)
|
2001-04-02 02:24:30 +02:00
|
|
|
{
|
2012-01-19 19:16:39 +01:00
|
|
|
struct __vpiBinaryConst*obj = new __vpiBinaryConst;
|
2001-04-02 02:24:30 +02:00
|
|
|
|
2002-04-14 05:53:20 +02:00
|
|
|
obj->signed_flag = 0;
|
2006-03-18 23:51:10 +01:00
|
|
|
obj->sized_flag = 0;
|
2001-04-02 02:24:30 +02:00
|
|
|
|
2002-04-14 05:53:20 +02:00
|
|
|
const char*bp = bits;
|
|
|
|
|
if (*bp == 's') {
|
|
|
|
|
bp += 1;
|
|
|
|
|
obj->signed_flag = 1;
|
|
|
|
|
}
|
|
|
|
|
|
2010-11-22 02:24:46 +01:00
|
|
|
obj->bits = vector4_from_text(bp, wid);
|
|
|
|
|
|
2012-01-19 19:16:39 +01:00
|
|
|
return obj;
|
2010-11-22 02:24:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
vvp_vector4_t vector4_from_text(const char*bits, unsigned wid)
|
|
|
|
|
{
|
|
|
|
|
vvp_vector4_t res (wid);
|
|
|
|
|
|
2006-03-06 06:43:15 +01:00
|
|
|
for (unsigned idx = 0 ; idx < wid ; idx += 1) {
|
|
|
|
|
vvp_bit4_t val = BIT4_0;
|
2010-11-22 02:24:46 +01:00
|
|
|
switch (bits[wid-idx-1]) {
|
2001-04-04 06:33:08 +02:00
|
|
|
case '0':
|
2006-03-06 06:43:15 +01:00
|
|
|
val = BIT4_0;
|
2001-04-04 06:33:08 +02:00
|
|
|
break;
|
|
|
|
|
case '1':
|
2006-03-06 06:43:15 +01:00
|
|
|
val = BIT4_1;
|
2001-04-04 06:33:08 +02:00
|
|
|
break;
|
|
|
|
|
case 'x':
|
2006-03-06 06:43:15 +01:00
|
|
|
val = BIT4_X;
|
2001-04-04 06:33:08 +02:00
|
|
|
break;
|
|
|
|
|
case 'z':
|
2006-03-06 06:43:15 +01:00
|
|
|
val = BIT4_Z;
|
2001-04-04 06:33:08 +02:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2010-11-22 02:24:46 +01:00
|
|
|
res.set_bit(idx, val);
|
2001-04-02 02:24:30 +02:00
|
|
|
}
|
|
|
|
|
|
2010-11-22 02:24:46 +01:00
|
|
|
return res;
|
2001-04-02 02:24:30 +02:00
|
|
|
}
|
|
|
|
|
|
2006-03-08 06:29:42 +01:00
|
|
|
struct __vpiBinaryParam : public __vpiBinaryConst {
|
2012-01-19 19:16:39 +01:00
|
|
|
__vpiBinaryParam();
|
2012-01-20 00:04:51 +01:00
|
|
|
int get_type_code(void) const;
|
2012-01-20 20:39:48 +01:00
|
|
|
int vpi_get(int code);
|
|
|
|
|
char*vpi_get_str(int code);
|
|
|
|
|
vpiHandle vpi_handle(int code);
|
2012-01-20 00:04:51 +01:00
|
|
|
|
2006-03-08 06:29:42 +01:00
|
|
|
const char*basename;
|
|
|
|
|
struct __vpiScope*scope;
|
2008-05-06 04:46:30 +02:00
|
|
|
unsigned file_idx;
|
|
|
|
|
unsigned lineno;
|
2006-03-08 06:29:42 +01:00
|
|
|
};
|
|
|
|
|
|
2008-05-06 04:46:30 +02:00
|
|
|
static int binary_param_get(int code, vpiHandle ref)
|
|
|
|
|
{
|
2012-01-19 19:16:39 +01:00
|
|
|
struct __vpiBinaryParam*rfp = dynamic_cast<__vpiBinaryParam*>(ref);
|
2008-05-06 04:46:30 +02:00
|
|
|
|
|
|
|
|
if (code == vpiLineNo) {
|
|
|
|
|
return rfp->lineno;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return binary_get(code, ref);
|
|
|
|
|
}
|
|
|
|
|
|
2006-03-08 06:29:42 +01:00
|
|
|
static char* binary_param_get_str(int code, vpiHandle obj)
|
|
|
|
|
{
|
2012-01-19 19:16:39 +01:00
|
|
|
struct __vpiBinaryParam*rfp = dynamic_cast<__vpiBinaryParam*>(obj);
|
2006-03-08 06:29:42 +01:00
|
|
|
|
2008-05-06 04:46:30 +02:00
|
|
|
if (code == vpiFile) {
|
|
|
|
|
return simple_set_rbuf_str(file_names[rfp->file_idx]);
|
2008-01-01 18:45:02 +01:00
|
|
|
}
|
2008-05-06 04:46:30 +02:00
|
|
|
|
2012-01-19 19:16:39 +01:00
|
|
|
return generic_get_str(code, rfp->scope, rfp->basename, NULL);
|
2006-03-08 06:29:42 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static vpiHandle binary_param_handle(int code, vpiHandle obj)
|
|
|
|
|
{
|
2012-01-19 19:16:39 +01:00
|
|
|
struct __vpiBinaryParam*rfp = dynamic_cast<__vpiBinaryParam*>(obj);
|
2006-03-08 06:29:42 +01:00
|
|
|
|
|
|
|
|
switch (code) {
|
|
|
|
|
case vpiScope:
|
2012-01-19 19:16:39 +01:00
|
|
|
return rfp->scope;
|
2006-03-08 06:29:42 +01:00
|
|
|
|
2009-01-16 20:09:48 +01:00
|
|
|
case vpiModule:
|
|
|
|
|
return vpip_module(rfp->scope);
|
|
|
|
|
|
2006-03-08 06:29:42 +01:00
|
|
|
default:
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-01-19 19:16:39 +01:00
|
|
|
inline __vpiBinaryParam::__vpiBinaryParam()
|
2012-01-20 23:15:26 +01:00
|
|
|
{ }
|
2006-03-08 06:29:42 +01:00
|
|
|
|
2012-01-20 00:04:51 +01:00
|
|
|
int __vpiBinaryParam::get_type_code(void) const
|
|
|
|
|
{ return vpiParameter; }
|
|
|
|
|
|
2012-01-20 20:39:48 +01:00
|
|
|
int __vpiBinaryParam::vpi_get(int code)
|
|
|
|
|
{ return binary_param_get(code, this); }
|
|
|
|
|
|
|
|
|
|
char*__vpiBinaryParam::vpi_get_str(int code)
|
|
|
|
|
{ return binary_param_get_str(code, this); }
|
|
|
|
|
|
|
|
|
|
vpiHandle __vpiBinaryParam::vpi_handle(int code)
|
|
|
|
|
{ return binary_param_handle(code, this); }
|
|
|
|
|
|
2006-03-18 23:51:10 +01:00
|
|
|
vpiHandle vpip_make_binary_param(char*name, const vvp_vector4_t&bits,
|
2008-05-06 04:46:30 +02:00
|
|
|
bool signed_flag,
|
|
|
|
|
long file_idx, long lineno)
|
2006-03-08 06:29:42 +01:00
|
|
|
{
|
|
|
|
|
struct __vpiBinaryParam*obj = new __vpiBinaryParam;
|
|
|
|
|
|
|
|
|
|
obj->bits = bits;
|
2006-03-18 23:51:10 +01:00
|
|
|
obj->signed_flag = signed_flag? 1 : 0;
|
|
|
|
|
obj->sized_flag = 0;
|
2006-03-08 06:29:42 +01:00
|
|
|
obj->basename = name;
|
|
|
|
|
obj->scope = vpip_peek_current_scope();
|
2008-05-06 04:46:30 +02:00
|
|
|
obj->file_idx = (unsigned) file_idx;
|
|
|
|
|
obj->lineno = (unsigned) lineno;
|
2006-03-08 06:29:42 +01:00
|
|
|
|
2012-01-19 19:16:39 +01:00
|
|
|
return obj;
|
2006-03-08 06:29:42 +01:00
|
|
|
}
|
2001-04-02 02:24:30 +02:00
|
|
|
|
2002-01-31 05:28:17 +01:00
|
|
|
|
2010-10-11 06:52:26 +02:00
|
|
|
static int dec_get(int code, vpiHandle)
|
2002-01-31 05:28:17 +01:00
|
|
|
{
|
|
|
|
|
|
|
|
|
|
switch (code) {
|
|
|
|
|
case vpiConstType:
|
|
|
|
|
return vpiDecConst;
|
|
|
|
|
|
2004-10-04 03:10:51 +02:00
|
|
|
case vpiSigned:
|
2002-01-31 05:28:17 +01:00
|
|
|
return 1;
|
|
|
|
|
|
|
|
|
|
case vpiSize:
|
|
|
|
|
return 32;
|
|
|
|
|
|
2008-11-09 01:26:55 +01:00
|
|
|
case vpiAutomatic:
|
|
|
|
|
return 0;
|
|
|
|
|
|
2009-01-30 02:23:09 +01:00
|
|
|
#ifdef CHECK_WITH_VALGRIND
|
|
|
|
|
case _vpiFromThr:
|
|
|
|
|
return _vpiNoThr;
|
|
|
|
|
#endif
|
|
|
|
|
|
2002-01-31 05:28:17 +01:00
|
|
|
default:
|
|
|
|
|
fprintf(stderr, "vvp error: get %d not supported "
|
|
|
|
|
"by vpiDecConst\n", code);
|
|
|
|
|
assert(0);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void dec_value(vpiHandle ref, p_vpi_value vp)
|
|
|
|
|
{
|
2012-01-19 19:16:39 +01:00
|
|
|
struct __vpiDecConst*rfp = dynamic_cast<__vpiDecConst*>(ref);
|
2003-03-13 05:59:21 +01:00
|
|
|
char*rbuf = need_result_buf(64 + 1, RBUF_VAL);
|
|
|
|
|
char*cp = rbuf;
|
2002-01-31 05:28:17 +01:00
|
|
|
|
|
|
|
|
switch (vp->format) {
|
|
|
|
|
|
|
|
|
|
case vpiObjTypeVal:
|
|
|
|
|
case vpiIntVal: {
|
|
|
|
|
vp->value.integer = rfp->value;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case vpiDecStrVal:
|
2003-03-13 05:59:21 +01:00
|
|
|
sprintf(rbuf, "%d", rfp->value);
|
2002-01-31 05:28:17 +01:00
|
|
|
|
2003-03-13 05:59:21 +01:00
|
|
|
vp->value.str = rbuf;
|
2002-01-31 05:28:17 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case vpiBinStrVal:
|
|
|
|
|
for(int bit=31; bit<=0;bit--){
|
|
|
|
|
*cp++ = "01"[ (rfp->value>>bit)&1 ];
|
|
|
|
|
}
|
|
|
|
|
*cp = 0;
|
|
|
|
|
|
2003-03-13 05:59:21 +01:00
|
|
|
vp->value.str = rbuf;
|
2002-01-31 05:28:17 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case vpiHexStrVal:
|
2003-03-13 05:59:21 +01:00
|
|
|
sprintf(rbuf, "%08x", rfp->value);
|
2002-01-31 05:28:17 +01:00
|
|
|
|
2003-03-13 05:59:21 +01:00
|
|
|
vp->value.str = rbuf;
|
2002-01-31 05:28:17 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case vpiOctStrVal:
|
2003-03-13 05:59:21 +01:00
|
|
|
sprintf(rbuf, "%011x", rfp->value);
|
2002-01-31 05:28:17 +01:00
|
|
|
|
2003-03-13 05:59:21 +01:00
|
|
|
vp->value.str = rbuf;
|
2002-01-31 05:28:17 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
fprintf(stderr, "vvp error (vpi_const.cc): format %d not supported "
|
2009-12-10 21:53:58 +01:00
|
|
|
"by vpiDecConst\n", (int)vp->format);
|
2002-01-31 05:28:17 +01:00
|
|
|
vp->format = vpiSuppressVal;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-01-19 19:16:39 +01:00
|
|
|
__vpiDecConst::__vpiDecConst(int val)
|
2002-05-17 06:12:19 +02:00
|
|
|
{
|
2012-01-19 19:16:39 +01:00
|
|
|
value = val;
|
2002-01-31 05:28:17 +01:00
|
|
|
}
|
|
|
|
|
|
2012-01-20 00:04:51 +01:00
|
|
|
int __vpiDecConst::get_type_code(void) const
|
|
|
|
|
{ return vpiConstant; }
|
|
|
|
|
|
2012-01-20 20:39:48 +01:00
|
|
|
int __vpiDecConst::vpi_get(int code)
|
|
|
|
|
{ return dec_get(code, this); }
|
|
|
|
|
|
|
|
|
|
void __vpiDecConst::vpi_get_value(p_vpi_value val)
|
|
|
|
|
{ dec_value(this, val); }
|
|
|
|
|
|
2010-10-11 06:52:26 +02:00
|
|
|
static int real_get(int code, vpiHandle)
|
2006-06-18 06:15:50 +02:00
|
|
|
{
|
|
|
|
|
|
|
|
|
|
switch (code) {
|
2008-03-22 03:16:19 +01:00
|
|
|
case vpiLineNo:
|
|
|
|
|
return 0; // Not implemented for now!
|
|
|
|
|
|
|
|
|
|
case vpiSize:
|
|
|
|
|
return 1;
|
|
|
|
|
|
2006-06-18 06:15:50 +02:00
|
|
|
case vpiConstType:
|
|
|
|
|
return vpiRealConst;
|
|
|
|
|
|
|
|
|
|
case vpiSigned:
|
|
|
|
|
return 1;
|
|
|
|
|
|
2008-11-09 01:26:55 +01:00
|
|
|
case vpiAutomatic:
|
|
|
|
|
return 0;
|
|
|
|
|
|
2009-01-30 02:23:09 +01:00
|
|
|
#ifdef CHECK_WITH_VALGRIND
|
|
|
|
|
case _vpiFromThr:
|
|
|
|
|
return _vpiNoThr;
|
|
|
|
|
#endif
|
|
|
|
|
|
2006-06-18 06:15:50 +02:00
|
|
|
default:
|
|
|
|
|
fprintf(stderr, "vvp error: get %d not supported "
|
|
|
|
|
"by vpiDecConst\n", code);
|
|
|
|
|
assert(0);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void real_value(vpiHandle ref, p_vpi_value vp)
|
|
|
|
|
{
|
2012-01-19 19:16:39 +01:00
|
|
|
struct __vpiRealConst*rfp = dynamic_cast<__vpiRealConst*>(ref);
|
2009-05-18 19:58:15 +02:00
|
|
|
vpip_real_get_value(rfp->value, vp);
|
2006-06-18 06:15:50 +02:00
|
|
|
}
|
|
|
|
|
|
2012-01-19 19:16:39 +01:00
|
|
|
inline __vpiRealConst::__vpiRealConst()
|
2012-01-20 23:15:26 +01:00
|
|
|
{ }
|
2006-06-18 06:15:50 +02:00
|
|
|
|
2012-01-20 00:04:51 +01:00
|
|
|
int __vpiRealConst::get_type_code(void) const
|
|
|
|
|
{ return vpiConstant; }
|
|
|
|
|
|
2012-01-20 20:39:48 +01:00
|
|
|
int __vpiRealConst::vpi_get(int code)
|
|
|
|
|
{ return real_get(code, this); }
|
|
|
|
|
|
|
|
|
|
void __vpiRealConst::vpi_get_value(p_vpi_value val)
|
|
|
|
|
{ real_value(this, val); }
|
|
|
|
|
|
2006-06-18 06:15:50 +02:00
|
|
|
vpiHandle vpip_make_real_const(double value)
|
|
|
|
|
{
|
2012-01-19 19:16:39 +01:00
|
|
|
struct __vpiRealConst*obj = new __vpiRealConst;
|
|
|
|
|
obj->value = value;
|
|
|
|
|
return obj;
|
2006-06-18 06:15:50 +02:00
|
|
|
}
|
|
|
|
|
|
2008-03-22 03:16:19 +01:00
|
|
|
struct __vpiRealParam : public __vpiRealConst {
|
2012-01-19 19:16:39 +01:00
|
|
|
__vpiRealParam();
|
2012-01-20 00:04:51 +01:00
|
|
|
int get_type_code(void) const;
|
2012-01-20 20:39:48 +01:00
|
|
|
int vpi_get(int code);
|
|
|
|
|
char*vpi_get_str(int code);
|
|
|
|
|
vpiHandle vpi_handle(int code);
|
|
|
|
|
|
2008-03-22 03:16:19 +01:00
|
|
|
const char*basename;
|
|
|
|
|
struct __vpiScope* scope;
|
2008-05-06 04:46:30 +02:00
|
|
|
unsigned file_idx;
|
|
|
|
|
unsigned lineno;
|
2008-03-22 03:16:19 +01:00
|
|
|
};
|
|
|
|
|
|
2008-05-06 04:46:30 +02:00
|
|
|
static int real_param_get(int code, vpiHandle ref)
|
|
|
|
|
{
|
2012-01-19 19:16:39 +01:00
|
|
|
struct __vpiRealParam*rfp = dynamic_cast<__vpiRealParam*>(ref);
|
2008-05-06 04:46:30 +02:00
|
|
|
|
|
|
|
|
if (code == vpiLineNo) {
|
|
|
|
|
return rfp->lineno;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return real_get(code, ref);
|
|
|
|
|
}
|
|
|
|
|
|
2008-03-22 03:16:19 +01:00
|
|
|
static char* real_param_get_str(int code, vpiHandle obj)
|
|
|
|
|
{
|
2012-01-19 19:16:39 +01:00
|
|
|
struct __vpiRealParam*rfp = dynamic_cast<__vpiRealParam*>(obj);
|
2008-03-22 03:16:19 +01:00
|
|
|
|
2008-05-06 04:46:30 +02:00
|
|
|
if (code == vpiFile) {
|
|
|
|
|
return simple_set_rbuf_str(file_names[rfp->file_idx]);
|
2008-03-22 03:16:19 +01:00
|
|
|
}
|
2008-05-06 04:46:30 +02:00
|
|
|
|
2012-01-19 19:16:39 +01:00
|
|
|
return generic_get_str(code, rfp->scope, rfp->basename, NULL);
|
2008-03-22 03:16:19 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static vpiHandle real_param_handle(int code, vpiHandle obj)
|
|
|
|
|
{
|
2012-01-19 19:16:39 +01:00
|
|
|
struct __vpiRealParam*rfp = dynamic_cast<__vpiRealParam*>(obj);
|
2008-03-22 03:16:19 +01:00
|
|
|
|
|
|
|
|
switch (code) {
|
|
|
|
|
case vpiScope:
|
2012-01-19 19:16:39 +01:00
|
|
|
return rfp->scope;
|
2008-03-22 03:16:19 +01:00
|
|
|
|
2009-01-16 20:09:48 +01:00
|
|
|
case vpiModule:
|
|
|
|
|
return vpip_module(rfp->scope);
|
|
|
|
|
|
2008-03-22 03:16:19 +01:00
|
|
|
default:
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-01-20 23:15:26 +01:00
|
|
|
|
2012-01-19 19:16:39 +01:00
|
|
|
inline __vpiRealParam::__vpiRealParam()
|
2012-01-20 23:15:26 +01:00
|
|
|
{ }
|
2012-01-19 19:16:39 +01:00
|
|
|
|
2012-01-20 00:04:51 +01:00
|
|
|
int __vpiRealParam::get_type_code(void) const
|
|
|
|
|
{ return vpiParameter; }
|
|
|
|
|
|
2012-01-20 20:39:48 +01:00
|
|
|
int __vpiRealParam::vpi_get(int code)
|
|
|
|
|
{ return real_param_get(code, this); }
|
|
|
|
|
|
|
|
|
|
char* __vpiRealParam::vpi_get_str(int code)
|
|
|
|
|
{ return real_param_get_str(code, this); }
|
|
|
|
|
|
|
|
|
|
vpiHandle __vpiRealParam::vpi_handle(int code)
|
|
|
|
|
{ return real_param_handle(code, this); }
|
|
|
|
|
|
2008-03-22 03:16:19 +01:00
|
|
|
|
2008-05-06 04:46:30 +02:00
|
|
|
vpiHandle vpip_make_real_param(char*name, double value,
|
|
|
|
|
long file_idx, long lineno)
|
2008-03-22 03:16:19 +01:00
|
|
|
{
|
2012-01-19 19:16:39 +01:00
|
|
|
struct __vpiRealParam*obj = new __vpiRealParam;
|
2008-03-22 03:16:19 +01:00
|
|
|
|
|
|
|
|
obj->value = value;
|
|
|
|
|
obj->basename = name;
|
|
|
|
|
obj->scope = vpip_peek_current_scope();
|
2008-05-06 04:46:30 +02:00
|
|
|
obj->file_idx = (unsigned) file_idx;
|
|
|
|
|
obj->lineno = (unsigned) lineno;
|
2008-03-22 03:16:19 +01:00
|
|
|
|
2012-01-19 19:16:39 +01:00
|
|
|
return obj;
|
2008-03-22 03:16:19 +01:00
|
|
|
}
|
2009-01-30 02:23:09 +01:00
|
|
|
|
|
|
|
|
#ifdef CHECK_WITH_VALGRIND
|
|
|
|
|
void constant_delete(vpiHandle item)
|
|
|
|
|
{
|
|
|
|
|
assert(item->vpi_type->type_code == vpiConstant);
|
|
|
|
|
switch(vpi_get(vpiConstType, item)) {
|
|
|
|
|
case vpiStringConst: {
|
2012-01-19 19:16:39 +01:00
|
|
|
struct __vpiStringConst*rfp = dynamic_cast<__vpiStringConst*>(item);
|
2009-01-30 02:23:09 +01:00
|
|
|
delete [] rfp->value;
|
|
|
|
|
free(rfp);
|
|
|
|
|
break; }
|
|
|
|
|
case vpiDecConst: {
|
2012-01-19 19:16:39 +01:00
|
|
|
struct __vpiDecConst*rfp = dynamic_cast<__vpiDecConst*>(item);
|
2009-01-30 02:23:09 +01:00
|
|
|
free(rfp);
|
|
|
|
|
break; }
|
|
|
|
|
case vpiBinaryConst: {
|
2012-01-19 19:16:39 +01:00
|
|
|
struct __vpiBinaryConst*rfp = dynamic_cast<__vpiBinaryConst*>(item);
|
2009-01-30 02:23:09 +01:00
|
|
|
delete rfp;
|
|
|
|
|
break; }
|
|
|
|
|
case vpiRealConst: {
|
2012-01-19 19:16:39 +01:00
|
|
|
struct __vpiRealConst*rfp = dynamic_cast<__vpiRealConst*>(item);
|
2009-01-30 02:23:09 +01:00
|
|
|
free(rfp);
|
|
|
|
|
break; }
|
|
|
|
|
default:
|
|
|
|
|
assert(0);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void parameter_delete(vpiHandle item)
|
|
|
|
|
{
|
|
|
|
|
switch(vpi_get(vpiConstType, item)) {
|
|
|
|
|
case vpiStringConst: {
|
2012-01-19 19:16:39 +01:00
|
|
|
struct __vpiStringParam*rfp = dynamic_cast<__vpiStringParam*>(item);
|
2009-01-30 02:23:09 +01:00
|
|
|
delete [] rfp->basename;
|
|
|
|
|
delete [] rfp->value;
|
|
|
|
|
free(rfp);
|
|
|
|
|
break; }
|
|
|
|
|
case vpiBinaryConst: {
|
2012-01-19 19:16:39 +01:00
|
|
|
struct __vpiBinaryParam*rfp = dynamic_cast<__vpiBinaryParam*>(item);
|
2009-01-30 02:23:09 +01:00
|
|
|
delete [] rfp->basename;
|
|
|
|
|
delete rfp;
|
|
|
|
|
break; }
|
|
|
|
|
case vpiRealConst: {
|
2012-01-19 19:16:39 +01:00
|
|
|
struct __vpiRealParam*rfp = dynamic_cast<__vpiRealParam*>(item);
|
2009-01-30 02:23:09 +01:00
|
|
|
delete [] rfp->basename;
|
|
|
|
|
free(rfp);
|
|
|
|
|
break; }
|
|
|
|
|
default:
|
|
|
|
|
assert(0);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#endif
|