Skip to content

Commit

Permalink
[PATCH] Add compiletf routine for deposit system task and fix string …
Browse files Browse the repository at this point in the history
…constants.

This patch adds a compiletf routine to the $deposit system task and
simplifies the calltf routine. It also patches the constant string code
to return an appropriate integer value when needed. A number of compiletf
routines that check for this can now be simplified since this (string
constants) no longer causes an assert in an integer environment.
  • Loading branch information
caryr authored and steveicarus committed Jul 24, 2007
1 parent 824f29a commit b23eb1b
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 41 deletions.
106 changes: 65 additions & 41 deletions vpi/sys_deposit.c
Expand Up @@ -26,54 +26,78 @@
# include "vpi_user.h"
# include <assert.h>

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);
}


Expand Down
10 changes: 10 additions & 0 deletions vvp/vpi_const.cc
Expand Up @@ -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<size;i ++){
for(int bit=7;bit>=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);
Expand Down

0 comments on commit b23eb1b

Please sign in to comment.