2022-12-04 21:49:05 +00:00
|
|
|
package com.htmlism.firepower.demo.asm
|
|
|
|
|
|
|
|
import com.htmlism.firepower.demo.str.Paragraph
|
|
|
|
|
|
|
|
sealed trait AsmBlock
|
|
|
|
|
|
|
|
case class CommentBlock(xs: List[String]) extends AsmBlock
|
|
|
|
|
2022-12-04 22:23:42 +00:00
|
|
|
case class NamedCodeBlock(name: String, comment: Option[String], intents: List[AsmBlock.Intent]) extends AsmBlock
|
2022-12-04 21:56:03 +00:00
|
|
|
|
2022-12-04 22:15:29 +00:00
|
|
|
case class AnonymousCodeBlock(intents: List[AsmBlock.Intent]) extends AsmBlock
|
2022-12-04 21:56:03 +00:00
|
|
|
|
|
|
|
object AsmBlock:
|
2022-12-04 22:23:42 +00:00
|
|
|
def toComment(s: String): String =
|
|
|
|
"; " + s
|
|
|
|
|
|
|
|
def withIndent(s: String): String =
|
|
|
|
" " + s
|
|
|
|
|
2022-12-04 22:17:55 +00:00
|
|
|
def toParagraphs(xs: AsmBlock): List[Paragraph] =
|
2022-12-04 21:49:05 +00:00
|
|
|
xs match
|
|
|
|
case CommentBlock(ys) =>
|
2022-12-04 22:17:55 +00:00
|
|
|
List(
|
2022-12-04 22:23:42 +00:00
|
|
|
Paragraph(ys.map(toComment))
|
2022-12-04 22:17:55 +00:00
|
|
|
)
|
2022-12-04 21:49:05 +00:00
|
|
|
|
2022-12-04 22:23:42 +00:00
|
|
|
case NamedCodeBlock(label, oComment, _) =>
|
|
|
|
val headerParagraph =
|
2022-12-04 22:17:55 +00:00
|
|
|
Paragraph(
|
2022-12-04 22:23:42 +00:00
|
|
|
List(label + ":") ++ oComment.map(toComment).map(withIndent).toList
|
2022-12-04 22:17:55 +00:00
|
|
|
)
|
2022-12-04 22:23:42 +00:00
|
|
|
|
|
|
|
val intentParagraphs =
|
|
|
|
Nil
|
|
|
|
|
|
|
|
headerParagraph :: intentParagraphs
|
2022-12-04 21:56:03 +00:00
|
|
|
|
2022-12-04 22:15:29 +00:00
|
|
|
case AnonymousCodeBlock(_) =>
|
2022-12-04 22:17:55 +00:00
|
|
|
Nil
|
2022-12-04 22:15:29 +00:00
|
|
|
|
|
|
|
case class Intent(label: Option[String], instructions: List[Intent.Instruction])
|
|
|
|
|
|
|
|
object Intent:
|
|
|
|
case class Instruction(code: String, comment: Option[String])
|
|
|
|
|
2022-12-04 21:56:03 +00:00
|
|
|
object CommentBlock:
|
2022-12-04 21:49:05 +00:00
|
|
|
def fromMultiline(s: String): CommentBlock =
|
|
|
|
CommentBlock(s.split("\\n").toList)
|