aboutsummaryrefslogtreecommitdiff
path: root/src/main/scala/firrtl/transforms/BlackBoxSourceHelper.scala
diff options
context:
space:
mode:
authorchick2020-08-14 19:47:53 -0700
committerJack Koenig2020-08-14 19:47:53 -0700
commit6fc742bfaf5ee508a34189400a1a7dbffe3f1cac (patch)
tree2ed103ee80b0fba613c88a66af854ae9952610ce /src/main/scala/firrtl/transforms/BlackBoxSourceHelper.scala
parentb516293f703c4de86397862fee1897aded2ae140 (diff)
All of src/ formatted with scalafmt
Diffstat (limited to 'src/main/scala/firrtl/transforms/BlackBoxSourceHelper.scala')
-rw-r--r--src/main/scala/firrtl/transforms/BlackBoxSourceHelper.scala55
1 files changed, 31 insertions, 24 deletions
diff --git a/src/main/scala/firrtl/transforms/BlackBoxSourceHelper.scala b/src/main/scala/firrtl/transforms/BlackBoxSourceHelper.scala
index a57973d5..5000e07a 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, FileInputStream, FileOutputStream, PrintWriter}
+import java.io.{File, FileInputStream, FileNotFoundException, FileOutputStream, PrintWriter}
import firrtl._
import firrtl.annotations._
@@ -11,31 +11,32 @@ import scala.collection.immutable.ListSet
sealed trait BlackBoxHelperAnno extends Annotation
-case class BlackBoxTargetDirAnno(targetDir: String) extends BlackBoxHelperAnno
- with NoTargetAnnotation {
+case class BlackBoxTargetDirAnno(targetDir: String) extends BlackBoxHelperAnno with NoTargetAnnotation {
override def serialize: String = s"targetDir\n$targetDir"
}
-case class BlackBoxResourceAnno(target: ModuleName, resourceId: String) extends BlackBoxHelperAnno
+case class BlackBoxResourceAnno(target: ModuleName, resourceId: String)
+ extends BlackBoxHelperAnno
with SingleTargetAnnotation[ModuleName] {
def duplicate(n: ModuleName) = this.copy(target = n)
override def serialize: String = s"resource\n$resourceId"
}
-case class BlackBoxInlineAnno(target: ModuleName, name: String, text: String) extends BlackBoxHelperAnno
+case class BlackBoxInlineAnno(target: ModuleName, name: String, text: String)
+ extends BlackBoxHelperAnno
with SingleTargetAnnotation[ModuleName] {
def duplicate(n: ModuleName) = this.copy(target = n)
override def serialize: String = s"inline\n$name\n$text"
}
-case class BlackBoxPathAnno(target: ModuleName, path: String) extends BlackBoxHelperAnno
+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"
}
-case class BlackBoxResourceFileNameAnno(resourceFileName: String) extends BlackBoxHelperAnno
- with NoTargetAnnotation {
+case class BlackBoxResourceFileNameAnno(resourceFileName: String) extends BlackBoxHelperAnno with NoTargetAnnotation {
override def serialize: String = s"resourceFileName\n$resourceFileName"
}
@@ -43,8 +44,10 @@ case class BlackBoxResourceFileNameAnno(resourceFileName: String) extends BlackB
* @param fileName the name of the BlackBox file (only used for error message generation)
* @param e an underlying exception that generated this
*/
-class BlackBoxNotFoundException(fileName: String, message: String) extends FirrtlUserException(
- s"BlackBox '$fileName' not found. Did you misspell it? Is it in src/{main,test}/resources?\n$message")
+class BlackBoxNotFoundException(fileName: String, message: String)
+ extends FirrtlUserException(
+ s"BlackBox '$fileName' not found. Did you misspell it? Is it in src/{main,test}/resources?\n$message"
+ )
/** Handle source for Verilog ExtModules (BlackBoxes)
*
@@ -72,15 +75,16 @@ class BlackBoxSourceHelper extends Transform with DependencyAPIMigration {
*/
def collectAnnos(annos: Seq[Annotation]): (ListSet[BlackBoxHelperAnno], File, File) =
annos.foldLeft((ListSet.empty[BlackBoxHelperAnno], DefaultTargetDir, new File(defaultFileListName))) {
- case ((acc, tdir, flistName), anno) => anno match {
- case BlackBoxTargetDirAnno(dir) =>
- val targetDir = new File(dir)
- if (!targetDir.exists()) { FileUtils.makeDirectory(targetDir.getAbsolutePath) }
- (acc, targetDir, flistName)
- case BlackBoxResourceFileNameAnno(fileName) => (acc, tdir, new File(fileName))
- case a: BlackBoxHelperAnno => (acc + a, tdir, flistName)
- case _ => (acc, tdir, flistName)
- }
+ case ((acc, tdir, flistName), anno) =>
+ anno match {
+ case BlackBoxTargetDirAnno(dir) =>
+ val targetDir = new File(dir)
+ if (!targetDir.exists()) { FileUtils.makeDirectory(targetDir.getAbsolutePath) }
+ (acc, targetDir, flistName)
+ case BlackBoxResourceFileNameAnno(fileName) => (acc, tdir, new File(fileName))
+ case a: BlackBoxHelperAnno => (acc + a, tdir, flistName)
+ case _ => (acc, tdir, flistName)
+ }
}
/**
@@ -112,14 +116,15 @@ class BlackBoxSourceHelper extends Transform with DependencyAPIMigration {
case BlackBoxInlineAnno(_, name, text) =>
val outFile = new File(targetDir, name)
(text, outFile)
- }.map { case (text, file) =>
- writeTextToFile(text, file)
- file
+ }.map {
+ case (text, file) =>
+ writeTextToFile(text, file)
+ file
}
// Issue #917 - We don't want to list Verilog header files ("*.vh") in our file list - they will automatically be included by reference.
def isHeader(name: String) = name.endsWith(".h") || name.endsWith(".vh") || name.endsWith(".svh")
- val verilogSourcesOnly = (resourceFiles ++ inlineFiles).filterNot{ f => isHeader(f.getName()) }
+ val verilogSourcesOnly = (resourceFiles ++ inlineFiles).filterNot { f => isHeader(f.getName()) }
val filelistFile = if (flistName.isAbsolute()) flistName else new File(targetDir, flistName.getName())
// We need the canonical path here, so verilator will create a path to the file that works from the targetDir,
@@ -137,12 +142,14 @@ class BlackBoxSourceHelper extends Transform with DependencyAPIMigration {
}
object BlackBoxSourceHelper {
+
/** Safely access a file converting [[FileNotFoundException]]s and [[NullPointerException]]s into
* [[BlackBoxNotFoundException]]s
* @param fileName the name of the file to be accessed (only used for error message generation)
* @param code some code to run
*/
- private def safeFile[A](fileName: String)(code: => A) = try { code } catch {
+ private def safeFile[A](fileName: String)(code: => A) = try { code }
+ catch {
case e @ (_: FileNotFoundException | _: NullPointerException) =>
throw new BlackBoxNotFoundException(fileName, e.getMessage)
}