From b95f68447f47ae2a1ec0038c5a706ec6f72d0561 Mon Sep 17 00:00:00 2001 From: Megan Wachs Date: Thu, 15 Feb 2018 14:01:47 -0800 Subject: [PATCH] RegFieldDesc: Prevent different RegField JSONS from overwriting eachother. --- src/main/scala/tilelink/RegisterRouter.scala | 7 ++++++- src/main/scala/util/GeneratorUtils.scala | 7 ++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/main/scala/tilelink/RegisterRouter.scala b/src/main/scala/tilelink/RegisterRouter.scala index 2d99a693..dc5b6319 100644 --- a/src/main/scala/tilelink/RegisterRouter.scala +++ b/src/main/scala/tilelink/RegisterRouter.scala @@ -111,7 +111,12 @@ case class TLRegisterNode( ("baseAddress" -> base) ~ ("regfields" -> regDescs) )) - ElaborationArtefacts.add(s"${base}.regmap.json", pretty(render(json))) + + var suffix = 0 + while( ElaborationArtefacts.contains(s"${base}.${suffix}.regmap.json")){ + suffix = suffix + 1 + } + ElaborationArtefacts.add(s"${base}.${suffix}regmap.json", pretty(render(json))) } } diff --git a/src/main/scala/util/GeneratorUtils.scala b/src/main/scala/util/GeneratorUtils.scala index c7830ddf..8d9d9339 100644 --- a/src/main/scala/util/GeneratorUtils.scala +++ b/src/main/scala/util/GeneratorUtils.scala @@ -139,7 +139,12 @@ trait GeneratorApp extends App with HasGeneratorUtilities { object ElaborationArtefacts { var files: Seq[(String, () => String)] = Nil - def add(extension: String, contents: => String) { + + def add(extension: String, contents: => String) = { files = (extension, () => contents) +: files } + + def contains(extension: String): Boolean = { + files.foldLeft(false)((t, s) => {s._1 == extension | t}) + } }