Support more parameter syntax.

This commit is contained in:
steve 2006-03-18 22:53:38 +00:00
parent 5b3ba8c306
commit f4a44df2cc
3 changed files with 54 additions and 30 deletions

View File

@ -17,7 +17,7 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/ */
#ifdef HAVE_CVS_IDENT #ifdef HAVE_CVS_IDENT
#ident "$Id: elab_scope.cc,v 1.36 2005/07/11 16:56:50 steve Exp $" #ident "$Id: elab_scope.cc,v 1.37 2006/03/18 22:53:38 steve Exp $"
#endif #endif
# include "config.h" # include "config.h"
@ -74,7 +74,6 @@ bool Module::elaborate_scope(Design*des, NetScope*scope) const
NetEParam*tmp = new NetEParam; NetEParam*tmp = new NetEParam;
tmp->set_line(*((*cur).second.expr)); tmp->set_line(*((*cur).second.expr));
if ((*cur).second.msb)
tmp->cast_signed( (*cur).second.signed_flag ); tmp->cast_signed( (*cur).second.signed_flag );
scope->set_parameter((*cur).first, tmp, 0, 0, false); scope->set_parameter((*cur).first, tmp, 0, 0, false);
@ -106,7 +105,7 @@ bool Module::elaborate_scope(Design*des, NetScope*scope) const
NetExpr*val = ex->elaborate_pexpr(des, scope); NetExpr*val = ex->elaborate_pexpr(des, scope);
NetExpr*msb = 0; NetExpr*msb = 0;
NetExpr*lsb = 0; NetExpr*lsb = 0;
bool signed_flag = false; bool signed_flag = (*cur).second.signed_flag;
/* If the parameter declaration includes msb and lsb, /* If the parameter declaration includes msb and lsb,
then use them to calculate a width for the then use them to calculate a width for the
@ -117,10 +116,21 @@ bool Module::elaborate_scope(Design*des, NetScope*scope) const
msb = (*cur).second.msb ->elaborate_pexpr(des, scope); msb = (*cur).second.msb ->elaborate_pexpr(des, scope);
assert(msb); assert(msb);
lsb = (*cur).second.lsb ->elaborate_pexpr(des, scope); lsb = (*cur).second.lsb ->elaborate_pexpr(des, scope);
signed_flag = (*cur).second.signed_flag;
} }
if (signed_flag) {
/* If explicitly signed, then say so. */
val->cast_signed(true);
} else if ((*cur).second.msb) {
/* If there is a range, then the signedness comes
from the type and not the expression. */
val->cast_signed(signed_flag); val->cast_signed(signed_flag);
} else {
/* otherwise, let the expression describe
itself. */
signed_flag = val->has_sign();
}
val = scope->set_parameter((*cur).first, val, val = scope->set_parameter((*cur).first, val,
msb, lsb, signed_flag); msb, lsb, signed_flag);
assert(val); assert(val);
@ -600,6 +610,9 @@ void PWhile::elaborate_scope(Design*des, NetScope*scope) const
/* /*
* $Log: elab_scope.cc,v $ * $Log: elab_scope.cc,v $
* Revision 1.37 2006/03/18 22:53:38 steve
* Support more parameter syntax.
*
* Revision 1.36 2005/07/11 16:56:50 steve * Revision 1.36 2005/07/11 16:56:50 steve
* Remove NetVariable and ivl_variable_t structures. * Remove NetVariable and ivl_variable_t structures.
* *

49
parse.y
View File

@ -19,7 +19,7 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/ */
#ifdef HAVE_CVS_IDENT #ifdef HAVE_CVS_IDENT
#ident "$Id: parse.y,v 1.209 2006/02/02 02:43:59 steve Exp $" #ident "$Id: parse.y,v 1.210 2006/03/18 22:53:38 steve Exp $"
#endif #endif
# include "config.h" # include "config.h"
@ -1898,6 +1898,33 @@ var_type
: K_reg { $$ = NetNet::REG; } : K_reg { $$ = NetNet::REG; }
; ;
/* In this rule we have matched the "parameter" keyword. The rule
generates a type (optional) and a list of assignments. */
parameter_assign_decl
: parameter_assign_list
| range { active_range = $1; active_signed = false; }
parameter_assign_list
{ active_range = 0;
active_signed = false;
}
| K_signed range { active_range = $2; active_signed = true; }
parameter_assign_list
{ active_range = 0;
active_signed = false;
}
| K_integer { active_range = 0; active_signed = true; }
parameter_assign_list
{ active_range = 0;
active_signed = false;
}
;
parameter_assign_list
: parameter_assign
| parameter_assign_list ',' parameter_assign
;
parameter_assign parameter_assign
: IDENTIFIER '=' expression : IDENTIFIER '=' expression
{ PExpr*tmp = $3; { PExpr*tmp = $3;
@ -1915,26 +1942,6 @@ parameter_assign
} }
; ;
parameter_assign_decl
: parameter_assign_list
| range { active_range = $1; active_signed = false; }
parameter_assign_list
{ active_range = 0;
active_signed = false;
}
| K_signed range { active_range = $2; active_signed = true; }
parameter_assign_list
{ active_range = 0;
active_signed = false;
}
;
parameter_assign_list
: parameter_assign
| parameter_assign_list ',' parameter_assign
;
/* Localparam assignments and assignment lists are broken into /* Localparam assignments and assignment lists are broken into
separate BNF so that I can call slightly different parameter separate BNF so that I can call slightly different parameter
handling code. They parse the same as parameters, they just handling code. They parse the same as parameters, they just

View File

@ -17,7 +17,7 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/ */
#ifdef HAVE_CVS_IDENT #ifdef HAVE_CVS_IDENT
#ident "$Id: vvp_scope.c,v 1.141 2006/03/15 05:52:20 steve Exp $" #ident "$Id: vvp_scope.c,v 1.142 2006/03/18 22:53:38 steve Exp $"
#endif #endif
# include "vvp_priv.h" # include "vvp_priv.h"
@ -2133,8 +2133,9 @@ int draw_scope(ivl_scope_t net, ivl_scope_t parent)
ivl_expr_string(pex)); ivl_expr_string(pex));
break; break;
case IVL_EX_NUMBER: case IVL_EX_NUMBER:
fprintf(vvp_out, "P_%p .param/l \"%s\", C4<", fprintf(vvp_out, "P_%p .param/l \"%s\", %sC4<",
par, ivl_parameter_basename(par)); par, ivl_parameter_basename(par),
ivl_expr_signed(pex)? "+":"");
{ const char*bits = ivl_expr_bits(pex); { const char*bits = ivl_expr_bits(pex);
unsigned nbits = ivl_expr_width(pex); unsigned nbits = ivl_expr_width(pex);
unsigned bb; unsigned bb;
@ -2203,6 +2204,9 @@ int draw_scope(ivl_scope_t net, ivl_scope_t parent)
/* /*
* $Log: vvp_scope.c,v $ * $Log: vvp_scope.c,v $
* Revision 1.142 2006/03/18 22:53:38 steve
* Support more parameter syntax.
*
* Revision 1.141 2006/03/15 05:52:20 steve * Revision 1.141 2006/03/15 05:52:20 steve
* Handle multiple part/bi devices connected together. * Handle multiple part/bi devices connected together.
* *