diff options
| author | Adam Izraelevitz | 2016-10-17 18:53:19 -0700 |
|---|---|---|
| committer | Angie Wang | 2016-10-17 18:53:19 -0700 |
| commit | 85baeda249e59c7d9d9f159aaf29ff46d685cf02 (patch) | |
| tree | cfb5f4a6a0a80f9033275de6e5e36b9d5b96faad /src/main/scala/firrtl/passes/memlib/YamlUtils.scala | |
| parent | 7d08b9a1486fef0459481f6e542464a29fbe1db5 (diff) | |
Reorganized memory blackboxing (#336)
* Reorganized memory blackboxing
Moved to new package memlib
Added comments
Moved utility functions around
Removed unused AnnotateValidMemConfigs.scala
* Fixed tests to pass
* Use DefAnnotatedMemory instead of AppendableInfo
* Broke passes up into simpler passes
AnnotateMemMacros ->
(ToMemIR, ResolveMaskGranularity)
UpdateDuplicateMemMacros ->
(RenameAnnotatedMemoryPorts, ResolveMemoryReference)
* Fixed to make tests run
* Minor changes from code review
* Removed vim comments and renamed ReplSeqMem
Diffstat (limited to 'src/main/scala/firrtl/passes/memlib/YamlUtils.scala')
| -rw-r--r-- | src/main/scala/firrtl/passes/memlib/YamlUtils.scala | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/src/main/scala/firrtl/passes/memlib/YamlUtils.scala b/src/main/scala/firrtl/passes/memlib/YamlUtils.scala new file mode 100644 index 00000000..a1088300 --- /dev/null +++ b/src/main/scala/firrtl/passes/memlib/YamlUtils.scala @@ -0,0 +1,36 @@ +package firrtl.passes +package memlib +import net.jcazevedo.moultingyaml._ +import java.io.{File, CharArrayWriter, PrintWriter} + +object CustomYAMLProtocol extends DefaultYamlProtocol { + // bottom depends on top +} + +class YamlFileReader(file: String) { + import CustomYAMLProtocol._ + def parse[A](implicit reader: YamlReader[A]) : Seq[A] = { + if (new File(file).exists) { + val yamlString = scala.io.Source.fromFile(file).getLines.mkString("\n") + yamlString.parseYamls flatMap (x => + try Some(reader read x) + catch { case e: Exception => None } + ) + } + else error("Yaml file doesn't exist!") + } +} + +class YamlFileWriter(file: String) { + import CustomYAMLProtocol._ + val outputBuffer = new CharArrayWriter + val separator = "--- \n" + def append(in: YamlValue) { + outputBuffer append s"$separator${in.prettyPrint}" + } + def dump() { + val outputFile = new PrintWriter(file) + outputFile write outputBuffer.toString + outputFile.close() + } +} |
