gpt4 book ai didi

Chisel:如何为SyncReadMem 类实现 "read"函数(或宏)?

转载 作者:行者123 更新时间:2023-12-04 07:40:17 24 4
gpt4 key购买 nike

谁能帮助我理解“读取”宏是如何实现的?我感觉实际上调用了下面的“do_read”函数,但无法弄清楚它是如何完成的。我对“SourceInfoTransform”类很感兴趣。谁能给我一个关于它的用法的提示?
下面列出了“SyncReadMem”实现。
在此先感谢您的帮助!
此致,
-费

sealed class SyncReadMem[T <: Data] private (t: T, n: BigInt, val readUnderWrite: SyncReadMem.ReadUnderWrite) extends MemBase[T](t, n) {
def read(x: UInt, en: Bool): T = macro SourceInfoTransform.xEnArg

/** @group SourceInfoTransformMacro */
def do_read(addr: UInt, enable: Bool)(implicit sourceInfo: SourceInfo, compileOptions: CompileOptions): T = {
val a = Wire(UInt())
a := DontCare
var port: Option[T] = None
when (enable) {
a := addr
port = Some(read(a))
}
port.get
}
}

最佳答案

SourceInfoTransform是一个转换 def read 的 Scala 宏进def do_read .宏的代码在 src/main/scala/chisel3/internal/sourceinfo/SourceInfoTransform.scalagithub.com/chipsalliance/chisel3 .在该文件中,有许多变换类用于处理具有不同参数数量的不同凿子构造。 SourceInfoTransform的主要用途是获取 Chisel/Scala 源代码的行号,以便它可以在异常和生成的 Firrtl 和 Verilog 中报告。这里is an article on macros ,还有更多可用的。
祝你好运。

关于Chisel:如何为SyncReadMem 类实现 "read"函数(或宏)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67513723/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com