q/src/core/PrintInstructions.go

61 lines
1.8 KiB
Go

package core
import (
"bytes"
"fmt"
"git.akyoto.dev/cli/q/src/asm"
"git.akyoto.dev/go/color/ansi"
)
// PrintInstructions shows the assembly instructions.
func (f *Function) PrintInstructions() {
ansi.Dim.Println("╭──────────────────────────────────────────────────────────────────────────────╮")
if len(f.Input) > 0 {
for i, input := range f.Input {
ansi.Dim.Printf("│ %-44s%-32s", input.Name, f.CPU.Input[i])
ansi.Dim.Print(" │\n")
}
ansi.Dim.Println("├──────────────────────────────────────────────────────────────────────────────┤")
}
for i, x := range f.Assembler.Instructions {
ansi.Dim.Print("│ ")
switch x.Mnemonic {
case asm.LABEL:
ansi.Yellow.Printf("%-44s", x.Data.String()+":")
case asm.COMMENT:
ansi.Dim.Printf("%-44s", x.Data.String())
default:
ansi.Green.Printf("%-12s", x.Mnemonic.String())
if x.Data != nil {
fmt.Printf("%-32s", x.Data.String())
} else {
fmt.Printf("%-32s", "")
}
}
registers := bytes.Buffer{}
used := f.RegisterHistory[i]
for _, reg := range f.CPU.All {
if used&(1<<reg) != 0 {
registers.WriteString("● ")
} else {
registers.WriteString("· ")
}
}
ansi.Dim.Print(registers.String())
ansi.Dim.Print(" │\n")
}
ansi.Dim.Println("╰──────────────────────────────────────────────────────────────────────────────╯")
}