Skip to content

Commit 663ef89

Browse files
committed
Merge branch 'master' into release
2 parents c227431 + 5977bd6 commit 663ef89

20 files changed

+427
-62
lines changed

chiselFrontend/src/main/scala/chisel3/core/Aggregate.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@ trait VecLike[T <: Data] extends collection.IndexedSeq[T] with HasId {
362362
* Record should only be extended by libraries and fairly sophisticated generators.
363363
* RTL writers should use [[Bundle]]. See [[Record#elements]] for an example.
364364
*/
365-
abstract class Record extends Aggregate {
365+
abstract class Record(private[chisel3] implicit val compileOptions: CompileOptions) extends Aggregate {
366366

367367
/** The collection of [[Data]]
368368
*
@@ -464,7 +464,7 @@ abstract class Record extends Aggregate {
464464
* }
465465
* }}}
466466
*/
467-
class Bundle extends Record {
467+
class Bundle(implicit compileOptions: CompileOptions) extends Record {
468468
override def className = "Bundle"
469469

470470
/** The collection of [[Data]]

chiselFrontend/src/main/scala/chisel3/core/BiConnect.scala

Lines changed: 38 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -80,35 +80,50 @@ object BiConnect {
8080
}
8181
}
8282
}
83-
// Handle Record case
84-
case (left_r: Record, right_r: Record) => {
85-
// Verify right has no extra fields that left doesn't have
86-
for((field, right_sub) <- right_r.elements) {
87-
if(!left_r.elements.isDefinedAt(field)) {
88-
if (connectCompileOptions.connectFieldsMustMatch) {
89-
throw MissingLeftFieldException(field)
90-
}
91-
}
83+
// Handle Records defined in Chisel._ code (change to NotStrict)
84+
case (left_r: Record, right_r: Record) => (left_r.compileOptions, right_r.compileOptions) match {
85+
case (ExplicitCompileOptions.NotStrict, _) =>
86+
left_r.bulkConnect(right_r)(sourceInfo, ExplicitCompileOptions.NotStrict)
87+
case (_, ExplicitCompileOptions.NotStrict) =>
88+
left_r.bulkConnect(right_r)(sourceInfo, ExplicitCompileOptions.NotStrict)
89+
case _ => recordConnect(sourceInfo, connectCompileOptions, left_r, right_r, context_mod)
90+
}
91+
92+
// Left and right are different subtypes of Data so fail
93+
case (left, right) => throw MismatchedException(left.toString, right.toString)
94+
}
95+
96+
// Do connection of two Records
97+
def recordConnect(sourceInfo: SourceInfo,
98+
connectCompileOptions: CompileOptions,
99+
left_r: Record,
100+
right_r: Record,
101+
context_mod: UserModule): Unit = {
102+
// Verify right has no extra fields that left doesn't have
103+
for((field, right_sub) <- right_r.elements) {
104+
if(!left_r.elements.isDefinedAt(field)) {
105+
if (connectCompileOptions.connectFieldsMustMatch) {
106+
throw MissingLeftFieldException(field)
92107
}
93-
// For each field in left, descend with right
94-
for((field, left_sub) <- left_r.elements) {
95-
try {
96-
right_r.elements.get(field) match {
97-
case Some(right_sub) => connect(sourceInfo, connectCompileOptions, left_sub, right_sub, context_mod)
98-
case None => {
99-
if (connectCompileOptions.connectFieldsMustMatch) {
100-
throw MissingRightFieldException(field)
101-
}
102-
}
108+
}
109+
}
110+
// For each field in left, descend with right
111+
for((field, left_sub) <- left_r.elements) {
112+
try {
113+
right_r.elements.get(field) match {
114+
case Some(right_sub) => connect(sourceInfo, connectCompileOptions, left_sub, right_sub, context_mod)
115+
case None => {
116+
if (connectCompileOptions.connectFieldsMustMatch) {
117+
throw MissingRightFieldException(field)
103118
}
104-
} catch {
105-
case BiConnectException(message) => throw BiConnectException(s".$field$message")
106119
}
107120
}
121+
} catch {
122+
case BiConnectException(message) => throw BiConnectException(s".$field$message")
108123
}
109-
// Left and right are different subtypes of Data so fail
110-
case (left, right) => throw MismatchedException(left.toString, right.toString)
111124
}
125+
}
126+
112127

113128
// These functions (finally) issue the connection operation
114129
// Issue with right as sink, left as source

chiselFrontend/src/main/scala/chisel3/core/Bits.scala

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -594,8 +594,11 @@ sealed class SInt private[core] (width: Width, lit: Option[SLit] = None)
594594
binop(sourceInfo, SInt(this.width), RemOp, that)
595595

596596
final def * (that: UInt): SInt = macro SourceInfoTransform.thatArg
597-
def do_* (that: UInt)(implicit sourceInfo: SourceInfo, compileOptions: CompileOptions): SInt =
598-
binop(sourceInfo, SInt(this.width + that.width), TimesOp, that)
597+
def do_* (that: UInt)(implicit sourceInfo: SourceInfo, compileOptions: CompileOptions): SInt = {
598+
val thatToSInt = that.zext()
599+
val result = binop(sourceInfo, SInt(this.width + thatToSInt.width), TimesOp, thatToSInt)
600+
result.tail(1).asSInt
601+
}
599602

600603
/** add (width +1) operator */
601604
final def +& (that: SInt): SInt = macro SourceInfoTransform.thatArg

chiselFrontend/src/main/scala/chisel3/core/Module.scala

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,10 @@ object Module {
3232

3333
val parent = Builder.currentModule
3434
val whenDepth: Int = Builder.whenDepth
35+
36+
// Save then clear clock and reset to prevent leaking scope, must be set again in the Module
3537
val clockAndReset: Option[ClockAndReset] = Builder.currentClockAndReset
38+
Builder.currentClockAndReset = None
3639

3740
// Execute the module, this has the following side effects:
3841
// - set currentModule
@@ -108,7 +111,7 @@ abstract class BaseModule extends HasId {
108111
require(_closed, "Can't get ports before module close")
109112
_ports.toSeq
110113
}
111-
114+
112115
// These methods allow checking some properties of ports before the module is closed,
113116
// mainly for compatibility purposes.
114117
protected def portsContains(elem: Data): Boolean = _ports contains elem

chiselFrontend/src/main/scala/chisel3/core/MonoConnect.scala

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -55,15 +55,31 @@ object MonoConnect {
5555
* during the recursive decent and then rethrow them with extra information added.
5656
* This gives the user a 'path' to where in the connections things went wrong.
5757
*/
58-
def connect(sourceInfo: SourceInfo, connectCompileOptions: CompileOptions, sink: Data, source: Data, context_mod: UserModule): Unit =
58+
//scalastyle:off cyclomatic.complexity method.length
59+
def connect(
60+
sourceInfo: SourceInfo,
61+
connectCompileOptions: CompileOptions,
62+
sink: Data,
63+
source: Data,
64+
context_mod: UserModule): Unit =
5965
(sink, source) match {
60-
// Handle element case (root case)
61-
case (sink_e: Element, source_e: Element) => {
66+
67+
// Handle legal element cases, note (Bool, Bool) is caught by the first two, as Bool is a UInt
68+
case (sink_e: Bool, source_e: UInt) =>
6269
elemConnect(sourceInfo, connectCompileOptions, sink_e, source_e, context_mod)
63-
// TODO(twigg): Verify the element-level classes are connectable
64-
}
70+
case (sink_e: UInt, source_e: Bool) =>
71+
elemConnect(sourceInfo, connectCompileOptions, sink_e, source_e, context_mod)
72+
case (sink_e: UInt, source_e: UInt) =>
73+
elemConnect(sourceInfo, connectCompileOptions, sink_e, source_e, context_mod)
74+
case (sink_e: SInt, source_e: SInt) =>
75+
elemConnect(sourceInfo, connectCompileOptions, sink_e, source_e, context_mod)
76+
case (sink_e: FixedPoint, source_e: FixedPoint) =>
77+
elemConnect(sourceInfo, connectCompileOptions, sink_e, source_e, context_mod)
78+
case (sink_e: Clock, source_e: Clock) =>
79+
elemConnect(sourceInfo, connectCompileOptions, sink_e, source_e, context_mod)
80+
6581
// Handle Vec case
66-
case (sink_v: Vec[Data @unchecked], source_v: Vec[Data @unchecked]) => {
82+
case (sink_v: Vec[Data @unchecked], source_v: Vec[Data @unchecked]) =>
6783
if(sink_v.length != source_v.length) { throw MismatchedVecException }
6884
for(idx <- 0 until sink_v.length) {
6985
try {
@@ -73,9 +89,9 @@ object MonoConnect {
7389
case MonoConnectException(message) => throw MonoConnectException(s"($idx)$message")
7490
}
7591
}
76-
}
92+
7793
// Handle Record case
78-
case (sink_r: Record, source_r: Record) => {
94+
case (sink_r: Record, source_r: Record) =>
7995
// For each field, descend with right
8096
for((field, sink_sub) <- sink_r.elements) {
8197
try {
@@ -91,7 +107,7 @@ object MonoConnect {
91107
case MonoConnectException(message) => throw MonoConnectException(s".$field$message")
92108
}
93109
}
94-
}
110+
95111
// Sink and source are different subtypes of data so fail
96112
case (sink, source) => throw MismatchedException(sink.toString, source.toString)
97113
}
File renamed without changes.
File renamed without changes.

src/main/scala/chisel3/testers/TesterDriver.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ object TesterDriver extends BackendCompilationUtilities {
2828

2929
// Copy CPP harness and other Verilog sources from resources into files
3030
val cppHarness = new File(path, "top.cpp")
31-
copyResourceToFile("/top.cpp", cppHarness)
31+
copyResourceToFile("/chisel3/top.cpp", cppHarness)
3232
val additionalVFiles = additionalVResources.map((name: String) => {
3333
val mangledResourceName = name.replace("/", "_")
3434
val out = new File(path, mangledResourceName)

src/test/scala/chiselTests/AnalogIntegrationSpec.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,10 +126,10 @@ class AnalogIntegrationTester(mod: => AnalogDUTModule) extends BasicTester {
126126
class AnalogIntegrationSpec extends ChiselFlatSpec {
127127
behavior of "Verilator"
128128
it should "support simple bidirectional wires" in {
129-
assertTesterPasses(new AnalogIntegrationTester(new AnalogSmallDUT), Seq("/AnalogBlackBox.v"))
129+
assertTesterPasses(new AnalogIntegrationTester(new AnalogSmallDUT), Seq("/chisel3/AnalogBlackBox.v"))
130130
}
131131
// Use this test once Verilator supports alias
132132
ignore should "support arbitrary bidirectional wires" in {
133-
assertTesterPasses(new AnalogIntegrationTester(new AnalogDUT), Seq("/AnalogBlackBox.v"))
133+
assertTesterPasses(new AnalogIntegrationTester(new AnalogDUT), Seq("/chisel3/AnalogBlackBox.v"))
134134
}
135135
}

src/test/scala/chiselTests/AnalogSpec.scala

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ class AnalogSpec extends ChiselFlatSpec {
130130
val mod = Module(new AnalogReaderBlackBox)
131131
mod.io.bus <> writer.io.bus
132132
check(mod)
133-
}, Seq("/AnalogBlackBox.v"))
133+
}, Seq("/chisel3/AnalogBlackBox.v"))
134134
}
135135

136136
it should "error if any bulk connected more than once" in {
@@ -149,7 +149,7 @@ class AnalogSpec extends ChiselFlatSpec {
149149
val mods = Seq.fill(2)(Module(new AnalogReaderBlackBox))
150150
attach(writer.io.bus, mods(0).io.bus, mods(1).io.bus)
151151
mods.foreach(check(_))
152-
}, Seq("/AnalogBlackBox.v"))
152+
}, Seq("/chisel3/AnalogBlackBox.v"))
153153
}
154154

155155
it should "work with 3 blackboxes separately attached via a wire" in {
@@ -160,7 +160,7 @@ class AnalogSpec extends ChiselFlatSpec {
160160
attach(busWire, mods(0).io.bus)
161161
attach(mods(1).io.bus, busWire)
162162
mods.foreach(check(_))
163-
}, Seq("/AnalogBlackBox.v"))
163+
}, Seq("/chisel3/AnalogBlackBox.v"))
164164
}
165165

166166
// This does not currently work in Verilator unless Firrtl does constant prop and dead code
@@ -173,7 +173,7 @@ class AnalogSpec extends ChiselFlatSpec {
173173
attach(busWire(1), mod.io.bus)
174174
attach(busWire(0), busWire(1))
175175
check(mod)
176-
}, Seq("/AnalogBlackBox.v"))
176+
}, Seq("/chisel3/AnalogBlackBox.v"))
177177
}
178178

179179
it should "work with blackboxes at different levels of the module hierarchy" in {
@@ -182,7 +182,7 @@ class AnalogSpec extends ChiselFlatSpec {
182182
val busWire = Wire(writer.io.bus)
183183
attach(writer.io.bus, mods(0).io.bus, mods(1).io.bus)
184184
mods.foreach(check(_))
185-
}, Seq("/AnalogBlackBox.v"))
185+
}, Seq("/chisel3/AnalogBlackBox.v"))
186186
}
187187

