Allow CreateParametersInstancePhase.getParameters to be reused (#1251)

Turned the method static to allow its reuse by other passes.
This commit is contained in:
Nandor Licker 2022-10-07 10:59:12 +03:00 committed by GitHub
parent e97982e0d9
commit a1d187b3a3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 21 additions and 17 deletions

View File

@ -13,13 +13,12 @@ import java.io.{File}
case class ConfigParametersAnnotation(p: Parameters) extends NoTargetAnnotation with Unserializable
class CreateParametersInstancePhase extends Phase with PreservesAll[Phase] {
override val prerequisites = Seq(Dependency(midas.stage.Checks))
// This copies the rocketChip get config code, but adds support for looking up a config class
// from one of many packages
def getConfigWithFallback(packages: Seq[String], configNames: Seq[String]): Config = {
object CreateParametersFromConfigString {
/**
* This copies the rocketChip get config code, but adds support for looking up a config class
* from one of many packages
*/
private def getConfigWithFallback(packages: Seq[String], configNames: Seq[String]): Config = {
// Recursively try to lookup config in a set of scala packages
def getConfig(remainingPackages: Seq[String], configName: String): Config = remainingPackages match {
// No fallback packages left
@ -42,18 +41,23 @@ class CreateParametersInstancePhase extends Phase with PreservesAll[Phase] {
})
}
// For host configurations, look up configs in one of three places:
// 1) The user specified project (eg. firesim.firesim)
// 2) firesim.configs -> Legacy SimConfigs
// 3) firesim.util -> this has a bunch of target agnostic configurations, like host frequency
// 4) midas -> This has debug features, etc
// Allows the user to concatenate configs together from different packages
// without needing to fully specify the class name for each config
// eg. FireSimConfig_F90MHz maps to: firesim.firesim.FiresimConfig_firesim.util.F90MHz
def getParameters(configProject: String, configClasses: Seq[String]): Parameters = {
/**
* Returns the parameters associated with a configuration.
*
* For host configurations, look up configs in one of three places:
* 1) The user specified project (eg. firesim.firesim)
* 2) firesim.configs -> Legacy SimConfigs
* 3) firesim.util -> this has a bunch of target agnostic configurations, like host frequency
* 4) midas -> This has debug features, etc
*/
def apply(configProject: String, configClasses: Seq[String]): Parameters = {
val packages = (configProject +: Seq("firesim.configs", "firesim.util", "midas")).distinct
new Config(getConfigWithFallback(packages, configClasses))
}
}
class CreateParametersInstancePhase extends Phase with PreservesAll[Phase] {
override val prerequisites = Seq(Dependency(midas.stage.Checks))
override def transform(annotations: AnnotationSeq): AnnotationSeq = {
val configPackage = annotations.collectFirst({ case ConfigPackageAnnotation(p) => p }).get
@ -62,7 +66,7 @@ class CreateParametersInstancePhase extends Phase with PreservesAll[Phase] {
// The output directory is specified on the command line; put it in the
// parameters object so it is visible to chisel elaborations.
val p = getParameters(configPackage, configClasses).alterPartial({ case OutputDir => targetDir })
val p = CreateParametersFromConfigString(configPackage, configClasses).alterPartial({ case OutputDir => targetDir })
ConfigParametersAnnotation(p) +: annotations
}
}