]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/vet/all: use SizesFor to calculate archbits
authorJosh Bleecher Snyder <josharian@gmail.com>
Thu, 2 Mar 2017 15:23:43 +0000 (07:23 -0800)
committerJosh Bleecher Snyder <josharian@gmail.com>
Thu, 2 Mar 2017 17:13:44 +0000 (17:13 +0000)
Change-Id: I99706807782f11e8d24baf953424a9e292a2cbac
Reviewed-on: https://go-review.googlesource.com/37668
Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com>
Reviewed-by: Rob Pike <r@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>

src/cmd/vet/all/main.go

index 70111116597f89e780bb705b07c9af68b8fbad72..0089d9d3efeb653a698da51ed88073606770d692 100644 (file)
@@ -15,6 +15,7 @@ import (
        "flag"
        "fmt"
        "go/build"
+       "go/types"
        "internal/testenv"
        "log"
        "os"
@@ -108,11 +109,11 @@ type whitelist map[string]int
 
 // load adds entries from the whitelist file, if present, for os/arch to w.
 func (w whitelist) load(goos string, goarch string) {
-       // Look up whether goarch is a 32-bit or 64-bit architecture.
-       archbits, ok := nbits[goarch]
-       if !ok {
-               log.Fatalf("unknown bitwidth for arch %q", goarch)
+       sz := types.SizesFor("gc", goarch)
+       if sz == nil {
+               log.Fatalf("unknown type sizes for arch %q", goarch)
        }
+       archbits := 8 * sz.Sizeof(types.Typ[types.UnsafePointer])
 
        // Look up whether goarch has a shared arch suffix,
        // such as mips64x for mips64 and mips64le.
@@ -338,23 +339,6 @@ NextLine:
        os.Stdout.Write(buf.Bytes())
 }
 
-// nbits maps from architecture names to the number of bits in a pointer.
-// TODO: figure out a clean way to avoid get this info rather than listing it here yet again.
-var nbits = map[string]int{
-       "386":      32,
-       "amd64":    64,
-       "amd64p32": 32,
-       "arm":      32,
-       "arm64":    64,
-       "mips":     32,
-       "mipsle":   32,
-       "mips64":   64,
-       "mips64le": 64,
-       "ppc64":    64,
-       "ppc64le":  64,
-       "s390x":    64,
-}
-
 // archAsmX maps architectures to the suffix usually used for their assembly files,
 // if different than the arch name itself.
 var archAsmX = map[string]string{