188188
// This does not currently work in Verilator, but does work in VCS
@@ -193,7 +193,7 @@ class AnalogSpec extends ChiselFlatSpec {
193193
connector.io.bus1 <> writer.io.bus
194194
reader.io.bus <> connector.io.bus2
195195
check(reader)
196-
}, Seq("/AnalogBlackBox.v"))
196+
}, Seq("/chisel3/AnalogBlackBox.v"))
197197
}
198198

199199
it should "NOT support conditional connection of analog types" in {
@@ -204,7 +204,7 @@ class AnalogSpec extends ChiselFlatSpec {
204204
mod.io.bus <> writer.io.bus
205205
}
206206
check(mod)
207-
}, Seq("/AnalogBlackBox.v"))
207+
}, Seq("/chisel3/AnalogBlackBox.v"))
208208
}
209209
}
210210
}

src/test/scala/chiselTests/BlackBox.scala

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -138,18 +138,18 @@ class BlackBoxWithParamsTester extends BasicTester {
138138
class BlackBoxSpec extends ChiselFlatSpec {
139139
"A BlackBoxed inverter" should "work" in {
140140
assertTesterPasses({ new BlackBoxTester },
141-
Seq("/BlackBoxTest.v"))
141+
Seq("/chisel3/BlackBoxTest.v"))
142142
}
143143
"Multiple BlackBoxes" should "work" in {
144144
assertTesterPasses({ new MultiBlackBoxTester },
145-
Seq("/BlackBoxTest.v"))
145+
Seq("/chisel3/BlackBoxTest.v"))
146146
}
147147
"A BlackBoxed register" should "work" in {
148148
assertTesterPasses({ new BlackBoxWithClockTester },
149-
Seq("/BlackBoxTest.v"))
149+
Seq("/chisel3/BlackBoxTest.v"))
150150
}
151151
"BlackBoxes with parameters" should "work" in {
152152
assertTesterPasses({ new BlackBoxWithParamsTester },
153-
Seq("/BlackBoxTest.v"))
153+
Seq("/chisel3/BlackBoxTest.v"))
154154
}
155155
}

src/test/scala/chiselTests/BlackBoxImpl.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ class BlackBoxMinus extends HasBlackBoxResource {
4747
val in2 = Input(UInt(16.W))
4848
val out = Output(UInt(16.W))
4949
})
50-
setResource("/BlackBoxTest.v")
50+
setResource("/chisel3/BlackBoxTest.v")
5151
}
5252

5353
class UsesBlackBoxMinusViaResource extends Module {

0 commit comments

Comments
 (0)