aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoralbertchen-sifive2018-10-01 17:23:34 -0700
committerJack Koenig2018-10-01 17:23:34 -0700
commit16f3dbda5c3868419cf78d4d83133cd34adf3303 (patch)
treeff5e28f2b455599a7ebff607c57e3f9fccf406de
parent29e5c0881291b2ab225eb1617592213de611a4a5 (diff)
add BlackBoxPathAnno (#903)
-rw-r--r--src/main/scala/firrtl/transforms/BlackBoxSourceHelper.scala18
-rw-r--r--src/test/scala/firrtlTests/transforms/BlacklBoxSourceHelperSpec.scala39
2 files changed, 56 insertions, 1 deletions
diff --git a/src/main/scala/firrtl/transforms/BlackBoxSourceHelper.scala b/src/main/scala/firrtl/transforms/BlackBoxSourceHelper.scala
index 182accf2..bf419840 100644
--- a/src/main/scala/firrtl/transforms/BlackBoxSourceHelper.scala
+++ b/src/main/scala/firrtl/transforms/BlackBoxSourceHelper.scala
@@ -2,7 +2,7 @@
package firrtl.transforms
-import java.io.{File, FileNotFoundException, FileOutputStream, PrintWriter}
+import java.io.{File, FileNotFoundException, FileInputStream, FileOutputStream, PrintWriter}
import firrtl._
import firrtl.Utils.throwInternalError
@@ -29,6 +29,12 @@ case class BlackBoxInlineAnno(target: ModuleName, name: String, text: String) ex
override def serialize: String = s"inline\n$name\n$text"
}
+case class BlackBoxPathAnno(target: ModuleName, path: String) extends BlackBoxHelperAnno
+ with SingleTargetAnnotation[ModuleName] {
+ def duplicate(n: ModuleName) = this.copy(target = n)
+ override def serialize: String = s"path\n$path"
+}
+
/** Handle source for Verilog ExtModules (BlackBoxes)
*
* This transform handles the moving of Verilog source for black boxes into the
@@ -71,6 +77,16 @@ class BlackBoxSourceHelper extends firrtl.Transform {
val resourceFiles: ListSet[File] = annos.collect {
case BlackBoxResourceAnno(_, resourceId) =>
BlackBoxSourceHelper.writeResourceToDirectory(resourceId, targetDir)
+ case BlackBoxPathAnno(_, path) =>
+ val fileName = path.split("/").last
+ val fromFile = new File(path)
+ val toFile = new File(targetDir, fileName)
+
+ val inputStream = new FileInputStream(fromFile).getChannel
+ val outputStream = new FileOutputStream(toFile).getChannel
+ outputStream.transferFrom(inputStream, 0, Long.MaxValue)
+
+ toFile
}
val inlineFiles: ListSet[File] = annos.collect {
diff --git a/src/test/scala/firrtlTests/transforms/BlacklBoxSourceHelperSpec.scala b/src/test/scala/firrtlTests/transforms/BlacklBoxSourceHelperSpec.scala
index 455ceb3f..7daebf21 100644
--- a/src/test/scala/firrtlTests/transforms/BlacklBoxSourceHelperSpec.scala
+++ b/src/test/scala/firrtlTests/transforms/BlacklBoxSourceHelperSpec.scala
@@ -49,6 +49,45 @@ class BlacklBoxSourceHelperTransformSpec extends LowTransformSpec {
| a1.foo <= x
""".stripMargin
+ "annotated external modules with absolute path" should "appear in output directory" in {
+
+ val absPath = new java.io.File("src/test/resources/blackboxes/AdderExtModule.v").getCanonicalPath
+ val annos = Seq(
+ BlackBoxTargetDirAnno("test_run_dir"),
+ BlackBoxPathAnno(moduleName, absPath)
+ )
+
+ execute(input, output, annos)
+
+ val module = new java.io.File("test_run_dir/AdderExtModule.v")
+ val fileList = new java.io.File(s"test_run_dir/${BlackBoxSourceHelper.fileListName}")
+
+ module.exists should be (true)
+ fileList.exists should be (true)
+
+ module.delete()
+ fileList.delete()
+ }
+
+ "annotated external modules with relative path" should "appear in output directory" in {
+
+ val annos = Seq(
+ BlackBoxTargetDirAnno("test_run_dir"),
+ BlackBoxPathAnno(moduleName, "src/test/resources/blackboxes/AdderExtModule.v")
+ )
+
+ execute(input, output, annos)
+
+ val module = new java.io.File("test_run_dir/AdderExtModule.v")
+ val fileList = new java.io.File(s"test_run_dir/${BlackBoxSourceHelper.fileListName}")
+
+ module.exists should be (true)
+ fileList.exists should be (true)
+
+ module.delete()
+ fileList.delete()
+ }
+
"annotated external modules" should "appear in output directory" in {
val annos = Seq(