2016-08-11 02:20:00 +02:00
|
|
|
// See LICENSE for license details.
|
|
|
|
|
|
|
|
package rocketchip
|
|
|
|
|
|
|
|
import Chisel._
|
|
|
|
import scala.collection.mutable.{LinkedHashSet,LinkedHashMap}
|
2016-08-26 02:26:28 +02:00
|
|
|
import cde._
|
2016-08-11 02:20:00 +02:00
|
|
|
import coreplex._
|
2016-08-26 02:26:28 +02:00
|
|
|
import java.io.{File, FileWriter}
|
|
|
|
|
2016-09-20 21:57:56 +02:00
|
|
|
/** Representation of the information this Generator needs to collect from external sources. */
|
2016-08-26 02:26:28 +02:00
|
|
|
case class ParsedInputNames(
|
|
|
|
targetDir: String,
|
2016-09-20 21:57:56 +02:00
|
|
|
topModuleProject: String,
|
2016-08-26 02:26:28 +02:00
|
|
|
topModuleClass: String,
|
|
|
|
configProject: String,
|
|
|
|
configs: String) {
|
|
|
|
val configClasses: Seq[String] = configs.split('_')
|
|
|
|
val fullConfigClasses: Seq[String] = configClasses.map(configProject + "." + _)
|
2016-09-20 21:57:56 +02:00
|
|
|
val fullTopModuleClass: String = topModuleProject + "." + topModuleClass
|
2016-08-26 02:26:28 +02:00
|
|
|
}
|
2016-08-11 02:20:00 +02:00
|
|
|
|
2016-09-20 21:57:56 +02:00
|
|
|
/** Common utilities we supply to all Generators. In particular, supplies the
|
|
|
|
* canonical ways of building various JVM elaboration-time structures.
|
|
|
|
*/
|
2016-08-26 02:26:28 +02:00
|
|
|
trait HasGeneratorUtilities {
|
|
|
|
def getConfig(names: ParsedInputNames): Config = {
|
|
|
|
names.fullConfigClasses.foldRight(new Config()) { case (currentName, config) =>
|
2016-08-12 01:15:23 +02:00
|
|
|
val currentConfig = try {
|
2016-08-26 02:26:28 +02:00
|
|
|
Class.forName(currentName).newInstance.asInstanceOf[Config]
|
2016-08-12 01:15:23 +02:00
|
|
|
} catch {
|
|
|
|
case e: java.lang.ClassNotFoundException =>
|
2016-08-26 02:26:28 +02:00
|
|
|
throwException(s"""Unable to find part "$currentName" from "${names.configs}", did you misspell it?""", e)
|
2016-08-12 01:15:23 +02:00
|
|
|
}
|
2016-08-26 02:26:28 +02:00
|
|
|
currentConfig ++ config
|
2016-08-11 02:20:00 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-26 02:26:28 +02:00
|
|
|
def getParameters(names: ParsedInputNames): Parameters = getParameters(getConfig(names))
|
2016-08-11 02:20:00 +02:00
|
|
|
|
2016-08-26 02:26:28 +02:00
|
|
|
def getParameters(config: Config): Parameters = Parameters.root(config.toInstance)
|
2016-08-11 02:20:00 +02:00
|
|
|
|
2016-08-26 02:26:28 +02:00
|
|
|
import chisel3.internal.firrtl.Circuit
|
|
|
|
def elaborate(names: ParsedInputNames, params: Parameters): Circuit = {
|
2016-08-12 01:15:23 +02:00
|
|
|
val gen = () =>
|
2016-08-26 02:26:28 +02:00
|
|
|
Class.forName(names.fullTopModuleClass)
|
2016-08-12 01:15:23 +02:00
|
|
|
.getConstructor(classOf[cde.Parameters])
|
|
|
|
.newInstance(params)
|
|
|
|
.asInstanceOf[Module]
|
2016-08-11 02:20:00 +02:00
|
|
|
|
2016-08-26 02:26:28 +02:00
|
|
|
Driver.elaborate(gen)
|
2016-08-12 01:15:23 +02:00
|
|
|
}
|
|
|
|
|
2016-08-26 02:26:28 +02: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-12 01:15:23 +02:00
|
|
|
}
|
2016-08-26 02:26:28 +02:00
|
|
|
}
|
2016-08-11 02:20:00 +02:00
|
|
|
|
2016-09-15 09:38:46 +02:00
|
|
|
|
2016-09-20 21:57:56 +02:00
|
|
|
/** Standardized command line interface for Scala entry point */
|
2016-08-26 02:26:28 +02:00
|
|
|
trait Generator extends App with HasGeneratorUtilities {
|
2016-09-20 21:57:56 +02:00
|
|
|
lazy val names: ParsedInputNames = {
|
2016-08-26 02:26:28 +02:00
|
|
|
require(args.size == 5, "Usage: sbt> " +
|
|
|
|
"run TargetDir TopModuleProjectName TopModuleName ConfigProjectName ConfigNameString")
|
|
|
|
ParsedInputNames(
|
|
|
|
targetDir = args(0),
|
2016-09-20 21:57:56 +02:00
|
|
|
topModuleProject = args(1),
|
2016-08-26 02:26:28 +02:00
|
|
|
topModuleClass = args(2),
|
|
|
|
configProject = args(3),
|
|
|
|
configs = args(4))
|
2016-08-12 01:15:23 +02:00
|
|
|
}
|
2016-09-15 09:38:46 +02:00
|
|
|
|
2016-09-20 21:57:56 +02:00
|
|
|
// Canonical ways of building various JVM elaboration-time structures
|
2016-09-15 09:38:46 +02:00
|
|
|
lazy val td = names.targetDir
|
2016-08-26 02:26:28 +02:00
|
|
|
lazy val config = getConfig(names)
|
|
|
|
lazy val world = config.toInstance
|
|
|
|
lazy val params = Parameters.root(world)
|
|
|
|
lazy val circuit = elaborate(names, params)
|
2016-09-15 09:38:46 +02:00
|
|
|
|
2016-09-20 21:57:56 +02:00
|
|
|
val longName: String // Exhaustive name used to interface with external build tool targets
|
|
|
|
|
|
|
|
/** Output FIRRTL, which an external compiler can turn into Verilog. */
|
|
|
|
def generateFirrtl {
|
|
|
|
Driver.dumpFirrtl(circuit, Some(new File(td, s"$longName.fir"))) // FIRRTL
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Output software test Makefrags, which provide targets for integration testing. */
|
|
|
|
def generateTestSuiteMakefrags {
|
2016-09-15 09:38:46 +02:00
|
|
|
TestGeneration.addSuite(new RegressionTestSuite(params(RegressionTestNames)))
|
|
|
|
writeOutputFile(td, s"$longName.d", TestGeneration.generateMakefrag) // Coreplex-specific test suites
|
2016-09-20 21:57:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/** Output Design Space Exploration knobs and constraints. */
|
|
|
|
def generateDSEConstraints {
|
2016-09-15 09:38:46 +02:00
|
|
|
writeOutputFile(td, s"${names.configs}.knb", world.getKnobs) // Knobs for DSE
|
|
|
|
writeOutputFile(td, s"${names.configs}.cst", world.getConstraints) // Constraints for DSE
|
2016-09-20 21:57:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/** Output a global Parameter dump, which an external script can turn into Verilog headers. */
|
|
|
|
def generateParameterDump {
|
|
|
|
writeOutputFile(td, s"$longName.prm", ParameterDump.getDump) // Parameters flagged with Dump()
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Output a global ConfigString, for use by the RISC-V software ecosystem. */
|
|
|
|
def generateConfigString {
|
2016-09-15 09:38:46 +02:00
|
|
|
ConfigStringOutput.contents.foreach(c => writeOutputFile(td, s"${names.configs}.cfg", c)) // String for software
|
|
|
|
}
|
2016-08-12 01:15:23 +02:00
|
|
|
}
|
2016-08-11 02:20:00 +02:00
|
|
|
|
2016-09-20 21:57:56 +02:00
|
|
|
object ConfigStringOutput {
|
|
|
|
var contents: Option[String] = None
|
|
|
|
}
|
|
|
|
|
|
|
|
/** An example Generator */
|
|
|
|
object RocketChipGenerator extends Generator
|
|
|
|
{
|
|
|
|
val longName = names.topModuleProject + "." + names.configs
|
|
|
|
generateFirrtl
|
|
|
|
generateTestSuiteMakefrags
|
|
|
|
generateDSEConstraints
|
|
|
|
generateConfigString
|
|
|
|
generateParameterDump
|
2016-08-11 02:20:00 +02:00
|
|
|
}
|