ucb-bar/chisel — pull request #169 by palmer-dabbelt (2014-04-01 09:17:40+00:00)
Title: (Flo) Emit correct literal widths

It appears that when Chisel generates a literal node it simply picks
the smallest bit width that will fit that value and then never updates
it. This means that if you do something like

UInt(width = 5) <- Mux(..., UInt(1), UInt(3))

you'll end up with the Flo node

T0 = mux'5 ... 1'1, 3'2

libflo won't parse this as a valid operation because the widths are
all mis-matched.

This patch is a bit of a mess, but I'm fairly sure it manages to emit
the correct width attached to every constant. The general idea is
that when a constant is emited another node is passed to emitRef()
that stores the width that should be attached to it. For most
operations this is just the output node, but for some it's the other
input node (comparison operations end up as a boolean, for example).
This will silently emit bad code if you write something like

Bool() <- (UInt(1) === UInt(2))

but I've yet to come across any of those.

This code is pretty much un-tested (it works on DES and the
tutorials), but I figure it's at least better than before.