From 0f7272036ff89357f20092bf8930a4dc6bd2c47c Mon Sep 17 00:00:00 2001 From: Aditya Naik Date: Wed, 18 Dec 2024 03:39:08 -0800 Subject: [PATCH] Fix ChiselEnum --- core/src/main/scala/chisel3/ChiselEnumImpl.scala | 14 +++----------- core/src/main/scala/chisel3/DataImpl.scala | 2 +- 2 files changed, 4 insertions(+), 12 deletions(-) diff --git a/core/src/main/scala/chisel3/ChiselEnumImpl.scala b/core/src/main/scala/chisel3/ChiselEnumImpl.scala index 967a5e39ae..3ff3d91390 100644 --- a/core/src/main/scala/chisel3/ChiselEnumImpl.scala +++ b/core/src/main/scala/chisel3/ChiselEnumImpl.scala @@ -70,8 +70,8 @@ private[chisel3] abstract class EnumTypeImpl(private[chisel3] val factory: Chise _wire := this.asUInt _wire } - _padded.asTypeOf(that) - case None => super.asTypeOf(that) + _padded._asTypeOfImpl(that) + case None => super._asTypeOfImpl(that) } } @@ -222,15 +222,7 @@ private[chisel3] abstract class EnumTypeImpl(private[chisel3] val factory: Chise for ((name, value) <- allNamesPadded) { when(this === value) { for ((r, c) <- result.zip(name)) { - // todo: this doesn't work in scala3 - // r := c.toChar.U - // ^^^^^^^^^^ - // value U is not a member of Char. - // An extension method was tried, - // but could not be fully constructed: - // - // chisel3.fromLongToLiteral(c.toChar) - // r := c.toChar.U + r := UInt.Lit(c.toChar, Width()) } } } diff --git a/core/src/main/scala/chisel3/DataImpl.scala b/core/src/main/scala/chisel3/DataImpl.scala index dc7201ca7f..062aba1f1f 100644 --- a/core/src/main/scala/chisel3/DataImpl.scala +++ b/core/src/main/scala/chisel3/DataImpl.scala @@ -861,7 +861,7 @@ private[chisel3] trait DataImpl extends HasId with NamedComponent { self: Data = /** Returns Some(width) if the width is known, else None. */ final def widthOption: Option[Int] = if (isWidthKnown) Some(getWidth) else None - protected def _asTypeOfImpl[T <: Data](that: T)(implicit sourceInfo: SourceInfo): T = { + private[chisel3] def _asTypeOfImpl[T <: Data](that: T)(implicit sourceInfo: SourceInfo): T = { that._fromUInt(this.asUInt).asInstanceOf[T].viewAsReadOnly { _ => "Return values of asTypeOf are now read-only" }