summaryrefslogtreecommitdiff
path: root/src/main
diff options
context:
space:
mode:
authorAndrew Waterman2016-02-03 23:51:06 -0800
committerAndrew Waterman2016-02-03 23:51:06 -0800
commitc5240a3bfe1c05a206c7c34c3c7c5007bbcc3680 (patch)
tree89893f19fba9aacc7e18ba8013b428e9f1e03482 /src/main
parent898efea92e9e13775b39dd7fb92cac420334b9c9 (diff)
parent7fc2ea6a14da441db9c47d094361fea07436f6d3 (diff)
Merge branch 'master' into blackbox
Diffstat (limited to 'src/main')
-rw-r--r--src/main/scala/Chisel/CoreUtil.scala41
-rw-r--r--src/main/scala/Chisel/Driver.scala3
-rw-r--r--src/main/scala/Chisel/FileSystemUtilities.scala10
-rw-r--r--src/main/scala/Chisel/Main.scala8
-rw-r--r--src/main/scala/Chisel/throwException.scala11
5 files changed, 62 insertions, 11 deletions
diff --git a/src/main/scala/Chisel/CoreUtil.scala b/src/main/scala/Chisel/CoreUtil.scala
index eed90410..0dc90c29 100644
--- a/src/main/scala/Chisel/CoreUtil.scala
+++ b/src/main/scala/Chisel/CoreUtil.scala
@@ -6,6 +6,9 @@ import internal._
import internal.Builder.pushCommand
import internal.firrtl._
+import scala.language.experimental.macros
+import scala.reflect.macros.blackbox.Context
+
object assert {
/** Checks for a condition to be valid in the circuit at all times. If the
* condition evaluates to false, the circuit simulation stops with an error.
@@ -20,26 +23,42 @@ object assert {
*
* @param cond condition, assertion fires (simulation fails) when false
* @param message optional message to print when the assertion fires
+ *
+ * @note currently cannot be used in core Chisel / libraries because macro
+ * defs need to be compiled first and the SBT project is not set up to do
+ * that
*/
- def apply(cond: Bool, message: String) {
+ def apply(cond: Bool, message: String): Unit = macro apply_impl_msg
+ def apply(cond: Bool): Unit = macro apply_impl // macros currently can't take default arguments
+
+ def apply_impl_msg(c: Context)(cond: c.Tree, message: c.Tree): c.Tree = {
+ import c.universe._
+ val p = c.enclosingPosition
+ val condStr = s"${p.source.file.name}:${p.line} ${p.lineContent.trim}"
+ val apply_impl_do = symbolOf[this.type].asClass.module.info.member(TermName("apply_impl_do"))
+ q"$apply_impl_do($cond, $condStr, _root_.scala.Some($message))"
+ }
+
+ def apply_impl(c: Context)(cond: c.Tree): c.Tree = {
+ import c.universe._
+ val p = c.enclosingPosition
+ val condStr = s"${p.source.file.name}:${p.line} ${p.lineContent.trim}"
+ val apply_impl_do = symbolOf[this.type].asClass.module.info.member(TermName("apply_impl_do"))
+ q"$apply_impl_do($cond, $condStr, _root_.scala.None)"
+ }
+
+ def apply_impl_do(cond: Bool, line: String, message: Option[String]) {
when (!Builder.dynamicContext.currentModule.get.reset) {
when(!cond) {
- if (message.isEmpty()) {
- printf(s"Assertion failed: (TODO: code / lineno)")
- } else {
- printf(s"Assertion failed: (TODO: code / lineno): $message")
+ message match {
+ case Some(str) => printf(s"Assertion failed: $line: $str\n")
+ case None => printf(s"Assertion failed: $line\n")
}
pushCommand(Stop(Node(Builder.dynamicContext.currentModule.get.clock), 1))
}
}
}
- /** A workaround for default-value overloading problems in Scala, just
- * 'assert(cond, "")' */
- def apply(cond: Bool) {
- assert(cond, "")
- }
-
/** An elaboration-time assertion, otherwise the same as the above run-time
* assertion. */
def apply(cond: Boolean, message: String) {
diff --git a/src/main/scala/Chisel/Driver.scala b/src/main/scala/Chisel/Driver.scala
index 6a5e2095..a6f61f69 100644
--- a/src/main/scala/Chisel/Driver.scala
+++ b/src/main/scala/Chisel/Driver.scala
@@ -113,4 +113,7 @@ object Driver extends BackendCompilationUtilities {
w.close()
f
}
+
+ // FIXME: This is hard coded and should come in from a command-line argument
+ def targetDir(): String = { "vsim/generated-src" }
}
diff --git a/src/main/scala/Chisel/FileSystemUtilities.scala b/src/main/scala/Chisel/FileSystemUtilities.scala
new file mode 100644
index 00000000..efb7178d
--- /dev/null
+++ b/src/main/scala/Chisel/FileSystemUtilities.scala
@@ -0,0 +1,10 @@
+// See LICENSE for details
+
+package Chisel
+
+@deprecated("FileSystemUtilities doesn't exist in chisel3", "3.0.0")
+trait FileSystemUtilities {
+ def createOutputFile(name: String) = {
+ new java.io.FileWriter(Driver.targetDir + "/" + name)
+ }
+}
diff --git a/src/main/scala/Chisel/Main.scala b/src/main/scala/Chisel/Main.scala
index 23abc763..750e8712 100644
--- a/src/main/scala/Chisel/Main.scala
+++ b/src/main/scala/Chisel/Main.scala
@@ -2,7 +2,15 @@
package Chisel
+import java.io.File
+
@deprecated("chiselMain doesn't exist in Chisel3", "3.0") object chiselMain {
def apply[T <: Module](args: Array[String], gen: () => T) =
Predef.assert(false)
+
+ def run[T <: Module] (args: Array[String], gen: () => T) = {
+ def circuit = Driver.elaborate(gen)
+ def output_file = new File(Driver.targetDir + "/" + circuit.name + ".fir")
+ Driver.dumpFirrtl(circuit, Option(output_file))
+ }
}
diff --git a/src/main/scala/Chisel/throwException.scala b/src/main/scala/Chisel/throwException.scala
new file mode 100644
index 00000000..998b2cd6
--- /dev/null
+++ b/src/main/scala/Chisel/throwException.scala
@@ -0,0 +1,11 @@
+// See LICENSE for details
+
+package Chisel
+
+@deprecated("throwException doesn't exist in Chisel3", "3.0.0")
+object throwException {
+ def apply(s: String, t: Throwable = null) = {
+ val xcpt = new Exception(s, t)
+ throw xcpt
+ }
+}