1

所以我在代码中的一行周围添加了块,但问题是当块更改范围时添加这个,使得在其中声明的变量在程序中的其他部分看不到

问题是在这样的情况下

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

他们也是一种在 when 块中添加这一行而不改变范围的方法

关键是在 when 块之外声明它,然后分配值需要我知道它的类型以及很多变量,这可能会变得很难

我想要实现的是这样的

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

不改变范围

4

1 回答 1

1

您好,感谢您对 Chisel 和 Rocket-chip 的关注!

您想要做的事情在 Scala 中是不可能的。这超出了 Chisel 作为嵌入式 DSL 的范围(双关语)。

但从根本上说,尚不清楚这是否有意义。一个 when 块表示连接发生在该条件下。如果你能写出这样的东西,当条件为假时,连接的值是多少?例如:

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

什么时候应该wire得到什么值value <= 100.U

获得不知道类型的好处的另一种方法可能是有一个 when 条件,相反的条件给出你想要的任何其他值

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
}
于 2019-06-02T22:05:16.557 回答