我正在寻找一个简单的方法来在 Verilog 中转换一个简单的 Chisel3 模块。
我采用凿子官方网页上给出的 Gcd 源代码。
import chisel3._
class GCD extends Module {
val io = IO(new Bundle {
val a = Input(UInt(32.W))
val b = Input(UInt(32.W))
val e = Input(Bool())
val z = Output(UInt(32.W))
val v = Output(Bool())
})
val x = Reg(UInt(32.W))
val y = Reg(UInt(32.W))
when (x > y) {
x := x -% y
}.otherwise {
y := y -% x
}
when (io.e) {
x := io.a
y := io.b
}
io.z := x
io.v := y === 0.U
}
我找不到如何编写 build.sbt 和类实例化以在 Verilog 中进行转换。
最佳答案
感谢您对 Chisel 的关注!我们通常鼓励人们使用我们的 chisel-template repo 作为 Chisel3 项目的起点:https://github.com/ucb-bar/chisel-template
如果你想做最简单的事情。创建此 build.sbt 并将其放在项目的根目录中。
scalaVersion := "2.12.13"
libraryDependencies += "edu.berkeley.cs" %% "chisel3" % "3.4.4"
将上述 GCD 源代码放在 GCD.scala 中,并在文件中添加以下内容:import chisel3.stage.ChiselStage
object GCDDriver extends App {
(new ChiselStage).emitVerilog(new GCD, args)
}
然后您可以通过运行以下命令生成 Verilog:sbt "runMain GCDDriver"
.默认输出目录是当前目录。您可以通过运行
sbt "runMain GCDDriver --help"
查看可用的命令行选项。例如 --target-dir
会让你改变目标目录
关于scala - 是否有一个如何从 Chisel3 模块生成 verilog 的简单示例?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40470153/