Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Strong enums #892

Merged
merged 16 commits into from
Oct 12, 2018
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions chiselFrontend/src/main/scala/chisel3/core/Bits.scala
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import chisel3.internal.firrtl.PrimOp._
*
* @define coll element
*/
abstract class Element(private[chisel3] val width: Width) extends Data {
abstract class Element extends Data {
hngenc marked this conversation as resolved.
Show resolved Hide resolved
private[chisel3] override def bind(target: Binding, parentDirection: SpecifiedDirection) {
binding = target
val resolvedDirection = SpecifiedDirection.fromParent(parentDirection, specifiedDirection)
Expand Down Expand Up @@ -69,7 +69,7 @@ private[chisel3] sealed trait ToBoolable extends Element {
* @define sumWidth @note The width of the returned $coll is `width of this` + `width of that`.
* @define unchangedWidth @note The width of the returned $coll is unchanged, i.e., the `width of this`.
*/
sealed abstract class Bits(width: Width) extends Element(width) with ToBoolable { //scalastyle:off number.of.methods
sealed abstract class Bits(private[chisel3] val width: Width) extends Element with ToBoolable { //scalastyle:off number.of.methods
// TODO: perhaps make this concrete?
// Arguments for: self-checking code (can't do arithmetic on bits)
// Arguments against: generates down to a FIRRTL UInt anyways
Expand Down Expand Up @@ -1693,7 +1693,7 @@ object FixedPoint {
*
* @note This API is experimental and subject to change
*/
final class Analog private (width: Width) extends Element(width) {
final class Analog private (private[chisel3] val width: Width) extends Element {
require(width.known, "Since Analog is only for use in BlackBoxes, width must be known")

private[core] override def typeEquivalent(that: Data): Boolean =
Expand Down
2 changes: 1 addition & 1 deletion chiselFrontend/src/main/scala/chisel3/core/Clock.scala
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ object Clock {
}

// TODO: Document this.
sealed class Clock extends Element(Width(1)) {
sealed class Clock(private[chisel3] val width: Width = Width(1)) extends Element {
def cloneType: this.type = Clock().asInstanceOf[this.type]

private[core] def typeEquivalent(that: Data): Boolean =
Expand Down
4 changes: 3 additions & 1 deletion chiselFrontend/src/main/scala/chisel3/core/Data.scala
Original file line number Diff line number Diff line change
Expand Up @@ -529,10 +529,12 @@ object WireInit {
/** RHS (source) for Invalidate API.
* Causes connection logic to emit a DefInvalid when connected to an output port (or wire).
*/
object DontCare extends Element(width = UnknownWidth()) {
object DontCare extends Element {
// This object should be initialized before we execute any user code that refers to it,
// otherwise this "Chisel" object will end up on the UserModule's id list.

private[chisel3] override val width: Width = UnknownWidth()

bind(DontCareBinding(), SpecifiedDirection.Output)
override def cloneType = DontCare

Expand Down
6 changes: 6 additions & 0 deletions chiselFrontend/src/main/scala/chisel3/core/MonoConnect.scala
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,12 @@ object MonoConnect {
elemConnect(sourceInfo, connectCompileOptions, sink_e, source_e, context_mod)
case (sink_e: Clock, source_e: Clock) =>
elemConnect(sourceInfo, connectCompileOptions, sink_e, source_e, context_mod)
case (sink_e: EnumType, source_e: UnsafeEnum) =>
elemConnect(sourceInfo, connectCompileOptions, sink_e, source_e, context_mod)
case (sink_e: EnumType, source_e: EnumType) if sink_e.getClass.equals(source_e.getClass) =>
elemConnect(sourceInfo, connectCompileOptions, sink_e, source_e, context_mod)
case (sink_e: UnsafeEnum, source_e: UInt) =>
elemConnect(sourceInfo, connectCompileOptions, sink_e, source_e, context_mod)

// Handle Vec case
case (sink_v: Vec[Data @unchecked], source_v: Vec[Data @unchecked]) =>
Expand Down
Loading