diff --git a/vpi/sys_deposit.c b/vpi/sys_deposit.c index 9a049ea62e..7233a266cc 100644 --- a/vpi/sys_deposit.c +++ b/vpi/sys_deposit.c @@ -26,54 +26,78 @@ # include "vpi_user.h" # include -static PLI_INT32 sys_deposit_calltf(PLI_BYTE8*name) +static PLI_INT32 sys_deposit_compiletf(PLI_BYTE8 *name) { - vpiHandle sys, argv, target, value; - s_vpi_value val; - - sys = vpi_handle(vpiSysTfCall, 0); - assert(sys); - argv = vpi_iterate(vpiArgument, sys); - if (!argv) - { - vpi_printf("ERROR: %s requires parameters " - "(target, value)\n", name); - return 0; - } - target = vpi_scan(argv); - assert(target); - value = vpi_scan(argv); - assert(value); - vpi_free_object(argv); - - val.format = vpiIntVal; - vpi_get_value(value, &val); - - switch (vpi_get(vpiType, target)) - { - default: - vpi_printf("ERROR: %s invalid target parameter\n", name); - break; - case vpiNet: - case vpiReg: + vpiHandle callh = vpi_handle(vpiSysTfCall, 0); + vpiHandle argv = vpi_iterate(vpiArgument, callh); + vpiHandle target, value; + + /* Check that there are arguments. */ + if (argv == 0) { + vpi_printf("ERROR: %s requires two arguments.\n", name); + vpi_control(vpiFinish, 1); + return 0; + } + + /* Check that there are at least two arguments. */ + target = vpi_scan(argv); /* This should never be zero. */ + value = vpi_scan(argv); + if (value == 0) { + vpi_printf("ERROR: %s requires two arguments.\n", name); + vpi_control(vpiFinish, 1); + return 0; + } + + /* Check the targets type. It must be a net or a register. */ + switch (vpi_get(vpiType, target)) { + case vpiNet: + case vpiReg: + break; + default: + vpi_printf("ERROR: invalid target type for %s.\n", name); + vpi_control(vpiFinish, 1); + return 0; + } + + /* Check that there is at most two arguments. */ + target = vpi_scan(argv); + if (target != 0) { + vpi_printf("ERROR: %s takes at most two arguments.\n", name); + vpi_control(vpiFinish, 1); + return 0; + } +} + +static PLI_INT32 sys_deposit_calltf(PLI_BYTE8 *name) +{ + vpiHandle callh, argv, target, value; + s_vpi_value val; + + callh = vpi_handle(vpiSysTfCall, 0); + argv = vpi_iterate(vpiArgument, callh); + target = vpi_scan(argv); + value = vpi_scan(argv); + + val.format = vpiIntVal; + vpi_get_value(value, &val); + vpi_put_value(target, &val, 0, vpiNoDelay); - break; - } - return 0; + vpi_free_object(argv); + return 0; } void sys_deposit_register() { - s_vpi_systf_data tf_data; - - tf_data.type = vpiSysTask; - tf_data.tfname = "$deposit"; - tf_data.calltf = sys_deposit_calltf; - tf_data.compiletf = 0; - tf_data.sizetf = 0; - tf_data.user_data = "$deposit"; - vpi_register_systf(&tf_data); + s_vpi_systf_data tf_data; + + tf_data.type = vpiSysTask; + tf_data.tfname = "$deposit"; + tf_data.calltf = sys_deposit_calltf; + tf_data.compiletf = sys_deposit_compiletf; + tf_data.sizetf = 0; + tf_data.user_data = "$deposit"; + vpi_register_systf(&tf_data); } diff --git a/vvp/vpi_const.cc b/vvp/vpi_const.cc index 96e4c9fa8b..f515d26a78 100644 --- a/vvp/vpi_const.cc +++ b/vvp/vpi_const.cc @@ -125,6 +125,16 @@ static void string_value(vpiHandle ref, p_vpi_value vp) assert(0); break; + case vpiIntVal: + vp->value.integer = 0; + for(int i=0; i=0; bit--){ + vp->value.integer <<= 1; + vp->value.integer += (rfp->value[i]>>bit)&1; + } + } + break; + default: fprintf(stderr, "ERROR (vpi_const.cc): vp->format: %d\n", vp->format); assert(0);