Commit bb2bbfa0 authored by Matthew Dempsky's avatar Matthew Dempsky

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: default avatarBrad Fitzpatrick <bradfitz@golang.org>
parent 214bf680
......@@ -177,25 +177,21 @@ 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")
Fatalf("naddr: nil sym %v", n)
}
if n.Name.Method && n.Type != nil && n.Type.Sym != nil && n.Type.Sym.Pkg != nil {
s = Pkglookup(s.Name, n.Type.Sym.Pkg)
Fatalf("naddr: weird method %v", n)
}
a.Type = obj.TYPE_MEM
......@@ -214,35 +210,12 @@ func Naddr(a *obj.Addr, n *Node) {
}
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:
func Addrconst(a *obj.Addr, v int64) {
a.Sym = nil
a.Type = obj.TYPE_CONST
a.Offset = 0
}
}
a.Offset = v
}
func newplist() *obj.Plist {
......
......@@ -17,14 +17,12 @@ import (
var makefuncdatasym_nsym int
func makefuncdatasym(nameprefix string, funcdatakind int64) *Sym {
var nod Node
sym := lookupN(nameprefix, makefuncdatasym_nsym)
makefuncdatasym_nsym++
pnod := newname(sym)
pnod.Class = PEXTERN
Nodconst(&nod, Types[TINT32], funcdatakind)
Gins(obj.AFUNCDATA, &nod, pnod)
p := Gins(obj.AFUNCDATA, nil, pnod)
Addrconst(&p.From, funcdatakind)
return sym
}
......@@ -376,13 +374,11 @@ func compile(fn *Node) {
setlineno(Curfn)
var nod1 Node
Nodconst(&nod1, Types[TINT32], 0)
nam := Curfn.Func.Nname
if isblank(nam) {
nam = nil
}
ptxt := Gins(obj.ATEXT, nam, &nod1)
ptxt := Gins(obj.ATEXT, nam, nil)
ptxt.From3 = new(obj.Addr)
if fn.Func.Dupok {
ptxt.From3.Offset |= obj.DUPOK
......@@ -432,8 +428,7 @@ func compile(fn *Node) {
}
switch n.Class {
case PAUTO, PPARAM, PPARAMOUT:
Nodconst(&nod1, Types[TUINTPTR], n.Type.Width)
p := Gins(obj.ATYPE, n, &nod1)
p := Gins(obj.ATYPE, n, nil)
p.From.Gotype = Linksym(ngotype(n))
}
}
......
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