chisel2-deprecated icon indicating copy to clipboard operation
chisel2-deprecated copied to clipboard

Complete deprecation of Literal construction via SInt, UInt, Bool

Open sdtwigg opened this issue 10 years ago • 0 comments

UInt(1) // current syntax for constructing a UInt literal 1
// vs.
UInt(width=1) // current syntax for constructing a wire of width 1
UInt(null, 1) // unadvised but accepted
UInt(OUTPUT, 1) // unadvised when not in port specification context but accepted

This is exceedingly problematic as at glances through code it is not immediately obvious when an unbound wire of some width is being constructed vs a literal of some value. Furthermore, it is a very common error to accidentally declare a literal in a Bundle description when a wire/port description was desired.

The types in Chisel ARE UInt and SInt, so it is most sensible to retain those words when describing wires, ports, and registers. New proposed constructors for literals are to add U and S methods to scala Integers, and B methods to scala Booleans via extension methods functionality.

1.U  // returns UInt literal of value 1 with unbound width*
-1.S // returns SInt literal of value -1 with unbound width*
true.B // returns Bool literal of value true
// Also, add two convenience objects for Chisel.Bool:
True  // returns Bool literal of value true
False // returns Bool literal of value false

For construction literals of user-specified width

LitU(value, width)
LitS(value, width)
LitB(value)
// or, perhaps as a better alternative
U(value, width)
S(value, width)
B(value, width)

*Note: It may be possible to auto-assign width to literals constructed with .U, .S, and .B if the frontend is willing to do some elementary typing of literals. (The key is to ensure literal vectors get an appropriate type). This may lead to some strange behavior; however, so investigation still must be performed.

sdtwigg avatar Apr 07 '15 23:04 sdtwigg