From a45fa004791a305df5303c0e645027becf73e98e Mon Sep 17 00:00:00 2001 From: Martin Whitaker Date: Mon, 30 May 2011 09:25:54 +0100 Subject: [PATCH] Modified rules for primitive gate port expression widths. The IEEE standard states that the port expressions used for arrays of primitive gates must be the exact width required, but is silent about the requirements for single instances. The consensus among other simulators is that for input ports of single instances, the expression is silently truncated to a single bit. This patch also fixes a compiler crash if an error is found when elaborating a primitive gate port expression. --- elaborate.cc | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/elaborate.cc b/elaborate.cc index dcb561b49..64f73daa4 100644 --- a/elaborate.cc +++ b/elaborate.cc @@ -812,7 +812,16 @@ void PGBuiltin::elaborate(Design*des, NetScope*scope) const sig = lval_sigs[idx]; } else { - NetExpr*tmp = elab_and_eval(des, scope, ex, -1); + // If this is an array, the port expression is required + // to be the exact width required (this will be checked + // later). But if this is a single instance, consensus + // is that we just take the LSB of the port expression. + NetExpr*tmp = elab_and_eval(des, scope, ex, msb_ ? -1 : 1); + if (tmp == 0) + continue; + if (msb_ == 0 && tmp->expr_width() != 1) + tmp = new NetESelect(tmp, make_const_0(1), 1, + IVL_SEL_IDX_UP); sig = tmp->synthesize(des, scope, tmp); delete tmp; }