From 82c8a4957317ffd9343ba28fc7ed7688455bfe07 Mon Sep 17 00:00:00 2001 From: Martin Whitaker Date: Sat, 9 Nov 2019 13:11:16 +0000 Subject: [PATCH] Fix for issue #281 - the condition operator may return a valid enum type. If the condition expression is 2-state, the result won't be blended, so the result will be a valid enum value if both true and false expressions return the same enum type. --- netlist.cc | 14 ++++++++++++++ netlist.h | 2 ++ 2 files changed, 16 insertions(+) diff --git a/netlist.cc b/netlist.cc index c0650959e..328e1a42b 100644 --- a/netlist.cc +++ b/netlist.cc @@ -2524,6 +2524,20 @@ NetETernary::~NetETernary() delete false_val_; } +const netenum_t* NetETernary::enumeration() const +{ + // If the condition can evaluate to an ambiguous value, + // the result may be blended, and so is not guaranteed + // to be a valid enumeration value. + if (cond_->expr_type() != IVL_VT_BOOL) + return 0; + + if (true_val_->enumeration() != false_val_->enumeration()) + return 0; + + return true_val_->enumeration(); +} + const NetExpr* NetETernary::cond_expr() const { return cond_; diff --git a/netlist.h b/netlist.h index ae546bc94..66eb0890e 100644 --- a/netlist.h +++ b/netlist.h @@ -4757,6 +4757,8 @@ class NetETernary : public NetExpr { NetETernary(NetExpr*c, NetExpr*t, NetExpr*f, unsigned wid, bool signed_flag); ~NetETernary(); + const netenum_t* enumeration() const; + const NetExpr*cond_expr() const; const NetExpr*true_expr() const; const NetExpr*false_expr() const;