Skip to content

Commit

Permalink
Don't allow multiple DontCare connections
Browse files Browse the repository at this point in the history
  • Loading branch information
ducky64 committed Mar 29, 2019
1 parent 860a129 commit 0d701d4
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 19 deletions.
37 changes: 18 additions & 19 deletions chiselFrontend/src/main/scala/chisel3/core/BiConnect.scala
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,20 @@ object BiConnect {
// Handle element case (root case)
case (left_a: Analog, right_a: Analog) =>
try {
analogAttach(sourceInfo, left_a, right_a, context_mod)
} catch {
// If attach fails, convert to BiConnectException
markAnalogConnected(sourceInfo, left_a, context_mod)
markAnalogConnected(sourceInfo, right_a, context_mod)
} catch { // convert attach exceptions to BiConnectExceptions
case attach.AttachException(message) => throw BiConnectException(message)
}
case (left_a: Analog, DontCare) => pushCommand(DefInvalid(sourceInfo, left_a.lref))
case (DontCare, right_a: Analog) => pushCommand(DefInvalid(sourceInfo, right_a.lref))
attach.impl(Seq(left_a, right_a), context_mod)
case (left_a: Analog, DontCare) =>
try {
markAnalogConnected(sourceInfo, left_a, context_mod)
} catch { // convert attach exceptions to BiConnectExceptions
case attach.AttachException(message) => throw BiConnectException(message)
}
pushCommand(DefInvalid(sourceInfo, left_a.lref))
case (DontCare, right_a: Analog) => connect(sourceInfo, connectCompileOptions, right, left, context_mod)
case (left_e: Element, right_e: Element) => {
elemConnect(sourceInfo, connectCompileOptions, left_e, right_e, context_mod)
// TODO(twigg): Verify the element-level classes are connectable
Expand Down Expand Up @@ -314,21 +321,13 @@ object BiConnect {
else throw UnknownRelationException
}

// This function checks if analog element-level attaching is allowed
// Then it either issues it or throws the appropriate exception.
def analogAttach(implicit sourceInfo: SourceInfo, left: Analog, right: Analog, contextModule: RawModule): Unit = {
// Error if left or right is BICONNECTED in the current module already
for (elt <- left :: right :: Nil) {
elt.biConnectLocs.get(contextModule) match {
case Some(sl) => throw AttachAlreadyBulkConnectedException(sl)
case None => // Do nothing
}
// This function checks if analog element-level attaching is allowed, then marks the Analog as connected
def markAnalogConnected(implicit sourceInfo: SourceInfo, analog: Analog, contextModule: RawModule): Unit = {
analog.biConnectLocs.get(contextModule) match {
case Some(sl) => throw AttachAlreadyBulkConnectedException(sl)
case None => // Do nothing
}

// Do the attachment
attach.impl(Seq(left, right), contextModule)
// Mark bulk connected
left.biConnectLocs(contextModule) = sourceInfo
right.biConnectLocs(contextModule) = sourceInfo
analog.biConnectLocs(contextModule) = sourceInfo
}
}
8 changes: 8 additions & 0 deletions src/test/scala/chiselTests/AnalogSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,14 @@ class AnalogSpec extends ChiselFlatSpec {
wires(0) <> wires(2)
})
}
a [ChiselException] should be thrownBy {
elaborate(new Module {
val io = IO(new Bundle {})
val wires = List.fill(2)(Wire(Analog(32.W)))
wires(0) <> DontCare
wires(0) <> wires(1)
})
}
}

it should "allow DontCare connection" in {
Expand Down

0 comments on commit 0d701d4

Please sign in to comment.