ハードウェア記述言語ChiselはScalaのプラットフォームの上に構築されている。大きく分けて2つのリポジトリから構成されている。
chisel3
: https://github.com/freechipsproject/chisel3firrtl
: https://github.com/freechipsproject/firrtl
chisel3のリポジトリは、ChiselのコードをFIRへ変換する。firrtlのリポジトリは、FIRのコードをVerilogに変換する。
以下のようなコードでsimple.scala
をコンパイルすると、emitVerilog
が呼び出される。
simple.scala
class simple extends Module { ... } object simple extends App { chisel3.Driver.emitVerilog(new simple()) }
print
デバッグを行うと、chisel3
リポジトリのchisel3/src/main/scala/chisel3/Driver.scala
内のemitVerilog()
とexecute()
が呼び出されることが分かる。
とりあえずはtargets
の変換を見てみることにした。
val targets =
Seq( classOf[DriverCompatibility.AddImplicitOutputFile],
classOf[DriverCompatibility.AddImplicitOutputAnnotationFile],
classOf[DriverCompatibility.DisableFirrtlStage],
classOf[ChiselStage],
classOf[DriverCompatibility.MutateOptionsManager],
classOf[DriverCompatibility.ReEnableFirrtlStage],
classOf[DriverCompatibility.FirrtlPreprocessing],
classOf[chisel3.stage.phases.MaybeFirrtlStage] )
それぞれ以下に実装がある。それぞれのクラスのtransform()
が呼ばれるらしい。
AddImplicitOutputFile
:chisel3/src/main/scala/chisel3/stage/phases/AddImplicitOutputFile.scala
AddImplicitOutputAnnotationFile
:chisel3/src/main/scala/chisel3/stage/phases/AddImplicitOutputAnnotationFile.scala
DisableFirrtlStage
:chisel3/src/main/scala/chisel3/stage/phases/DriverCompatibility.scala
ChiselStage
:chisel3/src/main/scala/chisel3/stage/ChiselStage.scala
MutateOptionsManager
:chisel3/src/main/scala/chisel3/stage/phases/DriverCompatibility.scala
ReEnableFirrtlStage
:chisel3/src/main/scala/chisel3/stage/phases/DriverCompatibility.scala
FirrtlPreprocessing
:chisel3/src/main/scala/chisel3/stage/phases/DriverCompatibility.scala
MaybeFirrtlStage
:chisel3/src/main/scala/chisel3/stage/phases/MaybeFirrtlStage.scala
最初のAnnotationのあたりはまだ理解できないので、ChiselStage
のあたりを読んでみる。
chisel3/src/main/scala/chisel3/stage/ChiselStage.scala
class ChiselStage extends Stage with PreservesAll[Phase] { val shell: Shell = new Shell("chisel") with ChiselCli with FirrtlCli private val targets = Seq( classOf[chisel3.stage.phases.Checks], classOf[chisel3.stage.phases.Elaborate], classOf[chisel3.stage.phases.AddImplicitOutputFile], classOf[chisel3.stage.phases.AddImplicitOutputAnnotationFile], classOf[chisel3.stage.phases.MaybeAspectPhase], classOf[chisel3.stage.phases.Emitter], classOf[chisel3.stage.phases.Convert], classOf[chisel3.stage.phases.MaybeFirrtlStage] )
Checks
:chisel3/src/main/scala/chisel3/stage/phases/Checks.scala
.- Sanity checks an
firrtl.AnnotationSeq
before running the mainfirrtl.options.Phase
s ofchisel3.stage.ChiselStage
.
- Sanity checks an
Elaborate
:chisel3/src/main/scala/chisel3/stage/phases/Elaborate.scala
.- Elaborate all
chisel3.stage.ChiselGeneratorAnnotation
s intochisel3.stage.ChiselCircuitAnnotation
s.
- Elaborate all
AddImplicitOutputFile
:chisel3/src/main/scala/chisel3/stage/phases/AddImplicitOutputFile.scala
.- Add a output file for a Chisel circuit, derived from the top module in the circuit, if no
ChiselOutputFileAnnotation
already exists.
- Add a output file for a Chisel circuit, derived from the top module in the circuit, if no
AddImplicitOutputAnnotationFile
:chisel3/src/main/scala/chisel3/stage/phases/AddImplicitOutputAnnotationFile.scala
.- Adds an
firrtl.options.OutputAnnotationFileAnnotation
if one does not exist. This replicates old behavior where an output annotation file was always written.
- Adds an
MaybeAspectPhase
:chisel3/src/main/scala/chisel3/stage/phases/MaybeAspectPhase.scala
.- Run
AspectPhase
if achisel3.aop.Aspect
is present.
- Run
Emiter
:chisel3/src/main/scala/chisel3/stage/phases/Emitter.scala
.Convert
:chisel3/src/main/scala/chisel3/stage/phases/Convert.scala
.MaybeFirrtlStage
:chisel3/src/main/scala/chisel3/stage/phases/MaybeFirrtlStage.scala
.- Run
firrtl.stage.FirrtlStage
if achisel3.stage.NoRunFirrtlCompilerAnnotation
is not present.
- Run