From 51b1804660907dbaac9849e5f9cc9594c776f6bf Mon Sep 17 00:00:00 2001 From: Martin Whitaker Date: Sun, 3 Feb 2008 19:34:25 +0000 Subject: [PATCH] Fix for pr1885847. Currently, if a localparam declaration does not include a type or range, the RHS expression is cast to an unsigned value. This patch changes this to make the localparam inherit the type of the RHS expression, as is done for parameter declarations and is specified by the Verilog-2001 standard. --- elab_scope.cc | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/elab_scope.cc b/elab_scope.cc index f0a2445cb..a530c7af7 100644 --- a/elab_scope.cc +++ b/elab_scope.cc @@ -173,7 +173,7 @@ bool Module::elaborate_scope(Design*des, NetScope*scope, NetExpr*val = ex->elaborate_pexpr(des, scope); NetExpr*msb = 0; NetExpr*lsb = 0; - bool signed_flag = false; + bool signed_flag = (*cur).second.signed_flag; /* If the parameter declaration includes msb and lsb, then use them to calculate a width for the @@ -184,10 +184,21 @@ bool Module::elaborate_scope(Design*des, NetScope*scope, msb = (*cur).second.msb ->elaborate_pexpr(des, scope); assert(msb); lsb = (*cur).second.lsb ->elaborate_pexpr(des, scope); - signed_flag = (*cur).second.signed_flag; } - val->cast_signed(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); + } else { + /* otherwise, let the expression describe + itself. */ + signed_flag = val->has_sign(); + } + val = scope->set_parameter((*cur).first, val, msb, lsb, signed_flag); assert(val);