Skip to content

Commit

Permalink
Merge pull request #1638 from freechipsproject/manipulate-names-issue…
Browse files Browse the repository at this point in the history
…s-refactor

Refactor ManipulateNames to use Target
  • Loading branch information
seldridge authored Jun 25, 2020
2 parents 04f6043 + 72ab5ef commit 672e2a9
Show file tree
Hide file tree
Showing 7 changed files with 924 additions and 216 deletions.
29 changes: 29 additions & 0 deletions src/main/scala/firrtl/features/LetterCaseTransform.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// See LICENSE for license details.

package firrtl.features

import firrtl.Namespace
import firrtl.transforms.ManipulateNames

import scala.reflect.ClassTag

/** Parent of transforms that do change the letter case of names in a FIRRTL circuit */
abstract class LetterCaseTransform[A <: ManipulateNames[_] : ClassTag] extends ManipulateNames[A] {

protected def newName: String => String

final def manipulate = (a: String, ns: Namespace) => newName(a) match {
case `a` => None
case b => Some(ns.newName(b))
}
}

/** Convert all FIRRTL names to lowercase */
final class LowerCaseNames extends LetterCaseTransform[LowerCaseNames] {
override protected def newName = (a: String) => a.toLowerCase
}

/** Convert all FIRRTL names to UPPERCASE */
final class UpperCaseNames extends LetterCaseTransform[UpperCaseNames] {
override protected def newName = (a: String) => a.toUpperCase
}
13 changes: 12 additions & 1 deletion src/main/scala/firrtl/stage/FirrtlAnnotations.scala
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,18 @@ object RunFirrtlTransformAnnotation extends HasShellOptions {
s"Unknown error when instantiating class $txName", e) }),
helpText = "Run these transforms during compilation",
shortOption = Some("fct"),
helpValueName = Some("<package>.<class>") ) )
helpValueName = Some("<package>.<class>") ),
new ShellOption[String](
longOption = "change-name-case",
toAnnotationSeq = _ match {
case "lower" => Seq(RunFirrtlTransformAnnotation(new firrtl.features.LowerCaseNames))
case "upper" => Seq(RunFirrtlTransformAnnotation(new firrtl.features.UpperCaseNames))
case a => throw new OptionsException(s"Unknown case '$a'. Did you misspell it?")
},
helpText = "Convert all FIRRTL names to a specific case",
helpValueName = Some("<lower|upper>")
)
)

}

Expand Down
Loading

0 comments on commit 672e2a9

Please sign in to comment.