Added assembler syntax highlighting

This commit is contained in:
Eduard Urbach 2024-06-27 16:05:23 +02:00
parent a62006b4c8
commit 61024bb133
Signed by: akyoto
GPG Key ID: C874F672B1AF20C0

View File

@ -227,21 +227,27 @@ func (f *Function) TokenToRegister(t token.Token, register cpu.Register) error {
// PrintAsm shows the assembly instructions.
func (f *Function) PrintAsm() {
ansi.Bold.Println(f.Name)
ansi.Dim.Println("╭────────────────────────────────────────────────────────────")
ansi.Dim.Println("╭────────────────────────────────────────────────╮")
for _, x := range f.Assembler.Instructions {
ansi.Dim.Print("│ ")
fmt.Print(x.Mnemonic.String())
if x.Mnemonic == asm.LABEL {
ansi.Yellow.Printf("%-46s", x.Data.String()+":")
} else {
ansi.Green.Printf("%-8s", x.Mnemonic.String())
if x.Data != nil {
fmt.Print(" " + x.Data.String())
fmt.Printf("%-38s", x.Data.String())
} else {
fmt.Printf("%-38s", "")
}
}
fmt.Print("\n")
ansi.Dim.Print(" │\n")
}
ansi.Dim.Println("╰────────────────────────────────────────────────────────────")
ansi.Dim.Println("╰────────────────────────────────────────────────")
}
// String returns the function name.