From faece5816ce2d70d9e16ec16c6f537872a43a4a4 Mon Sep 17 00:00:00 2001 From: Martin Whitaker Date: Tue, 26 Feb 2013 22:36:37 +0000 Subject: [PATCH] Fix implicit casts in assignments (part 3). This patch adds support for bool/bit vector types on the LHS of a parameter declaration and ensures implicit casts in parameter declarations are performed where necessary. --- net_design.cc | 37 ++++++++----------------------------- net_scope.cc | 4 +--- parse.y | 34 ++++++++++++++-------------------- 3 files changed, 23 insertions(+), 52 deletions(-) diff --git a/net_design.cc b/net_design.cc index f945dcf7b..5d0c5b9d9 100644 --- a/net_design.cc +++ b/net_design.cc @@ -1,5 +1,5 @@ /* - * Copyright (c) 2000-2012 Stephen Williams (steve@icarus.com) + * Copyright (c) 2000-2013 Stephen Williams (steve@icarus.com) * * This source code is free software; you can redistribute it * and/or modify it in source code form under the terms of the GNU @@ -452,7 +452,8 @@ void NetScope::evaluate_parameter_logic_(Design*des, param_ref_t cur) lv_width = (msb >= lsb) ? 1 + msb - lsb : 1 + lsb - msb; NetExpr*expr = elab_and_eval(des, val_scope, val_expr, lv_width, true, - (*cur).second.is_annotatable); + (*cur).second.is_annotatable, + (*cur).second.type); if (! expr) return; @@ -491,15 +492,7 @@ void NetScope::evaluate_parameter_logic_(Design*des, param_ref_t cur) sure the type is set right. Note that if the parameter doesn't have an explicit type or range, then it will get the signedness from the expression itself. */ - if (range_flag) { - /* If we have a real value convert it to an integer. */ - if(NetECReal*tmp = dynamic_cast(expr)) { - verinum nval(tmp->value().as_long64(), (unsigned)lv_width); - expr = new NetEConst(nval); - expr->set_line(*((*cur).second.val)); - (*cur).second.val = expr; - } - + if ((*cur).second.type != IVL_VT_NO_TYPE) { (*cur).second.val->cast_signed((*cur).second.signed_flag); } else if ((*cur).second.signed_flag) { (*cur).second.val->cast_signed(true); @@ -574,7 +567,8 @@ void NetScope::evaluate_parameter_real_(Design*des, param_ref_t cur) NetScope*val_scope = (*cur).second.val_scope; NetExpr*expr = elab_and_eval(des, val_scope, val_expr, -1, true, - (*cur).second.is_annotatable); + (*cur).second.is_annotatable, + (*cur).second.type); if (! expr) return; @@ -594,26 +588,10 @@ void NetScope::evaluate_parameter_real_(Design*des, param_ref_t cur) } break; - case IVL_VT_LOGIC: - case IVL_VT_BOOL: - if (NetEConst*tmp = dynamic_cast(expr)) { - verireal val (tmp->value().as_long()); - res = new NetECReal(val); - res->set_line(*tmp); - } else { - cerr << expr->get_fileline() - << ": error: " - << "Unable to evaluate parameter " - << (*cur).first << " value: " << *expr << endl; - des->errors += 1; - return; - } - break; - default: cerr << expr->get_fileline() << ": internal error: " - << "Unhandled expression type?" << endl; + << "Failed to cast expression?" << endl; des->errors += 1; return; break; @@ -683,6 +661,7 @@ void NetScope::evaluate_parameter_(Design*des, param_ref_t cur) } else { cur->second.solving = true; switch (cur->second.type) { + case IVL_VT_NO_TYPE: case IVL_VT_BOOL: case IVL_VT_LOGIC: evaluate_parameter_logic_(des, cur); diff --git a/net_scope.cc b/net_scope.cc index 6841813d8..eed6af6b8 100644 --- a/net_scope.cc +++ b/net_scope.cc @@ -1,5 +1,5 @@ /* - * Copyright (c) 2000-2012 Stephen Williams (steve@icarus.com) + * Copyright (c) 2000-2013 Stephen Williams (steve@icarus.com) * * This source code is free software; you can redistribute it * and/or modify it in source code form under the terms of the GNU @@ -138,8 +138,6 @@ void NetScope::set_parameter(perm_string key, bool is_annotatable, ref.range = range_list; ref.val = 0; ref.set_line(file_line); - - ivl_assert(file_line, type__ != IVL_VT_NO_TYPE); } /* diff --git a/parse.y b/parse.y index 4fa9aac55..1d3d9ae74 100644 --- a/parse.y +++ b/parse.y @@ -573,7 +573,7 @@ static void current_function_set_statement(const YYLTYPE&loc, vector %type net_type var_type net_type_opt %type gatetype switchtype %type port_direction port_direction_opt -%type bit_logic +%type bit_logic bit_logic_opt %type integer_vector_type %type parameter_value_opt @@ -4449,9 +4449,15 @@ net_decl_assigns bit_logic : K_logic { $$ = IVL_VT_LOGIC; } + | K_bool { $$ = IVL_VT_BOOL; /* Icarus misc */} | K_bit { $$ = IVL_VT_BOOL; /* IEEE1800 / IEEE1364-2009 */} ; +bit_logic_opt + : bit_logic + | { $$ = IVL_VT_NO_TYPE; } + ; + net_type : K_wire { $$ = NetNet::WIRE; } | K_tri { $$ = NetNet::TRI; } @@ -4476,25 +4482,13 @@ var_type ; param_type - : - { param_active_range = 0; - param_active_signed = false; - param_active_type = IVL_VT_LOGIC; - } - | range - { param_active_range = $1; - param_active_signed = false; - param_active_type = IVL_VT_LOGIC; - } - | K_signed - { param_active_range = 0; - param_active_signed = true; - param_active_type = IVL_VT_LOGIC; - } - | K_signed range - { param_active_range = $2; - param_active_signed = true; - param_active_type = IVL_VT_LOGIC; + : bit_logic_opt unsigned_signed_opt range_opt + { param_active_range = $3; + param_active_signed = $2; + if (($1 == IVL_VT_NO_TYPE) && ($3 != 0)) + param_active_type = IVL_VT_LOGIC; + else + param_active_type = $1; } | K_integer { param_active_range = make_range_from_width(integer_width);