Last active
August 5, 2016 23:22
-
-
Save muojp/79c5447a56d96ae58099a34862eacdab to your computer and use it in GitHub Desktop.
HalfAdder example in Chisel
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
scalaVersion := "2.11.8" | |
libraryDependencies += "edu.berkeley.cs" %% "chisel" % "latest.release" | |
libraryDependencies += "org.scalatest" %% "scalatest" % "2.2.6" % "test" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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