1
votes

so I am adding when block around a line in the code but the problem is adding this when block changes the scope making the variables declared inside it not seen from other parts in the program

The problem is that in cases like that

  val (_, _, d_done, refill_cnt) = edge_out.count(tl_out.d)}

so is their a way to add this line inside a when block without changing the scope

the point is declaring it outside the when block and then assigning the value requires me to know it's type and with lot's of variables that's can get hard

what i want to achive is something like that

when (refill_addr <80000000.U){
 val (_, _, d_done, refill_cnt) = edge_out.count(tl_out.d)}

Without changing the scope

1

1 Answers

1
votes

Hello and thank you for your interest in Chisel and rocket-chip!

What you are wanting to do isn't possible in Scala. This is outside of the scope (pun intended) of Chisel as an embedded DSL.

Fundamentally though, it's not clear if it would make sense anyway. A when block means that the connection occurs under the condition. If you were able to write something like that, what would the connected value be when the condition is false? For example:

when (value > 100.U) {
  val wire = 123.U
}
io.out := wire

What value should wire get when value <= 100.U?

An alternative approach where you get the benefits of not knowing the type could be to have a when condition with the opposite condition giving whatever other value you want

val (_, _, _d_done, _refill_cnt) = edge_out.count(tl_out.d)

// Note the wires here, the references above might be read-only references
val d_done = WireInit(_d_done)
val refill_cnt = WireInit(_refill_cnt)

when (refill_addr >= 80000000.U) {
  d_done := something
  refill_cnt := something_else
}