blob: de46cdcba4ad4973182b1cc4eff3eaa7b1b4e616 (
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
|
// SPDX-License-Identifier: Apache-2.0
package chiselTests
import chisel3._
import chisel3.stage.ChiselStage
import chisel3.util.Queue
import chisel3.internal.ChiselException
class ToTargetSpec extends ChiselFlatSpec with Utils {
var m: InstanceNameModule = _
ChiselStage.elaborate { m = new InstanceNameModule; m }
val mn = "InstanceNameModule"
val top = s"~$mn|$mn"
behavior.of(".toTarget")
val deprecationMsg = "Accessing the .instanceName or .toTarget of non-hardware Data is deprecated"
it should "work with module IO" in {
val io = m.io.toTarget.toString
assert(io == s"$top>io")
}
it should "not work for literals" in {
a[ChiselException] shouldBe thrownBy {
m.x.toTarget.toString
}
}
it should "work with non-hardware values (but be deprecated)" in {
val (ylog, y) = grabLog(m.y.toTarget.toString)
val (zlog, z) = grabLog(m.z.toTarget.toString)
assert(y == s"$top>y")
ylog should include(deprecationMsg)
assert(z == s"$top>z")
zlog should include(deprecationMsg)
}
it should "work with non-hardware bundle elements (but be deprecated)" in {
val (log, foo) = grabLog(m.z.foo.toTarget.toString)
log should include(deprecationMsg)
assert(foo == s"$top>z.foo")
}
it should "work with modules" in {
val q = m.q.toTarget.toString
assert(q == s"~$mn|Queue")
}
it should "warn on non-hardware types and provide information" in {
class Example extends Module {
val tpe = UInt(8.W)
val in = IO(Input(tpe))
val out = IO(Output(tpe))
out := in
}
var e: Example = null
chisel3.stage.ChiselStage.elaborate { e = new Example; e }
val (log, foo) = grabLog(e.tpe.toTarget)
log should include(
"Accessing the .instanceName or .toTarget of non-hardware Data is deprecated: 'tpe', in module 'Example'"
)
}
}
|