Commit 99fbccbd authored by Josh Bleecher Snyder's avatar Josh Bleecher Snyder

cmd/vet: use types.SizesFor

This eliminates a duplicate copy of
the SizesFor map.

Change-Id: I51e44ea8ee860901086616e3f4dfa32aaa9b4d2d
Reviewed-on: https://go-review.googlesource.com/37667
Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com>
Reviewed-by: default avatarRob Pike <r@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
parent 32a1736d
...@@ -36,10 +36,14 @@ const ( ...@@ -36,10 +36,14 @@ const (
// An asmArch describes assembly parameters for an architecture // An asmArch describes assembly parameters for an architecture
type asmArch struct { type asmArch struct {
name string name string
sizes *types.StdSizes
bigEndian bool bigEndian bool
stack string stack string
lr bool lr bool
// calculated during initialization
sizes types.Sizes
intSize int
ptrSize int
maxAlign int
} }
// An asmFunc describes the expected variables for a function on a given architecture. // An asmFunc describes the expected variables for a function on a given architecture.
...@@ -60,26 +64,19 @@ type asmVar struct { ...@@ -60,26 +64,19 @@ type asmVar struct {
inner []*asmVar inner []*asmVar
} }
// Common architecture word sizes and alignments.
var ( var (
size44 = &types.StdSizes{WordSize: 4, MaxAlign: 4} asmArch386 = asmArch{name: "386", bigEndian: false, stack: "SP", lr: false}
size48 = &types.StdSizes{WordSize: 4, MaxAlign: 8} asmArchArm = asmArch{name: "arm", bigEndian: false, stack: "R13", lr: true}
size88 = &types.StdSizes{WordSize: 8, MaxAlign: 8} asmArchArm64 = asmArch{name: "arm64", bigEndian: false, stack: "RSP", lr: true}
) asmArchAmd64 = asmArch{name: "amd64", bigEndian: false, stack: "SP", lr: false}
asmArchAmd64p32 = asmArch{name: "amd64p32", bigEndian: false, stack: "SP", lr: false}
var ( asmArchMips = asmArch{name: "mips", bigEndian: true, stack: "R29", lr: true}
asmArch386 = asmArch{"386", size44, false, "SP", false} asmArchMipsLE = asmArch{name: "mipsle", bigEndian: false, stack: "R29", lr: true}
asmArchArm = asmArch{"arm", size44, false, "R13", true} asmArchMips64 = asmArch{name: "mips64", bigEndian: true, stack: "R29", lr: true}
asmArchArm64 = asmArch{"arm64", size88, false, "RSP", true} asmArchMips64LE = asmArch{name: "mips64le", bigEndian: false, stack: "R29", lr: true}
asmArchAmd64 = asmArch{"amd64", size88, false, "SP", false} asmArchPpc64 = asmArch{name: "ppc64", bigEndian: true, stack: "R1", lr: true}
asmArchAmd64p32 = asmArch{"amd64p32", size48, false, "SP", false} asmArchPpc64LE = asmArch{name: "ppc64le", bigEndian: false, stack: "R1", lr: true}
asmArchMips = asmArch{"mips", size44, true, "R29", true} asmArchS390X = asmArch{name: "s390x", bigEndian: true, stack: "R15", lr: true}
asmArchMipsLE = asmArch{"mipsle", size44, false, "R29", true}
asmArchMips64 = asmArch{"mips64", size88, true, "R29", true}
asmArchMips64LE = asmArch{"mips64le", size88, false, "R29", true}
asmArchPpc64 = asmArch{"ppc64", size88, true, "R1", true}
asmArchPpc64LE = asmArch{"ppc64le", size88, false, "R1", true}
asmArchS390X = asmArch{"s390x", size88, true, "R15", true}
arches = []*asmArch{ arches = []*asmArch{
&asmArch386, &asmArch386,
...@@ -97,9 +94,17 @@ var ( ...@@ -97,9 +94,17 @@ var (
} }
) )
func (a *asmArch) intSize() int { return int(a.sizes.WordSize) } func init() {
func (a *asmArch) ptrSize() int { return int(a.sizes.WordSize) } for _, arch := range arches {
func (a *asmArch) maxAlign() int { return int(a.sizes.MaxAlign) } arch.sizes = types.SizesFor("gc", arch.name)
if arch.sizes == nil {
panic("missing SizesFor for gc/" + arch.name)
}
arch.intSize = int(arch.sizes.Sizeof(types.Typ[types.Int]))
arch.ptrSize = int(arch.sizes.Sizeof(types.Typ[types.UnsafePointer]))
arch.maxAlign = int(arch.sizes.Alignof(types.Typ[types.Int64]))
}
}
var ( var (
re = regexp.MustCompile re = regexp.MustCompile
...@@ -244,10 +249,10 @@ Files: ...@@ -244,10 +249,10 @@ Files:
} }
} }
localSize, _ = strconv.Atoi(m[4]) localSize, _ = strconv.Atoi(m[4])
localSize += archDef.intSize() localSize += archDef.intSize
if archDef.lr { if archDef.lr {
// Account for caller's saved LR // Account for caller's saved LR
localSize += archDef.intSize() localSize += archDef.intSize
} }
argSize, _ = strconv.Atoi(m[5]) argSize, _ = strconv.Atoi(m[5])
if fn == nil && !strings.Contains(fnName, "<>") { if fn == nil && !strings.Contains(fnName, "<>") {
...@@ -412,7 +417,7 @@ func appendComponentsRecursive(arch *asmArch, t types.Type, cc []component, suff ...@@ -412,7 +417,7 @@ func appendComponentsRecursive(arch *asmArch, t types.Type, cc []component, suff
switch kind { switch kind {
case 8: case 8:
if arch.ptrSize() == 4 { if arch.ptrSize == 4 {
w1, w2 := "lo", "hi" w1, w2 := "lo", "hi"
if arch.bigEndian { if arch.bigEndian {
w1, w2 = w2, w1 w1, w2 = w2, w1
...@@ -422,21 +427,21 @@ func appendComponentsRecursive(arch *asmArch, t types.Type, cc []component, suff ...@@ -422,21 +427,21 @@ func appendComponentsRecursive(arch *asmArch, t types.Type, cc []component, suff
} }
case asmEmptyInterface: case asmEmptyInterface:
cc = append(cc, newComponent(suffix+"_type", asmKind(arch.ptrSize()), "interface type", off, arch.ptrSize(), suffix)) cc = append(cc, newComponent(suffix+"_type", asmKind(arch.ptrSize), "interface type", off, arch.ptrSize, suffix))
cc = append(cc, newComponent(suffix+"_data", asmKind(arch.ptrSize()), "interface data", off+arch.ptrSize(), arch.ptrSize(), suffix)) cc = append(cc, newComponent(suffix+"_data", asmKind(arch.ptrSize), "interface data", off+arch.ptrSize, arch.ptrSize, suffix))
case asmInterface: case asmInterface:
cc = append(cc, newComponent(suffix+"_itable", asmKind(arch.ptrSize()), "interface itable", off, arch.ptrSize(), suffix)) cc = append(cc, newComponent(suffix+"_itable", asmKind(arch.ptrSize), "interface itable", off, arch.ptrSize, suffix))
cc = append(cc, newComponent(suffix+"_data", asmKind(arch.ptrSize()), "interface data", off+arch.ptrSize(), arch.ptrSize(), suffix)) cc = append(cc, newComponent(suffix+"_data", asmKind(arch.ptrSize), "interface data", off+arch.ptrSize, arch.ptrSize, suffix))
case asmSlice: case asmSlice:
cc = append(cc, newComponent(suffix+"_base", asmKind(arch.ptrSize()), "slice base", off, arch.ptrSize(), suffix)) cc = append(cc, newComponent(suffix+"_base", asmKind(arch.ptrSize), "slice base", off, arch.ptrSize, suffix))
cc = append(cc, newComponent(suffix+"_len", asmKind(arch.intSize()), "slice len", off+arch.ptrSize(), arch.intSize(), suffix)) cc = append(cc, newComponent(suffix+"_len", asmKind(arch.intSize), "slice len", off+arch.ptrSize, arch.intSize, suffix))
cc = append(cc, newComponent(suffix+"_cap", asmKind(arch.intSize()), "slice cap", off+arch.ptrSize()+arch.intSize(), arch.intSize(), suffix)) cc = append(cc, newComponent(suffix+"_cap", asmKind(arch.intSize), "slice cap", off+arch.ptrSize+arch.intSize, arch.intSize, suffix))
case asmString: case asmString:
cc = append(cc, newComponent(suffix+"_base", asmKind(arch.ptrSize()), "string base", off, arch.ptrSize(), suffix)) cc = append(cc, newComponent(suffix+"_base", asmKind(arch.ptrSize), "string base", off, arch.ptrSize, suffix))
cc = append(cc, newComponent(suffix+"_len", asmKind(arch.intSize()), "string len", off+arch.ptrSize(), arch.intSize(), suffix)) cc = append(cc, newComponent(suffix+"_len", asmKind(arch.intSize), "string len", off+arch.ptrSize, arch.intSize, suffix))
case asmComplex: case asmComplex:
fsize := size / 2 fsize := size / 2
...@@ -542,7 +547,7 @@ func (f *File) asmParseDecl(decl *ast.FuncDecl) map[string]*asmFunc { ...@@ -542,7 +547,7 @@ func (f *File) asmParseDecl(decl *ast.FuncDecl) map[string]*asmFunc {
offset = 0 offset = 0
addParams(decl.Type.Params.List, false) addParams(decl.Type.Params.List, false)
if decl.Type.Results != nil && len(decl.Type.Results.List) > 0 { if decl.Type.Results != nil && len(decl.Type.Results.List) > 0 {
offset += -offset & (arch.maxAlign() - 1) offset += -offset & (arch.maxAlign - 1)
addParams(decl.Type.Results.List, true) addParams(decl.Type.Results.List, true)
} }
fn.size = offset fn.size = offset
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment