如何从训练营示例中导入 getVerilog() 函数?

How to import getVerilog() function from the bootcamp examples?

我不确定我是否理解如何使用 getVerilog 函数: https://github.com/freechipsproject/chisel-bootcamp/blob/master/2.1_first_module.ipynb

[error] passthrough_test.scala:18:11: not found: value getVerilog
[error]   println(getVerilog(new PassThrough(10)))
[error]           ^
[error] one error found
[error] (Test / compileIncremental) Compilation failed
[error] Total time: 1 s, completed Nov 21, 2018 1:53:02 PM

我确实导入了 chisel3._ 但这似乎还不够。

getVerilog 方法仅在训练营中定义。对于 Chisel 3.2.0 之前的 Chisel 版本,有一个等效方法称为 Driver.emitVerilog。对于3.2.0之后的Chisel版本,正确的方法是(new chisel3.stage.ChiselStage).emitVerilog:

import chisel3._
import chisel3.stage.ChiselStage
    
class Foo extends Module {
  val io = IO(new Bundle {})
  
  printf("I'm a foo")
}

/* For Chisel versions <3.2.0 use the following: */
Driver.emitVerilog(new Foo)

/* For Chisel >=3.2.0 use the following: */
(new ChiselStage).emitVerilog(new Foo)

作为附加参考,getVerilog在Chisel Bootcamp中的具体实现是here. This looks almost identical to what Driver.emitVerilog is doing here. There was a similar, but slightly different question about generating Verilog that was

通常,如果您想知道某些 API 是否存在,搜索 Chisel3 API 参考资料会很有用。例如,您可以查阅 ChiselStage 的文档,了解将 Chisel 编译为 FIRRTL IR 或 Verilog 的相关方法:ChiselStage API.

为了更好地控制 Verilog 生成,如果使用 Chisel >=3.2.0,您需要使用 ChiselStage class' 方法 execute(args: Array[String], annotations: AnnotationSeq)。早期版本的 Chisel 应该使用 Driver 对象的方法 Driver.execute(args: Array[String], dut: () => RawModule).

注意:ChiselStage.emitVerilog 允许您将命令行参数和注释传递给 Chisel 编译器,以便更好地控制生成的 FIRRTL IR 或 Verilog。