cornell-brg / pymtl

Python-based hardware modeling framework
BSD 3-Clause "New" or "Revised" License
234 stars 83 forks source link

Invalid negative initial values are allowed when constructing Bits #109

Closed cbatten closed 9 years ago

cbatten commented 9 years ago
from pymtl import *

print "Unsigned initial values"
for i in xrange(0,7):
 print " Bits( 3, {:2} ) = {}".format( i, Bits( 3, i ) )

print "Signed initial values"
for i in xrange(-4,3):
 print " Bits( 3, {:2} ) = {}".format( i, Bits( 3, i ) )

print "These should throw an exception?"
print " Bits( 3, {:2} ) = {}".format( -5, Bits( 3, -5 ) )
print " Bits( 3, {:2} ) = {}".format( -6, Bits( 3, -6 ) )
print " Bits( 3, {:2} ) = {}".format( -7, Bits( 3, -7 ) )
print " Bits( 3, {:2} ) = {}".format( -8, Bits( 3, -8 ) )

print "These do thrown an exception"
print " Bits( 3, {:2} ) = {}".format(  -9, Bits( 3,  -9 ) )
print " Bits( 3, {:2} ) = {}".format( -10, Bits( 3, -10 ) )
print " Bits( 3, {:2} ) = {}".format( -11, Bits( 3, -11 ) )

I think we should throw an exception if we try to use an initial value of -5 in a 3-bit Bits object.