5

What is the simplest way to generate Verilog code from existing Chisel code?

Would i have to create my own build file?

For example from a standalone scala file (AND.scala) like the following one..

import Chisel._

class AND extends Module {
  val io = IO(new Bundle {
    val a = Bool(INPUT)
    val b = Bool(INPUT)
    val out = Bool(OUTPUT)
  })
  io.out := io.a & io.b
}

I have the complete Chisel3 Toolchain installed under ubuntu 16.4.

mtosch
  • 351
  • 4
  • 18
  • Does this answer your question? [Is there a simple example of how to generate verilog from Chisel3 module?](https://stackoverflow.com/questions/40470153/is-there-a-simple-example-of-how-to-generate-verilog-from-chisel3-module) – seldridge Jun 18 '20 at 17:55

1 Answers1

7

See answer here: Is there a simple example of how to generate verilog from Chisel3 module?

In short, create a build.sbt file at the root of your project with the following in it:

scalaVersion := "2.12.13"

resolvers ++= Seq(
  Resolver.sonatypeRepo("snapshots"),
  Resolver.sonatypeRepo("releases")
)

libraryDependencies += "edu.berkeley.cs" %% "chisel3" % "3.4.4"

Add this code to AND.scala

object ANDDriver extends App {
  (new chisel3.stage.ChiselStage).emitVerilog(new AND, args)
}

Type sbt run on the command line at the root of your project.

Jack Koenig
  • 5,840
  • 15
  • 21
  • 2
    Thank you very much for the quick answer! Guess i oversaw the other thread. I just tried it and it works. NOTE: jdk8 and sbt have to be installed for this to work! (jdk9 did not work for me) – mtosch Jan 24 '17 at 18:53
  • 1
    Anyway to generate verilog to a "target folder" instead of the same place as `build.sbt`? – iBug Feb 24 '19 at 13:23
  • 2
    Yep! Chisel and FIRRTL have command-line options. Notice how we pass `args` to `chisel3.Driver.execute`? We are propagating the command-line arguments sent to `ANDDriver` to Chisel. You can pass arguments like so: `sbt "run --help"`. The specific one for "target folder" is `--target-dir` or `-td`, ie. `sbt "run -td my_target_dir` – Jack Koenig Feb 24 '19 at 18:10
  • Thanks! +1 for your answer. – iBug Feb 26 '19 at 15:17
  • 1
    chisel3.Driver is deprecated. Can you update this answer? – nic Sep 23 '21 at 18:07
  • Done, thanks for the ping! – Jack Koenig Oct 05 '21 at 00:35