regmapper: refactor how json is emitted
This commit is contained in:
23
src/main/scala/regmapper/Annotation.scala
Normal file
23
src/main/scala/regmapper/Annotation.scala
Normal file
@ -0,0 +1,23 @@
|
||||
// See LICENSE.SiFive for license details.
|
||||
|
||||
package freechips.rocketchip.regmapper
|
||||
|
||||
import org.json4s.JsonDSL._
|
||||
import org.json4s.jackson.JsonMethods.{pretty, render}
|
||||
|
||||
object RegMappingAnnotation {
|
||||
def serialize(base: BigInt, name: String, mapping: RegField.Map*): String = {
|
||||
val regDescs = mapping.flatMap { case (byte, seq) =>
|
||||
seq.map(_.width).scanLeft(0)(_ + _).zip(seq).map { case (bit, f) =>
|
||||
val anonName = s"unnamedRegField${byte.toHexString}_${bit}"
|
||||
(f.desc.map{ _.name}.getOrElse(anonName)) -> f.toJson(byte, bit)
|
||||
}
|
||||
}
|
||||
|
||||
pretty(render(
|
||||
("peripheral" -> (
|
||||
("displayName" -> name) ~
|
||||
("baseAddress" -> s"0x${base.toInt.toHexString}") ~
|
||||
("regfields" -> regDescs)))))
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user