forked from mmcloughlin/avo
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
printer: shorten text size when argsize is zero
- Loading branch information
1 parent
9243d29
commit 5dea464
Showing
12 changed files
with
158 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package printer_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/mmcloughlin/avo/build" | ||
"github.com/mmcloughlin/avo/printer" | ||
"github.com/mmcloughlin/avo/reg" | ||
) | ||
|
||
func TestBasic(t *testing.T) { | ||
ctx := build.NewContext() | ||
ctx.Function("add") | ||
ctx.SignatureExpr("func(x, y uint64) uint64") | ||
x := ctx.Load(ctx.Param("x"), reg.RAX) | ||
y := ctx.Load(ctx.Param("y"), reg.R9) | ||
ctx.ADDQ(x, y) | ||
ctx.Store(y, ctx.ReturnIndex(0)) | ||
ctx.RET() | ||
|
||
AssertPrintsLines(t, ctx, printer.NewGoAsm, []string{ | ||
"// Code generated by avo. DO NOT EDIT.", | ||
"", | ||
"#include \"textflag.h\"", | ||
"", | ||
"// func add(x uint64, y uint64) uint64", | ||
"TEXT ·add(SB), 0, $0-24", | ||
"\tMOVQ\tx(FP), AX", | ||
"\tMOVQ\ty+8(FP), R9", | ||
"\tADDQ\tAX, R9", | ||
"\tMOVQ\tR9, ret+16(FP)", | ||
"\tRET", | ||
"", | ||
}) | ||
} | ||
|
||
func TestTextSize(t *testing.T) { | ||
ctx := build.NewContext() | ||
|
||
ctx.Function("noargs") | ||
ctx.SignatureExpr("func()") | ||
ctx.AllocLocal(16) | ||
ctx.RET() | ||
|
||
ctx.Function("withargs") | ||
ctx.SignatureExpr("func(x, y uint64) uint64") | ||
ctx.RET() | ||
|
||
AssertPrintsLines(t, ctx, printer.NewGoAsm, []string{ | ||
"// Code generated by avo. DO NOT EDIT.", | ||
"", | ||
"#include \"textflag.h\"", | ||
"", | ||
"// func noargs()", | ||
"TEXT ·noargs(SB), 0, $16", // expect only the frame size | ||
"\tRET", | ||
"", | ||
"// func withargs(x uint64, y uint64) uint64", | ||
"TEXT ·withargs(SB), 0, $0-24", // expect both frame size and argument size | ||
"\tRET", | ||
"", | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package printer_test | ||
|
||
import ( | ||
"strings" | ||
"testing" | ||
|
||
"github.com/mmcloughlin/avo/build" | ||
"github.com/mmcloughlin/avo/printer" | ||
) | ||
|
||
func AssertPrintsLines(t *testing.T, ctx *build.Context, pb printer.Builder, expect []string) { | ||
t.Helper() | ||
|
||
output := Print(t, ctx, pb) | ||
lines := strings.Split(output, "\n") | ||
|
||
if len(expect) != len(lines) { | ||
t.Fatalf("have %d lines of output; expected %d", len(lines), len(expect)) | ||
} | ||
|
||
for i := range expect { | ||
if expect[i] != lines[i] { | ||
t.Errorf("mismatch on line %d:\n\tgot\t%s\n\texpect\t%s\n", i, lines[i], expect[i]) | ||
} | ||
} | ||
} | ||
|
||
func Print(t *testing.T, ctx *build.Context, pb printer.Builder) string { | ||
t.Helper() | ||
|
||
f, errs := ctx.Result() | ||
if errs != nil { | ||
t.Fatal(errs) | ||
} | ||
|
||
p := pb(printer.NewDefaultConfig()) | ||
b, err := p.Print(f) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
return string(b) | ||
} |