Commit 786a2ef3 authored by Josh Bleecher Snyder's avatar Josh Bleecher Snyder

cmd/compile: use a uint8-sized named type for Addr.Type

No immediate reduction in the size of Addr.

Passes toolstash -cmp.

Change-Id: I78ea4c6e181b6e571ce70a5f1ae8158844eb197d
Reviewed-on: https://go-review.googlesource.com/20276Reviewed-by: default avatarMatthew Dempsky <mdempsky@google.com>
parent 8f5fb95d
...@@ -166,15 +166,15 @@ func zerorange(p *obj.Prog, frame int64, lo int64, hi int64, ax *uint32, x0 *uin ...@@ -166,15 +166,15 @@ func zerorange(p *obj.Prog, frame int64, lo int64, hi int64, ax *uint32, x0 *uin
return p return p
} }
func appendpp(p *obj.Prog, as int, ftype int, freg int, foffset int64, ttype int, treg int, toffset int64) *obj.Prog { func appendpp(p *obj.Prog, as int, ftype obj.AddrType, freg int, foffset int64, ttype obj.AddrType, treg int, toffset int64) *obj.Prog {
q := gc.Ctxt.NewProg() q := gc.Ctxt.NewProg()
gc.Clearp(q) gc.Clearp(q)
q.As = int16(as) q.As = int16(as)
q.Lineno = p.Lineno q.Lineno = p.Lineno
q.From.Type = int16(ftype) q.From.Type = ftype
q.From.Reg = int16(freg) q.From.Reg = int16(freg)
q.From.Offset = foffset q.From.Offset = foffset
q.To.Type = int16(ttype) q.To.Type = ttype
q.To.Reg = int16(treg) q.To.Reg = int16(treg)
q.To.Offset = toffset q.To.Offset = toffset
q.Link = p.Link q.Link = p.Link
......
...@@ -1408,7 +1408,7 @@ func sudoaddable(as int, n *gc.Node, a *obj.Addr) bool { ...@@ -1408,7 +1408,7 @@ func sudoaddable(as int, n *gc.Node, a *obj.Addr) bool {
} }
a.Type = obj.TYPE_NONE a.Type = obj.TYPE_NONE
a.Index = obj.TYPE_NONE a.Index = x86.REG_NONE
gc.Fixlargeoffset(&n1) gc.Fixlargeoffset(&n1)
gc.Naddr(a, &n1) gc.Naddr(a, &n1)
return true return true
......
...@@ -95,15 +95,15 @@ func zerorange(p *obj.Prog, frame int64, lo int64, hi int64, r0 *uint32) *obj.Pr ...@@ -95,15 +95,15 @@ func zerorange(p *obj.Prog, frame int64, lo int64, hi int64, r0 *uint32) *obj.Pr
return p return p
} }
func appendpp(p *obj.Prog, as int, ftype int, freg int, foffset int32, ttype int, treg int, toffset int32) *obj.Prog { func appendpp(p *obj.Prog, as int, ftype obj.AddrType, freg int, foffset int32, ttype obj.AddrType, treg int, toffset int32) *obj.Prog {
q := gc.Ctxt.NewProg() q := gc.Ctxt.NewProg()
gc.Clearp(q) gc.Clearp(q)
q.As = int16(as) q.As = int16(as)
q.Lineno = p.Lineno q.Lineno = p.Lineno
q.From.Type = int16(ftype) q.From.Type = ftype
q.From.Reg = int16(freg) q.From.Reg = int16(freg)
q.From.Offset = int64(foffset) q.From.Offset = int64(foffset)
q.To.Type = int16(ttype) q.To.Type = ttype
q.To.Reg = int16(treg) q.To.Reg = int16(treg)
q.To.Offset = int64(toffset) q.To.Offset = int64(toffset)
q.Link = p.Link q.Link = p.Link
......
...@@ -106,15 +106,15 @@ func zerorange(p *obj.Prog, frame int64, lo int64, hi int64) *obj.Prog { ...@@ -106,15 +106,15 @@ func zerorange(p *obj.Prog, frame int64, lo int64, hi int64) *obj.Prog {
return p return p
} }
func appendpp(p *obj.Prog, as int, ftype int, freg int, foffset int64, ttype int, treg int, toffset int64) *obj.Prog { func appendpp(p *obj.Prog, as int, ftype obj.AddrType, freg int, foffset int64, ttype obj.AddrType, treg int, toffset int64) *obj.Prog {
q := gc.Ctxt.NewProg() q := gc.Ctxt.NewProg()
gc.Clearp(q) gc.Clearp(q)
q.As = int16(as) q.As = int16(as)
q.Lineno = p.Lineno q.Lineno = p.Lineno
q.From.Type = int16(ftype) q.From.Type = ftype
q.From.Reg = int16(freg) q.From.Reg = int16(freg)
q.From.Offset = foffset q.From.Offset = foffset
q.To.Type = int16(ttype) q.To.Type = ttype
q.To.Reg = int16(treg) q.To.Reg = int16(treg)
q.To.Offset = toffset q.To.Offset = toffset
q.Link = p.Link q.Link = p.Link
......
...@@ -101,15 +101,15 @@ func zerorange(p *obj.Prog, frame int64, lo int64, hi int64) *obj.Prog { ...@@ -101,15 +101,15 @@ func zerorange(p *obj.Prog, frame int64, lo int64, hi int64) *obj.Prog {
return p return p
} }
func appendpp(p *obj.Prog, as int, ftype int, freg int, foffset int64, ttype int, treg int, toffset int64) *obj.Prog { func appendpp(p *obj.Prog, as int, ftype obj.AddrType, freg int, foffset int64, ttype obj.AddrType, treg int, toffset int64) *obj.Prog {
q := gc.Ctxt.NewProg() q := gc.Ctxt.NewProg()
gc.Clearp(q) gc.Clearp(q)
q.As = int16(as) q.As = int16(as)
q.Lineno = p.Lineno q.Lineno = p.Lineno
q.From.Type = int16(ftype) q.From.Type = ftype
q.From.Reg = int16(freg) q.From.Reg = int16(freg)
q.From.Offset = foffset q.From.Offset = foffset
q.To.Type = int16(ttype) q.To.Type = ttype
q.To.Reg = int16(treg) q.To.Reg = int16(treg)
q.To.Offset = toffset q.To.Offset = toffset
q.Link = p.Link q.Link = p.Link
......
...@@ -93,15 +93,15 @@ func zerorange(p *obj.Prog, frame int64, lo int64, hi int64) *obj.Prog { ...@@ -93,15 +93,15 @@ func zerorange(p *obj.Prog, frame int64, lo int64, hi int64) *obj.Prog {
return p return p
} }
func appendpp(p *obj.Prog, as int, ftype int, freg int, foffset int64, ttype int, treg int, toffset int64) *obj.Prog { func appendpp(p *obj.Prog, as int, ftype obj.AddrType, freg int, foffset int64, ttype obj.AddrType, treg int, toffset int64) *obj.Prog {
q := gc.Ctxt.NewProg() q := gc.Ctxt.NewProg()
gc.Clearp(q) gc.Clearp(q)
q.As = int16(as) q.As = int16(as)
q.Lineno = p.Lineno q.Lineno = p.Lineno
q.From.Type = int16(ftype) q.From.Type = ftype
q.From.Reg = int16(freg) q.From.Reg = int16(freg)
q.From.Offset = foffset q.From.Offset = foffset
q.To.Type = int16(ttype) q.To.Type = ttype
q.To.Reg = int16(treg) q.To.Reg = int16(treg)
q.To.Offset = toffset q.To.Offset = toffset
q.Link = p.Link q.Link = p.Link
......
...@@ -84,15 +84,15 @@ func zerorange(p *obj.Prog, frame int64, lo int64, hi int64, ax *uint32) *obj.Pr ...@@ -84,15 +84,15 @@ func zerorange(p *obj.Prog, frame int64, lo int64, hi int64, ax *uint32) *obj.Pr
return p return p
} }
func appendpp(p *obj.Prog, as int, ftype int, freg int, foffset int64, ttype int, treg int, toffset int64) *obj.Prog { func appendpp(p *obj.Prog, as int, ftype obj.AddrType, freg int, foffset int64, ttype obj.AddrType, treg int, toffset int64) *obj.Prog {
q := gc.Ctxt.NewProg() q := gc.Ctxt.NewProg()
gc.Clearp(q) gc.Clearp(q)
q.As = int16(as) q.As = int16(as)
q.Lineno = p.Lineno q.Lineno = p.Lineno
q.From.Type = int16(ftype) q.From.Type = ftype
q.From.Reg = int16(freg) q.From.Reg = int16(freg)
q.From.Offset = foffset q.From.Offset = foffset
q.To.Type = int16(ttype) q.To.Type = ttype
q.To.Reg = int16(treg) q.To.Reg = int16(treg)
q.To.Offset = toffset q.To.Offset = toffset
q.Link = p.Link q.Link = p.Link
......
...@@ -733,7 +733,7 @@ func copysub(a *obj.Addr, v *obj.Addr, s *obj.Addr, f int) int { ...@@ -733,7 +733,7 @@ func copysub(a *obj.Addr, v *obj.Addr, s *obj.Addr, f int) int {
if regtyp(v) { if regtyp(v) {
reg := int(v.Reg) reg := int(v.Reg)
if (a.Type == obj.TYPE_MEM || a.Type == obj.TYPE_ADDR) && int(a.Reg) == reg { if (a.Type == obj.TYPE_MEM || a.Type == obj.TYPE_ADDR) && int(a.Reg) == reg {
if (s.Reg == x86.REG_BP) && a.Index != obj.TYPE_NONE { if (s.Reg == x86.REG_BP) && a.Index != x86.REG_NONE {
return 1 /* can't use BP-base with index */ return 1 /* can't use BP-base with index */
} }
if f != 0 { if f != 0 {
......
...@@ -1067,7 +1067,7 @@ func aclass(ctxt *obj.Link, a *obj.Addr) int { ...@@ -1067,7 +1067,7 @@ func aclass(ctxt *obj.Link, a *obj.Addr) int {
return C_LAUTO return C_LAUTO
case obj.TYPE_NONE: case obj.NAME_NONE:
ctxt.Instoffset = a.Offset ctxt.Instoffset = a.Offset
t := int(immaddr(int32(ctxt.Instoffset))) t := int(immaddr(int32(ctxt.Instoffset)))
if t != 0 { if t != 0 {
...@@ -1115,7 +1115,7 @@ func aclass(ctxt *obj.Link, a *obj.Addr) int { ...@@ -1115,7 +1115,7 @@ func aclass(ctxt *obj.Link, a *obj.Addr) int {
case obj.TYPE_CONST, case obj.TYPE_CONST,
obj.TYPE_ADDR: obj.TYPE_ADDR:
switch a.Name { switch a.Name {
case obj.TYPE_NONE: case obj.NAME_NONE:
ctxt.Instoffset = a.Offset ctxt.Instoffset = a.Offset
if a.Reg != 0 { if a.Reg != 0 {
return aconsize(ctxt) return aconsize(ctxt)
......
...@@ -970,8 +970,7 @@ func aclass(ctxt *obj.Link, a *obj.Addr) int { ...@@ -970,8 +970,7 @@ func aclass(ctxt *obj.Link, a *obj.Addr) int {
case obj.TYPE_MEM: case obj.TYPE_MEM:
switch a.Name { switch a.Name {
case obj.NAME_EXTERN, case obj.NAME_EXTERN, obj.NAME_STATIC:
obj.NAME_STATIC:
if a.Sym == nil { if a.Sym == nil {
break break
} }
...@@ -999,7 +998,7 @@ func aclass(ctxt *obj.Link, a *obj.Addr) int { ...@@ -999,7 +998,7 @@ func aclass(ctxt *obj.Link, a *obj.Addr) int {
ctxt.Instoffset = int64(ctxt.Autosize) + a.Offset + 8 ctxt.Instoffset = int64(ctxt.Autosize) + a.Offset + 8
return autoclass(ctxt.Instoffset) return autoclass(ctxt.Instoffset)
case obj.TYPE_NONE: case obj.NAME_NONE:
ctxt.Instoffset = a.Offset ctxt.Instoffset = a.Offset
return oregclass(ctxt.Instoffset) return oregclass(ctxt.Instoffset)
} }
...@@ -1011,10 +1010,9 @@ func aclass(ctxt *obj.Link, a *obj.Addr) int { ...@@ -1011,10 +1010,9 @@ func aclass(ctxt *obj.Link, a *obj.Addr) int {
case obj.TYPE_TEXTSIZE: case obj.TYPE_TEXTSIZE:
return C_TEXTSIZE return C_TEXTSIZE
case obj.TYPE_CONST, case obj.TYPE_CONST, obj.TYPE_ADDR:
obj.TYPE_ADDR:
switch a.Name { switch a.Name {
case obj.TYPE_NONE: case obj.NAME_NONE:
ctxt.Instoffset = a.Offset ctxt.Instoffset = a.Offset
if a.Reg != 0 && a.Reg != REGZERO { if a.Reg != 0 && a.Reg != REGZERO {
goto aconsize goto aconsize
...@@ -1058,8 +1056,7 @@ func aclass(ctxt *obj.Link, a *obj.Addr) int { ...@@ -1058,8 +1056,7 @@ func aclass(ctxt *obj.Link, a *obj.Addr) int {
} }
return C_VCON return C_VCON
case obj.NAME_EXTERN, case obj.NAME_EXTERN, obj.NAME_STATIC:
obj.NAME_STATIC:
if a.Sym == nil { if a.Sym == nil {
break break
} }
......
...@@ -66,7 +66,7 @@ func savedata(ctxt *Link, s *LSym, p *Prog, file string) { ...@@ -66,7 +66,7 @@ func savedata(ctxt *Link, s *LSym, p *Prog, file string) {
} }
Symgrow(ctxt, s, int64(off+siz)) Symgrow(ctxt, s, int64(off+siz))
switch int(p.To.Type) { switch p.To.Type {
default: default:
ctxt.Diag("bad data: %v", p) ctxt.Diag("bad data: %v", p)
...@@ -88,7 +88,7 @@ func savedata(ctxt *Link, s *LSym, p *Prog, file string) { ...@@ -88,7 +88,7 @@ func savedata(ctxt *Link, s *LSym, p *Prog, file string) {
copy(s.P[off:off+siz], p.To.Val.(string)) copy(s.P[off:off+siz], p.To.Val.(string))
case TYPE_CONST, TYPE_ADDR: case TYPE_CONST, TYPE_ADDR:
if p.To.Sym != nil || int(p.To.Type) == TYPE_ADDR { if p.To.Sym != nil || p.To.Type == TYPE_ADDR {
r := Addrel(s) r := Addrel(s)
r.Off = off r.Off = off
r.Siz = uint8(siz) r.Siz = uint8(siz)
......
...@@ -144,10 +144,10 @@ import "encoding/binary" ...@@ -144,10 +144,10 @@ import "encoding/binary"
// scale = 1 // scale = 1
// //
type Addr struct { type Addr struct {
Type int16
Reg int16 Reg int16
Index int16 Index int16
Scale int16 // Sometimes holds a register. Scale int16 // Sometimes holds a register.
Type AddrType
Name int8 Name int8
Class int8 Class int8
Etype uint8 Etype uint8
...@@ -166,6 +166,8 @@ type Addr struct { ...@@ -166,6 +166,8 @@ type Addr struct {
Node interface{} // for use by compiler Node interface{} // for use by compiler
} }
type AddrType uint8
const ( const (
NAME_NONE = 0 + iota NAME_NONE = 0 + iota
NAME_EXTERN NAME_EXTERN
...@@ -178,11 +180,9 @@ const ( ...@@ -178,11 +180,9 @@ const (
) )
const ( const (
TYPE_NONE = 0 TYPE_NONE AddrType = 0
)
const ( TYPE_BRANCH AddrType = 5 + iota
TYPE_BRANCH = 5 + iota
TYPE_TEXTSIZE TYPE_TEXTSIZE
TYPE_MEM TYPE_MEM
TYPE_CONST TYPE_CONST
...@@ -228,7 +228,7 @@ type Prog struct { ...@@ -228,7 +228,7 @@ type Prog struct {
} }
// From3Type returns From3.Type, or TYPE_NONE when From3 is nil. // From3Type returns From3.Type, or TYPE_NONE when From3 is nil.
func (p *Prog) From3Type() int16 { func (p *Prog) From3Type() AddrType {
if p.From3 == nil { if p.From3 == nil {
return TYPE_NONE return TYPE_NONE
} }
......
...@@ -636,7 +636,7 @@ func aclass(ctxt *obj.Link, a *obj.Addr) int { ...@@ -636,7 +636,7 @@ func aclass(ctxt *obj.Link, a *obj.Addr) int {
case obj.TYPE_CONST, case obj.TYPE_CONST,
obj.TYPE_ADDR: obj.TYPE_ADDR:
switch a.Name { switch a.Name {
case obj.TYPE_NONE: case obj.NAME_NONE:
ctxt.Instoffset = a.Offset ctxt.Instoffset = a.Offset
if a.Reg != 0 { if a.Reg != 0 {
if -BIG <= ctxt.Instoffset && ctxt.Instoffset <= BIG { if -BIG <= ctxt.Instoffset && ctxt.Instoffset <= BIG {
......
...@@ -383,7 +383,7 @@ func Dconv(p *Prog, a *Addr) string { ...@@ -383,7 +383,7 @@ func Dconv(p *Prog, a *Addr) string {
} }
str = Rconv(int(a.Reg)) str = Rconv(int(a.Reg))
if a.Name != TYPE_NONE || a.Sym != nil { if a.Name != NAME_NONE || a.Sym != nil {
str = fmt.Sprintf("%v(%v)(REG)", Mconv(a), Rconv(int(a.Reg))) str = fmt.Sprintf("%v(%v)(REG)", Mconv(a), Rconv(int(a.Reg)))
} }
......
...@@ -4621,10 +4621,10 @@ func asmins(ctxt *obj.Link, p *obj.Prog) { ...@@ -4621,10 +4621,10 @@ func asmins(ctxt *obj.Link, p *obj.Prog) {
} }
if p.As != ALEAQ && p.As != ALEAL { if p.As != ALEAQ && p.As != ALEAL {
if p.From.Index != obj.TYPE_NONE && p.From.Scale > 0 { if p.From.Index != REG_NONE && p.From.Scale > 0 {
nacltrunc(ctxt, int(p.From.Index)) nacltrunc(ctxt, int(p.From.Index))
} }
if p.To.Index != obj.TYPE_NONE && p.To.Scale > 0 { if p.To.Index != REG_NONE && p.To.Scale > 0 {
nacltrunc(ctxt, int(p.To.Index)) nacltrunc(ctxt, int(p.To.Index))
} }
} }
......
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