mirror of
https://github.com/golang/go
synced 2024-11-18 11:55:01 -07:00
go/types: add a compiler param to SizesFor
The current StdSizes most closely matches the gc compiler, and the uses I know of that care which compiler the sizes are for are all for the gc compiler, so call the existing implementation "gc". Updates #17586 Fixes #19351 Change-Id: I2bdd694518fbe233473896321a1f9758b46ed79b Reviewed-on: https://go-review.googlesource.com/37666 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
This commit is contained in:
parent
542a60fbde
commit
32a1736d24
@ -35,7 +35,7 @@ func New(ctxt *build.Context, fset *token.FileSet, packages map[string]*types.Pa
|
||||
return &Importer{
|
||||
ctxt: ctxt,
|
||||
fset: fset,
|
||||
sizes: types.SizesFor(ctxt.GOARCH), // uses go/types default if GOARCH not found
|
||||
sizes: types.SizesFor(ctxt.Compiler, ctxt.GOARCH), // uses go/types default if GOARCH not found
|
||||
packages: packages,
|
||||
}
|
||||
}
|
||||
|
@ -121,7 +121,7 @@ type Config struct {
|
||||
Importer Importer
|
||||
|
||||
// If Sizes != nil, it provides the sizing functions for package unsafe.
|
||||
// Otherwise SizesFor("amd64") is used instead.
|
||||
// Otherwise SizesFor("gc", "amd64") is used instead.
|
||||
Sizes Sizes
|
||||
|
||||
// If DisableUnusedImportCheck is set, packages are not checked
|
||||
|
@ -247,7 +247,7 @@ func checkPkgFiles(files []*ast.File) {
|
||||
report(err)
|
||||
},
|
||||
Importer: importer.For(*compiler, nil),
|
||||
Sizes: types.SizesFor(build.Default.GOARCH),
|
||||
Sizes: types.SizesFor(build.Default.Compiler, build.Default.GOARCH),
|
||||
}
|
||||
|
||||
defer func() {
|
||||
|
@ -154,7 +154,7 @@ func (s *StdSizes) Sizeof(T Type) int64 {
|
||||
}
|
||||
|
||||
// common architecture word sizes and alignments
|
||||
var archSizes = map[string]*StdSizes{
|
||||
var gcArchSizes = map[string]*StdSizes{
|
||||
"386": {4, 4},
|
||||
"arm": {4, 4},
|
||||
"arm64": {8, 8},
|
||||
@ -171,16 +171,21 @@ var archSizes = map[string]*StdSizes{
|
||||
// update the doc string of SizesFor below.
|
||||
}
|
||||
|
||||
// SizesFor returns the Sizes for one of these architectures:
|
||||
// SizesFor returns the Sizes used by a compiler for an architecture.
|
||||
// The result is nil if a compiler/architecture pair is not known.
|
||||
//
|
||||
// Supported architectures for compiler "gc":
|
||||
// "386", "arm", "arm64", "amd64", "amd64p32", "mips", "mipsle",
|
||||
// "mips64", "mips64le", "ppc64", "ppc64le", "s390x".
|
||||
// The result is nil if an architecture is not known.
|
||||
func SizesFor(arch string) Sizes {
|
||||
return archSizes[arch]
|
||||
func SizesFor(compiler, arch string) Sizes {
|
||||
if compiler != "gc" {
|
||||
return nil
|
||||
}
|
||||
return gcArchSizes[arch]
|
||||
}
|
||||
|
||||
// stdSizes is used if Config.Sizes == nil.
|
||||
var stdSizes = SizesFor("amd64")
|
||||
var stdSizes = SizesFor("gc", "amd64")
|
||||
|
||||
func (conf *Config) alignof(T Type) int64 {
|
||||
if s := conf.Sizes; s != nil {
|
||||
|
Loading…
Reference in New Issue
Block a user