Add support for logic parameters.

This commit is contained in:
steve 2006-03-08 05:29:42 +00:00
parent 5f5a6b5396
commit 6f46d12e07
10 changed files with 192 additions and 59 deletions

View File

@ -17,7 +17,7 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
#ifdef HAVE_CVS_IDENT
#ident "$Id: vvp_scope.c,v 1.139 2006/01/02 05:33:20 steve Exp $"
#ident "$Id: vvp_scope.c,v 1.140 2006/03/08 05:29:42 steve Exp $"
#endif
# include "vvp_priv.h"
@ -2091,11 +2091,24 @@ int draw_scope(ivl_scope_t net, ivl_scope_t parent)
ivl_expr_t pex = ivl_parameter_expr(par);
switch (ivl_expr_type(pex)) {
case IVL_EX_STRING:
fprintf(vvp_out, "P_%p .param \"%s\", string, \"%s\";\n",
fprintf(vvp_out, "P_%p .param/str \"%s\", \"%s\";\n",
par, ivl_parameter_basename(par),
ivl_expr_string(pex));
break;
case IVL_EX_NUMBER:
fprintf(vvp_out, "P_%p .param/l \"%s\", C4<",
par, ivl_parameter_basename(par));
{ const char*bits = ivl_expr_bits(pex);
unsigned nbits = ivl_expr_width(pex);
unsigned bb;
for (bb = 0 ; bb < nbits; bb += 1)
fprintf(vvp_out, "%c", bits[nbits-bb-1]);
}
fprintf(vvp_out, ">;\n");
break;
default:
fprintf(vvp_out, "; parameter type %d unsupported\n",
ivl_expr_type(pex));
break;
}
}
@ -2153,6 +2166,9 @@ int draw_scope(ivl_scope_t net, ivl_scope_t parent)
/*
* $Log: vvp_scope.c,v $
* Revision 1.140 2006/03/08 05:29:42 steve
* Add support for logic parameters.
*
* Revision 1.139 2006/01/02 05:33:20 steve
* Node delays can be more general expressions in structural contexts.
*

View File

@ -1,7 +1,7 @@
/*
* Copyright (c) 2001 Stephen Williams (steve@icarus.com)
*
* $Id: README.txt,v 1.75 2006/01/02 05:32:06 steve Exp $
* $Id: README.txt,v 1.76 2006/03/08 05:29:42 steve Exp $
*/
VVP SIMULATION ENGINE
@ -101,22 +101,23 @@ objects.
The syntax of a parameter is:
<label> .param <name>, <type>, <value>;
<label> .param/str <name>, <value>;
<label> .param/b <name>, <value> [<msb>,<lsb>,<s>];
<label> .param/l <name>, <value> [<msb>,<lsb>,<s>];
<label> .param/r <name>, <value>;
The <name> is a string that names the parameter. The name is placed in
the current scope as a vpiParameter object. The <type> is one of the
following:
the current scope as a vpiParameter object. The .param suffix
specifies the parameter type.
real -- The parameter has a real value
string -- The parameter has a string value
[<msb>,<lsb>,<s>]
-- The parameter is a vector, with specified
indices. The <s> is s or u for signed or
unsigned.
.param/str -- The parameter has a string value
.param/l -- The parameter has a logic vector value
.param/b -- The parameter has a boolean vector value
.param/r -- The parameter has a real value
The value, then, is appropriate for the data type. For example:
P_123 .param "hello", string, "Hello, World.";
P_123 .param/str "hello", "Hello, World.";
FUNCTOR STATEMENTS:

View File

