Commit ba577811 authored by Josh Bleecher Snyder's avatar Josh Bleecher Snyder

cmd/5g, etc: prepare Node.Val to be unexported

Remove all uses of Node.Val outside of the gc package.

A subsequent, automated commit in the Go 1.6 cycle
will unexport Node.Val.

No functional changes. Passes toolstash -cmp.

Change-Id: Ia92ae6a7766c83ab3e45c69edab24a9581c824f9
Reviewed-on: https://go-review.googlesource.com/9267Reviewed-by: default avatarRuss Cox <rsc@golang.org>
parent 0112f6f6
...@@ -111,7 +111,7 @@ func split64(n *gc.Node, lo *gc.Node, hi *gc.Node) { ...@@ -111,7 +111,7 @@ func split64(n *gc.Node, lo *gc.Node, hi *gc.Node) {
case gc.OLITERAL: case gc.OLITERAL:
var n1 gc.Node var n1 gc.Node
gc.Convconst(&n1, n.Type, &n.Val) n.Convconst(&n1, n.Type)
i := n1.Int() i := n1.Int()
gc.Nodconst(lo, gc.Types[gc.TUINT32], int64(uint32(i))) gc.Nodconst(lo, gc.Types[gc.TUINT32], int64(uint32(i)))
i >>= 32 i >>= 32
...@@ -160,12 +160,12 @@ func gmove(f *gc.Node, t *gc.Node) { ...@@ -160,12 +160,12 @@ func gmove(f *gc.Node, t *gc.Node) {
var con gc.Node var con gc.Node
switch tt { switch tt {
default: default:
gc.Convconst(&con, t.Type, &f.Val) f.Convconst(&con, t.Type)
case gc.TINT16, case gc.TINT16,
gc.TINT8: gc.TINT8:
var con gc.Node var con gc.Node
gc.Convconst(&con, gc.Types[gc.TINT32], &f.Val) f.Convconst(&con, gc.Types[gc.TINT32])
var r1 gc.Node var r1 gc.Node
gc.Regalloc(&r1, con.Type, t) gc.Regalloc(&r1, con.Type, t)
gins(arm.AMOVW, &con, &r1) gins(arm.AMOVW, &con, &r1)
...@@ -176,7 +176,7 @@ func gmove(f *gc.Node, t *gc.Node) { ...@@ -176,7 +176,7 @@ func gmove(f *gc.Node, t *gc.Node) {
case gc.TUINT16, case gc.TUINT16,
gc.TUINT8: gc.TUINT8:
var con gc.Node var con gc.Node
gc.Convconst(&con, gc.Types[gc.TUINT32], &f.Val) f.Convconst(&con, gc.Types[gc.TUINT32])
var r1 gc.Node var r1 gc.Node
gc.Regalloc(&r1, con.Type, t) gc.Regalloc(&r1, con.Type, t)
gins(arm.AMOVW, &con, &r1) gins(arm.AMOVW, &con, &r1)
......
...@@ -160,7 +160,7 @@ func bignodes() { ...@@ -160,7 +160,7 @@ func bignodes() {
gc.Nodconst(&bigi, gc.Types[gc.TUINT64], 0) gc.Nodconst(&bigi, gc.Types[gc.TUINT64], 0)
bigi.SetBigInt(&i) bigi.SetBigInt(&i)
gc.Convconst(&bigf, gc.Types[gc.TFLOAT64], &bigi.Val) bigi.Convconst(&bigf, gc.Types[gc.TFLOAT64])
} }
/* /*
...@@ -191,7 +191,7 @@ func gmove(f *gc.Node, t *gc.Node) { ...@@ -191,7 +191,7 @@ func gmove(f *gc.Node, t *gc.Node) {
// convert constant to desired type // convert constant to desired type
if f.Op == gc.OLITERAL { if f.Op == gc.OLITERAL {
var con gc.Node var con gc.Node
gc.Convconst(&con, t.Type, &f.Val) f.Convconst(&con, t.Type)
f = &con f = &con
ft = tt // so big switch will choose a simple mov ft = tt // so big switch will choose a simple mov
......
...@@ -161,13 +161,13 @@ func gmove(f *gc.Node, t *gc.Node) { ...@@ -161,13 +161,13 @@ func gmove(f *gc.Node, t *gc.Node) {
var con gc.Node var con gc.Node
switch tt { switch tt {
default: default:
gc.Convconst(&con, t.Type, &f.Val) f.Convconst(&con, t.Type)
case gc.TINT32, case gc.TINT32,
gc.TINT16, gc.TINT16,
gc.TINT8: gc.TINT8:
var con gc.Node var con gc.Node
gc.Convconst(&con, gc.Types[gc.TINT64], &f.Val) f.Convconst(&con, gc.Types[gc.TINT64])
var r1 gc.Node var r1 gc.Node
gc.Regalloc(&r1, con.Type, t) gc.Regalloc(&r1, con.Type, t)
gins(arm64.AMOVD, &con, &r1) gins(arm64.AMOVD, &con, &r1)
...@@ -179,7 +179,7 @@ func gmove(f *gc.Node, t *gc.Node) { ...@@ -179,7 +179,7 @@ func gmove(f *gc.Node, t *gc.Node) {
gc.TUINT16, gc.TUINT16,
gc.TUINT8: gc.TUINT8:
var con gc.Node var con gc.Node
gc.Convconst(&con, gc.Types[gc.TUINT64], &f.Val) f.Convconst(&con, gc.Types[gc.TUINT64])
var r1 gc.Node var r1 gc.Node
gc.Regalloc(&r1, con.Type, t) gc.Regalloc(&r1, con.Type, t)
gins(arm64.AMOVD, &con, &r1) gins(arm64.AMOVD, &con, &r1)
...@@ -468,14 +468,13 @@ hard: ...@@ -468,14 +468,13 @@ hard:
} }
func intLiteral(n *gc.Node) (x int64, ok bool) { func intLiteral(n *gc.Node) (x int64, ok bool) {
if n == nil || n.Op != gc.OLITERAL { switch {
case n == nil:
return return
} case gc.Isconst(n, gc.CTINT):
switch n.Val.Ctype {
case gc.CTINT, gc.CTRUNE:
return n.Int(), true return n.Int(), true
case gc.CTBOOL: case gc.Isconst(n, gc.CTBOOL):
return int64(obj.Bool2int(n.Val.U.Bval)), true return int64(obj.Bool2int(n.Bool())), true
} }
return return
} }
......
...@@ -700,7 +700,7 @@ func split64(n *gc.Node, lo *gc.Node, hi *gc.Node) { ...@@ -700,7 +700,7 @@ func split64(n *gc.Node, lo *gc.Node, hi *gc.Node) {
case gc.OLITERAL: case gc.OLITERAL:
var n1 gc.Node var n1 gc.Node
gc.Convconst(&n1, n.Type, &n.Val) n.Convconst(&n1, n.Type)
i := n1.Int() i := n1.Int()
gc.Nodconst(lo, gc.Types[gc.TUINT32], int64(uint32(i))) gc.Nodconst(lo, gc.Types[gc.TUINT32], int64(uint32(i)))
i >>= 32 i >>= 32
...@@ -737,7 +737,7 @@ func bignodes() { ...@@ -737,7 +737,7 @@ func bignodes() {
bignodes_did = true bignodes_did = true
gc.Nodconst(&zerof, gc.Types[gc.TINT64], 0) gc.Nodconst(&zerof, gc.Types[gc.TINT64], 0)
gc.Convconst(&zerof, gc.Types[gc.TFLOAT64], &zerof.Val) zerof.Convconst(&zerof, gc.Types[gc.TFLOAT64])
var i big.Int var i big.Int
i.SetInt64(1) i.SetInt64(1)
...@@ -746,12 +746,12 @@ func bignodes() { ...@@ -746,12 +746,12 @@ func bignodes() {
gc.Nodconst(&bigi, gc.Types[gc.TUINT64], 0) gc.Nodconst(&bigi, gc.Types[gc.TUINT64], 0)
bigi.SetBigInt(&i) bigi.SetBigInt(&i)
gc.Convconst(&two63f, gc.Types[gc.TFLOAT64], &bigi.Val) bigi.Convconst(&two63f, gc.Types[gc.TFLOAT64])
gc.Nodconst(&bigi, gc.Types[gc.TUINT64], 0) gc.Nodconst(&bigi, gc.Types[gc.TUINT64], 0)
i.Lsh(&i, 1) i.Lsh(&i, 1)
bigi.SetBigInt(&i) bigi.SetBigInt(&i)
gc.Convconst(&two64f, gc.Types[gc.TFLOAT64], &bigi.Val) bigi.Convconst(&two64f, gc.Types[gc.TFLOAT64])
} }
func memname(n *gc.Node, t *gc.Type) { func memname(n *gc.Node, t *gc.Type) {
...@@ -790,7 +790,7 @@ func gmove(f *gc.Node, t *gc.Node) { ...@@ -790,7 +790,7 @@ func gmove(f *gc.Node, t *gc.Node) {
// convert constant to desired type // convert constant to desired type
if f.Op == gc.OLITERAL { if f.Op == gc.OLITERAL {
var con gc.Node var con gc.Node
gc.Convconst(&con, t.Type, &f.Val) f.Convconst(&con, t.Type)
f = &con f = &con
ft = gc.Simsimtype(con.Type) ft = gc.Simsimtype(con.Type)
} }
...@@ -1061,7 +1061,7 @@ func floatmove(f *gc.Node, t *gc.Node) { ...@@ -1061,7 +1061,7 @@ func floatmove(f *gc.Node, t *gc.Node) {
// convert constant to desired type // convert constant to desired type
if f.Op == gc.OLITERAL { if f.Op == gc.OLITERAL {
var con gc.Node var con gc.Node
gc.Convconst(&con, t.Type, &f.Val) f.Convconst(&con, t.Type)
f = &con f = &con
ft = gc.Simsimtype(con.Type) ft = gc.Simsimtype(con.Type)
......
...@@ -165,7 +165,7 @@ func bignodes() { ...@@ -165,7 +165,7 @@ func bignodes() {
gc.Nodconst(&bigi, gc.Types[gc.TUINT64], 0) gc.Nodconst(&bigi, gc.Types[gc.TUINT64], 0)
bigi.SetBigInt(&i) bigi.SetBigInt(&i)
gc.Convconst(&bigf, gc.Types[gc.TFLOAT64], &bigi.Val) bigi.Convconst(&bigf, gc.Types[gc.TFLOAT64])
} }
/* /*
...@@ -200,13 +200,13 @@ func gmove(f *gc.Node, t *gc.Node) { ...@@ -200,13 +200,13 @@ func gmove(f *gc.Node, t *gc.Node) {
var con gc.Node var con gc.Node
switch tt { switch tt {
default: default:
gc.Convconst(&con, t.Type, &f.Val) f.Convconst(&con, t.Type)
case gc.TINT32, case gc.TINT32,
gc.TINT16, gc.TINT16,
gc.TINT8: gc.TINT8:
var con gc.Node var con gc.Node
gc.Convconst(&con, gc.Types[gc.TINT64], &f.Val) f.Convconst(&con, gc.Types[gc.TINT64])
var r1 gc.Node var r1 gc.Node
gc.Regalloc(&r1, con.Type, t) gc.Regalloc(&r1, con.Type, t)
gins(ppc64.AMOVD, &con, &r1) gins(ppc64.AMOVD, &con, &r1)
...@@ -218,7 +218,7 @@ func gmove(f *gc.Node, t *gc.Node) { ...@@ -218,7 +218,7 @@ func gmove(f *gc.Node, t *gc.Node) {
gc.TUINT16, gc.TUINT16,
gc.TUINT8: gc.TUINT8:
var con gc.Node var con gc.Node
gc.Convconst(&con, gc.Types[gc.TUINT64], &f.Val) f.Convconst(&con, gc.Types[gc.TUINT64])
var r1 gc.Node var r1 gc.Node
gc.Regalloc(&r1, con.Type, t) gc.Regalloc(&r1, con.Type, t)
gins(ppc64.AMOVD, &con, &r1) gins(ppc64.AMOVD, &con, &r1)
...@@ -546,14 +546,13 @@ hard: ...@@ -546,14 +546,13 @@ hard:
} }
func intLiteral(n *gc.Node) (x int64, ok bool) { func intLiteral(n *gc.Node) (x int64, ok bool) {
if n == nil || n.Op != gc.OLITERAL { switch {
case n == nil:
return return
} case gc.Isconst(n, gc.CTINT):
switch n.Val.Ctype {
case gc.CTINT, gc.CTRUNE:
return n.Int(), true return n.Int(), true
case gc.CTBOOL: case gc.Isconst(n, gc.CTBOOL):
return int64(obj.Bool2int(n.Val.U.Bval)), true return int64(obj.Bool2int(n.Bool())), true
} }
return return
} }
......
...@@ -37,6 +37,15 @@ func (n *Node) SetBigInt(x *big.Int) { ...@@ -37,6 +37,15 @@ func (n *Node) SetBigInt(x *big.Int) {
n.Val.U.Xval.Val.Set(x) n.Val.U.Xval.Val.Set(x)
} }
// Bool returns n as an bool.
// n must be an boolean constant.
func (n *Node) Bool() bool {
if !Isconst(n, CTBOOL) {
Fatal("Int(%v)", n)
}
return n.Val.U.Bval
}
/* /*
* truncate float literal fv to 32-bit or 64-bit precision * truncate float literal fv to 32-bit or 64-bit precision
* according to type; return truncated value. * according to type; return truncated value.
...@@ -1426,32 +1435,30 @@ func iconv(x int64, et int) int64 { ...@@ -1426,32 +1435,30 @@ func iconv(x int64, et int) int64 {
return x return x
} }
/* // Convconst converts constant node n to type t and
* convert constant val to type t; leave in con. // places the result in con.
* for back end. func (n *Node) Convconst(con *Node, t *Type) {
*/
func Convconst(con *Node, t *Type, val *Val) {
tt := Simsimtype(t) tt := Simsimtype(t)
// copy the constant for conversion // copy the constant for conversion
Nodconst(con, Types[TINT8], 0) Nodconst(con, Types[TINT8], 0)
con.Type = t con.Type = t
con.Val = *val con.Val = n.Val
if Isint[tt] { if Isint[tt] {
con.Val.Ctype = CTINT con.Val.Ctype = CTINT
con.Val.U.Xval = new(Mpint) con.Val.U.Xval = new(Mpint)
var i int64 var i int64
switch val.Ctype { switch n.Val.Ctype {
default: default:
Fatal("convconst ctype=%d %v", val.Ctype, Tconv(t, obj.FmtLong)) Fatal("convconst ctype=%d %v", n.Val.Ctype, Tconv(t, obj.FmtLong))
case CTINT, CTRUNE: case CTINT, CTRUNE:
i = Mpgetfix(val.U.Xval) i = Mpgetfix(n.Val.U.Xval)
case CTBOOL: case CTBOOL:
i = int64(obj.Bool2int(val.U.Bval)) i = int64(obj.Bool2int(n.Val.U.Bval))
case CTNIL: case CTNIL:
i = 0 i = 0
...@@ -1479,7 +1486,6 @@ func Convconst(con *Node, t *Type, val *Val) { ...@@ -1479,7 +1486,6 @@ func Convconst(con *Node, t *Type, val *Val) {
con.Val.U.Cval.Real = *truncfltlit(&con.Val.U.Cval.Real, Types[TFLOAT32]) con.Val.U.Cval.Real = *truncfltlit(&con.Val.U.Cval.Real, Types[TFLOAT32])
con.Val.U.Cval.Imag = *truncfltlit(&con.Val.U.Cval.Imag, Types[TFLOAT32]) con.Val.U.Cval.Imag = *truncfltlit(&con.Val.U.Cval.Imag, Types[TFLOAT32])
} }
return return
} }
......
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