mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
cmd/compile: split Addrconst out of Naddr
There are only three Prog types that we were creating with an OLITERAL Node: ATEXT, ATYPE, and AFUNCDATA. ATEXT's value we later overwrite in defframe, and ATYPE's we don't even need. AFUNCDATA only needs integer constants, so get rid of all the non-int constant logic and skip creating a Node representation for the constant. While here, there are a few other Naddr code paths that are no longer needed, so turn those into Fatalfs. Passes toolstash/buildall. Change-Id: I4cc9b92c3011890afd4f31ebeba8b1b42b753cab Reviewed-on: https://go-review.googlesource.com/30074 Run-TryBot: Matthew Dempsky <mdempsky@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
This commit is contained in:
parent
214bf68097
commit
bb2bbfa086
2 changed files with 39 additions and 71 deletions
|
|
@ -177,72 +177,45 @@ func Naddr(a *obj.Addr, n *Node) {
|
|||
return
|
||||
}
|
||||
|
||||
switch n.Op {
|
||||
default:
|
||||
a := a // copy to let escape into Ctxt.Dconv
|
||||
if n.Op != ONAME {
|
||||
Debug['h'] = 1
|
||||
Dump("naddr", n)
|
||||
Fatalf("naddr: bad %v %v", n.Op, Ctxt.Dconv(a))
|
||||
|
||||
case ONAME:
|
||||
a.Offset = n.Xoffset
|
||||
s := n.Sym
|
||||
a.Node = n.Orig
|
||||
|
||||
//if(a->node >= (Node*)&n)
|
||||
// fatal("stack node");
|
||||
if s == nil {
|
||||
s = lookup(".noname")
|
||||
}
|
||||
if n.Name.Method && n.Type != nil && n.Type.Sym != nil && n.Type.Sym.Pkg != nil {
|
||||
s = Pkglookup(s.Name, n.Type.Sym.Pkg)
|
||||
}
|
||||
|
||||
a.Type = obj.TYPE_MEM
|
||||
switch n.Class {
|
||||
default:
|
||||
Fatalf("naddr: ONAME class %v %d\n", n.Sym, n.Class)
|
||||
|
||||
case PEXTERN, PFUNC:
|
||||
a.Name = obj.NAME_EXTERN
|
||||
|
||||
case PAUTO:
|
||||
a.Name = obj.NAME_AUTO
|
||||
|
||||
case PPARAM, PPARAMOUT:
|
||||
a.Name = obj.NAME_PARAM
|
||||
}
|
||||
|
||||
a.Sym = Linksym(s)
|
||||
|
||||
case OLITERAL:
|
||||
switch u := n.Val().U.(type) {
|
||||
default:
|
||||
Fatalf("naddr: const %L", n.Type)
|
||||
|
||||
case *Mpflt:
|
||||
a.Type = obj.TYPE_FCONST
|
||||
a.Val = u.Float64()
|
||||
|
||||
case *Mpint:
|
||||
a.Sym = nil
|
||||
a.Type = obj.TYPE_CONST
|
||||
a.Offset = u.Int64()
|
||||
|
||||
case string:
|
||||
datagostring(u, a)
|
||||
|
||||
case bool:
|
||||
a.Sym = nil
|
||||
a.Type = obj.TYPE_CONST
|
||||
a.Offset = int64(obj.Bool2int(u))
|
||||
|
||||
case *NilVal:
|
||||
a.Sym = nil
|
||||
a.Type = obj.TYPE_CONST
|
||||
a.Offset = 0
|
||||
}
|
||||
}
|
||||
|
||||
a.Offset = n.Xoffset
|
||||
s := n.Sym
|
||||
a.Node = n.Orig
|
||||
|
||||
if s == nil {
|
||||
Fatalf("naddr: nil sym %v", n)
|
||||
}
|
||||
if n.Name.Method && n.Type != nil && n.Type.Sym != nil && n.Type.Sym.Pkg != nil {
|
||||
Fatalf("naddr: weird method %v", n)
|
||||
}
|
||||
|
||||
a.Type = obj.TYPE_MEM
|
||||
switch n.Class {
|
||||
default:
|
||||
Fatalf("naddr: ONAME class %v %d\n", n.Sym, n.Class)
|
||||
|
||||
case PEXTERN, PFUNC:
|
||||
a.Name = obj.NAME_EXTERN
|
||||
|
||||
case PAUTO:
|
||||
a.Name = obj.NAME_AUTO
|
||||
|
||||
case PPARAM, PPARAMOUT:
|
||||
a.Name = obj.NAME_PARAM
|
||||
}
|
||||
|
||||
a.Sym = Linksym(s)
|
||||
}
|
||||
|
||||
func Addrconst(a *obj.Addr, v int64) {
|
||||
a.Sym = nil
|
||||
a.Type = obj.TYPE_CONST
|
||||
a.Offset = v
|
||||
}
|
||||
|
||||
func newplist() *obj.Plist {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue