Skip to content

Commit

Permalink
printer: cleaner output
Browse files Browse the repository at this point in the history
  • Loading branch information
mmcloughlin committed Dec 19, 2018
1 parent bc9a2aa commit 213d65e
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 21 deletions.
2 changes: 1 addition & 1 deletion examples/add/add.s
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ TEXT ·Add(SB),0,$0-24
MOVQ y+8(FP), CX
ADDQ AX, CX
MOVQ CX, ret+16(FP)
RET
RET
8 changes: 5 additions & 3 deletions examples/complex/complex.s
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@
TEXT ·Real(SB),0,$0-24
MOVSD x_real(FP), X0
MOVSD X0, ret+16(FP)
RET
RET

// func Imag(x complex128) float64
TEXT ·Imag(SB),0,$0-24
MOVSD x_imag+8(FP), X0
MOVSD X0, ret+16(FP)
RET
RET

// func Norm(x complex128) float64
TEXT ·Norm(SB),0,$0-24
MOVSD x_real(FP), X0
Expand All @@ -20,4 +22,4 @@ TEXT ·Norm(SB),0,$0-24
ADDSD X1, X0
SQRTSD X0, X2
MOVSD X2, ret+16(FP)
RET
RET
38 changes: 25 additions & 13 deletions examples/components/components.s
Original file line number Diff line number Diff line change
Expand Up @@ -5,64 +5,76 @@
TEXT ·FieldByte(SB),0,$0-184
MOVB s_Byte(FP), AL
MOVB AL, ret+176(FP)
RET
RET

// func FieldInt8(s Struct) int8
TEXT ·FieldInt8(SB),0,$0-184
MOVB s_Int8+1(FP), AL
MOVB AL, ret+176(FP)
RET
RET

// func FieldUint16(s Struct) uint16
TEXT ·FieldUint16(SB),0,$0-184
MOVW s_Uint16+2(FP), AX
MOVW AX, ret+176(FP)
RET
RET

// func FieldInt32(s Struct) int32
TEXT ·FieldInt32(SB),0,$0-184
MOVL s_Int32+4(FP), AX
MOVL AX, ret+176(FP)
RET
RET

// func FieldUint64(s Struct) uint64
TEXT ·FieldUint64(SB),0,$0-184
MOVQ s_Uint64+8(FP), AX
MOVQ AX, ret+176(FP)
RET
RET

// func FieldFloat32(s Struct) float32
TEXT ·FieldFloat32(SB),0,$0-184
MOVSS s_Float32+16(FP), X0
MOVSS X0, ret+176(FP)
RET
RET

// func FieldFloat64(s Struct) float64
TEXT ·FieldFloat64(SB),0,$0-184
MOVSD s_Float64+24(FP), X0
MOVSD X0, ret+176(FP)
RET
RET

// func FieldStringLen(s Struct) int
TEXT ·FieldStringLen(SB),0,$0-184
MOVQ s_String_len+40(FP), AX
MOVQ AX, ret+176(FP)
RET
RET

// func FieldSliceCap(s Struct) int
TEXT ·FieldSliceCap(SB),0,$0-184
MOVQ s_Slice_cap+64(FP), AX
MOVQ AX, ret+176(FP)
RET
RET

// func FieldArrayTwoBTwo(s Struct) byte
TEXT ·FieldArrayTwoBTwo(SB),0,$0-184
MOVB s_Array_2_B_2+114(FP), AL
MOVB AL, ret+176(FP)
RET
RET

// func FieldArrayOneC(s Struct) uint16
TEXT ·FieldArrayOneC(SB),0,$0-184
MOVW s_Array_1_C+100(FP), AX
MOVW AX, ret+176(FP)
RET
RET

// func FieldComplex64Imag(s Struct) float32
TEXT ·FieldComplex64Imag(SB),0,$0-184
MOVSS s_Complex64_imag+156(FP), X0
MOVSS X0, ret+176(FP)
RET
RET

// func FieldComplex128Real(s Struct) float64
TEXT ·FieldComplex128Real(SB),0,$0-184
MOVSD s_Complex128_real+160(FP), X0
MOVSD X0, ret+176(FP)
RET
RET
2 changes: 1 addition & 1 deletion examples/fnv1a/fnv1a.s
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ loop:
JMP loop
done:
MOVQ AX, ret+24(FP)
RET
RET
2 changes: 1 addition & 1 deletion examples/sum/sum.s
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ loop:
JMP loop
done:
MOVQ DX, ret+24(FP)
RET
RET
8 changes: 6 additions & 2 deletions printer/goasm.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,21 +31,25 @@ func (p *goasm) Print(f *avo.File) ([]byte, error) {
func (p *goasm) header() {
p.NL()
p.include("textflag.h")
p.NL()
}

func (p *goasm) include(path string) {
p.Printf("#include \"%s\"\n", path)
}

func (p *goasm) function(f *avo.Function) {
p.NL()
p.Comment(f.Stub())
p.Printf("TEXT %s%s(SB),0,$%d-%d\n", dot, f.Name, f.FrameBytes(), f.ArgumentBytes())

for _, node := range f.Nodes {
switch n := node.(type) {
case *avo.Instruction:
p.Printf("\t%s\t%s\n", n.Opcode, joinOperands(n.Operands))
if len(n.Operands) > 0 {
p.Printf("\t%s\t%s\n", n.Opcode, joinOperands(n.Operands))
} else {
p.Printf("\t%s\n", n.Opcode)
}
case avo.Label:
p.Printf("%s:\n", n)
default:
Expand Down

0 comments on commit 213d65e

Please sign in to comment.