1
0
mirror of https://github.com/golang/go synced 2024-11-18 05:04:47 -07: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:
Matthew Dempsky 2016-03-02 18:03:50 -08:00
parent 0024101b2d
commit a40b27e304
9 changed files with 35 additions and 115 deletions

View File

@ -34,16 +34,6 @@ var (
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() {
gc.Widthptr = 8
gc.Widthint = 8
@ -55,9 +45,6 @@ func betypeinit() {
movptr = x86.AMOVL
leaptr = x86.ALEAL
cmpptr = x86.ACMPL
typedefs[0].Sameas = gc.TINT32
typedefs[1].Sameas = gc.TUINT32
typedefs[2].Sameas = gc.TUINT32
}
if gc.Ctxt.Flag_dynlink {
@ -75,7 +62,6 @@ func Main() {
gc.Thearch.Thechar = thechar
gc.Thearch.Thestring = thestring
gc.Thearch.Thelinkarch = thelinkarch
gc.Thearch.Typedefs = typedefs
gc.Thearch.REGSP = x86.REGSP
gc.Thearch.REGCTXT = x86.REGCTXT
gc.Thearch.REGCALLX = x86.REG_BX

View File

@ -21,16 +21,6 @@ func linkarchinit() {
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() {
gc.Widthptr = 4
gc.Widthint = 4
@ -41,7 +31,6 @@ func Main() {
gc.Thearch.Thechar = thechar
gc.Thearch.Thestring = thestring
gc.Thearch.Thelinkarch = thelinkarch
gc.Thearch.Typedefs = typedefs
gc.Thearch.REGSP = arm.REGSP
gc.Thearch.REGCTXT = arm.REGCTXT
gc.Thearch.REGCALLX = arm.REG_R1

View File

@ -21,16 +21,6 @@ func linkarchinit() {
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() {
gc.Widthptr = 8
gc.Widthint = 8
@ -41,7 +31,6 @@ func Main() {
gc.Thearch.Thechar = thechar
gc.Thearch.Thestring = thestring
gc.Thearch.Thelinkarch = thelinkarch
gc.Thearch.Typedefs = typedefs
gc.Thearch.REGSP = arm64.REGSP
gc.Thearch.REGCTXT = arm64.REGCTXT
gc.Thearch.REGCALLX = arm64.REGRT1

View File

@ -618,39 +618,6 @@ func typeinit() {
Simtype[TFUNC] = 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_nel = int(Rnd(int64(Array_array)+int64(Widthptr), int64(Widthint)))
Array_cap = int(Rnd(int64(Array_nel)+int64(Widthint), int64(Widthint)))

View File

@ -305,12 +305,6 @@ const (
Ecomplit = 1 << 11 // type in composite literal
)
type Typedef struct {
Name string
Etype EType
Sameas EType
}
type Sig struct {
name string
pkg *Pkg
@ -670,7 +664,6 @@ type Arch struct {
Thechar int
Thestring string
Thelinkarch *obj.LinkArch
Typedefs []Typedef
REGSP int
REGCTXT int
REGCALLX int // BX

View File

@ -2077,6 +2077,18 @@ var basicTypes = [...]struct {
{"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 {
name string
op Op
@ -2223,12 +2235,29 @@ func lexinit1() {
s.Def = typenod(runetype)
s.Def.Name = new(Name)
// backend-specific builtin types (e.g. int).
for i := range Thearch.Typedefs {
s := Pkglookup(Thearch.Typedefs[i].Name, builtinpkg)
s.Def = typenod(Types[Thearch.Typedefs[i].Etype])
s.Def.Name = new(Name)
s.Origpkg = builtinpkg
// backend-dependent builtin types (e.g. int).
for _, s := range typedefs {
s1 := Pkglookup(s.name, builtinpkg)
sameas := s.sameas32
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)
}
}

View File

@ -29,16 +29,6 @@ func linkarchinit() {
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() {
gc.Widthptr = 8
gc.Widthint = 8
@ -49,7 +39,6 @@ func Main() {
gc.Thearch.Thechar = thechar
gc.Thearch.Thestring = thestring
gc.Thearch.Thelinkarch = thelinkarch
gc.Thearch.Typedefs = typedefs
gc.Thearch.REGSP = mips.REGSP
gc.Thearch.REGCTXT = mips.REGCTXT
gc.Thearch.REGCALLX = mips.REG_R1

View File

@ -29,16 +29,6 @@ func linkarchinit() {
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() {
gc.Widthptr = 8
gc.Widthint = 8
@ -54,7 +44,6 @@ func Main() {
gc.Thearch.Thechar = thechar
gc.Thearch.Thestring = thestring
gc.Thearch.Thelinkarch = thelinkarch
gc.Thearch.Typedefs = typedefs
gc.Thearch.REGSP = ppc64.REGSP
gc.Thearch.REGCTXT = ppc64.REGCTXT
gc.Thearch.REGCALLX = ppc64.REG_R3

View File

@ -23,16 +23,6 @@ func linkarchinit() {
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() {
gc.Widthptr = 4
gc.Widthint = 4
@ -43,7 +33,6 @@ func Main() {
gc.Thearch.Thechar = thechar
gc.Thearch.Thestring = thestring
gc.Thearch.Thelinkarch = thelinkarch
gc.Thearch.Typedefs = typedefs
gc.Thearch.REGSP = x86.REGSP
gc.Thearch.REGCTXT = x86.REGCTXT
gc.Thearch.REGCALLX = x86.REG_BX