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/src/main/scala/chisel3/internal/sourceinfo') 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 From 205d8bb34b2ac2acaef6d318a4f9e3aee181110e Mon Sep 17 00:00:00 2001 From: mergify[bot] Date: Tue, 7 Jun 2022 23:11:54 +0000 Subject: Add single argument Bits.extract (#2566) (#2568) (cherry picked from commit 255c56c3955a8c16191a6751e7d547cfcfd96705) Co-authored-by: Jared Barocsi <82000041+jared-barocsi@users.noreply.github.com>--- .../main/scala/chisel3/internal/sourceinfo/SourceInfoTransform.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'macros/src/main/scala/chisel3/internal/sourceinfo') diff --git a/macros/src/main/scala/chisel3/internal/sourceinfo/SourceInfoTransform.scala b/macros/src/main/scala/chisel3/internal/sourceinfo/SourceInfoTransform.scala index 6c83da00..d77e4f1e 100644 --- a/macros/src/main/scala/chisel3/internal/sourceinfo/SourceInfoTransform.scala +++ b/macros/src/main/scala/chisel3/internal/sourceinfo/SourceInfoTransform.scala @@ -268,7 +268,7 @@ class IntLiteralApplyTransform(val c: Context) extends AutoSourceTransform { 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) + |If you do want bit extraction, use .extract($arg) instead |""".stripMargin c.warning(c.enclosingPosition, msg) } -- cgit v1.2.3 From 9c79051866743ba5b8f922fc309abc1302ba5547 Mon Sep 17 00:00:00 2001 From: mergify[bot] Date: Wed, 8 Jun 2022 01:29:53 +0000 Subject: Enhance suggestion in literal extract warning (#2569) (#2570) Include the function being called in the suggestion. (cherry picked from commit 296623f6f41eb9f54899277621902679bb6b497c) Co-authored-by: Jack Koenig --- .../main/scala/chisel3/internal/sourceinfo/SourceInfoTransform.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'macros/src/main/scala/chisel3/internal/sourceinfo') diff --git a/macros/src/main/scala/chisel3/internal/sourceinfo/SourceInfoTransform.scala b/macros/src/main/scala/chisel3/internal/sourceinfo/SourceInfoTransform.scala index d77e4f1e..d772fd8b 100644 --- a/macros/src/main/scala/chisel3/internal/sourceinfo/SourceInfoTransform.scala +++ b/macros/src/main/scala/chisel3/internal/sourceinfo/SourceInfoTransform.scala @@ -268,7 +268,7 @@ class IntLiteralApplyTransform(val c: Context) extends AutoSourceTransform { 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 do want bit extraction, use .extract($arg) instead + |If you do want bit extraction, use .$func.extract($arg) instead. |""".stripMargin c.warning(c.enclosingPosition, msg) } -- cgit v1.2.3