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);