Skip to content

Commit

Permalink
printer: use tabwriter to align instructions (#8)
Browse files Browse the repository at this point in the history
  • Loading branch information
mmcloughlin committed Jan 11, 2019
1 parent 0e253b3 commit f77a2e3
Show file tree
Hide file tree
Showing 20 changed files with 1,876 additions and 1,821 deletions.
30 changes: 16 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,10 @@ After running `go generate` the [`add.s`](examples/add/add.s) file will contain
// func Add(x uint64, y uint64) uint64
TEXT ·Add(SB), NOSPLIT, $0-24
MOVQ x(FP), AX
MOVQ y+8(FP), CX
ADDQ AX, CX
MOVQ CX, ret+16(FP)
MOVQ x(FP), AX
MOVQ y+8(FP), CX
ADDQ AX, CX
MOVQ CX, ret+16(FP)
RET
```

Expand Down Expand Up @@ -137,18 +137,20 @@ The result from this code generator is:
// func Sum(xs []uint64) uint64
TEXT ·Sum(SB), NOSPLIT, $0-32
MOVQ xs_base(FP), AX
MOVQ xs_len+8(FP), CX
XORQ DX, DX
MOVQ xs_base(FP), AX
MOVQ xs_len+8(FP), CX
XORQ DX, DX
loop:
CMPQ CX, $0x00
JE done
ADDQ (AX), DX
ADDQ $0x08, AX
DECQ CX
JMP loop
CMPQ CX, $0x00
JE done
ADDQ (AX), DX
ADDQ $0x08, AX
DECQ CX
JMP loop
done:
MOVQ DX, ret+24(FP)
MOVQ DX, ret+24(FP)
RET
```

Expand Down
8 changes: 4 additions & 4 deletions examples/add/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ This produces [`add.s`](add.s) as follows:
// func Add(x uint64, y uint64) uint64
TEXT ·Add(SB), NOSPLIT, $0-24
MOVQ x(FP), AX
MOVQ y+8(FP), CX
ADDQ AX, CX
MOVQ CX, ret+16(FP)
MOVQ x(FP), AX
MOVQ y+8(FP), CX
ADDQ AX, CX
MOVQ CX, ret+16(FP)
RET
```
8 changes: 4 additions & 4 deletions examples/add/add.s
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

// func Add(x uint64, y uint64) uint64
TEXT ·Add(SB), NOSPLIT, $0-24
MOVQ x(FP), AX
MOVQ y+8(FP), CX
ADDQ AX, CX
MOVQ CX, ret+16(FP)
MOVQ x(FP), AX
MOVQ y+8(FP), CX
ADDQ AX, CX
MOVQ CX, ret+16(FP)
RET
4 changes: 2 additions & 2 deletions examples/args/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ This `avo` code will generate the following assembly. Note that parameter refere
```s
// func Second(x int32, y int32) int32
TEXT ·Second(SB), NOSPLIT, $0-12
MOVL y+4(FP), AX
MOVL AX, ret+8(FP)
MOVL y+4(FP), AX
MOVL AX, ret+8(FP)
RET
```

Expand Down
72 changes: 36 additions & 36 deletions examples/args/args.s
Original file line number Diff line number Diff line change
Expand Up @@ -4,108 +4,108 @@

// func Second(x int32, y int32) int32
TEXT ·Second(SB), NOSPLIT, $0-12
MOVL y+4(FP), AX
MOVL AX, ret+8(FP)
MOVL y+4(FP), AX
MOVL AX, ret+8(FP)
RET

// func StringLen(s string) int
TEXT ·StringLen(SB), NOSPLIT, $0-24
MOVQ s_len+8(FP), AX
MOVQ AX, ret+16(FP)
MOVQ s_len+8(FP), AX
MOVQ AX, ret+16(FP)
RET

// func SliceLen(s []int) int
TEXT ·SliceLen(SB), NOSPLIT, $0-32
MOVQ s_len+8(FP), AX
MOVQ AX, ret+24(FP)
MOVQ s_len+8(FP), AX
MOVQ AX, ret+24(FP)
RET

// func SliceCap(s []int) int
TEXT ·SliceCap(SB), NOSPLIT, $0-32
MOVQ s_cap+16(FP), AX
MOVQ AX, ret+24(FP)
MOVQ s_cap+16(FP), AX
MOVQ AX, ret+24(FP)
RET

// func ArrayThree(a [7]uint64) uint64
TEXT ·ArrayThree(SB), NOSPLIT, $0-64
MOVQ a_3+24(FP), AX
MOVQ AX, ret+56(FP)
MOVQ a_3+24(FP), AX
MOVQ AX, ret+56(FP)
RET

// func FieldByte(s Struct) byte
TEXT ·FieldByte(SB), NOSPLIT, $0-177
MOVB s_Byte(FP), AL
MOVB AL, ret+176(FP)
MOVB s_Byte(FP), AL
MOVB AL, ret+176(FP)
RET

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

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

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

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

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

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

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

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

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

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

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

// func FieldComplex128Real(s Struct) float64
TEXT ·FieldComplex128Real(SB), NOSPLIT, $0-184
MOVSD s_Complex128_real+160(FP), X0
MOVSD X0, ret+176(FP)
MOVSD s_Complex128_real+160(FP), X0
MOVSD X0, ret+176(FP)
RET
Binary file added examples/backup.tar.gz
Binary file not shown.
14 changes: 7 additions & 7 deletions examples/complex/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ Generated assembly:
```s
// func Norm(z complex128) float64
TEXT ·Norm(SB), NOSPLIT, $0-24
MOVSD z_real(FP), X0
MOVSD z_imag+8(FP), X1
MULSD X0, X0
MULSD X1, X1
ADDSD X1, X0
SQRTSD X0, X2
MOVSD X2, ret+16(FP)
MOVSD z_real(FP), X0
MOVSD z_imag+8(FP), X1
MULSD X0, X0
MULSD X1, X1
ADDSD X1, X0
SQRTSD X0, X2
MOVSD X2, ret+16(FP)
RET
```
22 changes: 11 additions & 11 deletions examples/complex/complex.s
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,23 @@

// func Real(z complex128) float64
TEXT ·Real(SB), NOSPLIT, $0-24
MOVSD z_real(FP), X0
MOVSD X0, ret+16(FP)
MOVSD z_real(FP), X0
MOVSD X0, ret+16(FP)
RET

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

// func Norm(z complex128) float64
TEXT ·Norm(SB), NOSPLIT, $0-24
MOVSD z_real(FP), X0
MOVSD z_imag+8(FP), X1
MULSD X0, X0
MULSD X1, X1
ADDSD X1, X0
SQRTSD X0, X2
MOVSD X2, ret+16(FP)
MOVSD z_real(FP), X0
MOVSD z_imag+8(FP), X1
MULSD X0, X0
MULSD X1, X1
ADDSD X1, X0
SQRTSD X0, X2
MOVSD X2, ret+16(FP)
RET
8 changes: 4 additions & 4 deletions examples/data/data.s
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ GLOBL bytes<>(SB), RODATA|NOPTR, $40

// func DataAt(i int) byte
TEXT ·DataAt(SB), NOSPLIT, $0-9
MOVQ i(FP), AX
LEAQ bytes<>(SB), CX
MOVB (CX)(AX*1), AL
MOVB AL, ret+8(FP)
MOVQ i(FP), AX
LEAQ bytes<>(SB), CX
MOVB (CX)(AX*1), AL
MOVB AL, ret+8(FP)
RET
Loading

0 comments on commit f77a2e3

Please sign in to comment.