hcf - Chisel3生成Verilog的新方法
https://mp.weixin.qq.com/s/eWAjUyE0fr_lmLqdCc7fTw
本文介绍将Chisel3模块生成为Verilog代码的几种新方法。
1. 原方法
当使用老方法生成Verilog代码时,提示方法被废弃,如下图所示:
Driver的提示如下:
execute的提示如下:
从提示中可以看出,生成Verilog推荐的方法为:
a. Use chisel3.stage.ChiselStage;
b. Use chisel3.stage.ChiselMain;
2. 新方法: chisel3.stage.ChiselStage
2.1 使用chisel3.stage.ChiselStage.execute方法
调用方法如下:
execute方法的签名如下:
其中:
a. 第一个参数相当于命令行参数;
b. 第二个参数是一个注解,这里传入的参数是ChiselGeneratorAnnotation;
ChiselGeneratorAnnotation中定义了一个elaborate方法用于构建电路:
这个elabrate方法在Elaborate阶段中被调用:
可以看出,这种生成Verilog的方法,需要了解ChiselGeneratorAnnotation这个实现细节。
2.2 使用new ChiselStage().emitVerilog
调用方法如下:
ChiselStage类的emitVerilog方法的签名如下:
这个方法的实现中:
a. 调用execute实现主要功能;
b. 传入一个“-X verilog”参数,用于生成verilog代码;
c. 生成一个ChiselGeneratorAnnotation注解,使得emitVerilog方法的annotations参数可以使用默认值,也就是空;
2.3 使用ChiselStage.emitVerilog
调用方法为:
ChiselStage.emitVerilog的实现如下:
该方法只包含一个参数,即生成模块的方法gen。返回的是一个字符串。无法对其传参控制如生成路径等。
3. 新方法: chisel3.stage.ChiselMain
调用方法如下:
ChiselMain继承自StageMain:
其实现也是调用ChiselStage.execute方法:
区别在于,只能传命令行参数,而不能直接传递注解参数。
z. 附录
z.1 Usage
ChiselMain.main(Array("--help"))的输出如下:
Usage: chisel [options] [...]
Shell Options
... optional unbounded args
-td, --target-dir
Work directory (default: '.')
-faf, --annotation-file
An input annotation file
-foaf, --output-annotation-file
An output annotation file
--show-registrations print discovered registered libraries and transforms
--help prints this usage text
Logging Options
-ll, --log-level {error|warn|info|debug|trace}
Set global logging verbosity (default: Warn
-cll, --class-log-level<fullclassname:{error|warn|info|debug|trace}>...</fullclassname:{error|warn|info|debug|trace}>
Set per-class logging verbosity
--log-file Log to a file instead of STDOUT
-lcn, --log-class-names Show class names and log level in logging output
Chisel Front End Options
-chnrf, --no-run-firrtl Do not run the FIRRTL compiler (generate FIRRTL IR from Chisel and exit)
--full-stacktrace Show full stack trace when an exception is thrown
--chisel-output-file
Write Chisel-generated FIRRTL to this file (default:.fir)
--module .
The name of a Chisel module to elaborate (module must be in the classpath)
FIRRTL Compiler Options
-i, --input-file An input FIRRTL file
-o, --output-file
The output FIRRTL file
--info-mode <ignore|use|gen|append>
Source file info handling mode (default: use)
--firrtl-source
An input FIRRTL circuit string
-fct, --custom-transforms.
Run these transforms during compilation
--change-name-case <lower|upper>
Convert all FIRRTL names to a specific case
-X, --compiler<none|high|middle|low|verilog|mverilog|sverilog></none|high|middle|low|verilog|mverilog|sverilog>
The FIRRTL compiler to use (default: verilog)
-E, --emit-circuit<chirrtl|high|middle|low|verilog|mverilog|sverilog></chirrtl|high|middle|low|verilog|mverilog|sverilog>
Run the specified circuit emitter (all modules in one file)
-e, --emit-modules<chirrtl|high|middle|low|verilog|mverilog|sverilog></chirrtl|high|middle|low|verilog|mverilog|sverilog>
Run the specified module emitter (one file per module)
--no-dedup Do NOT dedup modules
--warn:no-scala-version-deprecation
Suppress Scala 2.11 deprecation warning (ignored in Scala 2.12+)
--pretty:no-expr-inlining
Disable expression inlining
--dont-fold Disable folding of specific primitive operations
FIRRTL Transform Options
--no-dce Disable dead code elimination
--no-check-comb-loops Disable combinational loop checking
-fil, --inline[.[.]][,...]
Inline selected modules
-clks, --list-clocks -c::-m::-o:
List which signal drives each clock of every descendent of specified modules
--no-asa Disable assert submodule assumptions
--no-constant-propagation
Disable constant propagation elimination
AspectLibrary
--with-aspect .
The name/class of an aspect to compile with (must be a class/object without arguments!)
MemLib Options
-firw, --infer-rw Enable read/write port inference for memories
-frsq, --repl-seq-mem -c::-i::-o:
Blackbox and emit a configuration file for each sequential memory
z.2 build.sbt
name := "FullAdder"
version := "0.1"
scalaVersion := "2.12.10"
scalacOptions ++= Seq("-deprecation","-unchecked","-Xsource:2.11")
// https://mvnrepository.com/artifact/edu.berkeley.cs/chisel3
libraryDependencies += "edu.berkeley.cs" %% "chisel3" % "3.4.3"