summaryrefslogtreecommitdiff
path: root/chiselFrontend/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'chiselFrontend/src/main')
-rw-r--r--chiselFrontend/src/main/scala/chisel3/internal/SourceInfo.scala16
1 files changed, 13 insertions, 3 deletions
diff --git a/chiselFrontend/src/main/scala/chisel3/internal/SourceInfo.scala b/chiselFrontend/src/main/scala/chisel3/internal/SourceInfo.scala
index 5e3bf33e..f1130db4 100644
--- a/chiselFrontend/src/main/scala/chisel3/internal/SourceInfo.scala
+++ b/chiselFrontend/src/main/scala/chisel3/internal/SourceInfo.scala
@@ -19,9 +19,17 @@ import scala.reflect.macros.blackbox.Context
/** Abstract base class for generalized source information.
*/
-sealed trait SourceInfo
+sealed trait SourceInfo {
+ /** A prettier toString
+ *
+ * Make a useful message if SourceInfo is available, nothing otherwise
+ */
+ def makeMessage(f: String => String): String
+}
-sealed trait NoSourceInfo extends SourceInfo
+sealed trait NoSourceInfo extends SourceInfo {
+ def makeMessage(f: String => String): String = ""
+}
/** For when source info can't be generated because of a technical limitation, like for Reg because
* Scala macros don't support named or default arguments.
@@ -34,7 +42,9 @@ case object DeprecatedSourceInfo extends NoSourceInfo
/** For FIRRTL lines from a Scala source line.
*/
-case class SourceLine(filename: String, line: Int, col: Int) extends SourceInfo
+case class SourceLine(filename: String, line: Int, col: Int) extends SourceInfo {
+ def makeMessage(f: String => String): String = f(s"@[$filename $line:$col]")
+}
/** Provides a macro that returns the source information at the invocation point.
*/