aboutsummaryrefslogtreecommitdiff
path: root/src/main/scala/firrtl/features/LetterCaseTransform.scala
blob: 8686908a43db61526d525aaf1d91a9fbdb07fb37 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
// SPDX-License-Identifier: Apache-2.0

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
}