diff options
| author | ducky | 2015-12-11 12:47:44 -0800 |
|---|---|---|
| committer | ducky | 2015-12-11 12:53:39 -0800 |
| commit | 5859d231859c6a8b9c234e7a71cbc85e5d75f61b (patch) | |
| tree | f8115324c12c54a3077517f5b6b997cc16951c64 /src/main/scala/Chisel/CoreUtil.scala | |
| parent | 20951ecdbcb81c194ddcdd1e8241b1bdd647dd9f (diff) | |
Add support for printf and asserts, add testbench for asserts and printf
Diffstat (limited to 'src/main/scala/Chisel/CoreUtil.scala')
| -rw-r--r-- | src/main/scala/Chisel/CoreUtil.scala | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/src/main/scala/Chisel/CoreUtil.scala b/src/main/scala/Chisel/CoreUtil.scala new file mode 100644 index 00000000..41266cae --- /dev/null +++ b/src/main/scala/Chisel/CoreUtil.scala @@ -0,0 +1,27 @@ +// See LICENSE for license details. + +package Chisel + +import internal._ +import internal.Builder.pushCommand +import firrtl._ + +object assert { + def apply(cond: Bool, message: String="") { + when(!cond) { + if (message.isEmpty()) { + printf(s"Assertion failed: (TODO: code / lineno)") + } else { + printf(s"Assertion failed: (TODO: code / lineno): $message") + } + pushCommand(Stop(Node(Builder.dynamicContext.currentModule.get.clock), 1)) + } + } +} + +object printf { + def apply(fmt: String, data: Bits*) { + pushCommand(Printf(Node(Builder.dynamicContext.currentModule.get.clock), + fmt, data.map(Node(_)))) + } +} |
