From e6e35dba937599d098fc034eff2686e5ddc409e9 Mon Sep 17 00:00:00 2001 From: Dmitry Vyukov Date: Mon, 26 Oct 2020 10:51:06 +0100 Subject: sys/targets: add OS/Arch name consts We use strings to identify OS/Arch. These strings are duplicated throughout the code base massively. golangci-lint points to possiblity of typos and duplication. We already had to define these names in pkg/csource and disable checking for prog package. A future change triggers such warnings in another package. Add OS/Arch name consts to sys/targets so that they can be used to refer to OS/Arch. Use the consts everywhere. --- pkg/compiler/compiler_test.go | 10 +++++----- pkg/compiler/consts_test.go | 4 ++-- pkg/compiler/fuzz.go | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) (limited to 'pkg/compiler') diff --git a/pkg/compiler/compiler_test.go b/pkg/compiler/compiler_test.go index e5c7987d1..9bc93a519 100644 --- a/pkg/compiler/compiler_test.go +++ b/pkg/compiler/compiler_test.go @@ -66,11 +66,11 @@ func TestData(t *testing.T) { // E.g. if we failed to parse descriptions, we won't run type checking at all. // Because of this we have one file per phase. for _, name := range []string{"errors.txt", "errors2.txt", "errors3.txt", "warnings.txt", "all.txt"} { - for _, arch := range []string{"32_shmem", "64"} { + for _, arch := range []string{targets.TestArch32Shmem, targets.TestArch64} { name, arch := name, arch t.Run(fmt.Sprintf("%v/%v", name, arch), func(t *testing.T) { t.Parallel() - target := targets.List["test"][arch] + target := targets.List[targets.TestOS][arch] fileName := filepath.Join("testdata", name) em := ast.NewErrorMatcher(t, fileName) astDesc := ast.Parse(em.Data, name, em.ErrorHandler) @@ -182,7 +182,7 @@ s2 { if desc == nil { t.Fatal("failed to parse") } - p := Compile(desc, map[string]uint64{"SYS_foo": 1}, targets.List["test"]["64"], eh) + p := Compile(desc, map[string]uint64{"SYS_foo": 1}, targets.List[targets.TestOS][targets.TestArch64], eh) if p == nil { t.Fatal("failed to compile") } @@ -201,7 +201,7 @@ func TestCollectUnusedError(t *testing.T) { t.Fatal("failed to parse") } - _, err := CollectUnused(desc, targets.List["test"]["64"], nopErrorHandler) + _, err := CollectUnused(desc, targets.List[targets.TestOS][targets.TestArch64], nopErrorHandler) if err == nil { t.Fatal("CollectUnused should have failed but didn't") } @@ -252,7 +252,7 @@ func TestCollectUnused(t *testing.T) { t.Fatalf("Test %d: failed to parse", i) } - nodes, err := CollectUnused(desc, targets.List["test"]["64"], nil) + nodes, err := CollectUnused(desc, targets.List[targets.TestOS][targets.TestArch64], nil) if err != nil { t.Fatalf("Test %d: CollectUnused failed: %v", i, err) } diff --git a/pkg/compiler/consts_test.go b/pkg/compiler/consts_test.go index 77a124b04..685525bc9 100644 --- a/pkg/compiler/consts_test.go +++ b/pkg/compiler/consts_test.go @@ -23,7 +23,7 @@ func TestExtractConsts(t *testing.T) { if desc == nil { t.Fatalf("failed to parse input") } - target := targets.List["linux"]["amd64"] + target := targets.List[targets.Linux][targets.AMD64] fileInfo := ExtractConsts(desc, target, func(pos ast.Pos, msg string) { t.Fatalf("%v: %v", pos, msg) }) @@ -69,7 +69,7 @@ func TestConstErrors(t *testing.T) { em.DumpErrors() t.Fatalf("parsing failed") } - target := targets.List["linux"]["amd64"] + target := targets.List[targets.Linux][targets.AMD64] ExtractConsts(desc, target, em.ErrorHandler) em.Check() } diff --git a/pkg/compiler/fuzz.go b/pkg/compiler/fuzz.go index 3f888cdbd..ecb97834b 100644 --- a/pkg/compiler/fuzz.go +++ b/pkg/compiler/fuzz.go @@ -22,6 +22,6 @@ func Fuzz(data []byte) int { } var ( - fuzzTarget = targets.Get("test", "64") + fuzzTarget = targets.Get(targets.TestOS, targets.TestArch64) fuzzConsts = map[string]uint64{"A": 1, "B": 2, "C": 3, "SYS_A": 4, "SYS_B": 5, "SYS_C": 6} ) -- cgit mrf-deployment