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-12 01:15:23 +02:00
|
|
|
import cde.{Parameters, ParameterDump, Config, Field, CDEMatchError, World}
|
2016-08-11 02:20:00 +02:00
|
|
|
import coreplex._
|
|
|
|
|
2016-08-12 01:15:23 +02:00
|
|
|
object GeneratorUtils {
|
|
|
|
def getConfig(projectName: String, configClassName: String): Config = {
|
|
|
|
val aggregateConfigs = configClassName.split('_')
|
2016-08-11 02:20:00 +02:00
|
|
|
|
2016-08-12 01:15:23 +02:00
|
|
|
aggregateConfigs.foldRight(new Config()) { case (currentConfigName, finalConfig) =>
|
|
|
|
val currentConfig = try {
|
|
|
|
Class.forName(s"$projectName.$currentConfigName").newInstance.asInstanceOf[Config]
|
|
|
|
} catch {
|
|
|
|
case e: java.lang.ClassNotFoundException =>
|
|
|
|
throwException("Unable to find part \"" + currentConfigName +
|
|
|
|
"\" of configClassName \"" + configClassName +
|
|
|
|
"\", did you misspell it?", e)
|
|
|
|
}
|
|
|
|
currentConfig ++ finalConfig
|
2016-08-11 02:20:00 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-12 01:15:23 +02:00
|
|
|
def getParameters(config: Config): Parameters =
|
|
|
|
Parameters.root(config.toInstance)
|
2016-08-11 02:20:00 +02:00
|
|
|
|
2016-08-12 01:15:23 +02:00
|
|
|
def getParameters(projectName: String, configClassName: String): Parameters =
|
|
|
|
getParameters(getConfig(projectName, configClassName))
|
2016-08-11 02:20:00 +02:00
|
|
|
|
2016-08-12 01:15:23 +02:00
|
|
|
def elaborate(fullName: String, args: Array[String], params: Parameters) {
|
|
|
|
val gen = () =>
|
|
|
|
Class.forName(fullName)
|
|
|
|
.getConstructor(classOf[cde.Parameters])
|
|
|
|
.newInstance(params)
|
|
|
|
.asInstanceOf[Module]
|
2016-08-11 02:20:00 +02:00
|
|
|
|
2016-08-12 01:15:23 +02:00
|
|
|
chiselMain.run(args, gen)
|
|
|
|
}
|
|
|
|
|
|
|
|
def dumpParameters(fname: String) {
|
|
|
|
val pdFile = TestGeneration.createOutputFile(fname)
|
|
|
|
pdFile.write(ParameterDump.getDump)
|
|
|
|
pdFile.close
|
|
|
|
}
|
|
|
|
|
|
|
|
def dumpKnobs(configClassName: String, world: World) {
|
|
|
|
val knbFile = TestGeneration.createOutputFile(configClassName + ".knb")
|
|
|
|
knbFile.write(world.getKnobs)
|
|
|
|
knbFile.close
|
|
|
|
|
|
|
|
val cstFile = TestGeneration.createOutputFile(configClassName + ".cst")
|
|
|
|
cstFile.write(world.getConstraints)
|
|
|
|
cstFile.close
|
|
|
|
}
|
2016-08-11 02:20:00 +02:00
|
|
|
|
2016-08-12 01:15:23 +02:00
|
|
|
def dumpConfigString(fname: String, params: Parameters) {
|
|
|
|
val cfgFile = new java.io.FileOutputStream(Driver.targetDir + "/" + fname)
|
|
|
|
cfgFile.write(params(ConfigString))
|
|
|
|
cfgFile.close
|
|
|
|
}
|
|
|
|
}
|
|
|
|
import GeneratorUtils._
|
|
|
|
|
|
|
|
object RocketChipGenerator extends App {
|
|
|
|
val projectName = args(0)
|
|
|
|
val topModuleName = args(1)
|
|
|
|
val configClassName = args(2)
|
|
|
|
|
|
|
|
val config = getConfig(projectName, configClassName)
|
|
|
|
val world = config.toInstance
|
|
|
|
val paramsFromConfig = Parameters.root(world)
|
|
|
|
|
|
|
|
elaborate(s"$projectName.$topModuleName", args.drop(3), paramsFromConfig)
|
|
|
|
|
|
|
|
TestGeneration.addSuite(new RegressionTestSuite(paramsFromConfig(RegressionTestNames)))
|
2016-08-11 02:20:00 +02:00
|
|
|
TestGeneration.generateMakefrag(topModuleName, configClassName)
|
|
|
|
|
2016-08-12 01:15:23 +02:00
|
|
|
dumpParameters(s"$topModuleName.$configClassName.prm")
|
|
|
|
dumpKnobs(configClassName, world)
|
|
|
|
dumpConfigString(s"$configClassName.cfg", paramsFromConfig)
|
2016-08-11 02:20:00 +02:00
|
|
|
}
|