diff --git a/build/context.go b/build/context.go index b537047..52921d8 100644 --- a/build/context.go +++ b/build/context.go @@ -5,13 +5,14 @@ import ( "fmt" "go/types" + "golang.org/x/tools/go/packages" + "github.com/mmcloughlin/avo/attr" "github.com/mmcloughlin/avo/buildtags" "github.com/mmcloughlin/avo/gotypes" "github.com/mmcloughlin/avo/ir" "github.com/mmcloughlin/avo/operand" "github.com/mmcloughlin/avo/reg" - "golang.org/x/tools/go/packages" ) // Context maintains state for incrementally building an avo File. diff --git a/build/zmov.go b/build/zmov.go index bfd9b08..ca9bb55 100644 --- a/build/zmov.go +++ b/build/zmov.go @@ -3,8 +3,9 @@ package build import ( - "github.com/mmcloughlin/avo/operand" "go/types" + + "github.com/mmcloughlin/avo/operand" ) func (c *Context) mov(a, b operand.Op, an, bn int, t *types.Basic) { diff --git a/internal/gen/ctors.go b/internal/gen/ctors.go index 79d3627..eeb75d7 100644 --- a/internal/gen/ctors.go +++ b/internal/gen/ctors.go @@ -27,6 +27,7 @@ func (c *ctors) Generate(is []inst.Instruction) ([]byte, error) { c.Printf("package x86\n\n") c.Printf("import (\n") c.Printf("\t\"errors\"\n") + c.NL() c.Printf("\tintrep \"%s/ir\"\n", pkg) c.Printf("\t\"%s/reg\"\n", pkg) c.Printf("\t\"%s/operand\"\n", pkg) diff --git a/internal/gen/ctorstest.go b/internal/gen/ctorstest.go index 844a495..297e9fe 100644 --- a/internal/gen/ctorstest.go +++ b/internal/gen/ctorstest.go @@ -25,6 +25,7 @@ func (c *ctorstest) Generate(is []inst.Instruction) ([]byte, error) { c.Printf("import (\n") c.Printf("\t\"testing\"\n") c.Printf("\t\"math\"\n") + c.NL() c.Printf("\t\"%s/reg\"\n", pkg) c.Printf("\t\"%s/operand\"\n", pkg) c.Printf(")\n\n") diff --git a/internal/gen/gen_test.go b/internal/gen/gen_test.go index c369fa1..b497d5d 100644 --- a/internal/gen/gen_test.go +++ b/internal/gen/gen_test.go @@ -3,7 +3,7 @@ package gen import "testing" func TestBuilderInterfaces(t *testing.T) { - var _ = []Builder{ + _ = []Builder{ NewAsmTest, NewGoData, NewGoDataTest, diff --git a/internal/gen/mov.go b/internal/gen/mov.go index 4162f05..cf8c232 100644 --- a/internal/gen/mov.go +++ b/internal/gen/mov.go @@ -28,6 +28,7 @@ func (m *mov) Generate(is []inst.Instruction) ([]byte, error) { m.Printf("import (\n") m.Printf("\t\"go/types\"\n") + m.NL() m.Printf("\t\"%s/operand\"\n", pkg) m.Printf(")\n\n") diff --git a/script/bootstrap b/script/bootstrap index 8a589bf..ba5973f 100755 --- a/script/bootstrap +++ b/script/bootstrap @@ -20,3 +20,6 @@ go get -u github.com/dlespiau/covertool # asmfmt for enforcing assembly style go get -u github.com/klauspost/asmfmt/cmd/asmfmt + +# gofumports for stricter formatting +go get -u mvdan.cc/gofumpt/gofumports diff --git a/script/fmt b/script/fmt new file mode 100755 index 0000000..80ff752 --- /dev/null +++ b/script/fmt @@ -0,0 +1,15 @@ +#!/bin/bash -ex + +repo="github.com/mmcloughlin/avo" + +# Files to apply formatting to. Exclude stadtx since some of it was imported +# from the original repo. +files=$(find . -name '*.go' -not -path '*/stadtx/*') + +# Remove blank lines in import blocks. This will force formatting to group +# imports correctly. +sed -i.fmtbackup '/^import (/,/)/ { /^$$/ d; }' ${files} +find . -name '*.fmtbackup' -delete + +# gofumports is goimports with stricter formatting. +gofumports -w -local ${repo} ${files} diff --git a/script/lint b/script/lint index fe8922a..de47561 100755 --- a/script/lint +++ b/script/lint @@ -4,6 +4,10 @@ ./script/generate test -z "$(git status --porcelain)" +# Still clean after formatting. +./script/fmt +test -z "$(git status --porcelain)" + # And it's still clean after asmfmt. # Note: we want to confirm we agree with asmfmt without actually depending on it. find . -name '*.s' | xargs asmfmt -w diff --git a/x86/zctors.go b/x86/zctors.go index 0101d1a..816c0d1 100644 --- a/x86/zctors.go +++ b/x86/zctors.go @@ -4,6 +4,7 @@ package x86 import ( "errors" + intrep "github.com/mmcloughlin/avo/ir" "github.com/mmcloughlin/avo/operand" "github.com/mmcloughlin/avo/reg" diff --git a/x86/zctors_test.go b/x86/zctors_test.go index b8cebc7..1c70339 100644 --- a/x86/zctors_test.go +++ b/x86/zctors_test.go @@ -3,10 +3,11 @@ package x86 import ( - "github.com/mmcloughlin/avo/operand" - "github.com/mmcloughlin/avo/reg" "math" "testing" + + "github.com/mmcloughlin/avo/operand" + "github.com/mmcloughlin/avo/reg" ) func TestADCBValidForms(t *testing.T) {