Add support for passing a null object to $display

This commit is contained in:
Cary R 2020-12-13 23:00:42 -08:00
parent f4d22af4bd
commit 05a4e72b1a
5 changed files with 123 additions and 4 deletions

View File

@ -1,7 +1,7 @@
#ifndef SV_VPI_USER_H
#define SV_VPI_USER_H
/*
* Copyright (c) 2010-2014 Stephen Williams (steve@icarus.com)
* Copyright (c) 2010-2020 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
@ -72,6 +72,9 @@ EXTERN_C_START
/********* Many-to-One ***********/
#define vpiMember 742
/********* generic object properties ***********/
#define vpiNullConst 11
/********* task/function properties **********/
#define vpiOtherFunc 6

View File

@ -384,6 +384,10 @@ static void draw_vpi_taskfunc_args(const char*call_string,
args[idx].stack = 0;
break;
}
case IVL_EX_NULL:
snprintf(buffer, sizeof buffer, "null");
args[idx].text = strdup(buffer);
continue;
/* Everything else will need to be evaluated and
passed as a constant to the vpi task. */
default:
@ -424,6 +428,8 @@ static void draw_vpi_taskfunc_args(const char*call_string,
buffer[0] = 0;
break;
default:
fprintf(stderr, "%s:%d: Sorry, cannot generate code for argument %d.\n",
ivl_expr_file(expr), ivl_expr_lineno(expr), idx+1);
fprintf(vvp_out, "\nXXXX Unexpected argument: call_string=<%s>, arg=%u, type=%d\n",
call_string, idx, ivl_expr_value(expr));
fflush(vvp_out);

View File

@ -631,6 +631,11 @@ bool vpi_handle_resolv_list_s::resolve(bool mes)
// check for memory word M<mem,base,wid>
}
if (strcmp(label(), "null") == 0) {
val.ptr = vpip_make_null_const();
sym_set_value(sym_vpi, label(), val);
}
if (val.ptr) {
*handle = (vpiHandle) val.ptr;
return true;

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2001-2018 Stephen Williams (steve@icarus.com)
* Copyright (c) 2001-2020 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
@ -395,7 +395,6 @@ void __vpiBinaryConst::vpi_get_value(p_vpi_value val)
}
}
/*
* 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
@ -757,6 +756,99 @@ vpiHandle vpip_make_real_param(char*name, double value,
return obj;
}
/*
* Make a VPI null constant
*/
inline __vpiNullConst::__vpiNullConst()
{ }
int __vpiNullConst::get_type_code(void) const
{ return vpiConstant; }
int __vpiNullConst::vpi_get(int code)
{
switch (code) {
case vpiLineNo:
return 0; // Not implemented for now!
case vpiSize:
return 32;
case vpiConstType:
return vpiNullConst;
case vpiSigned:
return 0;
case vpiAutomatic:
return 0;
#if defined(CHECK_WITH_VALGRIND) || defined(BR916_STOPGAP_FIX)
case _vpiFromThr:
return _vpiNoThr;
#endif
default:
fprintf(stderr, "vvp error: get %d not supported "
"by vpiNullConst\n", code);
assert(0);
return 0;
}
}
void __vpiNullConst::vpi_get_value(p_vpi_value val)
{
char*rbuf = (char *) need_result_buf(64 + 1, RBUF_VAL);
switch (val->format) {
case vpiObjTypeVal:
val->format = vpiStringVal;
case vpiBinStrVal:
case vpiDecStrVal:
case vpiOctStrVal:
case vpiHexStrVal:
case vpiStringVal:
sprintf(rbuf, "null");
val->value.str = rbuf;
break;
case vpiScalarVal:
val->value.scalar = vpi0;
break;
case vpiIntVal:
val->value.integer = 0;
break;
case vpiVectorVal:
val->value.vector = (p_vpi_vecval)
need_result_buf(2*sizeof(s_vpi_vecval),
RBUF_VAL);
for (unsigned idx = 0; idx < 2; idx += 1) {
val->value.vector[idx].aval = 0;
val->value.vector[idx].bval = 0;
}
break;
case vpiRealVal:
val->value.real = 0.0;
break;
default:
fprintf(stderr, "vvp error: format %d not supported "
"by vpiNullConst\n", (int)val->format);
val->format = vpiSuppressVal;
break;
}
}
vpiHandle vpip_make_null_const()
{
struct __vpiNullConst*obj = new __vpiNullConst;
return obj;
}
#ifdef CHECK_WITH_VALGRIND
void constant_delete(vpiHandle item)
{
@ -774,6 +866,9 @@ void constant_delete(vpiHandle item)
case vpiRealConst:
delete dynamic_cast<__vpiRealConst*>(item);
break;
case vpiNullConst:
delete dynamic_cast<__vpiNullConst*>(item);
break;
default:
assert(0);
}

View File

@ -1,7 +1,7 @@
#ifndef IVL_vpi_priv_H
#define IVL_vpi_priv_H
/*
* Copyright (c) 2001-2018 Stephen Williams (steve@icarus.com)
* Copyright (c) 2001-2020 Stephen Williams (steve@icarus.com)
* Copyright (c) 2016 CERN Michele Castellana (michele.castellana@cern.ch)
*
* This source code is free software; you can redistribute it
@ -888,6 +888,16 @@ vpiHandle vpip_make_real_const(double value);
vpiHandle vpip_make_real_param(char*name, double value, bool local_flag,
long file_idx, long lineno);
class __vpiNullConst : public __vpiHandle {
public:
explicit __vpiNullConst();
int get_type_code(void) const;
int vpi_get(int code);
void vpi_get_value(p_vpi_value val);
};
vpiHandle vpip_make_null_const();
/*
* This one looks like a constant, but really is a vector in the current
* thread.