diff options
| author | Jared Barocsi | 2021-07-29 16:31:08 -0700 |
|---|---|---|
| committer | GitHub | 2021-07-29 16:31:08 -0700 |
| commit | 04210ee30acd437bccfe694ddd895e5f450ba01f (patch) | |
| tree | 18212689f16299da9b3df210b92f6a2353c60e9b /src/main/scala/firrtl/Utils.scala | |
| parent | 2630537cf956eea3768c5bd8e57de839f7d3700a (diff) | |
Dedup attribute annos (#2297)
* Add new util "groupByIntoSeq"
* Restore annotation order when dedupping annotations
* Attribute annotations now deduplicate
* Implement doc string anno dedup
Co-authored-by: Jack Koenig <koenig@sifive.com>
Diffstat (limited to 'src/main/scala/firrtl/Utils.scala')
| -rw-r--r-- | src/main/scala/firrtl/Utils.scala | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/src/main/scala/firrtl/Utils.scala b/src/main/scala/firrtl/Utils.scala index e29c1a3b..e2bb06ff 100644 --- a/src/main/scala/firrtl/Utils.scala +++ b/src/main/scala/firrtl/Utils.scala @@ -967,6 +967,17 @@ object Utils extends LazyLogging { Mux(cond, tval, fval, tval.tpe) } + /** Similar to Seq.groupBy except that it preserves ordering of elements within each group */ + def groupByIntoSeq[A, K](xs: Iterable[A])(f: A => K): Seq[(K, Seq[A])] = { + val map = mutable.LinkedHashMap.empty[K, mutable.ListBuffer[A]] + for (x <- xs) { + val key = f(x) + val l = map.getOrElseUpdate(key, mutable.ListBuffer.empty[A]) + l += x + } + map.view.map({ case (k, vs) => k -> vs.toList }).toList + } + object True { private val _True = UIntLiteral(1, IntWidth(1)) |
