add resource comments

This commit is contained in:
Mark Canlas 2020-08-26 02:37:12 -04:00
parent f432fdc767
commit cfb6bbbc92
3 changed files with 16 additions and 5 deletions

View File

@ -50,14 +50,22 @@ case class Subroutine(name: String, fragment: AsmFragment, jumpRegistry: ListSet
case class DefinitionGroup(comment: String, xs: List[Definition[_]]) extends TopLevelAsmDocumentFragment {
def toAsm: String = {
val commentLine =
val groupCommentLine =
"; " + comment
val definitionLines =
xs
.map(d => f"define ${d.name}%-20s${d.value}")
.map { d =>
d.comment match {
case Some(c) =>
f"define ${d.name}%-20s${d.value} ; $c"
(commentLine :: definitionLines)
case None =>
f"define ${d.name}%-20s${d.value}"
}
}
(groupCommentLine :: definitionLines)
.mkString("\n")
}
}
@ -75,6 +83,9 @@ class DefinitionGroupContext {
DefinitionGroup(s, xs.toList)
}
/**
* @param comment Typically used by resources to describe their type safety
*/
case class Definition[A: Operand](name: String, x: A, comment: Option[String]) {
lazy val value: String =
implicitly[Operand[A]]

View File

@ -24,7 +24,7 @@ object ReadWriteLocation {
new Definable[ReadWriteLocation[A]] {
def toDefinitions(x: ReadWriteLocation[A]): List[Definition[ZeroAddress]] =
List {
Definition(x.name, x.address)
Definition(x.name, x.address, "Read/write location for A values")
}
}
}

View File

@ -21,7 +21,7 @@ object VolatileDevice {
new Definable[VolatileDevice[A]] {
def toDefinitions(x: VolatileDevice[A]): List[Definition[ZeroAddress]] =
List {
Definition(x.name, x.address)
Definition(x.name, x.address, "Volatile generator for A values")
}
}
}