2008-07-31 23:05:27 +02:00
|
|
|
/*
|
2009-02-27 00:22:21 +01:00
|
|
|
* Copyright (C) 2008-2009 Cary R. (cygcary@yahoo.com)
|
2008-07-31 23:05:27 +02:00
|
|
|
*
|
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
|
* it 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.,
|
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include <assert.h>
|
|
|
|
|
#include <math.h>
|
|
|
|
|
#include <string.h>
|
|
|
|
|
#include <vpi_user.h>
|
2008-08-30 06:11:44 +02:00
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* This routine returns 1 if the argument supports has a numeric value,
|
|
|
|
|
* otherwise it returns 0.
|
|
|
|
|
*
|
|
|
|
|
* This is copied from sys_priv.c.
|
|
|
|
|
*/
|
|
|
|
|
static unsigned is_numeric_obj(vpiHandle obj)
|
|
|
|
|
{
|
|
|
|
|
unsigned rtn = 0;
|
|
|
|
|
|
2008-09-30 03:06:47 +02:00
|
|
|
assert(obj);
|
|
|
|
|
|
2008-08-30 06:11:44 +02:00
|
|
|
switch(vpi_get(vpiType, obj)) {
|
|
|
|
|
case vpiConstant:
|
|
|
|
|
case vpiParameter:
|
|
|
|
|
/* These cannot be a string constant. */
|
|
|
|
|
if (vpi_get(vpiConstType, obj) != vpiStringConst) rtn = 1;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
/* These can have a valid numeric value. */
|
|
|
|
|
case vpiIntegerVar:
|
|
|
|
|
case vpiMemoryWord:
|
|
|
|
|
case vpiNet:
|
|
|
|
|
case vpiPartSelect:
|
|
|
|
|
case vpiRealVar:
|
|
|
|
|
case vpiReg:
|
|
|
|
|
case vpiTimeVar:
|
2009-02-27 00:22:21 +01:00
|
|
|
rtn = 1;
|
2008-08-30 06:11:44 +02:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return rtn;
|
|
|
|
|
}
|
2008-07-31 23:05:27 +02:00
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Check that the function is called with the correct argument.
|
|
|
|
|
*/
|
|
|
|
|
static PLI_INT32 sys_clog2_compiletf(PLI_BYTE8 *name)
|
|
|
|
|
{
|
|
|
|
|
vpiHandle callh = vpi_handle(vpiSysTfCall, 0);
|
2008-09-30 03:06:47 +02:00
|
|
|
vpiHandle argv, arg;
|
|
|
|
|
|
2008-07-31 23:05:27 +02:00
|
|
|
assert(callh != 0);
|
2008-09-30 03:06:47 +02:00
|
|
|
argv = vpi_iterate(vpiArgument, callh);
|
|
|
|
|
(void) name; /* Not used! */
|
2008-07-31 23:05:27 +02:00
|
|
|
|
|
|
|
|
/* We must have an argument. */
|
|
|
|
|
if (argv == 0) {
|
Rework $plusarg routines.
This patch addresses a number of issues:
Rewrote the $test$plusargs and $value$plusargs routines to have
better error/warning messages, to support runtime strings, to
correctly load bit based values (truncating, padding, negative
value), added support for the real formats using strtod() and
added "x/X" as an alias for "h/H" to match the other part of
Icarus.
Rewrite the vpip_{bin,oct,hex}_str_to_vec4 routines to ignore
embedded "_" characters. Add support for a negative value and
set the entire value to 'bx if an invalid digit is found. A
warning is printed for this case.
Rewrite vpip_dec_str_to_vec4 to ignore embedded "_" characters,
to support a single "x" or "z" constant and to return 'bx if an
invalid digit is found. A warning is printed for this case.
It simplifies the system task/functions error/warning messages.
It removes the signed flag for the bin and dec string conversions.
This was not being used (was always false) and the new negative
value support makes this obsolete.
Add support for a real variable to handle Bin, Oct, Dec and Hex
strings. They are converted into a vvp_vector4_t which is then
converted to a real value.
Add support for setting a bit based value using a real value.
Removed an unneeded rfp signal in vpip_make_reg()
2008-11-13 22:28:19 +01:00
|
|
|
vpi_printf("ERROR: %s:%d: ", vpi_get_str(vpiFile, callh),
|
2008-07-31 23:05:27 +02:00
|
|
|
(int)vpi_get(vpiLineNo, callh));
|
|
|
|
|
vpi_printf("$clog2 requires one numeric argument.\n");
|
|
|
|
|
vpi_control(vpiFinish, 1);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* The argument must be numeric. */
|
|
|
|
|
arg = vpi_scan(argv);
|
|
|
|
|
if (! is_numeric_obj(arg)) {
|
Rework $plusarg routines.
This patch addresses a number of issues:
Rewrote the $test$plusargs and $value$plusargs routines to have
better error/warning messages, to support runtime strings, to
correctly load bit based values (truncating, padding, negative
value), added support for the real formats using strtod() and
added "x/X" as an alias for "h/H" to match the other part of
Icarus.
Rewrite the vpip_{bin,oct,hex}_str_to_vec4 routines to ignore
embedded "_" characters. Add support for a negative value and
set the entire value to 'bx if an invalid digit is found. A
warning is printed for this case.
Rewrite vpip_dec_str_to_vec4 to ignore embedded "_" characters,
to support a single "x" or "z" constant and to return 'bx if an
invalid digit is found. A warning is printed for this case.
It simplifies the system task/functions error/warning messages.
It removes the signed flag for the bin and dec string conversions.
This was not being used (was always false) and the new negative
value support makes this obsolete.
Add support for a real variable to handle Bin, Oct, Dec and Hex
strings. They are converted into a vvp_vector4_t which is then
converted to a real value.
Add support for setting a bit based value using a real value.
Removed an unneeded rfp signal in vpip_make_reg()
2008-11-13 22:28:19 +01:00
|
|
|
vpi_printf("ERROR: %s:%d: ", vpi_get_str(vpiFile, callh),
|
2008-07-31 23:05:27 +02:00
|
|
|
(int)vpi_get(vpiLineNo, callh));
|
|
|
|
|
vpi_printf("The first argument to $clog2 must be numeric.\n");
|
|
|
|
|
vpi_control(vpiFinish, 1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* We can have a maximum of one argument. */
|
|
|
|
|
if (vpi_scan(argv) != 0) {
|
|
|
|
|
char msg [64];
|
2008-09-30 03:06:47 +02:00
|
|
|
unsigned argc;
|
|
|
|
|
|
Rework $plusarg routines.
This patch addresses a number of issues:
Rewrote the $test$plusargs and $value$plusargs routines to have
better error/warning messages, to support runtime strings, to
correctly load bit based values (truncating, padding, negative
value), added support for the real formats using strtod() and
added "x/X" as an alias for "h/H" to match the other part of
Icarus.
Rewrite the vpip_{bin,oct,hex}_str_to_vec4 routines to ignore
embedded "_" characters. Add support for a negative value and
set the entire value to 'bx if an invalid digit is found. A
warning is printed for this case.
Rewrite vpip_dec_str_to_vec4 to ignore embedded "_" characters,
to support a single "x" or "z" constant and to return 'bx if an
invalid digit is found. A warning is printed for this case.
It simplifies the system task/functions error/warning messages.
It removes the signed flag for the bin and dec string conversions.
This was not being used (was always false) and the new negative
value support makes this obsolete.
Add support for a real variable to handle Bin, Oct, Dec and Hex
strings. They are converted into a vvp_vector4_t which is then
converted to a real value.
Add support for setting a bit based value using a real value.
Removed an unneeded rfp signal in vpip_make_reg()
2008-11-13 22:28:19 +01:00
|
|
|
snprintf(msg, 64, "ERROR: %s:%d:",
|
2008-07-31 23:05:27 +02:00
|
|
|
vpi_get_str(vpiFile, callh),
|
|
|
|
|
(int)vpi_get(vpiLineNo, callh));
|
|
|
|
|
|
2008-09-30 03:06:47 +02:00
|
|
|
argc = 1;
|
2008-07-31 23:05:27 +02:00
|
|
|
while (vpi_scan(argv)) argc += 1;
|
|
|
|
|
|
|
|
|
|
vpi_printf("%s $clog2 takes at most one argument.\n", msg);
|
|
|
|
|
vpi_printf("%*s Found %u extra argument%s.\n",
|
2008-08-26 18:44:44 +02:00
|
|
|
(int) strlen(msg), " ", argc, argc == 1 ? "" : "s");
|
2008-07-31 23:05:27 +02:00
|
|
|
vpi_control(vpiFinish, 1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static PLI_INT32 sys_clog2_calltf(PLI_BYTE8 *name)
|
|
|
|
|
{
|
|
|
|
|
vpiHandle callh = vpi_handle(vpiSysTfCall, 0);
|
|
|
|
|
vpiHandle argv = vpi_iterate(vpiArgument, callh);
|
|
|
|
|
vpiHandle arg;
|
|
|
|
|
s_vpi_value val;
|
2008-08-16 04:28:11 +02:00
|
|
|
s_vpi_vecval vec;
|
2008-09-30 03:06:47 +02:00
|
|
|
(void) name; /* Not used! */
|
2008-07-31 23:05:27 +02:00
|
|
|
|
|
|
|
|
/* Get the argument. */
|
|
|
|
|
arg = vpi_scan(argv);
|
|
|
|
|
vpi_free_object(argv);
|
|
|
|
|
|
2008-08-16 04:28:11 +02:00
|
|
|
vec = vpip_calc_clog2(arg);
|
2008-07-31 23:05:27 +02:00
|
|
|
|
2008-08-16 04:28:11 +02:00
|
|
|
val.format = vpiVectorVal;
|
|
|
|
|
val.value.vector = &vec;
|
2008-07-31 23:05:27 +02:00
|
|
|
vpi_put_value(callh, &val, 0, vpiNoDelay);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Register the function with Verilog.
|
|
|
|
|
*/
|
|
|
|
|
void sys_clog2_register(void)
|
|
|
|
|
{
|
|
|
|
|
s_vpi_systf_data tf_data;
|
|
|
|
|
|
|
|
|
|
tf_data.type = vpiSysFunc;
|
|
|
|
|
tf_data.sysfunctype = vpiIntFunc;
|
|
|
|
|
tf_data.calltf = sys_clog2_calltf;
|
|
|
|
|
tf_data.compiletf = sys_clog2_compiletf;
|
|
|
|
|
tf_data.sizetf = 0;
|
|
|
|
|
tf_data.tfname = "$clog2";
|
|
|
|
|
tf_data.user_data = 0;
|
|
|
|
|
vpi_register_systf(&tf_data);
|
|
|
|
|
}
|