util: updates to internal Generator API
This commit is contained in:
parent
bd50a1a4bc
commit
7dad486707
@ -29,25 +29,25 @@ case class ParsedInputNames(
|
|||||||
* canonical ways of building various JVM elaboration-time structures.
|
* canonical ways of building various JVM elaboration-time structures.
|
||||||
*/
|
*/
|
||||||
trait HasGeneratorUtilities {
|
trait HasGeneratorUtilities {
|
||||||
def getConfig(names: ParsedInputNames): Config = {
|
def getConfig(fullConfigClassNames: Seq[String]): Config = {
|
||||||
new Config(names.fullConfigClasses.foldRight(Parameters.empty) { case (currentName, config) =>
|
new Config(fullConfigClassNames.foldRight(Parameters.empty) { case (currentName, config) =>
|
||||||
val currentConfig = try {
|
val currentConfig = try {
|
||||||
Class.forName(currentName).newInstance.asInstanceOf[Config]
|
Class.forName(currentName).newInstance.asInstanceOf[Config]
|
||||||
} catch {
|
} catch {
|
||||||
case e: java.lang.ClassNotFoundException =>
|
case e: java.lang.ClassNotFoundException =>
|
||||||
throwException(s"""Unable to find part "$currentName" from "${names.configs}", did you misspell it?""", e)
|
throwException(s"""Unable to find part "$currentName" from "$fullConfigClassNames", did you misspell it?""", e)
|
||||||
}
|
}
|
||||||
currentConfig ++ config
|
currentConfig ++ config
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
def getParameters(names: ParsedInputNames): Parameters = getParameters(getConfig(names))
|
def getParameters(names: Seq[String]): Parameters = getParameters(getConfig(names))
|
||||||
|
|
||||||
def getParameters(config: Config): Parameters = config.toInstance
|
def getParameters(config: Config): Parameters = config.toInstance
|
||||||
|
|
||||||
def elaborate(names: ParsedInputNames, params: Parameters): Circuit = {
|
def elaborate(fullTopModuleClassName: String, params: Parameters): Circuit = {
|
||||||
val gen = () =>
|
val gen = () =>
|
||||||
Class.forName(names.fullTopModuleClass)
|
Class.forName(fullTopModuleClassName)
|
||||||
.getConstructor(classOf[Parameters])
|
.getConstructor(classOf[Parameters])
|
||||||
.newInstance(params)
|
.newInstance(params)
|
||||||
.asInstanceOf[RawModule]
|
.asInstanceOf[RawModule]
|
||||||
@ -69,16 +69,7 @@ trait HasGeneratorUtilities {
|
|||||||
}
|
}
|
||||||
res.toString
|
res.toString
|
||||||
}
|
}
|
||||||
|
|
||||||
def writeOutputFile(targetDir: String, fname: String, contents: String): File = {
|
|
||||||
val f = new File(targetDir, fname)
|
|
||||||
val fw = new FileWriter(f)
|
|
||||||
fw.write(contents)
|
|
||||||
fw.close
|
|
||||||
f
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/** Standardized command line interface for Scala entry point */
|
/** Standardized command line interface for Scala entry point */
|
||||||
trait GeneratorApp extends App with HasGeneratorUtilities {
|
trait GeneratorApp extends App with HasGeneratorUtilities {
|
||||||
@ -95,10 +86,10 @@ trait GeneratorApp extends App with HasGeneratorUtilities {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Canonical ways of building various JVM elaboration-time structures
|
// Canonical ways of building various JVM elaboration-time structures
|
||||||
lazy val td = names.targetDir
|
lazy val td: String = names.targetDir
|
||||||
lazy val config = getConfig(names)
|
lazy val config: Config = getConfig(names.fullConfigClasses)
|
||||||
lazy val params = config.toInstance
|
lazy val params: Parameters = config.toInstance
|
||||||
lazy val circuit = elaborate(names, params)
|
lazy val circuit: Circuit = elaborate(names.fullTopModuleClass, params)
|
||||||
|
|
||||||
val longName: String // Exhaustive name used to interface with external build tool targets
|
val longName: String // Exhaustive name used to interface with external build tool targets
|
||||||
|
|
||||||
@ -136,6 +127,14 @@ trait GeneratorApp extends App with HasGeneratorUtilities {
|
|||||||
writeOutputFile(td, s"${names.configs}.${extension}", contents ())
|
writeOutputFile(td, s"${names.configs}.${extension}", contents ())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
def writeOutputFile(targetDir: String, fname: String, contents: String): File = {
|
||||||
|
val f = new File(targetDir, fname)
|
||||||
|
val fw = new FileWriter(f)
|
||||||
|
fw.write(contents)
|
||||||
|
fw.close
|
||||||
|
f
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
object ElaborationArtefacts {
|
object ElaborationArtefacts {
|
||||||
|
Loading…
Reference in New Issue
Block a user