From 8ca012c214fb5b69d22f49988cf947e91eba9ebb Mon Sep 17 00:00:00 2001 From: Schuyler Eldridge Date: Sat, 2 Mar 2024 00:39:08 -0500 Subject: [PATCH] Make logger annotations unserializable Change logger annotations to mix-in the Unserializable trait so that they will not emitted by a stage. These annotations are not intended to be seen by CIRCT and these should be stripped from the output FIRRTL text. Signed-off-by: Schuyler Eldridge --- firrtl/src/main/scala/logger/LoggerAnnotations.scala | 12 +++++++++--- .../scala/circtTests/stage/ChiselStageSpec.scala | 6 ++++++ 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/firrtl/src/main/scala/logger/LoggerAnnotations.scala b/firrtl/src/main/scala/logger/LoggerAnnotations.scala index 0185492e363..1f11ce42179 100644 --- a/firrtl/src/main/scala/logger/LoggerAnnotations.scala +++ b/firrtl/src/main/scala/logger/LoggerAnnotations.scala @@ -3,7 +3,7 @@ package logger import firrtl.annotations.{Annotation, NoTargetAnnotation} -import firrtl.options.{HasShellOptions, ShellOption} +import firrtl.options.{HasShellOptions, ShellOption, Unserializable} /** An annotation associated with a Logger command line option */ sealed trait LoggerOption { this: Annotation => } @@ -16,6 +16,7 @@ sealed trait LoggerOption { this: Annotation => } case class LogLevelAnnotation(globalLogLevel: LogLevel.Value = LogLevel.None) extends NoTargetAnnotation with LoggerOption + with Unserializable object LogLevelAnnotation extends HasShellOptions { @@ -39,6 +40,7 @@ object LogLevelAnnotation extends HasShellOptions { case class ClassLogLevelAnnotation(className: String, level: LogLevel.Value) extends NoTargetAnnotation with LoggerOption + with Unserializable object ClassLogLevelAnnotation extends HasShellOptions { @@ -63,7 +65,7 @@ object ClassLogLevelAnnotation extends HasShellOptions { * - maps to [[LoggerOptions.logFileName]] * - enabled with `--log-file` */ -case class LogFileAnnotation(file: Option[String]) extends NoTargetAnnotation with LoggerOption +case class LogFileAnnotation(file: Option[String]) extends NoTargetAnnotation with LoggerOption with Unserializable object LogFileAnnotation extends HasShellOptions { @@ -81,7 +83,11 @@ object LogFileAnnotation extends HasShellOptions { /** Enables class names in log output * - enabled with `-lcn/--log-class-names` */ -case object LogClassNamesAnnotation extends NoTargetAnnotation with LoggerOption with HasShellOptions { +case object LogClassNamesAnnotation + extends NoTargetAnnotation + with LoggerOption + with HasShellOptions + with Unserializable { val options = Seq( new ShellOption[Unit]( diff --git a/src/test/scala/circtTests/stage/ChiselStageSpec.scala b/src/test/scala/circtTests/stage/ChiselStageSpec.scala index 5e2ea98c3ba..f0d24d48721 100644 --- a/src/test/scala/circtTests/stage/ChiselStageSpec.scala +++ b/src/test/scala/circtTests/stage/ChiselStageSpec.scala @@ -1133,6 +1133,12 @@ class ChiselStageSpec extends AnyFunSpec with Matchers with chiselTests.Utils { } log2 shouldNot include("Done elaborating.") } + + it("should not emit logger annotations") { + import chisel3.RawModule + (ChiselStage.emitCHIRRTL(new RawModule {}) should not).include("LogLevelAnnotation") + (ChiselStage.emitCHIRRTL(new RawModule {}, Array("-ll", "info")) should not).include("LogLevelAnnotation") + } } describe("ChiselStage$ exception handling") {