From 63f25ac4b4d7c9bd530ff1875ad38d835a82e051 Mon Sep 17 00:00:00 2001 From: mergify[bot] Date: Fri, 3 Jun 2022 18:33:13 +0000 Subject: Deprecate implicit .U() and .S() syntax for literal bit extracts (backport #2534) (#2559) * Deprecate .U() and .S() syntax for literal bit extracts (#2534) (cherry picked from commit cadaf33a650ef898fdab2f81244e4ad6a07a9ea8) # Conflicts: # macros/src/main/scala/chisel3/internal/sourceinfo/SourceInfoTransform.scala * Fix backport conflict (#2560) Co-authored-by: Jared Barocsi <82000041+jared-barocsi@users.noreply.github.com>--- .../internal/sourceinfo/SourceInfoTransform.scala | 28 ++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'macros') diff --git a/macros/src/main/scala/chisel3/internal/sourceinfo/SourceInfoTransform.scala b/macros/src/main/scala/chisel3/internal/sourceinfo/SourceInfoTransform.scala index 3e310774..6c83da00 100644 --- a/macros/src/main/scala/chisel3/internal/sourceinfo/SourceInfoTransform.scala +++ b/macros/src/main/scala/chisel3/internal/sourceinfo/SourceInfoTransform.scala @@ -249,3 +249,31 @@ class SourceInfoWhiteboxTransform(val c: whitebox.Context) extends AutoSourceTra q"$thisObj.$doFuncTerm($that)($implicitSourceInfo, $implicitCompileOptions)" } } + +// Workaround for https://github.com/sbt/sbt/issues/3966 +object IntLiteralApplyTransform + +class IntLiteralApplyTransform(val c: Context) extends AutoSourceTransform { + import c.universe._ + + def safeApply(x: c.Tree): c.Tree = { + c.macroApplication match { + case q"$_.$clazz($lit).$func.apply($arg)" => + if ( + Set("U", "S").contains(func.toString) && + Set("fromStringToLiteral", "fromIntToLiteral", "fromLongToIteral", "fromBigIntToLiteral").contains( + clazz.toString + ) + ) { + val msg = + s"""Passing an Int to .$func is usually a mistake: It does *not* set the width but does a bit extract. + |Did you mean .$func($arg.W)? + |If you want to hide this message, assign .$func to a val first, then invoke .apply($arg) + |""".stripMargin + c.warning(c.enclosingPosition, msg) + } + case _ => // do nothing + } + q"$thisObj.$doFuncTerm($x)($implicitSourceInfo, $implicitCompileOptions)" + } +} -- cgit v1.2.3