我试图了解RocketChip中AsyncQueue的实现,并且对在布尔数据类型(而不是 Option)上使用 option 方法感到非常困惑。在代码中,我们有一个参数类:
case class AsyncQueueParams(
depth: Int = 8,
sync: Int = 3,
safe: Boolean = true,
narrow: Boolean = false)
{
require (depth > 0 && isPow2(depth))
require (sync >= 2)
val bits = log2Ceil(depth)
val wires = if (narrow) 1 else depth
}
然后当使用上述内容时:
class AsyncBundle[T <: Data](private val gen: T, val params: AsyncQueueParams = AsyncQueueParams()) extends Bundle {
val mem = Output(Vec(params.wires, gen))
val ridx = Input (UInt((params.bits+1).W))
val widx = Output(UInt((params.bits+1).W))
val index = params.narrow.option(Input(UInt(params.bits.W)))
// Signals used to self-stabilize a safe AsyncQueue
val safe = params.safe.option(new AsyncBundleSafety) // <--- Never seen use of option !!
}
现在,我可以猜到这里的意图是什么,以限制 val safe &narrow 的创建。我的问题是这个选项是在哪里定义的?我查看了布尔值的scala 文档。我不认为选项是布尔类的成员。有人可以解释一下吗?