From 7bad3d2ec316f24f3da79d1dfef19e128cfe8bf5 Mon Sep 17 00:00:00 2001 From: mergify[bot] Date: Fri, 12 Aug 2022 20:04:33 +0000 Subject: Add ability to suppress enum cast warnings (#2671) (#2674) (cherry picked from commit 1ad820f7f549eddcd7188b737f59a240e48a7f0a) Co-authored-by: Zachary Yedidia --- docs/src/explanations/chisel-enum.md | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'docs') diff --git a/docs/src/explanations/chisel-enum.md b/docs/src/explanations/chisel-enum.md index a390aea4..16b5570d 100644 --- a/docs/src/explanations/chisel-enum.md +++ b/docs/src/explanations/chisel-enum.md @@ -17,6 +17,7 @@ import chisel3._ import chisel3.util._ import chisel3.stage.ChiselStage import chisel3.experimental.ChiselEnum +import chisel3.experimental.suppressEnumCastWarning ``` ```scala mdoc:invisible @@ -167,6 +168,30 @@ val (log2, _) = grabLog(ChiselStage.emitChirrtl(new SafeFromUInt)) println(s"```\n$log2```") ``` +You can also suppress the warning by using `suppressEnumCastWarning`. This is +primarily used for casting from [[UInt]] to a Bundle type that contains an +Enum, where the [[UInt]] is known to be valid for the Bundle type. + +```scala mdoc +class MyBundle extends Bundle { + val addr = UInt(8.W) + val op = Opcode() +} + +class SuppressedFromUInt extends Module { + val in = IO(Input(UInt(15.W))) + val out = IO(Output(new MyBundle())) + suppressEnumCastWarning { + out := in.asTypeOf(new MyBundle) + } +} +``` + +```scala mdoc:invisible +val (log3, _) = grabLog(ChiselStage.emitChirrtl(new SuppressedFromUInt)) +assert(log3.isEmpty) +``` + ## Testing The _Type_ of the enums values is `.Type` which can be useful for passing the values -- cgit v1.2.3