@ -17,7 +17,7 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
#ifdef HAVE_CVS_IDENT
#ident "$Id: compile.cc,v 1.217 2006/02/02 02:44:00 steve Exp $"
#ident "$Id: compile.cc,v 1.218 2006/03/08 05:29:42 steve Exp $"
#endif
# include "arith.h"
@ -686,30 +686,7 @@ void input_connect(vvp_net_t*fdx, unsigned port, char*label)
&& (tp[1] == 0)
&& (strspn(label+3, "01xz")+3 == (unsigned)(tp-label))) {
size_t v4size = tp-label-3;
vvp_vector4_t tmp (v4size);
for (unsigned idx = 0 ; idx < v4size ; idx += 1) {
vvp_bit4_t bit;
switch (label[3+idx]) {
case '0':
bit = BIT4_0;
break;
case '1':
bit = BIT4_1;
break;
case 'x':
bit = BIT4_X;
break;
case 'z':
bit = BIT4_Z;
break;
default:
assert(0);
break;
}
tmp.set_bit(v4size-idx-1, bit);
}
vvp_vector4_t tmp = c4string_to_vector4(label);
// Inputs that are constants are schedule to execute as
// soon at the simulation starts. In Verilog, constants
@ -1496,11 +1473,19 @@ void compile_thread(char*start_sym, char*flag)
free(flag);
}
void compile_param_string(char*label, char*name, char*str, char*value)
void compile_param_logic(char*label, char*name, char*value)
{
assert(strcmp(str,"string") == 0);
free(str);
vvp_vector4_t value4 = c4string_to_vector4(value);
vpiHandle obj = vpip_make_binary_param(name, value4);
compile_vpi_symbol(label, obj);
vpip_attach_to_current_scope(obj);
free(label);
free(value);
}
void compile_param_string(char*label, char*name, char*value)
{
vpiHandle obj = vpip_make_string_param(name, value);
compile_vpi_symbol(label, obj);
vpip_attach_to_current_scope(obj);
@ -1510,6 +1495,9 @@ void compile_param_string(char*label, char*name, char*str, char*value)
/*
* $Log: compile.cc,v $
* Revision 1.218 2006/03/08 05:29:42 steve
* Add support for logic parameters.
*
* Revision 1.217 2006/02/02 02:44:00 steve
* Allow part selects of memory words in l-values.
*

View File

@ -19,7 +19,7 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
#ifdef HAVE_CVS_IDENT
#ident "$Id: compile.h,v 1.78 2006/01/02 05:32:07 steve Exp $"
#ident "$Id: compile.h,v 1.79 2006/03/08 05:29:42 steve Exp $"
#endif
# include <stdio.h>
@ -182,8 +182,8 @@ extern void compile_timescale(long units);
extern void compile_vpi_symbol(const char*label, vpiHandle obj);
extern void compile_vpi_lookup(vpiHandle *objref, char*label);
extern void compile_param_string(char*label, char*name,
char*str, char*value);
extern void compile_param_string(char*label, char*name, char*value);
extern void compile_param_logic(char*label, char*name, char*value);
/*
* This function schedules a lookup of an indexed label. The ref
@ -342,6 +342,9 @@ extern void compile_alias_real(char*label, char*name,
/*
* $Log: compile.h,v $
* Revision 1.79 2006/03/08 05:29:42 steve
* Add support for logic parameters.
*
* Revision 1.78 2006/01/02 05:32:07 steve
* Require explicit delay node from source.
*

View File

@ -19,7 +19,7 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
#ifdef HAVE_CVS_IDENT
#ident "$Id: lexor.lex,v 1.58 2006/01/02 05:32:07 steve Exp $"
#ident "$Id: lexor.lex,v 1.59 2006/03/08 05:29:42 steve Exp $"
#endif
# include "parse_misc.h"
@ -114,7 +114,8 @@
".net8/s" { return K_NET8_S; }
".net/real" { return K_NET_R; }
".net/s" { return K_NET_S; }
".param" { return K_PARAM; }
".param/l" { return K_PARAM_L; }
".param/str" { return K_PARAM_STR; }
".part" { return K_PART; }
".part/pv" { return K_PART_PV; }
".part/v" { return K_PART_V; }
@ -205,6 +206,9 @@ int yywrap()
/*
* $Log: lexor.lex,v $
* Revision 1.59 2006/03/08 05:29:42 steve
* Add support for logic parameters.
*
* Revision 1.58 2006/01/02 05:32:07 steve
* Require explicit delay node from source.
*

View File

@ -19,7 +19,7 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
#ifdef HAVE_CVS_IDENT
#ident "$Id: parse.y,v 1.80 2006/01/02 05:32:07 steve Exp $"
#ident "$Id: parse.y,v 1.81 2006/03/08 05:29:42 steve Exp $"
#endif
# include "parse_misc.h"
@ -64,7 +64,7 @@ extern FILE*yyin;
%token K_CONCAT K_DELAY K_DFF
%token K_EVENT K_EVENT_OR K_EXTEND_S K_FUNCTOR K_NET K_NET_S K_NET_R
%token K_NET8 K_NET8_S
%token K_PARAM K_PART K_PART_PV
%token K_PARAM_STR K_PARAM_L K_PART K_PART_PV
%token K_PART_V K_REDUCE_AND K_REDUCE_OR K_REDUCE_XOR
%token K_REDUCE_NAND K_REDUCE_NOR K_REDUCE_XNOR K_REPEAT
%token K_RESOLV K_SCOPE K_SHIFTL K_SHIFTR K_THREAD K_TIMESCALE K_UFUNC
@ -498,8 +498,11 @@ statement
/* Parameter statements come in a few simple forms. The most basic
is the string parameter. */
| T_LABEL K_PARAM T_STRING ',' T_SYMBOL ',' T_STRING ';'
{ compile_param_string($1, $3, $5, $7); }
| T_LABEL K_PARAM_STR T_STRING ',' T_STRING ';'
{ compile_param_string($1, $3, $5); }
| T_LABEL K_PARAM_L T_STRING ',' T_SYMBOL ';'
{ compile_param_logic($1, $3, $5); }
/* Oh and by the way, empty statements are OK as well. */
@ -733,6 +736,9 @@ int compile_design(const char*path)
/*
* $Log: parse.y,v $
* Revision 1.81 2006/03/08 05:29:42 steve
* Add support for logic parameters.
*
* Revision 1.80 2006/01/02 05:32:07 steve
* Require explicit delay node from source.
*

View File

@ -17,7 +17,7 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
#ifdef HAVE_CVS_IDENT
#ident "$Id: vpi_const.cc,v 1.33 2006/03/06 05:43:15 steve Exp $"
#ident "$Id: vpi_const.cc,v 1.34 2006/03/08 05:29:42 steve Exp $"
#endif
# include "vpi_priv.h"
@ -253,7 +253,8 @@ vpiHandle vpip_make_string_param(char*name, char*text)
static int binary_get(int code, vpiHandle ref)
{
struct __vpiBinaryConst*rfp = (struct __vpiBinaryConst*)ref;
assert(ref->vpi_type->type_code == vpiConstant);
assert(ref->vpi_type->type_code == vpiConstant
|| ref->vpi_type->type_code == vpiParameter);
switch (code) {
case vpiConstType:
@ -276,10 +277,10 @@ static int binary_get(int code, vpiHandle ref)
static void binary_value(vpiHandle ref, p_vpi_value vp)
{
assert(ref->vpi_type->type_code == vpiConstant);
assert(ref->vpi_type->type_code == vpiConstant
|| ref->vpi_type->type_code == vpiParameter);
struct __vpiBinaryConst*rfp = (struct __vpiBinaryConst*)ref;
char*rbuf = 0;
switch (vp->format) {
@ -324,8 +325,7 @@ vpiHandle vpip_make_binary_const(unsigned wid, char*bits)
{
struct __vpiBinaryConst*obj;
obj = (struct __vpiBinaryConst*)
malloc(sizeof (struct __vpiBinaryConst));
obj = new __vpiBinaryConst;
obj->base.vpi_type = &vpip_binary_rt;
obj->signed_flag = 0;
@ -361,6 +361,69 @@ vpiHandle vpip_make_binary_const(unsigned wid, char*bits)
return &(obj->base);
}
struct __vpiBinaryParam : public __vpiBinaryConst {
const char*basename;
struct __vpiScope*scope;
};
static char* binary_param_get_str(int code, vpiHandle obj)
{
struct __vpiBinaryParam*rfp = (struct __vpiBinaryParam*)obj;
char *rbuf = need_result_buf(strlen(rfp->basename) + 1, RBUF_STR);
assert(obj->vpi_type->type_code == vpiParameter);
switch (code) {
case vpiName:
strcpy(rbuf, rfp->basename);
return rbuf;
default:
return 0;
}
}
static vpiHandle binary_param_handle(int code, vpiHandle obj)
{
struct __vpiBinaryParam*rfp = (struct __vpiBinaryParam*)obj;
assert(obj->vpi_type->type_code == vpiParameter);
switch (code) {
case vpiScope:
return &rfp->scope->base;
default:
return 0;
}
}
static const struct __vpirt vpip_binary_param_rt = {
vpiParameter,
binary_get,
binary_param_get_str,
binary_value,
0,
binary_param_handle,
0,
0,
0
};
vpiHandle vpip_make_binary_param(char*name, const vvp_vector4_t&bits)
{
struct __vpiBinaryParam*obj = new __vpiBinaryParam;
obj->base.vpi_type = &vpip_binary_param_rt;
obj->bits = bits;
obj->signed_flag = 0;
obj->basename = name;
obj->scope = vpip_peek_current_scope();
return &obj->base;
}
static int dec_get(int code, vpiHandle ref)
@ -465,6 +528,9 @@ vpiHandle vpip_make_dec_const(int value)
/*
* $Log: vpi_const.cc,v $
* Revision 1.34 2006/03/08 05:29:42 steve
* Add support for logic parameters.
*
* Revision 1.33 2006/03/06 05:43:15 steve
* Cleanup vpi_const to use vec4 values.
*

View File

@ -19,7 +19,7 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
#ifdef HAVE_CVS_IDENT
#ident "$Id: vpi_priv.h,v 1.68 2006/03/06 05:43:15 steve Exp $"
#ident "$Id: vpi_priv.h,v 1.69 2006/03/08 05:29:42 steve Exp $"
#endif
# include "vpi_user.h"
@ -295,6 +295,7 @@ struct __vpiBinaryConst {
};
vpiHandle vpip_make_binary_const(unsigned wid, char*bits);
vpiHandle vpip_make_binary_param(char*name, const vvp_vector4_t&bits);
struct __vpiDecConst {
struct __vpiHandle base;
@ -427,6 +428,9 @@ extern char *need_result_buf(unsigned cnt, vpi_rbuf_t type);
/*
* $Log: vpi_priv.h,v $
* Revision 1.69 2006/03/08 05:29:42 steve
* Add support for logic parameters.
*
* Revision 1.68 2006/03/06 05:43:15 steve
* Cleanup vpi_const to use vec4 values.
*

View File

@ -16,7 +16,7 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
#ident "$Id: vvp_net.cc,v 1.50 2006/01/03 06:19:31 steve Exp $"
#ident "$Id: vvp_net.cc,v 1.51 2006/03/08 05:29:42 steve Exp $"
# include "config.h"
# include "vvp_net.h"
@ -1119,6 +1119,42 @@ vvp_vector4_t vector2_to_vector4(const vvp_vector2_t&that, unsigned wid)
return res;
}
vvp_vector4_t c4string_to_vector4(const char*str)
{
assert((str[0]=='C') && (str[1]=='4') && (str[2]=='<'));
str += 3;
char*tp = str + strspn(str,"01xz");
assert(tp[0] == '>');
vvp_vector4_t tmp (tp-str);
for (unsigned idx = 0 ; idx < tmp.size() ; idx += 1) {
vvp_bit4_t bit;
switch (str[idx]) {
case '0':
bit = BIT4_0;
break;
case '1':
bit = BIT4_1;
break;
case 'x':
bit = BIT4_X;
break;
case 'z':
bit = BIT4_Z;
break;
default:
assert(0);
bit = BIT4_0;
break;
}
tmp.set_bit(tmp.size()-idx-1, bit);
}
return tmp;
}
ostream& operator<< (ostream&out, const vvp_vector2_t&that)
{
if (that.is_NaN()) {
@ -2127,6 +2163,9 @@ vvp_bit4_t compare_gtge_signed(const vvp_vector4_t&a,
/*
* $Log: vvp_net.cc,v $
* Revision 1.51 2006/03/08 05:29:42 steve
* Add support for logic parameters.
*
* Revision 1.50 2006/01/03 06:19:31 steve
* Support wide divide nodes.
*

View File

@ -18,7 +18,7 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
#ident "$Id: vvp_net.h,v 1.49 2005/11/26 17:16:05 steve Exp $"
#ident "$Id: vvp_net.h,v 1.50 2006/03/08 05:29:42 steve Exp $"
# include "config.h"
# include <stddef.h>
@ -309,6 +309,9 @@ extern vvp_vector2_t operator * (const vvp_vector2_t&, const vvp_vector2_t&);
extern vvp_vector2_t operator / (const vvp_vector2_t&, const vvp_vector2_t&);
extern vvp_vector2_t operator % (const vvp_vector2_t&, const vvp_vector2_t&);
extern vvp_vector4_t vector2_to_vector4(const vvp_vector2_t&, unsigned wid);
/* A c4string is of the form C4<...> where ... are bits. */
extern vvp_vector4_t c4string_to_vector4(const char*str);
extern ostream& operator<< (ostream&, const vvp_vector2_t&);
/*
@ -1005,6 +1008,9 @@ inline void vvp_send_vec4_pv(vvp_net_ptr_t ptr, const vvp_vector4_t&val,
/*
* $Log: vvp_net.h,v $
* Revision 1.50 2006/03/08 05:29:42 steve
* Add support for logic parameters.
*
* Revision 1.49 2005/11/26 17:16:05 steve
* Force instruction that can be indexed.
*