summaryrefslogtreecommitdiff
path: root/chiselFrontend/src/main/scala/chisel3/internal/Error.scala
diff options
context:
space:
mode:
Diffstat (limited to 'chiselFrontend/src/main/scala/chisel3/internal/Error.scala')
-rw-r--r--chiselFrontend/src/main/scala/chisel3/internal/Error.scala62
1 files changed, 48 insertions, 14 deletions
diff --git a/chiselFrontend/src/main/scala/chisel3/internal/Error.scala b/chiselFrontend/src/main/scala/chisel3/internal/Error.scala
index 2346181a..07f4db73 100644
--- a/chiselFrontend/src/main/scala/chisel3/internal/Error.scala
+++ b/chiselFrontend/src/main/scala/chisel3/internal/Error.scala
@@ -6,7 +6,38 @@ import scala.collection.mutable.{ArrayBuffer, LinkedHashMap}
import chisel3.core._
-class ChiselException(message: String, cause: Throwable) extends Exception(message, cause)
+class ChiselException(message: String, cause: Throwable = null) extends Exception(message, cause) {
+
+ val blacklistPackages = Set("chisel3", "scala", "java", "sun", "sbt")
+ val builderName = "chisel3.internal.Builder"
+
+ /** trims the top of the stack of elements belonging to [[blacklistPackages]]
+ * then trims the bottom elements until it reaches [[builderName]]
+ * then continues trimming elements belonging to [[blacklistPackages]]
+ */
+ def trimmedStackTrace: Array[StackTraceElement] = {
+ def isBlacklisted(ste: StackTraceElement) = {
+ val packageName = ste.getClassName().takeWhile(_ != '.')
+ blacklistPackages.contains(packageName)
+ }
+
+ val trimmedLeft = getStackTrace().view.dropWhile(isBlacklisted)
+ val trimmedReverse = trimmedLeft.reverse
+ .dropWhile(ste => !ste.getClassName.startsWith(builderName))
+ .dropWhile(isBlacklisted)
+ trimmedReverse.reverse.toArray
+ }
+
+ def chiselStackTrace: String = {
+ val trimmed = trimmedStackTrace
+ val sw = new java.io.StringWriter
+ sw.write(toString + "\n")
+ sw.write("\t...\n")
+ trimmed.foreach(ste => sw.write(s"\tat $ste\n"))
+ sw.write("\t... (Stack trace trimmed to user code only, rerun with --full-stacktrace if you wish to see the full stack trace)\n")
+ sw.toString
+ }
+}
private[chisel3] object throwException {
def apply(s: String, t: Throwable = null): Nothing =
@@ -14,6 +45,12 @@ private[chisel3] object throwException {
}
/** Records and reports runtime errors and warnings. */
+private[chisel3] object ErrorLog {
+ val depTag = s"[${Console.BLUE}deprecated${Console.RESET}]"
+ val warnTag = s"[${Console.YELLOW}warn${Console.RESET}]"
+ val errTag = s"[${Console.RED}error${Console.RESET}]"
+}
+
private[chisel3] class ErrorLog {
/** Log an error message */
def error(m: => String): Unit =
@@ -43,33 +80,30 @@ private[chisel3] class ErrorLog {
/** Throw an exception if any errors have yet occurred. */
def checkpoint(): Unit = {
- val depTag = s"[${Console.BLUE}deprecated${Console.RESET}]"
- val warnTag = s"[${Console.YELLOW}warn${Console.RESET}]"
- val errTag = s"[${Console.RED}error${Console.RESET}]"
deprecations.foreach { case ((message, sourceLoc), count) =>
- println(s"$depTag $sourceLoc ($count calls): $message")
+ println(s"${ErrorLog.depTag} $sourceLoc ($count calls): $message")
}
errors foreach println
if (!deprecations.isEmpty) {
- println(s"$warnTag ${Console.YELLOW}There were ${deprecations.size} deprecated function(s) used." +
+ println(s"${ErrorLog.warnTag} ${Console.YELLOW}There were ${deprecations.size} deprecated function(s) used." +
s" These may stop compiling in a future release - you are encouraged to fix these issues.${Console.RESET}")
- println(s"$warnTag Line numbers for deprecations reported by Chisel may be inaccurate; enable scalac compiler deprecation warnings via either of the following methods:")
- println(s"$warnTag In the sbt interactive console, enter:")
- println(s"""$warnTag set scalacOptions in ThisBuild ++= Seq("-unchecked", "-deprecation")""")
- println(s"$warnTag or, in your build.sbt, add the line:")
- println(s"""$warnTag scalacOptions := Seq("-unchecked", "-deprecation")""")
+ println(s"${ErrorLog.warnTag} Line numbers for deprecations reported by Chisel may be inaccurate; enable scalac compiler deprecation warnings via either of the following methods:")
+ println(s"${ErrorLog.warnTag} In the sbt interactive console, enter:")
+ println(s"""${ErrorLog.warnTag} set scalacOptions in ThisBuild ++= Seq("-unchecked", "-deprecation")""")
+ println(s"${ErrorLog.warnTag} or, in your build.sbt, add the line:")
+ println(s"""${ErrorLog.warnTag} scalacOptions := Seq("-unchecked", "-deprecation")""")
}
val allErrors = errors.filter(_.isFatal)
val allWarnings = errors.filter(!_.isFatal)
if (!allWarnings.isEmpty && !allErrors.isEmpty) {
- println(s"$errTag There were ${Console.RED}${allErrors.size} error(s)${Console.RESET} and ${Console.YELLOW}${allWarnings.size} warning(s)${Console.RESET} during hardware elaboration.")
+ println(s"${ErrorLog.errTag} There were ${Console.RED}${allErrors.size} error(s)${Console.RESET} and ${Console.YELLOW}${allWarnings.size} warning(s)${Console.RESET} during hardware elaboration.")
} else if (!allWarnings.isEmpty) {
- println(s"$warnTag There were ${Console.YELLOW}${allWarnings.size} warning(s)${Console.RESET} during hardware elaboration.")
+ println(s"${ErrorLog.warnTag} There were ${Console.YELLOW}${allWarnings.size} warning(s)${Console.RESET} during hardware elaboration.")
} else if (!allErrors.isEmpty) {
- println(s"$errTag There were ${Console.RED}${allErrors.size} error(s)${Console.RESET} during hardware elaboration.")
+ println(s"${ErrorLog.errTag} There were ${Console.RED}${allErrors.size} error(s)${Console.RESET} during hardware elaboration.")
}
if (!allErrors.isEmpty) {