0

I have, tab=Array(1.U, 6.U, 5.U, 2.U, 4.U, 3.U) and Y=Seq(b,g,g,g,b,g), tab is an array of UInt. I want to do a map on tab as follows:

tab.map(case idx=>Y(idx))

But I keep getting the error: found chisel3.core.UInt, required Int. I tried using the function peek() to convert idx to an Int by doing

tab.map(case idx=>Y(peek(idx).toInt)

but I get peek not found. I also saw that I cannot convert a chisel UInt to an Int here but did not understand the use of peek well with the example given. So please, is there another approach to do the above? Thanks!

Foutse
  • 125
  • 1
  • 10

1 Answers1

0

The immediate problem is that you cannot access the elements of scala collections using a hardware construct like UInt or SInt. It should work if you wrap Y in a Vec. Depending on your overall module this would probably look like

val YVec = VecInit(Y)
val mappedY = tab.map { case idx => YVec(idx) }
Chick Markley
  • 4,023
  • 16
  • 17
  • It seems that this does not apply to Sequence of strings.I get the error VecInit() cannot be applied to (Seq[String]) – Foutse Oct 23 '17 at 00:47
  • Yes, you cannot VecInit strings, but if your values are alphabetic you should be able to represent them as an 8 or 16 bit UInts. If you want to do full strings you would have to make Vec of Vecs where the inner Vec's are strings. A lot more hardware to manage all that. – Chick Markley Oct 23 '17 at 06:34