summaryrefslogtreecommitdiff
path: root/src/main/scala/Chisel/CoreUtil.scala
blob: 41266cae7b51fe1b2b9373c74a2e5e23aead6144 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
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(_))))
  }
}