diff options
| author | Aditya Naik | 2024-05-29 17:28:22 -0700 |
|---|---|---|
| committer | Aditya Naik | 2024-05-29 17:28:22 -0700 |
| commit | bc92bb62f9f6a090e74392993e4fcfdd1f6b0676 (patch) | |
| tree | 160eb4cc2770eaf0c189fab9442d04b2b00b7919 /core/src/main/scala/chisel3/experimental/ChiselEnum.scala | |
| parent | 878d488a7c8e0d6973de58b3164022c6a102e449 (diff) | |
i got 99 errors but "firrtl not found" aint one
Diffstat (limited to 'core/src/main/scala/chisel3/experimental/ChiselEnum.scala')
| -rw-r--r-- | core/src/main/scala/chisel3/experimental/ChiselEnum.scala | 60 |
1 files changed, 9 insertions, 51 deletions
diff --git a/core/src/main/scala/chisel3/experimental/ChiselEnum.scala b/core/src/main/scala/chisel3/experimental/ChiselEnum.scala index 37c6fb58..27b07199 100644 --- a/core/src/main/scala/chisel3/experimental/ChiselEnum.scala +++ b/core/src/main/scala/chisel3/experimental/ChiselEnum.scala @@ -2,8 +2,6 @@ package chisel3.experimental -import scala.language.experimental.macros -import scala.reflect.macros.blackbox.Context import scala.collection.mutable import chisel3._ import chisel3.internal.Builder.pushOp @@ -116,27 +114,20 @@ abstract class EnumType(private[chisel3] val factory: ChiselEnum, selfAnnotating this := factory.apply(that.asUInt) } - final def ===(that: EnumType): Bool = macro SourceInfoTransform.thatArg - final def =/=(that: EnumType): Bool = macro SourceInfoTransform.thatArg - final def <(that: EnumType): Bool = macro SourceInfoTransform.thatArg - final def <=(that: EnumType): Bool = macro SourceInfoTransform.thatArg - final def >(that: EnumType): Bool = macro SourceInfoTransform.thatArg - final def >=(that: EnumType): Bool = macro SourceInfoTransform.thatArg - - def do_===(that: EnumType)(implicit sourceInfo: SourceInfo, compileOptions: CompileOptions): Bool = + def ===(that: EnumType)(implicit sourceInfo: SourceInfo, compileOptions: CompileOptions): Bool = compop(sourceInfo, EqualOp, that) - def do_=/=(that: EnumType)(implicit sourceInfo: SourceInfo, compileOptions: CompileOptions): Bool = + def =/=(that: EnumType)(implicit sourceInfo: SourceInfo, compileOptions: CompileOptions): Bool = compop(sourceInfo, NotEqualOp, that) - def do_<(that: EnumType)(implicit sourceInfo: SourceInfo, compileOptions: CompileOptions): Bool = + def <(that: EnumType)(implicit sourceInfo: SourceInfo, compileOptions: CompileOptions): Bool = compop(sourceInfo, LessOp, that) - def do_>(that: EnumType)(implicit sourceInfo: SourceInfo, compileOptions: CompileOptions): Bool = + def >(that: EnumType)(implicit sourceInfo: SourceInfo, compileOptions: CompileOptions): Bool = compop(sourceInfo, GreaterOp, that) - def do_<=(that: EnumType)(implicit sourceInfo: SourceInfo, compileOptions: CompileOptions): Bool = + def <=(that: EnumType)(implicit sourceInfo: SourceInfo, compileOptions: CompileOptions): Bool = compop(sourceInfo, LessEqOp, that) - def do_>=(that: EnumType)(implicit sourceInfo: SourceInfo, compileOptions: CompileOptions): Bool = + def >=(that: EnumType)(implicit sourceInfo: SourceInfo, compileOptions: CompileOptions): Bool = compop(sourceInfo, GreaterEqOp, that) - override def do_asUInt(implicit sourceInfo: SourceInfo, compileOptions: CompileOptions): UInt = + override def asUInt(implicit sourceInfo: SourceInfo, compileOptions: CompileOptions): UInt = pushOp(DefPrim(sourceInfo, UInt(width), AsUIntOp, ref)) protected[chisel3] override def width: Width = factory.width @@ -317,10 +308,7 @@ abstract class EnumFactory { enumRecords.find(_.inst.litValue == id).map(_.name) } - protected def Value: Type = macro EnumMacros.ValImpl - protected def Value(id: UInt): Type = macro EnumMacros.ValCustomImpl - - protected def do_Value(name: String): Type = { + protected def Value(name: String): Type = { val result = new Type // We have to use UnknownWidth here, because we don't actually know what the final width will be @@ -334,7 +322,7 @@ abstract class EnumFactory { result } - protected def do_Value(name: String, id: UInt): Type = { + protected def Value(name: String, id: UInt): Type = { // TODO: These throw ExceptionInInitializerError which can be confusing to the user. Get rid of the error, and just // throw an exception if (id.litOption.isEmpty) { @@ -401,36 +389,6 @@ abstract class EnumFactory { } } -private[chisel3] object EnumMacros { - def ValImpl(c: Context): c.Tree = { - import c.universe._ - - // Much thanks to michael_s for this solution: - // stackoverflow.com/questions/18450203/retrieve-the-name-of-the-value-a-scala-macro-invocation-will-be-assigned-to - val term = c.internal.enclosingOwner - val name = term.name.decodedName.toString.trim - - if (name.contains(" ")) { - c.abort(c.enclosingPosition, "Value cannot be called without assigning to an enum") - } - - q"""this.do_Value($name)""" - } - - def ValCustomImpl(c: Context)(id: c.Expr[UInt]): c.universe.Tree = { - import c.universe._ - - val term = c.internal.enclosingOwner - val name = term.name.decodedName.toString.trim - - if (name.contains(" ")) { - c.abort(c.enclosingPosition, "Value cannot be called without assigning to an enum") - } - - q"""this.do_Value($name, $id)""" - } -} - // This is an enum type that can be connected directly to UInts. It is used as a "glue" to cast non-literal UInts // to enums. private[chisel3] class UnsafeEnum(override val width: Width) extends EnumType(UnsafeEnum, selfAnnotating = false) { |
