summaryrefslogtreecommitdiff
path: root/chiselFrontend/src/main/scala/Chisel/internal/SourceInfo.scala
diff options
context:
space:
mode:
authorJim Lawson2016-06-03 12:38:28 -0700
committerJim Lawson2016-06-03 12:38:28 -0700
commit9dd286b8613beba58e053ed00d15877d3a4b02c9 (patch)
tree6ae9268d8e7e6532e5b8a0f3ad51d6c345623376 /chiselFrontend/src/main/scala/Chisel/internal/SourceInfo.scala
parent70271cd8c3811cb518e81d1d5eb3ed20cb1e2063 (diff)
parentfd53af8642237998e23456a3fd1648ac84607db0 (diff)
Merge branch 'master' into front_end_dependency
Diffstat (limited to 'chiselFrontend/src/main/scala/Chisel/internal/SourceInfo.scala')
-rw-r--r--chiselFrontend/src/main/scala/Chisel/internal/SourceInfo.scala51
1 files changed, 51 insertions, 0 deletions
diff --git a/chiselFrontend/src/main/scala/Chisel/internal/SourceInfo.scala b/chiselFrontend/src/main/scala/Chisel/internal/SourceInfo.scala
new file mode 100644
index 00000000..66bfc7a4
--- /dev/null
+++ b/chiselFrontend/src/main/scala/Chisel/internal/SourceInfo.scala
@@ -0,0 +1,51 @@
+// See LICENSE for license details.
+
+// This file contains macros for adding source locators at the point of invocation.
+//
+// This is not part of coreMacros to disallow this macro from being implicitly invoked in Chisel
+// frontend (and generating source locators in Chisel core), which is almost certainly a bug.
+//
+// Note: While these functions and definitions are not private (macros can't be
+// private), these are NOT meant to be part of the public API (yet) and no
+// forward compatibility guarantees are made.
+// A future revision may stabilize the source locator API to allow library
+// writers to append source locator information at the point of a library
+// function invocation.
+
+package Chisel.internal.sourceinfo
+
+import scala.language.experimental.macros
+import scala.reflect.macros.blackbox.Context
+
+/** Abstract base class for generalized source information.
+ */
+sealed trait SourceInfo
+
+sealed trait NoSourceInfo extends SourceInfo
+
+/** 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.
+ */
+case object UnlocatableSourceInfo extends NoSourceInfo
+
+/** For when source info isn't generated because the function is deprecated and we're lazy.
+ */
+case object DeprecatedSourceInfo extends NoSourceInfo
+
+/** For FIRRTL lines from a Scala source line.
+ */
+case class SourceLine(filename: String, line: Int, col: Int) extends SourceInfo
+
+/** Provides a macro that returns the source information at the invocation point.
+ */
+object SourceInfoMacro {
+ def generate_source_info(c: Context): c.Tree = {
+ import c.universe._
+ val p = c.enclosingPosition
+ q"_root_.Chisel.internal.sourceinfo.SourceLine(${p.source.file.name}, ${p.line}, ${p.column})"
+ }
+}
+
+object SourceInfo {
+ implicit def materialize: SourceInfo = macro SourceInfoMacro.generate_source_info
+}