@@ -3,11 +3,15 @@ package chisel3.simulator
33import svsim ._
44import chisel3 ._
55
6+ import chisel3 .experimental .SourceInfo
7+
68object PeekPokeAPI extends PeekPokeAPI
79
810trait PeekPokeAPI {
9- case class FailedExpectationException [T ](observed : T , expected : T , message : String )
10- extends Exception (s " Failed Expectation: Observed value ' $observed' != $expected. $message" )
11+ case class FailedExpectationException [T ](sourceInfo : SourceInfo , observed : T , expected : T , message : String )
12+ extends Exception (
13+ s " Failed Expectation: Observed value ' $observed' != $expected. $message ${sourceInfo.makeMessage(x => x)}"
14+ )
1115
1216 implicit class testableClock (clock : Clock ) {
1317 def step (cycles : Int = 1 ): Unit = {
@@ -56,24 +60,24 @@ trait PeekPokeAPI {
5660 }
5761
5862 final def peek (): T = encode(data.peekValue())
59- final def expect (expected : T ): Unit = {
63+ final def expect (expected : T )( implicit sourceInfo : SourceInfo ) : Unit = {
6064 data.expect(
6165 expected.litValue,
6266 encode(_).litValue,
6367 (observed : BigInt , expected : BigInt ) => s " Expectation failed: observed value $observed != $expected"
6468 )
6569 }
66- final def expect (expected : T , message : String ): Unit = {
70+ final def expect (expected : T , message : String )( implicit sourceInfo : SourceInfo ) : Unit = {
6771 data.expect(expected.litValue, encode(_).litValue, (_ : BigInt , _ : BigInt ) => message)
6872 }
69- final def expect (expected : BigInt ): Unit = {
73+ final def expect (expected : BigInt )( implicit sourceInfo : SourceInfo ) : Unit = {
7074 data.expect(
7175 expected,
7276 _.asBigInt,
7377 (observed : BigInt , expected : BigInt ) => s " Expectation failed: observed value $observed != $expected"
7478 )
7579 }
76- final def expect (expected : BigInt , message : String ): Unit = {
80+ final def expect (expected : BigInt , message : String )( implicit sourceInfo : SourceInfo ) : Unit = {
7781 data.expect(expected, _.asBigInt, (_ : BigInt , _ : BigInt ) => message)
7882 }
7983
@@ -126,13 +130,16 @@ trait PeekPokeAPI {
126130 expected : T ,
127131 encode : (Simulation .Value ) => T ,
128132 buildMessage : (T , T ) => String
133+ )(
134+ implicit sourceInfo : SourceInfo
129135 ): Unit = {
130136 val module = AnySimulatedModule .current
131137 module.willPeek()
132138 val simulationPort = module.port(data)
133139 simulationPort.check(isSigned = isSigned) { observedValue =>
134140 val observed = encode(observedValue)
135- if (observed != expected) throw FailedExpectationException (observed, expected, buildMessage(observed, expected))
141+ if (observed != expected)
142+ throw FailedExpectationException (sourceInfo, observed, expected, buildMessage(observed, expected))
136143 }
137144 }
138145 }
0 commit comments