all: upgrade golangci-lint and formatters (#240)
This commit is contained in:
committed by
GitHub
parent
553930530f
commit
72b8db9c80
@@ -4,17 +4,34 @@ run:
|
|||||||
linters:
|
linters:
|
||||||
enable-all: true
|
enable-all: true
|
||||||
disable:
|
disable:
|
||||||
- funlen
|
- cyclop
|
||||||
- maligned
|
- errname
|
||||||
- lll
|
- exhaustivestruct
|
||||||
- gosec
|
- forbidigo
|
||||||
- prealloc
|
- forcetypeassert
|
||||||
- unparam
|
- funlen
|
||||||
- gochecknoglobals
|
- gochecknoglobals
|
||||||
- gochecknoinits
|
- gochecknoinits
|
||||||
- gomnd
|
- godox
|
||||||
- wsl
|
- goerr113
|
||||||
- godox
|
- golint
|
||||||
|
- gomnd
|
||||||
|
- gosec
|
||||||
|
- ifshort
|
||||||
|
- interfacer
|
||||||
|
- ireturn
|
||||||
|
- lll
|
||||||
|
- maligned
|
||||||
|
- nlreturn
|
||||||
|
- paralleltest
|
||||||
|
- prealloc
|
||||||
|
- scopelint
|
||||||
|
- tagliatelle
|
||||||
|
- testpackage
|
||||||
|
- unparam
|
||||||
|
- varnamelen
|
||||||
|
- wrapcheck
|
||||||
|
- wsl
|
||||||
|
|
||||||
linters-settings:
|
linters-settings:
|
||||||
depguard:
|
depguard:
|
||||||
@@ -22,6 +39,11 @@ linters-settings:
|
|||||||
packages:
|
packages:
|
||||||
- github.com/mmcloughlin/avo
|
- github.com/mmcloughlin/avo
|
||||||
- golang.org/x/
|
- golang.org/x/
|
||||||
|
gci:
|
||||||
|
sections:
|
||||||
|
- standard
|
||||||
|
- default
|
||||||
|
- prefix(github.com/mmcloughlin/avo)
|
||||||
|
|
||||||
issues:
|
issues:
|
||||||
exclude-use-default: false
|
exclude-use-default: false
|
||||||
@@ -29,6 +51,6 @@ issues:
|
|||||||
# errcheck: Almost all programs ignore errors on these functions and in most cases it's ok
|
# errcheck: Almost all programs ignore errors on these functions and in most cases it's ok
|
||||||
- Error return value of .((os\.)?std(out|err)\..*|.*Close|.*Flush|os\.Remove(All)?|.*printf?|os\.(Un)?Setenv). is not checked
|
- Error return value of .((os\.)?std(out|err)\..*|.*Close|.*Flush|os\.Remove(All)?|.*printf?|os\.(Un)?Setenv). is not checked
|
||||||
# gocritic: https://github.com/go-critic/go-critic/issues/762
|
# gocritic: https://github.com/go-critic/go-critic/issues/762
|
||||||
- ' with `(len|cap|real|imag)`'
|
- " with `(len|cap|real|imag)`"
|
||||||
# We want to allow all caps in certain cases.
|
# We want to allow all caps in certain cases.
|
||||||
- "ALL_CAPS in Go names"
|
- "ALL_CAPS in Go names"
|
||||||
|
|||||||
@@ -107,7 +107,7 @@ func DownloadGoSourceFile(outpath, v, srcpath string) (err error) {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := ioutil.WriteFile(outpath, buf.Bytes(), 0644); err != nil {
|
if err := ioutil.WriteFile(outpath, buf.Bytes(), 0o644); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package build
|
package build
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
|
|
||||||
@@ -45,7 +46,8 @@ func (e *ErrorList) AddAt(p src.Position, err error) {
|
|||||||
e.Add(Error{p, err})
|
e.Add(Error{p, err})
|
||||||
}
|
}
|
||||||
|
|
||||||
// addext appends an error to the list, tagged with the
|
// addext appends an error to the list, tagged with the first external position
|
||||||
|
// outside this package.
|
||||||
func (e *ErrorList) addext(err error) {
|
func (e *ErrorList) addext(err error) {
|
||||||
e.Add(exterr(err))
|
e.Add(exterr(err))
|
||||||
}
|
}
|
||||||
@@ -59,7 +61,7 @@ func (e ErrorList) Err() error {
|
|||||||
return e
|
return e
|
||||||
}
|
}
|
||||||
|
|
||||||
// An ErrorList implements the error interface.
|
// Error implements the error interface.
|
||||||
func (e ErrorList) Error() string {
|
func (e ErrorList) Error() string {
|
||||||
switch len(e) {
|
switch len(e) {
|
||||||
case 0:
|
case 0:
|
||||||
@@ -74,7 +76,8 @@ func (e ErrorList) Error() string {
|
|||||||
// an ErrorList. Otherwise it just logs the err string. Reports at most max
|
// an ErrorList. Otherwise it just logs the err string. Reports at most max
|
||||||
// errors, or unlimited if max is 0.
|
// errors, or unlimited if max is 0.
|
||||||
func LogError(l *log.Logger, err error, max int) {
|
func LogError(l *log.Logger, err error, max int) {
|
||||||
if list, ok := err.(ErrorList); ok {
|
var list ErrorList
|
||||||
|
if errors.As(err, &list) {
|
||||||
for i, e := range list {
|
for i, e := range list {
|
||||||
if max > 0 && i == max {
|
if max > 0 && i == max {
|
||||||
l.Print("too many errors")
|
l.Print("too many errors")
|
||||||
|
|||||||
@@ -63,7 +63,7 @@ func TestLogErrorList(t *testing.T) {
|
|||||||
for i := 1; i <= m; i++ {
|
for i := 1; i <= m; i++ {
|
||||||
expect += fmt.Sprintf("prefix: %s:%d: some kind of error\n", filename, i)
|
expect += fmt.Sprintf("prefix: %s:%d: some kind of error\n", filename, i)
|
||||||
}
|
}
|
||||||
expect += fmt.Sprintf("prefix: too many errors\n")
|
expect += "prefix: too many errors\n"
|
||||||
|
|
||||||
got := buf.String()
|
got := buf.String()
|
||||||
if got != expect {
|
if got != expect {
|
||||||
|
|||||||
@@ -9,7 +9,6 @@ import (
|
|||||||
"github.com/mmcloughlin/avo/gotypes"
|
"github.com/mmcloughlin/avo/gotypes"
|
||||||
"github.com/mmcloughlin/avo/ir"
|
"github.com/mmcloughlin/avo/ir"
|
||||||
"github.com/mmcloughlin/avo/operand"
|
"github.com/mmcloughlin/avo/operand"
|
||||||
|
|
||||||
"github.com/mmcloughlin/avo/reg"
|
"github.com/mmcloughlin/avo/reg"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -2,10 +2,9 @@ package build
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/mmcloughlin/avo/attr"
|
"github.com/mmcloughlin/avo/attr"
|
||||||
|
"github.com/mmcloughlin/avo/gotypes"
|
||||||
"github.com/mmcloughlin/avo/operand"
|
"github.com/mmcloughlin/avo/operand"
|
||||||
"github.com/mmcloughlin/avo/reg"
|
"github.com/mmcloughlin/avo/reg"
|
||||||
|
|
||||||
"github.com/mmcloughlin/avo/gotypes"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
//go:generate avogen -output zmov.go mov
|
//go:generate avogen -output zmov.go mov
|
||||||
|
|||||||
@@ -209,7 +209,7 @@ func (o Option) ToOption() Option { return o }
|
|||||||
func (o Option) Validate() error {
|
func (o Option) Validate() error {
|
||||||
for _, t := range o {
|
for _, t := range o {
|
||||||
if err := t.Validate(); err != nil {
|
if err := t.Validate(); err != nil {
|
||||||
return fmt.Errorf("invalid term \"%s\": %s", t, err)
|
return fmt.Errorf("invalid term %q: %w", t, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
|||||||
@@ -7,9 +7,8 @@ import (
|
|||||||
"go/types"
|
"go/types"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
"github.com/mmcloughlin/avo/reg"
|
|
||||||
|
|
||||||
"github.com/mmcloughlin/avo/operand"
|
"github.com/mmcloughlin/avo/operand"
|
||||||
|
"github.com/mmcloughlin/avo/reg"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Sizes provides type sizes used by the standard Go compiler on amd64.
|
// Sizes provides type sizes used by the standard Go compiler on amd64.
|
||||||
@@ -31,7 +30,6 @@ type Component interface {
|
|||||||
// during any previous calls to Component methods, they will be returned at
|
// during any previous calls to Component methods, they will be returned at
|
||||||
// resolution time.
|
// resolution time.
|
||||||
Resolve() (*Basic, error)
|
Resolve() (*Basic, error)
|
||||||
|
|
||||||
Dereference(r reg.Register) Component // dereference a pointer
|
Dereference(r reg.Register) Component // dereference a pointer
|
||||||
Base() Component // base pointer of a string or slice
|
Base() Component // base pointer of a string or slice
|
||||||
Len() Component // length of a string or slice
|
Len() Component // length of a string or slice
|
||||||
|
|||||||
@@ -1,14 +1,14 @@
|
|||||||
package gotypes
|
package gotypes
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
"go/token"
|
"go/token"
|
||||||
"go/types"
|
"go/types"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/mmcloughlin/avo/reg"
|
|
||||||
|
|
||||||
"github.com/mmcloughlin/avo/operand"
|
"github.com/mmcloughlin/avo/operand"
|
||||||
|
"github.com/mmcloughlin/avo/reg"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestBasicKindsArePrimitive(t *testing.T) {
|
func TestBasicKindsArePrimitive(t *testing.T) {
|
||||||
@@ -39,6 +39,7 @@ func TestPointersArePrimitive(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func AssertPrimitive(t *testing.T, typ types.Type) {
|
func AssertPrimitive(t *testing.T, typ types.Type) {
|
||||||
|
t.Helper()
|
||||||
c := NewComponent(typ, operand.NewParamAddr("primitive", 0))
|
c := NewComponent(typ, operand.NewParamAddr("primitive", 0))
|
||||||
if _, err := c.Resolve(); err != nil {
|
if _, err := c.Resolve(); err != nil {
|
||||||
t.Errorf("expected type %s to be primitive: got error '%s'", typ, err)
|
t.Errorf("expected type %s to be primitive: got error '%s'", typ, err)
|
||||||
@@ -92,7 +93,7 @@ func TestComponentErrorChaining(t *testing.T) {
|
|||||||
}
|
}
|
||||||
for _, c := range cases {
|
for _, c := range cases {
|
||||||
_, err := c.Resolve()
|
_, err := c.Resolve()
|
||||||
if err != expect {
|
if !errors.Is(err, expect) {
|
||||||
t.Fatal("chaining should preserve error")
|
t.Fatal("chaining should preserve error")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"flag"
|
"flag"
|
||||||
|
"fmt"
|
||||||
"go/build"
|
"go/build"
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
@@ -43,12 +44,17 @@ func main() {
|
|||||||
log.SetPrefix("avogen: ")
|
log.SetPrefix("avogen: ")
|
||||||
log.SetFlags(0)
|
log.SetFlags(0)
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
if err := run(); err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func run() error {
|
||||||
// Build generator.
|
// Build generator.
|
||||||
t := flag.Arg(0)
|
t := flag.Arg(0)
|
||||||
builder := generators[t]
|
builder := generators[t]
|
||||||
if builder == nil {
|
if builder == nil {
|
||||||
log.Fatalf("unknown generator type '%s'", t)
|
return fmt.Errorf("unknown generator type '%s'", t)
|
||||||
}
|
}
|
||||||
|
|
||||||
g := builder(printer.NewArgvConfig())
|
g := builder(printer.NewArgvConfig())
|
||||||
@@ -58,7 +64,7 @@ func main() {
|
|||||||
if *output != "" {
|
if *output != "" {
|
||||||
f, err := os.Create(*output)
|
f, err := os.Create(*output)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
return err
|
||||||
}
|
}
|
||||||
defer f.Close()
|
defer f.Close()
|
||||||
w = f
|
w = f
|
||||||
@@ -71,7 +77,7 @@ func main() {
|
|||||||
l := load.NewLoaderFromDataDir(*datadir)
|
l := load.NewLoaderFromDataDir(*datadir)
|
||||||
r, err := l.Load()
|
r, err := l.Load()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
return err
|
||||||
}
|
}
|
||||||
is = r
|
is = r
|
||||||
}
|
}
|
||||||
@@ -81,10 +87,12 @@ func main() {
|
|||||||
|
|
||||||
// Write.
|
// Write.
|
||||||
if _, err := w.Write(b); err != nil {
|
if _, err := w.Write(b); err != nil {
|
||||||
log.Fatal(err)
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if generr != nil {
|
if generr != nil {
|
||||||
log.Fatal(generr)
|
return generr
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -187,11 +187,17 @@ func (t *Table) SuffixesTypeName() string {
|
|||||||
// SuffixesConst returns the constant for a list of suffixes. Suffixes is a
|
// SuffixesConst returns the constant for a list of suffixes. Suffixes is a
|
||||||
// generated array type, so the list is a value not slice type.
|
// generated array type, so the list is a value not slice type.
|
||||||
func (t *Table) SuffixesConst(suffixes inst.Suffixes) string {
|
func (t *Table) SuffixesConst(suffixes inst.Suffixes) string {
|
||||||
|
return t.SuffixesTypeName() + t.SuffixesList(suffixes)
|
||||||
|
}
|
||||||
|
|
||||||
|
// SuffixesList returns the constant literal for a list of suffixes, type name
|
||||||
|
// not included. Use SuffxesConst if the type is required.
|
||||||
|
func (t *Table) SuffixesList(suffixes inst.Suffixes) string {
|
||||||
var parts []string
|
var parts []string
|
||||||
for _, suffix := range suffixes {
|
for _, suffix := range suffixes {
|
||||||
parts = append(parts, t.SuffixConst(suffix))
|
parts = append(parts, t.SuffixConst(suffix))
|
||||||
}
|
}
|
||||||
return t.SuffixesTypeName() + "{" + strings.Join(parts, ", ") + "}"
|
return "{" + strings.Join(parts, ", ") + "}"
|
||||||
}
|
}
|
||||||
|
|
||||||
// SuffixesClass returns the enumeration representing all suffixes classes.
|
// SuffixesClass returns the enumeration representing all suffixes classes.
|
||||||
|
|||||||
@@ -6,10 +6,9 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/mmcloughlin/avo/internal/api"
|
"github.com/mmcloughlin/avo/internal/api"
|
||||||
|
"github.com/mmcloughlin/avo/internal/inst"
|
||||||
"github.com/mmcloughlin/avo/internal/prnt"
|
"github.com/mmcloughlin/avo/internal/prnt"
|
||||||
"github.com/mmcloughlin/avo/printer"
|
"github.com/mmcloughlin/avo/printer"
|
||||||
|
|
||||||
"github.com/mmcloughlin/avo/internal/inst"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type ctorstest struct {
|
type ctorstest struct {
|
||||||
|
|||||||
@@ -134,7 +134,7 @@ func (t *optab) suffixesType(is []inst.Instruction) {
|
|||||||
var entries []string
|
var entries []string
|
||||||
for _, class := range inst.SuffixesClasses(is) {
|
for _, class := range inst.SuffixesClasses(is) {
|
||||||
for _, suffixes := range class {
|
for _, suffixes := range class {
|
||||||
entry := fmt.Sprintf("%s: %#v", t.table.SuffixesConst(suffixes), suffixes.Strings())
|
entry := fmt.Sprintf("%s: %s", t.table.SuffixesList(suffixes), stringsliteral(suffixes.Strings()))
|
||||||
entries = append(entries, entry)
|
entries = append(entries, entry)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -177,7 +177,7 @@ func (t *optab) isasEnum(is []inst.Instruction) {
|
|||||||
// Mapping method to produce the list of ISAs.
|
// Mapping method to produce the list of ISAs.
|
||||||
lists := map[string]string{}
|
lists := map[string]string{}
|
||||||
for _, isas := range inst.ISACombinations(is) {
|
for _, isas := range inst.ISACombinations(is) {
|
||||||
lists[api.ISAsIdentifier(isas)] = fmt.Sprintf("%#v", isas)
|
lists[api.ISAsIdentifier(isas)] = stringsliteral(isas)
|
||||||
}
|
}
|
||||||
t.mapping(e, "List", "[]string", "nil", lists)
|
t.mapping(e, "List", "[]string", "nil", lists)
|
||||||
}
|
}
|
||||||
@@ -286,3 +286,14 @@ func (t *optab) stringmethod(e *Enum) {
|
|||||||
}
|
}
|
||||||
t.mapping(e, "String", "string", `""`, s)
|
t.mapping(e, "String", "string", `""`, s)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func stringsliteral(ss []string) string {
|
||||||
|
if ss == nil {
|
||||||
|
return "nil"
|
||||||
|
}
|
||||||
|
var quoted []string
|
||||||
|
for _, s := range ss {
|
||||||
|
quoted = append(quoted, strconv.Quote(s))
|
||||||
|
}
|
||||||
|
return "{" + strings.Join(quoted, ", ") + "}"
|
||||||
|
}
|
||||||
|
|||||||
@@ -855,7 +855,7 @@ func dedupe(fs []inst.Form) []inst.Form {
|
|||||||
return uniq
|
return uniq
|
||||||
}
|
}
|
||||||
|
|
||||||
// sortforms sorts a list of forms
|
// sortforms sorts a list of forms.
|
||||||
func sortforms(fs []inst.Form) {
|
func sortforms(fs []inst.Form) {
|
||||||
sort.Slice(fs, func(i, j int) bool {
|
sort.Slice(fs, func(i, j int) bool {
|
||||||
return sortkey(fs[i]) < sortkey(fs[j])
|
return sortkey(fs[i]) < sortkey(fs[j])
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ func Assembles(t *testing.T, asm []byte) {
|
|||||||
defer clean()
|
defer clean()
|
||||||
|
|
||||||
asmfilename := filepath.Join(dir, "asm.s")
|
asmfilename := filepath.Join(dir, "asm.s")
|
||||||
if err := ioutil.WriteFile(asmfilename, asm, 0600); err != nil {
|
if err := ioutil.WriteFile(asmfilename, asm, 0o600); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -96,11 +96,13 @@ func GoTool() string {
|
|||||||
|
|
||||||
// goexec runs a "go" command and checks the output.
|
// goexec runs a "go" command and checks the output.
|
||||||
func goexec(t *testing.T, arg ...string) {
|
func goexec(t *testing.T, arg ...string) {
|
||||||
|
t.Helper()
|
||||||
Exec(t, GoTool(), arg...)
|
Exec(t, GoTool(), arg...)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Logger builds a logger that writes to the test object.
|
// Logger builds a logger that writes to the test object.
|
||||||
func Logger(tb testing.TB) *log.Logger {
|
func Logger(tb testing.TB) *log.Logger {
|
||||||
|
tb.Helper()
|
||||||
return log.New(Writer(tb), "test", log.LstdFlags)
|
return log.New(Writer(tb), "test", log.LstdFlags)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -110,6 +112,7 @@ type writer struct {
|
|||||||
|
|
||||||
// Writer builds a writer that logs all writes to the test object.
|
// Writer builds a writer that logs all writes to the test object.
|
||||||
func Writer(tb testing.TB) io.Writer {
|
func Writer(tb testing.TB) io.Writer {
|
||||||
|
tb.Helper()
|
||||||
return writer{tb}
|
return writer{tb}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
2
ir/ir.go
2
ir/ir.go
@@ -298,7 +298,7 @@ func (d Datum) Interval() (int, int) {
|
|||||||
return d.Offset, d.Offset + d.Value.Bytes()
|
return d.Offset, d.Offset + d.Value.Bytes()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Overlaps returns true
|
// Overlaps returns whether d overlaps with other.
|
||||||
func (d Datum) Overlaps(other Datum) bool {
|
func (d Datum) Overlaps(other Datum) bool {
|
||||||
s, e := d.Interval()
|
s, e := d.Interval()
|
||||||
so, eo := other.Interval()
|
so, eo := other.Interval()
|
||||||
|
|||||||
@@ -5,7 +5,6 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/mmcloughlin/avo/operand"
|
"github.com/mmcloughlin/avo/operand"
|
||||||
|
|
||||||
"github.com/mmcloughlin/avo/reg"
|
"github.com/mmcloughlin/avo/reg"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -257,14 +257,17 @@ func ComputeCFG(t *testing.T, f *ir.Function) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func AssertSuccessors(t *testing.T, f *ir.Function, expect map[string][]string) {
|
func AssertSuccessors(t *testing.T, f *ir.Function, expect map[string][]string) {
|
||||||
|
t.Helper()
|
||||||
AssertEqual(t, "successors", OpcodeSuccessorGraph(f), expect)
|
AssertEqual(t, "successors", OpcodeSuccessorGraph(f), expect)
|
||||||
}
|
}
|
||||||
|
|
||||||
func AssertPredecessors(t *testing.T, f *ir.Function, expect map[string][]string) {
|
func AssertPredecessors(t *testing.T, f *ir.Function, expect map[string][]string) {
|
||||||
|
t.Helper()
|
||||||
AssertEqual(t, "predecessors", OpcodePredecessorGraph(f), expect)
|
AssertEqual(t, "predecessors", OpcodePredecessorGraph(f), expect)
|
||||||
}
|
}
|
||||||
|
|
||||||
func AssertEqual(t *testing.T, what string, got, expect interface{}) {
|
func AssertEqual(t *testing.T, what string, got, expect interface{}) {
|
||||||
|
t.Helper()
|
||||||
t.Logf("%s=%#v\n", what, got)
|
t.Logf("%s=%#v\n", what, got)
|
||||||
if reflect.DeepEqual(expect, got) {
|
if reflect.DeepEqual(expect, got) {
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -83,6 +83,7 @@ func TestLivenessBasic(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func AssertLiveness(t *testing.T, ctx *build.Context, in, out [][]reg.Register) {
|
func AssertLiveness(t *testing.T, ctx *build.Context, in, out [][]reg.Register) {
|
||||||
|
t.Helper()
|
||||||
fn := ConstructLiveness(t, ctx)
|
fn := ConstructLiveness(t, ctx)
|
||||||
is := fn.Instructions()
|
is := fn.Instructions()
|
||||||
|
|
||||||
@@ -97,12 +98,14 @@ func AssertLiveness(t *testing.T, ctx *build.Context, in, out [][]reg.Register)
|
|||||||
}
|
}
|
||||||
|
|
||||||
func AssertRegistersMatchSet(t *testing.T, rs []reg.Register, s reg.MaskSet) {
|
func AssertRegistersMatchSet(t *testing.T, rs []reg.Register, s reg.MaskSet) {
|
||||||
|
t.Helper()
|
||||||
if !s.Equals(reg.NewMaskSetFromRegisters(rs)) {
|
if !s.Equals(reg.NewMaskSetFromRegisters(rs)) {
|
||||||
t.Fatalf("register slice does not match set: %#v and %#v", rs, s)
|
t.Fatalf("register slice does not match set: %#v and %#v", rs, s)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func ConstructLiveness(t *testing.T, ctx *build.Context) *ir.Function {
|
func ConstructLiveness(t *testing.T, ctx *build.Context) *ir.Function {
|
||||||
|
t.Helper()
|
||||||
return BuildFunction(t, ctx, pass.LabelTarget, pass.CFG, pass.Liveness)
|
return BuildFunction(t, ctx, pass.LabelTarget, pass.CFG, pass.Liveness)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
18
reg/x86.go
18
reg/x86.go
@@ -100,19 +100,19 @@ func gp(s Spec, id Index, name string, flags ...Info) GPPhysical {
|
|||||||
|
|
||||||
// General purpose registers.
|
// General purpose registers.
|
||||||
var (
|
var (
|
||||||
// Low byte
|
// Low byte.
|
||||||
AL = gp(S8L, 0, "AL")
|
AL = gp(S8L, 0, "AL")
|
||||||
CL = gp(S8L, 1, "CL")
|
CL = gp(S8L, 1, "CL")
|
||||||
DL = gp(S8L, 2, "DL")
|
DL = gp(S8L, 2, "DL")
|
||||||
BL = gp(S8L, 3, "BL")
|
BL = gp(S8L, 3, "BL")
|
||||||
|
|
||||||
// High byte
|
// High byte.
|
||||||
AH = gp(S8H, 0, "AH")
|
AH = gp(S8H, 0, "AH")
|
||||||
CH = gp(S8H, 1, "CH")
|
CH = gp(S8H, 1, "CH")
|
||||||
DH = gp(S8H, 2, "DH")
|
DH = gp(S8H, 2, "DH")
|
||||||
BH = gp(S8H, 3, "BH")
|
BH = gp(S8H, 3, "BH")
|
||||||
|
|
||||||
// 8-bit
|
// 8-bit.
|
||||||
SPB = gp(S8, 4, "SP", Restricted)
|
SPB = gp(S8, 4, "SP", Restricted)
|
||||||
BPB = gp(S8, 5, "BP", BasePointer)
|
BPB = gp(S8, 5, "BP", BasePointer)
|
||||||
SIB = gp(S8, 6, "SI")
|
SIB = gp(S8, 6, "SI")
|
||||||
@@ -126,7 +126,7 @@ var (
|
|||||||
R14B = gp(S8, 14, "R14")
|
R14B = gp(S8, 14, "R14")
|
||||||
R15B = gp(S8, 15, "R15")
|
R15B = gp(S8, 15, "R15")
|
||||||
|
|
||||||
// 16-bit
|
// 16-bit.
|
||||||
AX = gp(S16, 0, "AX")
|
AX = gp(S16, 0, "AX")
|
||||||
CX = gp(S16, 1, "CX")
|
CX = gp(S16, 1, "CX")
|
||||||
DX = gp(S16, 2, "DX")
|
DX = gp(S16, 2, "DX")
|
||||||
@@ -144,7 +144,7 @@ var (
|
|||||||
R14W = gp(S16, 14, "R14")
|
R14W = gp(S16, 14, "R14")
|
||||||
R15W = gp(S16, 15, "R15")
|
R15W = gp(S16, 15, "R15")
|
||||||
|
|
||||||
// 32-bit
|
// 32-bit.
|
||||||
EAX = gp(S32, 0, "AX")
|
EAX = gp(S32, 0, "AX")
|
||||||
ECX = gp(S32, 1, "CX")
|
ECX = gp(S32, 1, "CX")
|
||||||
EDX = gp(S32, 2, "DX")
|
EDX = gp(S32, 2, "DX")
|
||||||
@@ -162,7 +162,7 @@ var (
|
|||||||
R14L = gp(S32, 14, "R14")
|
R14L = gp(S32, 14, "R14")
|
||||||
R15L = gp(S32, 15, "R15")
|
R15L = gp(S32, 15, "R15")
|
||||||
|
|
||||||
// 64-bit
|
// 64-bit.
|
||||||
RAX = gp(S64, 0, "AX")
|
RAX = gp(S64, 0, "AX")
|
||||||
RCX = gp(S64, 1, "CX")
|
RCX = gp(S64, 1, "CX")
|
||||||
RDX = gp(S64, 2, "DX")
|
RDX = gp(S64, 2, "DX")
|
||||||
@@ -230,7 +230,7 @@ func vec(s Spec, id Index, name string, flags ...Info) VecPhysical {
|
|||||||
|
|
||||||
// Vector registers.
|
// Vector registers.
|
||||||
var (
|
var (
|
||||||
// 128-bit
|
// 128-bit.
|
||||||
X0 = vec(S128, 0, "X0")
|
X0 = vec(S128, 0, "X0")
|
||||||
X1 = vec(S128, 1, "X1")
|
X1 = vec(S128, 1, "X1")
|
||||||
X2 = vec(S128, 2, "X2")
|
X2 = vec(S128, 2, "X2")
|
||||||
@@ -264,7 +264,7 @@ var (
|
|||||||
X30 = vec(S128, 30, "X30")
|
X30 = vec(S128, 30, "X30")
|
||||||
X31 = vec(S128, 31, "X31")
|
X31 = vec(S128, 31, "X31")
|
||||||
|
|
||||||
// 256-bit
|
// 256-bit.
|
||||||
Y0 = vec(S256, 0, "Y0")
|
Y0 = vec(S256, 0, "Y0")
|
||||||
Y1 = vec(S256, 1, "Y1")
|
Y1 = vec(S256, 1, "Y1")
|
||||||
Y2 = vec(S256, 2, "Y2")
|
Y2 = vec(S256, 2, "Y2")
|
||||||
@@ -298,7 +298,7 @@ var (
|
|||||||
Y30 = vec(S256, 30, "Y30")
|
Y30 = vec(S256, 30, "Y30")
|
||||||
Y31 = vec(S256, 31, "Y31")
|
Y31 = vec(S256, 31, "Y31")
|
||||||
|
|
||||||
// 512-bit
|
// 512-bit.
|
||||||
Z0 = vec(S512, 0, "Z0")
|
Z0 = vec(S512, 0, "Z0")
|
||||||
Z1 = vec(S512, 1, "Z1")
|
Z1 = vec(S512, 1, "Z1")
|
||||||
Z2 = vec(S512, 2, "Z2")
|
Z2 = vec(S512, 2, "Z2")
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
go install ./internal/cmd/asmvet
|
go install ./internal/cmd/asmvet
|
||||||
|
|
||||||
# Install golangci-lint
|
# Install golangci-lint
|
||||||
golangci_lint_version='v1.23.6'
|
golangci_lint_version='v1.45.2'
|
||||||
golangci_install_script="https://raw.githubusercontent.com/golangci/golangci-lint/${golangci_lint_version}/install.sh"
|
golangci_install_script="https://raw.githubusercontent.com/golangci/golangci-lint/${golangci_lint_version}/install.sh"
|
||||||
curl -sfL "${golangci_install_script}" | sh -s -- -b "$GOPATH/bin" "${golangci_lint_version}"
|
curl -sfL "${golangci_install_script}" | sh -s -- -b "$GOPATH/bin" "${golangci_lint_version}"
|
||||||
|
|
||||||
@@ -17,5 +17,8 @@ go install github.com/dlespiau/covertool@v0.0.0-20180314162135-b0c4c6d0583a
|
|||||||
# asmfmt for enforcing assembly style
|
# asmfmt for enforcing assembly style
|
||||||
go install github.com/klauspost/asmfmt/cmd/asmfmt@v1.3.1
|
go install github.com/klauspost/asmfmt/cmd/asmfmt@v1.3.1
|
||||||
|
|
||||||
# gofumports for stricter formatting
|
# goimports for import grouping.
|
||||||
go install mvdan.cc/gofumpt/gofumports@v0.0.0-20200412215918-a91da47f375c
|
go install golang.org/x/tools/cmd/goimports@v0.1.10
|
||||||
|
|
||||||
|
# gofumpt for stricter formatting.
|
||||||
|
go install mvdan.cc/gofumpt@v0.2.1
|
||||||
|
|||||||
@@ -8,8 +8,11 @@ files=$(find . -name '*.go' -not -path '*/stadtx/*')
|
|||||||
|
|
||||||
# Remove blank lines in import blocks. This will force formatting to group
|
# Remove blank lines in import blocks. This will force formatting to group
|
||||||
# imports correctly.
|
# imports correctly.
|
||||||
sed -i.fmtbackup '/^import (/,/)/ { /^$$/ d; }' ${files}
|
sed -i.fmtbackup '/^import (/,/)/ { /^[ \t]*$/ d; }' ${files}
|
||||||
find . -name '*.fmtbackup' -delete
|
find . -name '*.fmtbackup' -delete
|
||||||
|
|
||||||
# gofumports is goimports with stricter formatting.
|
# goimports for import grouping.
|
||||||
gofumports -w -local ${repo} ${files}
|
goimports -w -local "${repo}" ${files}
|
||||||
|
|
||||||
|
# gofumpt for stricter gofmt-compatible format.
|
||||||
|
gofumpt -w ${files}
|
||||||
|
|||||||
@@ -90,6 +90,7 @@ func TestCases(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func MustInstruction(t *testing.T) func(*ir.Instruction, error) *ir.Instruction {
|
func MustInstruction(t *testing.T) func(*ir.Instruction, error) *ir.Instruction {
|
||||||
|
t.Helper()
|
||||||
return func(i *ir.Instruction, err error) *ir.Instruction {
|
return func(i *ir.Instruction, err error) *ir.Instruction {
|
||||||
t.Helper()
|
t.Helper()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
124
x86/zoptab.go
124
x86/zoptab.go
@@ -215,20 +215,20 @@ func (s sffxs) Strings() []string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var sffxsstringsmap = map[sffxs][]string{
|
var sffxsstringsmap = map[sffxs][]string{
|
||||||
sffxs{sffxBCST, sffxZ}: []string{"BCST", "Z"},
|
{sffxBCST, sffxZ}: {"BCST", "Z"},
|
||||||
sffxs{sffxBCST}: []string{"BCST"},
|
{sffxBCST}: {"BCST"},
|
||||||
sffxs{sffxRD_SAE, sffxZ}: []string{"RD_SAE", "Z"},
|
{sffxRD_SAE, sffxZ}: {"RD_SAE", "Z"},
|
||||||
sffxs{sffxRD_SAE}: []string{"RD_SAE"},
|
{sffxRD_SAE}: {"RD_SAE"},
|
||||||
sffxs{sffxRN_SAE, sffxZ}: []string{"RN_SAE", "Z"},
|
{sffxRN_SAE, sffxZ}: {"RN_SAE", "Z"},
|
||||||
sffxs{sffxRN_SAE}: []string{"RN_SAE"},
|
{sffxRN_SAE}: {"RN_SAE"},
|
||||||
sffxs{sffxRU_SAE, sffxZ}: []string{"RU_SAE", "Z"},
|
{sffxRU_SAE, sffxZ}: {"RU_SAE", "Z"},
|
||||||
sffxs{sffxRU_SAE}: []string{"RU_SAE"},
|
{sffxRU_SAE}: {"RU_SAE"},
|
||||||
sffxs{sffxRZ_SAE, sffxZ}: []string{"RZ_SAE", "Z"},
|
{sffxRZ_SAE, sffxZ}: {"RZ_SAE", "Z"},
|
||||||
sffxs{sffxRZ_SAE}: []string{"RZ_SAE"},
|
{sffxRZ_SAE}: {"RZ_SAE"},
|
||||||
sffxs{sffxSAE, sffxZ}: []string{"SAE", "Z"},
|
{sffxSAE, sffxZ}: {"SAE", "Z"},
|
||||||
sffxs{sffxSAE}: []string{"SAE"},
|
{sffxSAE}: {"SAE"},
|
||||||
sffxs{sffxZ}: []string{"Z"},
|
{sffxZ}: {"Z"},
|
||||||
sffxs{}: []string(nil),
|
{}: nil,
|
||||||
}
|
}
|
||||||
|
|
||||||
type sffxscls uint8
|
type sffxscls uint8
|
||||||
@@ -327,54 +327,54 @@ func (i isas) List() []string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var isaslisttable = [][]string{
|
var isaslisttable = [][]string{
|
||||||
[]string(nil),
|
nil,
|
||||||
[]string{"ADX"},
|
{"ADX"},
|
||||||
[]string{"SSE2"},
|
{"SSE2"},
|
||||||
[]string{"SSE"},
|
{"SSE"},
|
||||||
[]string{"SSE3"},
|
{"SSE3"},
|
||||||
[]string{"AES"},
|
{"AES"},
|
||||||
[]string{"BMI"},
|
{"BMI"},
|
||||||
[]string{"SSE4.1"},
|
{"SSE4.1"},
|
||||||
[]string{"BMI2"},
|
{"BMI2"},
|
||||||
[]string{"CLFLUSH"},
|
{"CLFLUSH"},
|
||||||
[]string{"CLFLUSHOPT"},
|
{"CLFLUSHOPT"},
|
||||||
[]string{"CMOV"},
|
{"CMOV"},
|
||||||
[]string{"CPUID"},
|
{"CPUID"},
|
||||||
[]string{"SSE4.2"},
|
{"SSE4.2"},
|
||||||
[]string{"AVX512DQ"},
|
{"AVX512DQ"},
|
||||||
[]string{"AVX512BW"},
|
{"AVX512BW"},
|
||||||
[]string{"AVX512F"},
|
{"AVX512F"},
|
||||||
[]string{"LZCNT"},
|
{"LZCNT"},
|
||||||
[]string{"MONITOR"},
|
{"MONITOR"},
|
||||||
[]string{"MOVBE"},
|
{"MOVBE"},
|
||||||
[]string{"SSSE3"},
|
{"SSSE3"},
|
||||||
[]string{"PCLMULQDQ"},
|
{"PCLMULQDQ"},
|
||||||
[]string{"POPCNT"},
|
{"POPCNT"},
|
||||||
[]string{"MMX+"},
|
{"MMX+"},
|
||||||
[]string{"RDRAND"},
|
{"RDRAND"},
|
||||||
[]string{"RDSEED"},
|
{"RDSEED"},
|
||||||
[]string{"RDTSC"},
|
{"RDTSC"},
|
||||||
[]string{"RDTSCP"},
|
{"RDTSCP"},
|
||||||
[]string{"SHA"},
|
{"SHA"},
|
||||||
[]string{"AVX"},
|
{"AVX"},
|
||||||
[]string{"AVX512F", "AVX512VL"},
|
{"AVX512F", "AVX512VL"},
|
||||||
[]string{"AES", "AVX"},
|
{"AES", "AVX"},
|
||||||
[]string{"AVX512DQ", "AVX512VL"},
|
{"AVX512DQ", "AVX512VL"},
|
||||||
[]string{"AVX2"},
|
{"AVX2"},
|
||||||
[]string{"F16C"},
|
{"F16C"},
|
||||||
[]string{"AVX512VL"},
|
{"AVX512VL"},
|
||||||
[]string{"AVX512BW", "AVX512VL"},
|
{"AVX512BW", "AVX512VL"},
|
||||||
[]string{"AVX512ER"},
|
{"AVX512ER"},
|
||||||
[]string{"FMA3"},
|
{"FMA3"},
|
||||||
[]string{"AVX512CD", "AVX512VL"},
|
{"AVX512CD", "AVX512VL"},
|
||||||
[]string{"AVX512CD"},
|
{"AVX512CD"},
|
||||||
[]string{"AVX", "PCLMULQDQ"},
|
{"AVX", "PCLMULQDQ"},
|
||||||
[]string{"AVX512VBMI", "AVX512VL"},
|
{"AVX512VBMI", "AVX512VL"},
|
||||||
[]string{"AVX512VBMI"},
|
{"AVX512VBMI"},
|
||||||
[]string{"AVX512IFMA", "AVX512VL"},
|
{"AVX512IFMA", "AVX512VL"},
|
||||||
[]string{"AVX512IFMA"},
|
{"AVX512IFMA"},
|
||||||
[]string{"AVX512VPOPCNTDQ"},
|
{"AVX512VPOPCNTDQ"},
|
||||||
[]string{"AVX512BW", "AVX512F"},
|
{"AVX512BW", "AVX512F"},
|
||||||
}
|
}
|
||||||
|
|
||||||
type opc uint16
|
type opc uint16
|
||||||
|
|||||||
Reference in New Issue
Block a user