2016-08-10 17:20:00 -07:00
|
|
|
// See LICENSE for license details.
|
|
|
|
|
|
|
|
package rocketchip
|
|
|
|
|
|
|
|
import Chisel._
|
|
|
|
import scala.collection.mutable.{LinkedHashSet,LinkedHashMap}
|
2016-08-25 17:26:28 -07:00
|
|
|
import cde._
|
2016-08-10 17:20:00 -07:00
|
|
|
import coreplex._
|
2016-08-25 17:26:28 -07:00
|
|
|
import java.io.{File, FileWriter}
|
|
|
|
|
|
|
|
case class ParsedInputNames(
|
|
|
|
targetDir: String,
|
|
|
|
topProject: String,
|
|
|
|
topModuleClass: String,
|
|
|
|
configProject: String,
|
|
|
|
configs: String) {
|
|
|
|
val configClasses: Seq[String] = configs.split('_')
|
|
|
|
val fullConfigClasses: Seq[String] = configClasses.map(configProject + "." + _)
|
|
|
|
val fullTopModuleClass: String = topProject + "." + topModuleClass
|
|
|
|
}
|
2016-08-10 17:20:00 -07:00
|
|
|
|
2016-08-25 17:26:28 -07:00
|
|
|
trait HasGeneratorUtilities {
|
|
|
|
def getConfig(names: ParsedInputNames): Config = {
|
|
|
|
names.fullConfigClasses.foldRight(new Config()) { case (currentName, config) =>
|
2016-08-11 16:15:23 -07:00
|
|
|
val currentConfig = try {
|
2016-08-25 17:26:28 -07:00
|
|
|
Class.forName(currentName).newInstance.asInstanceOf[Config]
|
2016-08-11 16:15:23 -07:00
|
|
|
} catch {
|
|
|
|
case e: java.lang.ClassNotFoundException =>
|
2016-08-25 17:26:28 -07:00
|
|
|
throwException(s"""Unable to find part "$currentName" from "${names.configs}", did you misspell it?""", e)
|
2016-08-11 16:15:23 -07:00
|
|
|
}
|
2016-08-25 17:26:28 -07:00
|
|
|
currentConfig ++ config
|
2016-08-10 17:20:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-25 17:26:28 -07:00
|
|
|
def getParameters(names: ParsedInputNames): Parameters = getParameters(getConfig(names))
|
2016-08-10 17:20:00 -07:00
|
|
|
|
2016-08-25 17:26:28 -07:00
|
|
|
def getParameters(config: Config): Parameters = Parameters.root(config.toInstance)
|
2016-08-10 17:20:00 -07:00
|
|
|
|
2016-08-25 17:26:28 -07:00
|
|
|
import chisel3.internal.firrtl.Circuit
|
|
|
|
def elaborate(names: ParsedInputNames, params: Parameters): Circuit = {
|
2016-08-11 16:15:23 -07:00
|
|
|
val gen = () =>
|
2016-08-25 17:26:28 -07:00
|
|
|
Class.forName(names.fullTopModuleClass)
|
2016-08-11 16:15:23 -07:00
|
|
|
.getConstructor(classOf[cde.Parameters])
|
|
|
|
.newInstance(params)
|
|
|
|
.asInstanceOf[Module]
|
2016-08-10 17:20:00 -07:00
|
|
|
|
2016-08-25 17:26:28 -07:00
|
|
|
Driver.elaborate(gen)
|
2016-08-11 16:15:23 -07:00
|
|
|
}
|
|
|
|
|
2016-08-25 17:26:28 -07:00
|
|
|
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
|
2016-08-11 16:15:23 -07:00
|
|
|
}
|
2016-08-25 17:26:28 -07:00
|
|
|
}
|
2016-08-10 17:20:00 -07:00
|
|
|
|
2016-08-25 17:26:28 -07:00
|
|
|
trait Generator extends App with HasGeneratorUtilities {
|
|
|
|
lazy val names = {
|
|
|
|
require(args.size == 5, "Usage: sbt> " +
|
|
|
|
"run TargetDir TopModuleProjectName TopModuleName ConfigProjectName ConfigNameString")
|
|
|
|
ParsedInputNames(
|
|
|
|
targetDir = args(0),
|
|
|
|
topProject = args(1),
|
|
|
|
topModuleClass = args(2),
|
|
|
|
configProject = args(3),
|
|
|
|
configs = args(4))
|
2016-08-11 16:15:23 -07:00
|
|
|
}
|
2016-08-25 17:26:28 -07:00
|
|
|
lazy val config = getConfig(names)
|
|
|
|
lazy val world = config.toInstance
|
|
|
|
lazy val params = Parameters.root(world)
|
|
|
|
lazy val circuit = elaborate(names, params)
|
2016-08-11 16:15:23 -07:00
|
|
|
}
|
2016-08-10 17:20:00 -07:00
|
|
|
|
2016-08-25 17:26:28 -07:00
|
|
|
object RocketChipGenerator extends Generator {
|
|
|
|
val longName = names.topModuleClass + "." + names.configs
|
|
|
|
val td = names.targetDir
|
|
|
|
Driver.dumpFirrtl(circuit, Some(new File(td, s"$longName.fir"))) // FIRRTL
|
|
|
|
TestGeneration.addSuite(new RegressionTestSuite(params(RegressionTestNames)))
|
|
|
|
writeOutputFile(td, s"$longName.d", TestGeneration.generateMakefrag) // Coreplex-specific test suites
|
|
|
|
writeOutputFile(td, s"$longName.prm", ParameterDump.getDump) // Parameters flagged with Dump()
|
|
|
|
writeOutputFile(td, s"${names.configs}.knb", world.getKnobs) // Knobs for DSE
|
|
|
|
writeOutputFile(td, s"${names.configs}.cst", world.getConstraints) // Constraints for DSE
|
2016-09-10 23:39:29 -07:00
|
|
|
writeOutputFile(td, s"${names.configs}.cfg", params(ConfigString).get) // String for software
|
2016-08-10 17:20:00 -07:00
|
|
|
}
|