stop exceptions on empty conf files (#43)

* stop exceptions on empty conf files

* emit empty verilog file | warn users

* put else's on same line as closing bracket
This commit is contained in:
Abraham Gonzalez
2019-03-18 10:15:50 -07:00
committed by Colin Schmidt
parent de94c2376a
commit 817726ff1f
2 changed files with 21 additions and 4 deletions

View File

@@ -839,6 +839,19 @@ object MacroCompiler extends App {
}
case None =>
}
} else {
// Warn user
System.err println "WARNING: Empty *.mems.conf file. No memories generated."
// Emit empty verilog file if no macros found
params.get(Verilog) match {
case Some(verilogFile: String) => {
// Create an empty verilog file
val verilogWriter = new FileWriter(new File(verilogFile))
verilogWriter.close()
}
case None =>
}
}
} catch {
case e: java.util.NoSuchElementException =>

View File

@@ -47,9 +47,13 @@ object MemConf {
val regex = raw"\s*name\s+(\w+)\s+depth\s+(\d+)\s+width\s+(\d+)\s+ports\s+([^\s]+)\s+(?:mask_gran\s+(\d+))?\s*".r
def fromString(s: String): Seq[MemConf] = {
s.split("\n").toSeq.map(_ match {
case MemConf.regex(name, depth, width, ports, maskGran) => MemConf(name, depth.toInt, width.toInt, MemPort.fromString(ports), Option(maskGran).map(_.toInt))
case _ => throw new Exception(s"Error parsing MemConf string : ${s}")
})
if (s.isEmpty) {
Seq[MemConf]()
} else {
s.split("\n").toSeq.map(_ match {
case MemConf.regex(name, depth, width, ports, maskGran) => MemConf(name, depth.toInt, width.toInt, MemPort.fromString(ports), Option(maskGran).map(_.toInt))
case _ => throw new Exception(s"Error parsing MemConf string : ${s}")
})
}
}
}