diff --git a/README.md b/README.md index f65444b..b7d11b5 100644 --- a/README.md +++ b/README.md @@ -37,7 +37,6 @@ $ go get -u github.com/mmcloughlin/avo ```go //go:build ignore -// +build ignore package main diff --git a/attr/make_textflag.go b/attr/make_textflag.go index f5fc3ff..14f92fa 100644 --- a/attr/make_textflag.go +++ b/attr/make_textflag.go @@ -1,5 +1,4 @@ //go:build ignore -// +build ignore package main diff --git a/build/zinstructions_test.go b/build/zinstructions_test.go index 2427ef9..3312b9c 100644 --- a/build/zinstructions_test.go +++ b/build/zinstructions_test.go @@ -1,7 +1,6 @@ // Code generated by command: avogen -output zinstructions_test.go buildtest. DO NOT EDIT. //go:build !integration -// +build !integration package build diff --git a/buildtags/syntax_go116.go b/buildtags/syntax_go116.go index 07c5068..e9d393d 100644 --- a/buildtags/syntax_go116.go +++ b/buildtags/syntax_go116.go @@ -1,5 +1,4 @@ //go:build !go1.17 -// +build !go1.17 package buildtags diff --git a/buildtags/syntax_go117.go b/buildtags/syntax_go117.go index a6dca4e..b624dee 100644 --- a/buildtags/syntax_go117.go +++ b/buildtags/syntax_go117.go @@ -1,5 +1,4 @@ //go:build go1.17 && !go1.18 -// +build go1.17,!go1.18 package buildtags diff --git a/buildtags/syntax_go118.go b/buildtags/syntax_go118.go index 7e70c72..d372f86 100644 --- a/buildtags/syntax_go118.go +++ b/buildtags/syntax_go118.go @@ -1,5 +1,4 @@ //go:build go1.18 -// +build go1.18 package buildtags diff --git a/examples/add/README.md b/examples/add/README.md index 68aefab..8625fa3 100644 --- a/examples/add/README.md +++ b/examples/add/README.md @@ -7,7 +7,6 @@ The [code generator](asm.go) is as follows: [embedmd]:# (asm.go) ```go //go:build ignore -// +build ignore package main diff --git a/examples/add/asm.go b/examples/add/asm.go index 8c3d841..1f6496a 100644 --- a/examples/add/asm.go +++ b/examples/add/asm.go @@ -1,5 +1,4 @@ //go:build ignore -// +build ignore package main diff --git a/examples/args/asm.go b/examples/args/asm.go index 69f87e4..f8fb8ef 100644 --- a/examples/args/asm.go +++ b/examples/args/asm.go @@ -1,5 +1,4 @@ //go:build ignore -// +build ignore package main diff --git a/examples/complex/asm.go b/examples/complex/asm.go index e973565..6d14629 100644 --- a/examples/complex/asm.go +++ b/examples/complex/asm.go @@ -1,5 +1,4 @@ //go:build ignore -// +build ignore package main diff --git a/examples/data/asm.go b/examples/data/asm.go index de55f32..b2ad1a2 100644 --- a/examples/data/asm.go +++ b/examples/data/asm.go @@ -1,5 +1,4 @@ //go:build ignore -// +build ignore package main diff --git a/examples/dot/asm.go b/examples/dot/asm.go index da7ddf4..9e23d0a 100644 --- a/examples/dot/asm.go +++ b/examples/dot/asm.go @@ -1,5 +1,4 @@ //go:build ignore -// +build ignore package main diff --git a/examples/ext/asm.go b/examples/ext/asm.go index d752b38..0c9d933 100644 --- a/examples/ext/asm.go +++ b/examples/ext/asm.go @@ -1,5 +1,4 @@ //go:build ignore -// +build ignore package main diff --git a/examples/fnv1a/asm.go b/examples/fnv1a/asm.go index 809a1c9..1a59592 100644 --- a/examples/fnv1a/asm.go +++ b/examples/fnv1a/asm.go @@ -1,5 +1,4 @@ //go:build ignore -// +build ignore package main diff --git a/examples/geohash/asm.go b/examples/geohash/asm.go index 81fbacd..f087303 100644 --- a/examples/geohash/asm.go +++ b/examples/geohash/asm.go @@ -1,5 +1,4 @@ //go:build ignore -// +build ignore package main diff --git a/examples/md5x16/asm.go b/examples/md5x16/asm.go index 3d5e793..1919e20 100644 --- a/examples/md5x16/asm.go +++ b/examples/md5x16/asm.go @@ -1,5 +1,4 @@ //go:build ignore -// +build ignore package main diff --git a/examples/pragma/asm.go b/examples/pragma/asm.go index 067b92f..141318b 100644 --- a/examples/pragma/asm.go +++ b/examples/pragma/asm.go @@ -1,5 +1,4 @@ //go:build ignore -// +build ignore package main diff --git a/examples/returns/asm.go b/examples/returns/asm.go index 26121d3..0fd5dcd 100644 --- a/examples/returns/asm.go +++ b/examples/returns/asm.go @@ -1,5 +1,4 @@ //go:build ignore -// +build ignore package main diff --git a/examples/sha1/asm.go b/examples/sha1/asm.go index 509aff3..05d75d5 100644 --- a/examples/sha1/asm.go +++ b/examples/sha1/asm.go @@ -1,5 +1,4 @@ //go:build ignore -// +build ignore package main diff --git a/examples/stadtx/asm.go b/examples/stadtx/asm.go index 8e849c6..e445e39 100644 --- a/examples/stadtx/asm.go +++ b/examples/stadtx/asm.go @@ -1,4 +1,4 @@ -// +build ignore +//go:build ignore package main diff --git a/examples/sum/asm.go b/examples/sum/asm.go index 22963fe..50333b3 100644 --- a/examples/sum/asm.go +++ b/examples/sum/asm.go @@ -1,5 +1,4 @@ //go:build ignore -// +build ignore package main diff --git a/internal/gen/buildtest.go b/internal/gen/buildtest.go index 582b58e..ad24d26 100644 --- a/internal/gen/buildtest.go +++ b/internal/gen/buildtest.go @@ -20,7 +20,7 @@ func NewBuildTest(cfg printer.Config) Interface { func (b *buildtest) Generate(is []inst.Instruction) ([]byte, error) { b.Printf("// %s\n\n", b.cfg.GeneratedWarning()) - b.BuildTag("!integration") + b.BuildConstraint("!integration") b.NL() b.Printf("package build\n\n") b.Printf("import (\n") diff --git a/internal/gen/ctorstest.go b/internal/gen/ctorstest.go index a3832c9..b271d2f 100644 --- a/internal/gen/ctorstest.go +++ b/internal/gen/ctorstest.go @@ -23,7 +23,7 @@ func NewCtorsTest(cfg printer.Config) Interface { func (c *ctorstest) Generate(is []inst.Instruction) ([]byte, error) { c.Printf("// %s\n\n", c.cfg.GeneratedWarning()) - c.BuildTag("!integration") + c.BuildConstraint("!integration") c.NL() c.Printf("package x86\n\n") c.Printf("import (\n") @@ -65,7 +65,7 @@ func NewCtorsStress(cfg printer.Config) Interface { func (c *ctorsstress) Generate(is []inst.Instruction) ([]byte, error) { c.Printf("// %s\n\n", c.cfg.GeneratedWarning()) - c.BuildTag("stress") + c.BuildConstraint("stress") c.NL() c.Printf("package x86\n\n") c.Printf("import (\n") @@ -112,7 +112,7 @@ func NewCtorsBench(cfg printer.Config) Interface { func (c *ctorsbench) Generate(is []inst.Instruction) ([]byte, error) { c.Printf("// %s\n\n", c.cfg.GeneratedWarning()) - c.BuildTag("stress") + c.BuildConstraint("stress") c.NL() c.Printf("package x86\n\n") c.Printf("import (\n") diff --git a/internal/inst/stress_test.go b/internal/inst/stress_test.go index 193bc27..aa1b8be 100644 --- a/internal/inst/stress_test.go +++ b/internal/inst/stress_test.go @@ -2,7 +2,6 @@ // stress-test only build. //go:build stress -// +build stress package inst diff --git a/internal/prnt/printer.go b/internal/prnt/printer.go index cc9e89e..06d6e91 100644 --- a/internal/prnt/printer.go +++ b/internal/prnt/printer.go @@ -4,6 +4,7 @@ package prnt import ( "bytes" "fmt" + "go/build/constraint" "io" "strings" ) @@ -75,9 +76,13 @@ func (g *Generator) Comment(lines ...string) { } } -// BuildTag outputs a build tag. -func (g *Generator) BuildTag(tag string) { - g.Comment("+build " + tag) +// BuildConstraint outputs a build constraint. +func (g *Generator) BuildConstraint(expr string) { + line := fmt.Sprintf("//go:build %s", expr) + if _, err := constraint.Parse(line); err != nil { + g.AddError(err) + } + g.Linef(line) } // AddError records an error in code generation. The first non-nil error will diff --git a/operand/make_const.go b/operand/make_const.go index 4297530..be968c5 100644 --- a/operand/make_const.go +++ b/operand/make_const.go @@ -1,5 +1,4 @@ //go:build ignore -// +build ignore package main diff --git a/tests/alloc/gp8/asm.go b/tests/alloc/gp8/asm.go index 040f7e1..512cd10 100644 --- a/tests/alloc/gp8/asm.go +++ b/tests/alloc/gp8/asm.go @@ -1,5 +1,4 @@ //go:build ignore -// +build ignore package main diff --git a/tests/alloc/masks/asm.go b/tests/alloc/masks/asm.go index ce4bf76..9c23f11 100644 --- a/tests/alloc/masks/asm.go +++ b/tests/alloc/masks/asm.go @@ -1,5 +1,4 @@ //go:build ignore -// +build ignore package main diff --git a/tests/alloc/upper32/asm.go b/tests/alloc/upper32/asm.go index 817b8ee..4bd9d72 100644 --- a/tests/alloc/upper32/asm.go +++ b/tests/alloc/upper32/asm.go @@ -1,5 +1,4 @@ //go:build ignore -// +build ignore package main diff --git a/tests/alloc/zeroing/asm.go b/tests/alloc/zeroing/asm.go index 9c7734e..a82c97b 100644 --- a/tests/alloc/zeroing/asm.go +++ b/tests/alloc/zeroing/asm.go @@ -1,5 +1,4 @@ //go:build ignore -// +build ignore package main diff --git a/tests/cast/asm.go b/tests/cast/asm.go index 6362220..569d889 100644 --- a/tests/cast/asm.go +++ b/tests/cast/asm.go @@ -1,5 +1,4 @@ //go:build ignore -// +build ignore package main diff --git a/tests/fixedbugs/issue100/allocfail/asm.go b/tests/fixedbugs/issue100/allocfail/asm.go index b663962..a6c9aee 100644 --- a/tests/fixedbugs/issue100/allocfail/asm.go +++ b/tests/fixedbugs/issue100/allocfail/asm.go @@ -1,5 +1,4 @@ //go:build ignore -// +build ignore package main diff --git a/tests/fixedbugs/issue100/minrepro/asm.go b/tests/fixedbugs/issue100/minrepro/asm.go index 2af2b78..2aafcdc 100644 --- a/tests/fixedbugs/issue100/minrepro/asm.go +++ b/tests/fixedbugs/issue100/minrepro/asm.go @@ -1,5 +1,4 @@ //go:build ignore -// +build ignore package main diff --git a/tests/fixedbugs/issue122/asm.go b/tests/fixedbugs/issue122/asm.go index 26f48b1..f0acad4 100644 --- a/tests/fixedbugs/issue122/asm.go +++ b/tests/fixedbugs/issue122/asm.go @@ -1,5 +1,4 @@ //go:build ignore -// +build ignore package main diff --git a/tests/fixedbugs/issue191/asm.go b/tests/fixedbugs/issue191/asm.go index f6373d5..1aa6d22 100644 --- a/tests/fixedbugs/issue191/asm.go +++ b/tests/fixedbugs/issue191/asm.go @@ -1,5 +1,4 @@ //go:build ignore -// +build ignore package main diff --git a/tests/fixedbugs/issue195/asm.go b/tests/fixedbugs/issue195/asm.go index 9f1a10c..f8d15e5 100644 --- a/tests/fixedbugs/issue195/asm.go +++ b/tests/fixedbugs/issue195/asm.go @@ -1,5 +1,4 @@ //go:build ignore -// +build ignore package main diff --git a/tests/fixedbugs/issue336/asm.go b/tests/fixedbugs/issue336/asm.go index ff60018..d1e5f46 100644 --- a/tests/fixedbugs/issue336/asm.go +++ b/tests/fixedbugs/issue336/asm.go @@ -1,5 +1,4 @@ //go:build ignore -// +build ignore package main diff --git a/tests/fixedbugs/issue50/asm.go b/tests/fixedbugs/issue50/asm.go index 26b8556..00ac04d 100644 --- a/tests/fixedbugs/issue50/asm.go +++ b/tests/fixedbugs/issue50/asm.go @@ -1,5 +1,4 @@ //go:build ignore -// +build ignore package main diff --git a/tests/fixedbugs/issue62/asm.go b/tests/fixedbugs/issue62/asm.go index 0a9bd44..307a448 100644 --- a/tests/fixedbugs/issue62/asm.go +++ b/tests/fixedbugs/issue62/asm.go @@ -1,5 +1,4 @@ //go:build ignore -// +build ignore package main diff --git a/tests/fixedbugs/issue65/asm.go b/tests/fixedbugs/issue65/asm.go index edca6eb..1604da4 100644 --- a/tests/fixedbugs/issue65/asm.go +++ b/tests/fixedbugs/issue65/asm.go @@ -1,5 +1,4 @@ //go:build ignore -// +build ignore package main diff --git a/tests/fixedbugs/issue68/asm.go b/tests/fixedbugs/issue68/asm.go index 8ef87aa..c835cfe 100644 --- a/tests/fixedbugs/issue68/asm.go +++ b/tests/fixedbugs/issue68/asm.go @@ -1,5 +1,4 @@ //go:build ignore -// +build ignore package main diff --git a/tests/fixedbugs/issue76/asm.go b/tests/fixedbugs/issue76/asm.go index 7782277..7a0f660 100644 --- a/tests/fixedbugs/issue76/asm.go +++ b/tests/fixedbugs/issue76/asm.go @@ -1,5 +1,4 @@ //go:build ignore -// +build ignore package main diff --git a/tests/fixedbugs/issue89/asm.go b/tests/fixedbugs/issue89/asm.go index 2a6e487..0d4a402 100644 --- a/tests/fixedbugs/issue89/asm.go +++ b/tests/fixedbugs/issue89/asm.go @@ -1,5 +1,4 @@ //go:build ignore -// +build ignore package main diff --git a/tests/fmt/asm.go b/tests/fmt/asm.go index 8ef6e58..dd2a617 100644 --- a/tests/fmt/asm.go +++ b/tests/fmt/asm.go @@ -1,5 +1,4 @@ //go:build ignore -// +build ignore package main diff --git a/tests/labels/asm.go b/tests/labels/asm.go index 4db710e..532a70c 100644 --- a/tests/labels/asm.go +++ b/tests/labels/asm.go @@ -1,5 +1,4 @@ //go:build ignore -// +build ignore package main diff --git a/tests/signature/asm.go b/tests/signature/asm.go index 996d411..4b8b98b 100644 --- a/tests/signature/asm.go +++ b/tests/signature/asm.go @@ -1,5 +1,4 @@ //go:build ignore -// +build ignore package main diff --git a/tests/textflag/make_attrtest.go b/tests/textflag/make_attrtest.go index f4e4914..8eced39 100644 --- a/tests/textflag/make_attrtest.go +++ b/tests/textflag/make_attrtest.go @@ -1,5 +1,4 @@ //go:build ignore -// +build ignore package main diff --git a/tests/thirdparty/make_workflow.go b/tests/thirdparty/make_workflow.go index 39dcc56..669d627 100644 --- a/tests/thirdparty/make_workflow.go +++ b/tests/thirdparty/make_workflow.go @@ -1,5 +1,4 @@ //go:build ignore -// +build ignore package main diff --git a/x86/stress_test.go b/x86/stress_test.go index 50e96a2..0f1f7fb 100644 --- a/x86/stress_test.go +++ b/x86/stress_test.go @@ -2,7 +2,6 @@ // are limited to stress-test mode. //go:build stress -// +build stress package x86 diff --git a/x86/zctors_test.go b/x86/zctors_test.go index 56e9def..6c44b33 100644 --- a/x86/zctors_test.go +++ b/x86/zctors_test.go @@ -1,7 +1,6 @@ // Code generated by command: avogen -output zctors_test.go ctorstest. DO NOT EDIT. //go:build !integration -// +build !integration package x86