如何使用 "hierarchical path" 的 chisel/scala?

How to use "hierarchical path" of chisel/scala?

在 verilog 中有这样一种方法来访问其他模块的东西,据我所知它被称为 "hierarchical path",这是一个 verilog RTL

module A;
  reg a;
endmodule
module tb;
  A u_A();
  wire b;
  assign b = u_A.a; // hierarchical path
endmodule 

你能告诉我如何访问 Chisel/Scala 中其他模块的 Reg/Wire 吗?

据我所知,这在 chisel3 中是不可能的。如果你尝试你会得到一个错误

An exception or error caused a run to abort: Connection between sink (chisel3.core.UInt@b) and source (chisel3.core.UInt@1b) failed @: Source is unreadable from current module. 
chisel3.internal.ChiselException: Connection between sink (chisel3.core.UInt@b) and source (chisel3.core.UInt@1b) failed @: Source is unreadable from current module

如果你想将它暴露给外部模块,你应该通过 io 机制来实现。 也就是说,可以通过使用实验性功能 MultiIOModule

创建直接访问模块的语法外观
import chisel3._
import chisel3.experimental._

class A extends MultiIOModule {
  val reg = Reg(UInt(16.W))
  val r = IO(Output(reg))
  r := reg
}

class B extends MultiIOModule {
  val u_A = Module(new A)
  val b = Wire(UInt(16.W))
  b := u_A.r
}