Skip to content

Commit a482a98

Browse files
committed
Remove reflectiveSelectable import
1 parent 2b547d5 commit a482a98

File tree

12 files changed

+269
-285
lines changed

12 files changed

+269
-285
lines changed
Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
// SPDX-License-Identifier: Apache-2.0
2+
3+
package chisel3.util
4+
5+
import chisel3._
6+
import chisel3.util.BitPat
7+
import _root_.circt.stage.ChiselStage
8+
import org.scalatest.flatspec.AnyFlatSpec
9+
import org.scalatest.matchers.should.Matchers
10+
11+
object EnumExample extends ChiselEnum {
12+
val VAL1, VAL2, VAL3 = Value
13+
}
14+
15+
class BitPatSpec extends AnyFlatSpec with Matchers {
16+
behavior.of(classOf[BitPat].toString)
17+
18+
it should "convert a BitPat to readable form" in {
19+
val testPattern = "0" * 32 + "1" * 32 + "?" * 32 + "?01" * 32
20+
BitPat("b" + testPattern).toString should be(s"BitPat($testPattern)")
21+
}
22+
23+
it should "convert a BitPat to raw form" in {
24+
val testPattern = "0" * 32 + "1" * 32 + "?" * 32 + "?01" * 32
25+
BitPat("b" + testPattern).rawString should be(testPattern)
26+
}
27+
28+
it should "not fail if BitPat width is 0" in {
29+
intercept[IllegalArgumentException] { BitPat("b") }
30+
}
31+
32+
it should "concat BitPat via ##" in {
33+
(BitPat.Y(4) ## BitPat.dontCare(3) ## BitPat.N(2)).toString should be(s"BitPat(1111???00)")
34+
}
35+
36+
it should "throw when BitPat apply to a Hardware" in {
37+
intercept[java.lang.IllegalArgumentException] {
38+
ChiselStage.emitCHIRRTL(new chisel3.Module {
39+
BitPat(chisel3.Reg(chisel3.Bool()))
40+
})
41+
}
42+
}
43+
44+
it should "index and return new BitPat" in {
45+
val b = BitPat("b1001???")
46+
b(0) should be(BitPat.dontCare(1))
47+
b(6) should be(BitPat.Y())
48+
b(5) should be(BitPat.N())
49+
}
50+
51+
it should "slice and return new BitPat" in {
52+
val b = BitPat("b1001???")
53+
b(2, 0) should be(BitPat("b???"))
54+
b(4, 3) should be(BitPat("b01"))
55+
b(6, 6) should be(BitPat("b1"))
56+
}
57+
58+
it should "parse UInt literals correctly" in {
59+
BitPat(0.U) should be(new BitPat(0, 1, 1))
60+
// Note that this parses as 1-bit width, there are other APIs that don't support zero-width UInts correctly
61+
BitPat(0.U(0.W)) should be(new BitPat(0, 1, 1))
62+
BitPat(1.U) should be(new BitPat(1, 1, 1))
63+
BitPat(2.U) should be(new BitPat(2, 3, 2))
64+
BitPat(0xdeadbeefL.U) should be(new BitPat(BigInt("deadbeef", 16), BigInt("ffffffff", 16), 32))
65+
}
66+
67+
it should "support .hasDontCares" in {
68+
BitPat("b?").hasDontCares should be(true)
69+
BitPat("b??").hasDontCares should be(true)
70+
BitPat("b0?").hasDontCares should be(true)
71+
BitPat("b?1").hasDontCares should be(true)
72+
BitPat("b0").hasDontCares should be(false)
73+
BitPat("b10").hasDontCares should be(false)
74+
BitPat("b01").hasDontCares should be(false)
75+
BitPat(0xdeadbeefL.U).hasDontCares should be(false)
76+
// Zero-width not supported yet
77+
intercept[IllegalArgumentException] { BitPat("b").hasDontCares should be(false) }
78+
}
79+
80+
it should "support .allZeros" in {
81+
BitPat("b?").allZeros should be(false)
82+
BitPat("b??").allZeros should be(false)
83+
BitPat("b0?").allZeros should be(false)
84+
BitPat("b?1").allZeros should be(false)
85+
BitPat("b0").allZeros should be(true)
86+
BitPat("b10").allZeros should be(false)
87+
BitPat("b01").allZeros should be(false)
88+
BitPat(0.U(128.W)).allZeros should be(true)
89+
BitPat.N(23).allZeros should be(true)
90+
BitPat(0xdeadbeefL.U).allZeros should be(false)
91+
// Zero-width not supported yet
92+
intercept[IllegalArgumentException] { BitPat("b").allZeros should be(true) }
93+
}
94+
95+
it should "support .allOnes" in {
96+
BitPat("b?").allOnes should be(false)
97+
BitPat("b??").allOnes should be(false)
98+
BitPat("b0?").allOnes should be(false)
99+
BitPat("b?1").allOnes should be(false)
100+
BitPat("b0").allOnes should be(false)
101+
BitPat("b10").allOnes should be(false)
102+
BitPat("b01").allOnes should be(false)
103+
BitPat("b1").allOnes should be(true)
104+
BitPat("b" + ("1" * 128)).allOnes should be(true)
105+
BitPat.Y(23).allOnes should be(true)
106+
BitPat(0xdeadbeefL.U).allOnes should be(false)
107+
// Zero-width not supported yet
108+
intercept[IllegalArgumentException] { BitPat("b").allOnes should be(true) }
109+
}
110+
111+
it should "support .allDontCares" in {
112+
BitPat("b?").allDontCares should be(true)
113+
BitPat("b??").allDontCares should be(true)
114+
BitPat("b0?").allDontCares should be(false)
115+
BitPat("b?1").allDontCares should be(false)
116+
BitPat("b0").allDontCares should be(false)
117+
BitPat("b10").allDontCares should be(false)
118+
BitPat("b1").allDontCares should be(false)
119+
BitPat("b" + ("1" * 128)).allDontCares should be(false)
120+
BitPat.dontCare(23).allDontCares should be(true)
121+
BitPat(0xdeadbeefL.U).allDontCares should be(false)
122+
// Zero-width not supported yet
123+
intercept[IllegalArgumentException] { BitPat("b").allDontCares should be(true) }
124+
}
125+
126+
it should "convert to BitPat from ChiselEnum" in {
127+
val b = BitPat(EnumExample.VAL1)
128+
val c = BitPat(EnumExample.VAL3)
129+
b should be(BitPat("b00"))
130+
c should be(BitPat("b10"))
131+
}
132+
}
Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
// SPDX-License-Identifier: Apache-2.0
2+
3+
package chiselTests
4+
5+
import chisel3._
6+
import circt.stage.ChiselStage.emitCHIRRTL
7+
import org.scalatest.flatspec.AnyFlatSpec
8+
import org.scalatest.matchers.should.Matchers
9+
10+
class BundleWithAnonymousInner(val w: Int) extends Bundle {
11+
val inner = new Bundle {
12+
val foo = Input(UInt(w.W))
13+
}
14+
}
15+
16+
class AutoNestedCloneSpec extends AnyFlatSpec with Matchers {
17+
18+
behavior.of("autoCloneType of inner Bundle in Chisel3")
19+
20+
it should "clone a doubly-nested inner bundle successfully" in {
21+
emitCHIRRTL {
22+
class Outer(val w: Int) extends Module {
23+
class Middle(val w: Int) {
24+
class InnerIOType extends Bundle {
25+
val in = Input(UInt(w.W))
26+
}
27+
def getIO: InnerIOType = new InnerIOType
28+
}
29+
val io = IO(new Bundle {})
30+
val myWire = Wire((new Middle(w)).getIO)
31+
}
32+
new Outer(2)
33+
}
34+
}
35+
36+
it should "clone an anonymous inner bundle successfully" in {
37+
emitCHIRRTL {
38+
class TestTop(val w: Int) extends Module {
39+
val io = IO(new Bundle {})
40+
val myWire = Wire(new Bundle { val a = UInt(w.W) })
41+
}
42+
new TestTop(2)
43+
}
44+
}
45+
46+
it should "pick the correct $outer instance for an anonymous inner bundle" in {
47+
emitCHIRRTL {
48+
class Inner(val w: Int) extends Module {
49+
val io = IO(new Bundle {
50+
val in = Input(UInt(w.W))
51+
val out = Output(UInt(w.W))
52+
})
53+
}
54+
class Outer(val w: Int) extends Module {
55+
val io = IO(new Bundle {
56+
val in = Input(UInt(w.W))
57+
val out = Output(UInt(w.W))
58+
})
59+
val i = Module(new Inner(w))
60+
val iw = Wire(chiselTypeOf(i.io))
61+
iw <> io
62+
i.io <> iw
63+
}
64+
new Outer(2)
65+
}
66+
}
67+
68+
it should "clone an anonymous, bound, inner bundle of another bundle successfully" in {
69+
emitCHIRRTL {
70+
class TestModule(w: Int) extends Module {
71+
val io = IO(new BundleWithAnonymousInner(w))
72+
val w0 = WireDefault(io)
73+
val w1 = WireDefault(io.inner)
74+
}
75+
new TestModule(8)
76+
}
77+
}
78+
79+
it should "clone an anonymous, inner bundle of a Module, bound to another bundle successfully" in {
80+
emitCHIRRTL {
81+
class TestModule(w: Int) extends Module {
82+
val bun = new Bundle {
83+
val foo = UInt(w.W)
84+
}
85+
val io = IO(new Bundle {
86+
val inner = Input(bun)
87+
})
88+
val w0 = WireDefault(io)
89+
val w1 = WireDefault(io.inner)
90+
}
91+
new TestModule(8)
92+
}
93+
}
94+
95+
it should "clone a double-nested anonymous Bundle" in {
96+
emitCHIRRTL {
97+
class TestModule() extends Module {
98+
val io = IO(new Bundle {
99+
val inner = Input(new Bundle {
100+
val x = UInt(8.W)
101+
})
102+
})
103+
}
104+
new TestModule()
105+
}
106+
}
107+
108+
it should "support an anonymous doubly-nested inner bundle" in {
109+
emitCHIRRTL {
110+
class Outer(val w: Int) extends Module {
111+
class Middle(val w: Int) {
112+
def getIO: Bundle = new Bundle {
113+
val in = Input(UInt(w.W))
114+
}
115+
}
116+
val io = IO(new Bundle {})
117+
val myWire = Wire((new Middle(w)).getIO)
118+
}
119+
new Outer(2)
120+
}
121+
}
122+
123+
it should "support anonymous Inner bundles that capture type parameters from outer Bundles" in {
124+
emitCHIRRTL(new Module {
125+
class MyBundle[T <: Data](n: Int, gen: T) extends Bundle {
126+
val foo = new Bundle {
127+
val x = Input(Vec(n, gen))
128+
}
129+
val bar = Output(Option(new { def mkBundle = new Bundle { val x = Vec(n, gen) } }).get.mkBundle)
130+
}
131+
val io = IO(new MyBundle(4, UInt(8.W)))
132+
val myWire = WireInit(io.foo)
133+
val myWire2 = WireInit(io.bar)
134+
io.bar.x := io.foo.x
135+
})
136+
}
137+
}

src/test/scala-2/chiselTests/ProbeSpec.scala

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import chisel3.testing.scalatest.FileCheck
1212
import circt.stage.ChiselStage
1313
import org.scalatest.flatspec.AnyFlatSpec
1414
import org.scalatest.matchers.should.Matchers
15-
import scala.reflect.Selectable.reflectiveSelectable
1615

1716
class ProbeSpec extends AnyFlatSpec with Matchers with FileCheck with ChiselSim {
1817
// Strip SourceInfos and split into lines

0 commit comments

Comments
 (0)