6502-opcodes/firepower-demo/src/main/scala/com/htmlism/firepower/demo/asm/AsmBlock.scala

39 lines
970 B
Scala
Raw Normal View History

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:15:29 +00:00
case class NamedCodeBlock(name: 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: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(
Paragraph(ys.map("; " + _))
)
2022-12-04 21:49:05 +00:00
2022-12-04 22:15:29 +00:00
case NamedCodeBlock(label, _) =>
2022-12-04 22:17:55 +00:00
List(
Paragraph(
List(label + ":")
)
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)