diff --git a/src/codegen/Label.go b/src/codegen/Label.go index 6e0487c..d9a5ffa 100644 --- a/src/codegen/Label.go +++ b/src/codegen/Label.go @@ -22,6 +22,6 @@ func (a *Label) Equals(v ssa.Value) bool { func (v *Label) Inputs() []ssa.Value { return nil } func (v *Label) IsConst() bool { return false } -func (v *Label) String() string { return v.Name } func (v *Label) Replace(ssa.Value, ssa.Value) {} +func (v *Label) String() string { return ssa.CleanLabel(v.Name) } func (v *Label) Type() types.Type { return types.Void } \ No newline at end of file diff --git a/src/ssa/Block.go b/src/ssa/Block.go index a7d34d2..0b21fbe 100644 --- a/src/ssa/Block.go +++ b/src/ssa/Block.go @@ -260,7 +260,7 @@ func (b *Block) ReplaceAllUses(old Value, new Value) { // String returns the block label. func (b *Block) String() string { - return b.Label + return CleanLabel(b.Label) } // Unidentify deletes the identifier for the given value. diff --git a/src/ssa/Branch.go b/src/ssa/Branch.go index 5104f4c..c00db8f 100644 --- a/src/ssa/Branch.go +++ b/src/ssa/Branch.go @@ -37,5 +37,5 @@ func (b *Branch) Replace(old Value, new Value) { // String returns a human-readable representation of the branch. func (b *Branch) String() string { - return fmt.Sprintf("branch(%p, %s, %s)", b.Condition, b.Then.Label, b.Else.Label) + return fmt.Sprintf("branch(%p, %s, %s)", b.Condition, CleanLabel(b.Then.Label), CleanLabel(b.Else.Label)) } \ No newline at end of file diff --git a/src/ssa/CleanLabel.go b/src/ssa/CleanLabel.go new file mode 100644 index 0000000..f4dad13 --- /dev/null +++ b/src/ssa/CleanLabel.go @@ -0,0 +1,14 @@ +package ssa + +import "strings" + +// CleanLabel removes the function name from the label. +func CleanLabel(label string) string { + pos := strings.IndexByte(label, ':') + + if pos != -1 && pos != len(label)-1 { + return label[pos+1:] + } + + return label +} \ No newline at end of file diff --git a/src/ssa/Jump.go b/src/ssa/Jump.go index 46c4d69..62f2131 100644 --- a/src/ssa/Jump.go +++ b/src/ssa/Jump.go @@ -31,5 +31,5 @@ func (j *Jump) Replace(Value, Value) {} // String returns a human-readable representation of the jump. func (j *Jump) String() string { - return fmt.Sprintf("jump(%s)", j.To.Label) + return fmt.Sprintf("jump(%s)", CleanLabel(j.To.Label)) } \ No newline at end of file diff --git a/src/verbose/ASM.go b/src/verbose/ASM.go index 0ab7270..eb6cb95 100644 --- a/src/verbose/ASM.go +++ b/src/verbose/ASM.go @@ -4,10 +4,10 @@ import ( _ "embed" "fmt" "reflect" - "strings" "git.urbach.dev/cli/q/src/asm" "git.urbach.dev/cli/q/src/core" + "git.urbach.dev/cli/q/src/ssa" "git.urbach.dev/cli/q/src/token" "git.urbach.dev/go/color/ansi" ) @@ -69,7 +69,7 @@ func printAssembly(f *core.Function) { imm.Print(instr.Number) case *asm.Call: mnemonic.Print(" call ") - label.Print(instr.Label) + label.Print(ssa.CleanLabel(instr.Label)) case *asm.CallExtern: mnemonic.Print(" call extern ") label.Print(instr.Library + "." + instr.Function) @@ -108,12 +108,12 @@ func printAssembly(f *core.Function) { mnemonic.Print(" jump ") } - label.Print(strings.TrimPrefix(instr.Label, f.FullName)) + label.Print(ssa.CleanLabel(instr.Label)) case *asm.Label: if instr.Name == f.FullName { function.Printf("%s:", instr.Name) } else { - label.Printf("\n%s:", strings.TrimPrefix(instr.Name, f.FullName)) + label.Printf("\n%s:", ssa.CleanLabel(instr.Name)) } case *asm.Load: mnemonic.Printf(" load %db ", instr.Length) @@ -134,7 +134,7 @@ func printAssembly(f *core.Function) { mnemonic.Print(" address ") register.Print(instr.Destination) other.Print(", ") - label.Print(instr.Label) + label.Print(ssa.CleanLabel(instr.Label)) case *asm.Move: mnemonic.Print(" move ") register.Print(instr.Destination)