hdl.ast: accept Signals with identical min/max bounds.

And produce a 0-bit signal.

Fixes #58.
This commit is contained in:
whitequark 2019-04-21 07:16:59 +00:00
parent 083016d747
commit 33f9bd2a1d
2 changed files with 16 additions and 7 deletions

View file

@ -593,11 +593,15 @@ class Signal(Value, DUID):
if max is None:
max = 2
max -= 1 # make both bounds inclusive
if not min < max:
raise ValueError("Lower bound {} should be less than higher bound {}"
.format(min, max))
if min > max:
raise ValueError("Lower bound {} should be less or equal to higher bound {}"
.format(min, max + 1))
self.signed = min < 0 or max < 0
self.nbits = builtins.max(bits_for(min, self.signed), bits_for(max, self.signed))
if min == max:
self.nbits = 0
else:
self.nbits = builtins.max(bits_for(min, self.signed),
bits_for(max, self.signed))
else:
if not (min is None and max is None):