@@ -6,32 +6,44 @@ import chisel3._
6
6
import chisel3 .testers .BasicTester
7
7
import chisel3 .experimental .BundleLiterals ._
8
8
import chisel3 .experimental .BundleLiteralException
9
+ import chisel3 .experimental .ChiselEnum
9
10
10
11
class BundleLiteralSpec extends ChiselFlatSpec {
12
+ object MyEnum extends ChiselEnum {
13
+ val sA, sB = Value
14
+ }
15
+ object MyEnumB extends ChiselEnum {
16
+ val sA, sB = Value
17
+ }
11
18
class MyBundle extends Bundle {
12
19
val a = UInt (8 .W )
13
20
val b = Bool ()
21
+ val c = MyEnum ()
14
22
}
15
23
16
24
" bundle literals" should " work in RTL" in {
17
- val outsideBundleLit = (new MyBundle ).Lit (_.a -> 42 .U , _.b -> true .B )
25
+ val outsideBundleLit = (new MyBundle ).Lit (_.a -> 42 .U , _.b -> true .B , _.c -> MyEnum .sB )
18
26
assertTesterPasses{ new BasicTester {
19
27
// TODO: add direct bundle compare operations, when that feature is added
20
28
chisel3.assert(outsideBundleLit.a === 42 .U )
21
29
chisel3.assert(outsideBundleLit.b === true .B )
30
+ chisel3.assert(outsideBundleLit.c === MyEnum .sB)
22
31
23
- val bundleLit = (new MyBundle ).Lit (_.a -> 42 .U , _.b -> true .B )
32
+ val bundleLit = (new MyBundle ).Lit (_.a -> 42 .U , _.b -> true .B , _.c -> MyEnum .sB )
24
33
chisel3.assert(bundleLit.a === 42 .U )
25
34
chisel3.assert(bundleLit.b === true .B )
35
+ chisel3.assert(bundleLit.c === MyEnum .sB)
26
36
27
37
chisel3.assert(bundleLit.a === outsideBundleLit.a)
28
38
chisel3.assert(bundleLit.b === outsideBundleLit.b)
39
+ chisel3.assert(bundleLit.c === outsideBundleLit.c)
29
40
30
41
val bundleWire = Wire (new MyBundle )
31
42
bundleWire := outsideBundleLit
32
43
33
44
chisel3.assert(bundleWire.a === 42 .U )
34
45
chisel3.assert(bundleWire.b === true .B )
46
+ chisel3.assert(bundleWire.c === MyEnum .sB)
35
47
36
48
stop()
37
49
} }
@@ -56,35 +68,42 @@ class BundleLiteralSpec extends ChiselFlatSpec {
56
68
val b = new Bundle {
57
69
val c = Bool ()
58
70
val d = UInt (8 .W )
71
+ val e = MyEnum ()
59
72
}
73
+ val f = MyEnum ()
60
74
}
61
75
62
76
" contained bundles" should " work" in {
63
77
assertTesterPasses{ new BasicTester {
64
78
// Specify the inner Bundle value as a Bundle literal
65
79
val explicitBundleLit = (new MyOuterBundle ).Lit (
66
- _.a -> (new MyBundle ).Lit (_.a -> 42 .U , _.b -> true .B )
80
+ _.a -> (new MyBundle ).Lit (_.a -> 42 .U , _.b -> true .B , _.c -> MyEnum .sB )
67
81
)
68
82
chisel3.assert(explicitBundleLit.a.a === 42 .U )
69
83
chisel3.assert(explicitBundleLit.a.b === true .B )
84
+ chisel3.assert(explicitBundleLit.a.c === MyEnum .sB)
70
85
71
86
// Specify the inner Bundle fields directly
72
87
val expandedBundleLit = (new MyOuterBundle ).Lit (
73
88
_.a.a -> 42 .U , _.a.b -> true .B ,
74
- _.b.c -> false .B , _.b.d -> 255 .U
89
+ _.b.c -> false .B , _.b.d -> 255 .U , _.b.e -> MyEnum .sB,
90
+ _.f -> MyEnum .sB
75
91
)
76
92
chisel3.assert(expandedBundleLit.a.a === 42 .U )
77
93
chisel3.assert(expandedBundleLit.a.b === true .B )
94
+ chisel3.assert(expandedBundleLit.f === MyEnum .sB)
78
95
chisel3.assert(expandedBundleLit.b.c === false .B )
79
96
chisel3.assert(expandedBundleLit.b.d === 255 .U )
97
+ chisel3.assert(expandedBundleLit.b.e === MyEnum .sB)
80
98
81
99
// Anonymously contruct the inner Bundle literal
82
100
// A bit of weird syntax that depends on implementation details of the Bundle literal constructor
83
101
val childBundleLit = (new MyOuterBundle ).Lit (
84
- b => b.b -> b.b.Lit (_.c -> false .B , _.d -> 255 .U )
102
+ b => b.b -> b.b.Lit (_.c -> false .B , _.d -> 255 .U , _.e -> MyEnum .sB )
85
103
)
86
104
chisel3.assert(childBundleLit.b.c === false .B )
87
105
chisel3.assert(childBundleLit.b.d === 255 .U )
106
+ chisel3.assert(childBundleLit.b.e === MyEnum .sB)
88
107
89
108
stop()
90
109
} }
@@ -93,11 +112,12 @@ class BundleLiteralSpec extends ChiselFlatSpec {
93
112
" Bundle literals" should " assign" in {
94
113
assertTesterPasses{ new BasicTester {
95
114
val bundleWire = Wire (Output (new MyBundle ))
96
- val bundleLit = (new MyBundle ).Lit (_.a -> 42 .U , _.b -> true .B )
115
+ val bundleLit = (new MyBundle ).Lit (_.a -> 42 .U , _.b -> true .B , _.c -> MyEnum .sB )
97
116
bundleWire := bundleLit
98
117
99
118
chisel3.assert(bundleWire.a === 42 .U )
100
119
chisel3.assert(bundleWire.b === true .B )
120
+ chisel3.assert(bundleWire.c === MyEnum .sB)
101
121
stop()
102
122
} }
103
123
}
@@ -152,4 +172,13 @@ class BundleLiteralSpec extends ChiselFlatSpec {
152
172
exc.getMessage should include (" non-type-equivalent value" )
153
173
exc.getMessage should include (" .b" )
154
174
}
175
+
176
+ " bundle literals with non-type-equivalent enum element fields" should " fail" in {
177
+ val exc = intercept[BundleLiteralException ] { elaborate { new RawModule {
178
+ (new MyBundle ).Lit (_.c -> MyEnumB .sB)
179
+ }}}
180
+ exc.getMessage should include (" non-type-equivalent enum value" )
181
+ exc.getMessage should include (" .c" )
182
+ }
183
+
155
184
}
0 commit comments