mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
cmd/compile: cleanup gdata slightly
In sinit.go, gdata can already handle strings and complex, so no reason to handle them separately. In obj.go, inline gdatastring and gdatacomplex into gdata, since it's the only caller. Allows extracting out the common Linksym calls. Passes toolstash -cmp. Change-Id: I3cb18d9b4206a8a269c36e0d30a345d8e6caba1f Reviewed-on: https://go-review.googlesource.com/31498 Run-TryBot: Matthew Dempsky <mdempsky@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Josh Bleecher Snyder <josharian@gmail.com>
This commit is contained in:
parent
213ee3d20e
commit
a2f77e9ef8
2 changed files with 24 additions and 57 deletions
|
|
@ -361,25 +361,19 @@ func gdata(nam *Node, nr *Node, wid int) {
|
|||
if nam.Sym == nil {
|
||||
Fatalf("gdata nil nam sym")
|
||||
}
|
||||
s := Linksym(nam.Sym)
|
||||
|
||||
switch nr.Op {
|
||||
case OLITERAL:
|
||||
switch u := nr.Val().U.(type) {
|
||||
case *Mpcplx:
|
||||
gdatacomplex(nam, u)
|
||||
|
||||
case string:
|
||||
gdatastring(nam, u)
|
||||
|
||||
case bool:
|
||||
i := int64(obj.Bool2int(u))
|
||||
Linksym(nam.Sym).WriteInt(Ctxt, nam.Xoffset, wid, i)
|
||||
s.WriteInt(Ctxt, nam.Xoffset, wid, i)
|
||||
|
||||
case *Mpint:
|
||||
Linksym(nam.Sym).WriteInt(Ctxt, nam.Xoffset, wid, u.Int64())
|
||||
s.WriteInt(Ctxt, nam.Xoffset, wid, u.Int64())
|
||||
|
||||
case *Mpflt:
|
||||
s := Linksym(nam.Sym)
|
||||
f := u.Float64()
|
||||
switch nam.Type.Etype {
|
||||
case TFLOAT32:
|
||||
|
|
@ -388,6 +382,23 @@ func gdata(nam *Node, nr *Node, wid int) {
|
|||
s.WriteFloat64(Ctxt, nam.Xoffset, f)
|
||||
}
|
||||
|
||||
case *Mpcplx:
|
||||
r := u.Real.Float64()
|
||||
i := u.Imag.Float64()
|
||||
switch nam.Type.Etype {
|
||||
case TCOMPLEX64:
|
||||
s.WriteFloat32(Ctxt, nam.Xoffset, float32(r))
|
||||
s.WriteFloat32(Ctxt, nam.Xoffset+4, float32(i))
|
||||
case TCOMPLEX128:
|
||||
s.WriteFloat64(Ctxt, nam.Xoffset, r)
|
||||
s.WriteFloat64(Ctxt, nam.Xoffset+8, i)
|
||||
}
|
||||
|
||||
case string:
|
||||
symdata := stringsym(u)
|
||||
s.WriteAddr(Ctxt, nam.Xoffset, Widthptr, symdata, 0)
|
||||
s.WriteInt(Ctxt, nam.Xoffset+int64(Widthptr), Widthint, int64(len(u)))
|
||||
|
||||
default:
|
||||
Fatalf("gdata unhandled OLITERAL %v", nr)
|
||||
}
|
||||
|
|
@ -397,38 +408,15 @@ func gdata(nam *Node, nr *Node, wid int) {
|
|||
Fatalf("gdata ADDR left op %v", nr.Left.Op)
|
||||
}
|
||||
to := nr.Left
|
||||
Linksym(nam.Sym).WriteAddr(Ctxt, nam.Xoffset, wid, Linksym(to.Sym), to.Xoffset)
|
||||
s.WriteAddr(Ctxt, nam.Xoffset, wid, Linksym(to.Sym), to.Xoffset)
|
||||
|
||||
case ONAME:
|
||||
if nr.Class != PFUNC {
|
||||
Fatalf("gdata NAME not PFUNC %d", nr.Class)
|
||||
}
|
||||
Linksym(nam.Sym).WriteAddr(Ctxt, nam.Xoffset, wid, Linksym(funcsym(nr.Sym)), nr.Xoffset)
|
||||
s.WriteAddr(Ctxt, nam.Xoffset, wid, Linksym(funcsym(nr.Sym)), nr.Xoffset)
|
||||
|
||||
default:
|
||||
Fatalf("gdata unhandled op %v %v\n", nr, nr.Op)
|
||||
}
|
||||
}
|
||||
|
||||
func gdatacomplex(nam *Node, cval *Mpcplx) {
|
||||
t := Types[cplxsubtype(nam.Type.Etype)]
|
||||
r := cval.Real.Float64()
|
||||
i := cval.Imag.Float64()
|
||||
s := Linksym(nam.Sym)
|
||||
|
||||
switch t.Etype {
|
||||
case TFLOAT32:
|
||||
s.WriteFloat32(Ctxt, nam.Xoffset, float32(r))
|
||||
s.WriteFloat32(Ctxt, nam.Xoffset+4, float32(i))
|
||||
case TFLOAT64:
|
||||
s.WriteFloat64(Ctxt, nam.Xoffset, r)
|
||||
s.WriteFloat64(Ctxt, nam.Xoffset+8, i)
|
||||
}
|
||||
}
|
||||
|
||||
func gdatastring(nam *Node, sval string) {
|
||||
s := Linksym(nam.Sym)
|
||||
symdata := stringsym(sval)
|
||||
s.WriteAddr(Ctxt, nam.Xoffset, Widthptr, symdata, 0)
|
||||
s.WriteInt(Ctxt, nam.Xoffset+int64(Widthptr), Widthint, int64(len(sval)))
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue