Skip to content

Instantly share code, notes, and snippets.

@muojp
Last active August 5, 2016 23:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save muojp/79c5447a56d96ae58099a34862eacdab to your computer and use it in GitHub Desktop.
Save muojp/79c5447a56d96ae58099a34862eacdab to your computer and use it in GitHub Desktop.
HalfAdder example in Chisel
scalaVersion := "2.11.8"
libraryDependencies += "edu.berkeley.cs" %% "chisel" % "latest.release"
libraryDependencies += "org.scalatest" %% "scalatest" % "2.2.6" % "test"
package com.example.adder
import Chisel._
class HalfAdder extends Module {
val io = new Bundle {
val a = Bool(INPUT)
val b = Bool(INPUT)
val s = Bool(OUTPUT)
val c = Bool(OUTPUT)
}
io.s := io.a ^ io.b
io.c := io.a & io.b
}
class HalfAdderTester(c: HalfAdder) extends Tester(c) {
for (i <- 0 to 1) {
for (j <- 0 to 1) {
poke(c.io.a, i)
poke(c.io.b, j)
expect(c.io.s, (i ^ j) == 1)
expect(c.io.c, (i & j) == 1)
step(1)
}
}
}
object HalfAdderBuilder {
def s = Array[String]("--backend", "v", "--genHarness")
def t = Array[String]("--backend", "c", "--compile", "--test", "--genHarness")
def main(args: Array[String]): Unit = {
chiselMain(s, () => Module(new HalfAdder))
// chiselMainTest(t, () => Module(new HalfAdder)) { c => new HalfAdderTester(c) }
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment