From 9a94d557381177c0c7f9059d3189466bd6ec0608 Mon Sep 17 00:00:00 2001 From: Cary R Date: Sun, 21 Mar 2010 22:00:44 -0700 Subject: [PATCH] Ignore zero replication constants. This patch enhances elaboration to drop/ignore zero replication count constants. Not doing this was causing problems later in the compiler. We still pass non-constant expressions since both user and system functions must be run for their possible side effects. Constants can never have a side effect so just dropping them is acceptable. --- elab_expr.cc | 25 ++++++++++++++++++++----- tgt-vvp/eval_expr.c | 2 +- 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/elab_expr.cc b/elab_expr.cc index eee54849a..e277154f3 100644 --- a/elab_expr.cc +++ b/elab_expr.cc @@ -1686,11 +1686,9 @@ NetExpr* PEConcat::elaborate_expr(Design*des, NetScope*scope, repeat = rep; } - /* Make the empty concat expression. */ - NetEConcat*tmp = new NetEConcat(parms_.count(), repeat); - tmp->set_line(*this); - unsigned wid_sum = 0; + unsigned parm_cnt = 0; + svector parms(parms_.count()); /* Elaborate all the parameters and attach them to the concat node. */ for (unsigned idx = 0 ; idx < parms_.count() ; idx += 1) { @@ -1724,8 +1722,25 @@ NetExpr* PEConcat::elaborate_expr(Design*des, NetScope*scope, continue; } + /* We are going to ignore zero width constants. */ + if ((ex->expr_width() == 0) && dynamic_cast(ex)) { + parms[idx] = 0; + } else { + parms[idx] = ex; + parm_cnt += 1; + } wid_sum += ex->expr_width(); - tmp->set(idx, ex); + } + + /* Make the empty concat expression. */ + NetEConcat*tmp = new NetEConcat(parm_cnt, repeat); + tmp->set_line(*this); + + /* Remove any zero width constants. */ + unsigned off = 0; + for (unsigned idx = 0 ; idx < parm_cnt ; idx += 1) { + while (parms[off+idx] == 0) off += 1; + tmp->set(idx, parms[off+idx]); } tmp->set_width(wid_sum * tmp->repeat()); diff --git a/tgt-vvp/eval_expr.c b/tgt-vvp/eval_expr.c index 84449a883..b696c9d84 100644 --- a/tgt-vvp/eval_expr.c +++ b/tgt-vvp/eval_expr.c @@ -3134,7 +3134,7 @@ static void draw_eval_expr_dest(ivl_expr_t exp, struct vector_info dest, break; } - /* Fallback, is to draw the expression by width, and mov it to + /* Fallback, is to draw the expression by width, and move it to the required dest. */ tmp = draw_eval_expr_wid(exp, dest.wid, stuff_ok_flag); assert(tmp.wid == dest.wid);