diff options
| author | mergify[bot] | 2022-06-03 18:33:13 +0000 |
|---|---|---|
| committer | GitHub | 2022-06-03 18:33:13 +0000 |
| commit | 63f25ac4b4d7c9bd530ff1875ad38d835a82e051 (patch) | |
| tree | 51de9ec1f0596a75573d3e9c23868352b0297e09 /macros | |
| parent | 5bec54e535dca53c9347caddb0b395c4651a0919 (diff) | |
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>
Diffstat (limited to 'macros')
| -rw-r--r-- | macros/src/main/scala/chisel3/internal/sourceinfo/SourceInfoTransform.scala | 28 |
1 files changed, 28 insertions, 0 deletions
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)" + } +} |
