mirror of
https://github.com/golang/go.git
synced 2025-05-21 07:13:27 +00:00
cmd/compile: eliminate arch-specific typedefs
Arch backends already provide us Widthint and Widthptr, which is ample information to figure out how to define the universal "int", "uint", and "uintptr" types. No need for providing a generic typedef mechanism beyond that. Change-Id: I35c0c17a67c80605a9208b93d77d6960b2cbb17d Reviewed-on: https://go-review.googlesource.com/20153 Run-TryBot: Matthew Dempsky <mdempsky@google.com> Reviewed-by: Dave Cheney <dave@cheney.net> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
This commit is contained in:
parent
0024101b2d
commit
a40b27e304
@ -34,16 +34,6 @@ var (
|
|||||||
cmpptr int = x86.ACMPQ
|
cmpptr int = x86.ACMPQ
|
||||||
)
|
)
|
||||||
|
|
||||||
/*
|
|
||||||
* go declares several platform-specific type aliases:
|
|
||||||
* int, uint, and uintptr
|
|
||||||
*/
|
|
||||||
var typedefs = []gc.Typedef{
|
|
||||||
{"int", gc.TINT, gc.TINT64},
|
|
||||||
{"uint", gc.TUINT, gc.TUINT64},
|
|
||||||
{"uintptr", gc.TUINTPTR, gc.TUINT64},
|
|
||||||
}
|
|
||||||
|
|
||||||
func betypeinit() {
|
func betypeinit() {
|
||||||
gc.Widthptr = 8
|
gc.Widthptr = 8
|
||||||
gc.Widthint = 8
|
gc.Widthint = 8
|
||||||
@ -55,9 +45,6 @@ func betypeinit() {
|
|||||||
movptr = x86.AMOVL
|
movptr = x86.AMOVL
|
||||||
leaptr = x86.ALEAL
|
leaptr = x86.ALEAL
|
||||||
cmpptr = x86.ACMPL
|
cmpptr = x86.ACMPL
|
||||||
typedefs[0].Sameas = gc.TINT32
|
|
||||||
typedefs[1].Sameas = gc.TUINT32
|
|
||||||
typedefs[2].Sameas = gc.TUINT32
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if gc.Ctxt.Flag_dynlink {
|
if gc.Ctxt.Flag_dynlink {
|
||||||
@ -75,7 +62,6 @@ func Main() {
|
|||||||
gc.Thearch.Thechar = thechar
|
gc.Thearch.Thechar = thechar
|
||||||
gc.Thearch.Thestring = thestring
|
gc.Thearch.Thestring = thestring
|
||||||
gc.Thearch.Thelinkarch = thelinkarch
|
gc.Thearch.Thelinkarch = thelinkarch
|
||||||
gc.Thearch.Typedefs = typedefs
|
|
||||||
gc.Thearch.REGSP = x86.REGSP
|
gc.Thearch.REGSP = x86.REGSP
|
||||||
gc.Thearch.REGCTXT = x86.REGCTXT
|
gc.Thearch.REGCTXT = x86.REGCTXT
|
||||||
gc.Thearch.REGCALLX = x86.REG_BX
|
gc.Thearch.REGCALLX = x86.REG_BX
|
||||||
|
@ -21,16 +21,6 @@ func linkarchinit() {
|
|||||||
|
|
||||||
var MAXWIDTH int64 = (1 << 32) - 1
|
var MAXWIDTH int64 = (1 << 32) - 1
|
||||||
|
|
||||||
/*
|
|
||||||
* go declares several platform-specific type aliases:
|
|
||||||
* int, uint, and uintptr
|
|
||||||
*/
|
|
||||||
var typedefs = []gc.Typedef{
|
|
||||||
{"int", gc.TINT, gc.TINT32},
|
|
||||||
{"uint", gc.TUINT, gc.TUINT32},
|
|
||||||
{"uintptr", gc.TUINTPTR, gc.TUINT32},
|
|
||||||
}
|
|
||||||
|
|
||||||
func betypeinit() {
|
func betypeinit() {
|
||||||
gc.Widthptr = 4
|
gc.Widthptr = 4
|
||||||
gc.Widthint = 4
|
gc.Widthint = 4
|
||||||
@ -41,7 +31,6 @@ func Main() {
|
|||||||
gc.Thearch.Thechar = thechar
|
gc.Thearch.Thechar = thechar
|
||||||
gc.Thearch.Thestring = thestring
|
gc.Thearch.Thestring = thestring
|
||||||
gc.Thearch.Thelinkarch = thelinkarch
|
gc.Thearch.Thelinkarch = thelinkarch
|
||||||
gc.Thearch.Typedefs = typedefs
|
|
||||||
gc.Thearch.REGSP = arm.REGSP
|
gc.Thearch.REGSP = arm.REGSP
|
||||||
gc.Thearch.REGCTXT = arm.REGCTXT
|
gc.Thearch.REGCTXT = arm.REGCTXT
|
||||||
gc.Thearch.REGCALLX = arm.REG_R1
|
gc.Thearch.REGCALLX = arm.REG_R1
|
||||||
|
@ -21,16 +21,6 @@ func linkarchinit() {
|
|||||||
|
|
||||||
var MAXWIDTH int64 = 1 << 50
|
var MAXWIDTH int64 = 1 << 50
|
||||||
|
|
||||||
/*
|
|
||||||
* go declares several platform-specific type aliases:
|
|
||||||
* int, uint, and uintptr
|
|
||||||
*/
|
|
||||||
var typedefs = []gc.Typedef{
|
|
||||||
{"int", gc.TINT, gc.TINT64},
|
|
||||||
{"uint", gc.TUINT, gc.TUINT64},
|
|
||||||
{"uintptr", gc.TUINTPTR, gc.TUINT64},
|
|
||||||
}
|
|
||||||
|
|
||||||
func betypeinit() {
|
func betypeinit() {
|
||||||
gc.Widthptr = 8
|
gc.Widthptr = 8
|
||||||
gc.Widthint = 8
|
gc.Widthint = 8
|
||||||
@ -41,7 +31,6 @@ func Main() {
|
|||||||
gc.Thearch.Thechar = thechar
|
gc.Thearch.Thechar = thechar
|
||||||
gc.Thearch.Thestring = thestring
|
gc.Thearch.Thestring = thestring
|
||||||
gc.Thearch.Thelinkarch = thelinkarch
|
gc.Thearch.Thelinkarch = thelinkarch
|
||||||
gc.Thearch.Typedefs = typedefs
|
|
||||||
gc.Thearch.REGSP = arm64.REGSP
|
gc.Thearch.REGSP = arm64.REGSP
|
||||||
gc.Thearch.REGCTXT = arm64.REGCTXT
|
gc.Thearch.REGCTXT = arm64.REGCTXT
|
||||||
gc.Thearch.REGCALLX = arm64.REGRT1
|
gc.Thearch.REGCALLX = arm64.REGRT1
|
||||||
|
@ -618,39 +618,6 @@ func typeinit() {
|
|||||||
Simtype[TFUNC] = Tptr
|
Simtype[TFUNC] = Tptr
|
||||||
Simtype[TUNSAFEPTR] = Tptr
|
Simtype[TUNSAFEPTR] = Tptr
|
||||||
|
|
||||||
// pick up the backend thearch.typedefs
|
|
||||||
for i = range Thearch.Typedefs {
|
|
||||||
s := Lookup(Thearch.Typedefs[i].Name)
|
|
||||||
s1 := Pkglookup(Thearch.Typedefs[i].Name, builtinpkg)
|
|
||||||
|
|
||||||
etype := Thearch.Typedefs[i].Etype
|
|
||||||
if int(etype) >= len(Types) {
|
|
||||||
Fatalf("typeinit: %s bad etype", s.Name)
|
|
||||||
}
|
|
||||||
sameas := Thearch.Typedefs[i].Sameas
|
|
||||||
if int(sameas) >= len(Types) {
|
|
||||||
Fatalf("typeinit: %s bad sameas", s.Name)
|
|
||||||
}
|
|
||||||
Simtype[etype] = sameas
|
|
||||||
minfltval[etype] = minfltval[sameas]
|
|
||||||
maxfltval[etype] = maxfltval[sameas]
|
|
||||||
Minintval[etype] = Minintval[sameas]
|
|
||||||
Maxintval[etype] = Maxintval[sameas]
|
|
||||||
|
|
||||||
t = Types[etype]
|
|
||||||
if t != nil {
|
|
||||||
Fatalf("typeinit: %s already defined", s.Name)
|
|
||||||
}
|
|
||||||
|
|
||||||
t = typ(etype)
|
|
||||||
t.Sym = s1
|
|
||||||
|
|
||||||
dowidth(t)
|
|
||||||
Types[etype] = t
|
|
||||||
s1.Def = typenod(t)
|
|
||||||
s1.Def.Name = new(Name)
|
|
||||||
}
|
|
||||||
|
|
||||||
Array_array = int(Rnd(0, int64(Widthptr)))
|
Array_array = int(Rnd(0, int64(Widthptr)))
|
||||||
Array_nel = int(Rnd(int64(Array_array)+int64(Widthptr), int64(Widthint)))
|
Array_nel = int(Rnd(int64(Array_array)+int64(Widthptr), int64(Widthint)))
|
||||||
Array_cap = int(Rnd(int64(Array_nel)+int64(Widthint), int64(Widthint)))
|
Array_cap = int(Rnd(int64(Array_nel)+int64(Widthint), int64(Widthint)))
|
||||||
|
@ -305,12 +305,6 @@ const (
|
|||||||
Ecomplit = 1 << 11 // type in composite literal
|
Ecomplit = 1 << 11 // type in composite literal
|
||||||
)
|
)
|
||||||
|
|
||||||
type Typedef struct {
|
|
||||||
Name string
|
|
||||||
Etype EType
|
|
||||||
Sameas EType
|
|
||||||
}
|
|
||||||
|
|
||||||
type Sig struct {
|
type Sig struct {
|
||||||
name string
|
name string
|
||||||
pkg *Pkg
|
pkg *Pkg
|
||||||
@ -670,7 +664,6 @@ type Arch struct {
|
|||||||
Thechar int
|
Thechar int
|
||||||
Thestring string
|
Thestring string
|
||||||
Thelinkarch *obj.LinkArch
|
Thelinkarch *obj.LinkArch
|
||||||
Typedefs []Typedef
|
|
||||||
REGSP int
|
REGSP int
|
||||||
REGCTXT int
|
REGCTXT int
|
||||||
REGCALLX int // BX
|
REGCALLX int // BX
|
||||||
|
@ -2077,6 +2077,18 @@ var basicTypes = [...]struct {
|
|||||||
{"any", TANY},
|
{"any", TANY},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var typedefs = [...]struct {
|
||||||
|
name string
|
||||||
|
etype EType
|
||||||
|
width *int
|
||||||
|
sameas32 EType
|
||||||
|
sameas64 EType
|
||||||
|
}{
|
||||||
|
{"int", TINT, &Widthint, TINT32, TINT64},
|
||||||
|
{"uint", TUINT, &Widthint, TUINT32, TUINT64},
|
||||||
|
{"uintptr", TUINTPTR, &Widthptr, TUINT32, TUINT64},
|
||||||
|
}
|
||||||
|
|
||||||
var builtinFuncs = [...]struct {
|
var builtinFuncs = [...]struct {
|
||||||
name string
|
name string
|
||||||
op Op
|
op Op
|
||||||
@ -2223,12 +2235,29 @@ func lexinit1() {
|
|||||||
s.Def = typenod(runetype)
|
s.Def = typenod(runetype)
|
||||||
s.Def.Name = new(Name)
|
s.Def.Name = new(Name)
|
||||||
|
|
||||||
// backend-specific builtin types (e.g. int).
|
// backend-dependent builtin types (e.g. int).
|
||||||
for i := range Thearch.Typedefs {
|
for _, s := range typedefs {
|
||||||
s := Pkglookup(Thearch.Typedefs[i].Name, builtinpkg)
|
s1 := Pkglookup(s.name, builtinpkg)
|
||||||
s.Def = typenod(Types[Thearch.Typedefs[i].Etype])
|
|
||||||
s.Def.Name = new(Name)
|
sameas := s.sameas32
|
||||||
s.Origpkg = builtinpkg
|
if *s.width == 8 {
|
||||||
|
sameas = s.sameas64
|
||||||
|
}
|
||||||
|
|
||||||
|
Simtype[s.etype] = sameas
|
||||||
|
minfltval[s.etype] = minfltval[sameas]
|
||||||
|
maxfltval[s.etype] = maxfltval[sameas]
|
||||||
|
Minintval[s.etype] = Minintval[sameas]
|
||||||
|
Maxintval[s.etype] = Maxintval[sameas]
|
||||||
|
|
||||||
|
t := typ(s.etype)
|
||||||
|
t.Sym = s1
|
||||||
|
Types[s.etype] = t
|
||||||
|
s1.Def = typenod(t)
|
||||||
|
s1.Def.Name = new(Name)
|
||||||
|
s1.Origpkg = builtinpkg
|
||||||
|
|
||||||
|
dowidth(t)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -29,16 +29,6 @@ func linkarchinit() {
|
|||||||
|
|
||||||
var MAXWIDTH int64 = 1 << 50
|
var MAXWIDTH int64 = 1 << 50
|
||||||
|
|
||||||
/*
|
|
||||||
* go declares several platform-specific type aliases:
|
|
||||||
* int, uint, and uintptr
|
|
||||||
*/
|
|
||||||
var typedefs = []gc.Typedef{
|
|
||||||
{"int", gc.TINT, gc.TINT64},
|
|
||||||
{"uint", gc.TUINT, gc.TUINT64},
|
|
||||||
{"uintptr", gc.TUINTPTR, gc.TUINT64},
|
|
||||||
}
|
|
||||||
|
|
||||||
func betypeinit() {
|
func betypeinit() {
|
||||||
gc.Widthptr = 8
|
gc.Widthptr = 8
|
||||||
gc.Widthint = 8
|
gc.Widthint = 8
|
||||||
@ -49,7 +39,6 @@ func Main() {
|
|||||||
gc.Thearch.Thechar = thechar
|
gc.Thearch.Thechar = thechar
|
||||||
gc.Thearch.Thestring = thestring
|
gc.Thearch.Thestring = thestring
|
||||||
gc.Thearch.Thelinkarch = thelinkarch
|
gc.Thearch.Thelinkarch = thelinkarch
|
||||||
gc.Thearch.Typedefs = typedefs
|
|
||||||
gc.Thearch.REGSP = mips.REGSP
|
gc.Thearch.REGSP = mips.REGSP
|
||||||
gc.Thearch.REGCTXT = mips.REGCTXT
|
gc.Thearch.REGCTXT = mips.REGCTXT
|
||||||
gc.Thearch.REGCALLX = mips.REG_R1
|
gc.Thearch.REGCALLX = mips.REG_R1
|
||||||
|
@ -29,16 +29,6 @@ func linkarchinit() {
|
|||||||
|
|
||||||
var MAXWIDTH int64 = 1 << 50
|
var MAXWIDTH int64 = 1 << 50
|
||||||
|
|
||||||
/*
|
|
||||||
* go declares several platform-specific type aliases:
|
|
||||||
* int, uint, and uintptr
|
|
||||||
*/
|
|
||||||
var typedefs = []gc.Typedef{
|
|
||||||
{"int", gc.TINT, gc.TINT64},
|
|
||||||
{"uint", gc.TUINT, gc.TUINT64},
|
|
||||||
{"uintptr", gc.TUINTPTR, gc.TUINT64},
|
|
||||||
}
|
|
||||||
|
|
||||||
func betypeinit() {
|
func betypeinit() {
|
||||||
gc.Widthptr = 8
|
gc.Widthptr = 8
|
||||||
gc.Widthint = 8
|
gc.Widthint = 8
|
||||||
@ -54,7 +44,6 @@ func Main() {
|
|||||||
gc.Thearch.Thechar = thechar
|
gc.Thearch.Thechar = thechar
|
||||||
gc.Thearch.Thestring = thestring
|
gc.Thearch.Thestring = thestring
|
||||||
gc.Thearch.Thelinkarch = thelinkarch
|
gc.Thearch.Thelinkarch = thelinkarch
|
||||||
gc.Thearch.Typedefs = typedefs
|
|
||||||
gc.Thearch.REGSP = ppc64.REGSP
|
gc.Thearch.REGSP = ppc64.REGSP
|
||||||
gc.Thearch.REGCTXT = ppc64.REGCTXT
|
gc.Thearch.REGCTXT = ppc64.REGCTXT
|
||||||
gc.Thearch.REGCALLX = ppc64.REG_R3
|
gc.Thearch.REGCALLX = ppc64.REG_R3
|
||||||
|
@ -23,16 +23,6 @@ func linkarchinit() {
|
|||||||
|
|
||||||
var MAXWIDTH int64 = (1 << 32) - 1
|
var MAXWIDTH int64 = (1 << 32) - 1
|
||||||
|
|
||||||
/*
|
|
||||||
* go declares several platform-specific type aliases:
|
|
||||||
* int, uint, and uintptr
|
|
||||||
*/
|
|
||||||
var typedefs = []gc.Typedef{
|
|
||||||
{"int", gc.TINT, gc.TINT32},
|
|
||||||
{"uint", gc.TUINT, gc.TUINT32},
|
|
||||||
{"uintptr", gc.TUINTPTR, gc.TUINT32},
|
|
||||||
}
|
|
||||||
|
|
||||||
func betypeinit() {
|
func betypeinit() {
|
||||||
gc.Widthptr = 4
|
gc.Widthptr = 4
|
||||||
gc.Widthint = 4
|
gc.Widthint = 4
|
||||||
@ -43,7 +33,6 @@ func Main() {
|
|||||||
gc.Thearch.Thechar = thechar
|
gc.Thearch.Thechar = thechar
|
||||||
gc.Thearch.Thestring = thestring
|
gc.Thearch.Thestring = thestring
|
||||||
gc.Thearch.Thelinkarch = thelinkarch
|
gc.Thearch.Thelinkarch = thelinkarch
|
||||||
gc.Thearch.Typedefs = typedefs
|
|
||||||
gc.Thearch.REGSP = x86.REGSP
|
gc.Thearch.REGSP = x86.REGSP
|
||||||
gc.Thearch.REGCTXT = x86.REGCTXT
|
gc.Thearch.REGCTXT = x86.REGCTXT
|
||||||
gc.Thearch.REGCALLX = x86.REG_BX
|
gc.Thearch.REGCALLX = x86.REG_BX
|
||||||
|
Loading…
x
Reference in New Issue
Block a user