Commit ac1cdd13 authored by Michael Hudson-Doyle's avatar Michael Hudson-Doyle Committed by Ian Lance Taylor

cmd/5g, etc, cmd/internal/gc, cmd/internal/obj, etc: coalesce bool2int implementations

There were 10 implementations of the trivial bool2int function, 9 of which
were the only thing in their file.  Remove all of them in favor of one in
cmd/internal/obj.

Change-Id: I9c51d30716239df51186860b9842a5e9b27264d3
Reviewed-on: https://go-review.googlesource.com/9230Reviewed-by: default avatarIan Lance Taylor <iant@golang.org>
parent 67783935
// Copyright 2015 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package main
func bool2int(b bool) int {
if b {
return 1
}
return 0
}
// Copyright 2015 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package main
func bool2int(b bool) int {
if b {
return 1
}
return 0
}
......@@ -447,7 +447,7 @@ func intLiteral(n *gc.Node) (x int64, ok bool) {
case gc.CTINT, gc.CTRUNE:
return gc.Mpgetfix(n.Val.U.Xval), true
case gc.CTBOOL:
return int64(bool2int(n.Val.U.Bval)), true
return int64(obj.Bool2int(n.Val.U.Bval)), true
}
return
}
......
// Copyright 2015 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package main
func bool2int(b bool) int {
if b {
return 1
}
return 0
}
// Copyright 2015 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package main
func bool2int(b bool) int {
if b {
return 1
}
return 0
}
......@@ -526,7 +526,7 @@ func intLiteral(n *gc.Node) (x int64, ok bool) {
case gc.CTINT, gc.CTRUNE:
return gc.Mpgetfix(n.Val.U.Xval), true
case gc.CTBOOL:
return int64(bool2int(n.Val.U.Bval)), true
return int64(obj.Bool2int(n.Val.U.Bval)), true
}
return
}
......
// Copyright 2015 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package main
func bool2int(b bool) int {
if b {
return 1
}
return 0
}
......@@ -1417,7 +1417,7 @@ func Convconst(con *Node, t *Type, val *Val) {
i = Mpgetfix(val.U.Xval)
case CTBOOL:
i = int64(bool2int(val.U.Bval))
i = int64(obj.Bool2int(val.U.Bval))
case CTNIL:
i = 0
......
......@@ -87,7 +87,7 @@ func Gbranch(as int, t *Type, likely int) *obj.Prog {
p.To.Val = nil
if as != obj.AJMP && likely != 0 && Thearch.Thechar != '9' && Thearch.Thechar != '7' {
p.From.Type = obj.TYPE_CONST
p.From.Offset = int64(bool2int(likely > 0))
p.From.Offset = int64(obj.Bool2int(likely > 0))
}
return p
......@@ -417,7 +417,7 @@ func Naddr(a *obj.Addr, n *Node) {
case CTBOOL:
a.Sym = nil
a.Type = obj.TYPE_CONST
a.Offset = int64(bool2int(n.Val.U.Bval))
a.Offset = int64(obj.Bool2int(n.Val.U.Bval))
case CTNIL:
a.Sym = nil
......
......@@ -191,17 +191,17 @@ func cmpstackvar(a *Node, b *Node) int {
}
if a.Used != b.Used {
return bool2int(b.Used) - bool2int(a.Used)
return obj.Bool2int(b.Used) - obj.Bool2int(a.Used)
}
ap := bool2int(haspointers(a.Type))
bp := bool2int(haspointers(b.Type))
ap := obj.Bool2int(haspointers(a.Type))
bp := obj.Bool2int(haspointers(b.Type))
if ap != bp {
return bp - ap
}
ap = bool2int(a.Needzero)
bp = bool2int(b.Needzero)
ap = obj.Bool2int(a.Needzero)
bp = obj.Bool2int(b.Needzero)
if ap != bp {
return bp - ap
}
......
......@@ -678,7 +678,7 @@ func haspointers(t *Type) bool {
ret = true
}
t.Haspointers = 1 + uint8(bool2int(ret))
t.Haspointers = 1 + uint8(obj.Bool2int(ret))
return ret
}
......@@ -1066,7 +1066,7 @@ ok:
ot = dcommontype(s, ot, t)
xt = ot - 3*Widthptr
ot = duint8(s, ot, uint8(bool2int(isddd)))
ot = duint8(s, ot, uint8(obj.Bool2int(isddd)))
// two slice headers: in and out.
ot = int(Rnd(int64(ot), int64(Widthptr)))
......@@ -1146,7 +1146,7 @@ ok:
}
ot = duint16(s, ot, uint16(mapbucket(t).Width))
ot = duint8(s, ot, uint8(bool2int(isreflexive(t.Down))))
ot = duint8(s, ot, uint8(obj.Bool2int(isreflexive(t.Down))))
case TPTR32, TPTR64:
if t.Type.Etype == TANY {
......
......@@ -1831,8 +1831,8 @@ OpSwitch:
n.Type = nil
return
}
et := bool2int(checkmake(t, "len", l) < 0)
et |= bool2int(r != nil && checkmake(t, "cap", r) < 0)
et := obj.Bool2int(checkmake(t, "len", l) < 0)
et |= obj.Bool2int(r != nil && checkmake(t, "cap", r) < 0)
if et != 0 {
n.Type = nil
return
......@@ -2820,12 +2820,12 @@ func keydup(n *Node, hash []*Node) {
if Eqtype(a.Left.Type, n.Type) {
cmp.Right = a.Left
evconst(&cmp)
b = uint32(bool2int(cmp.Val.U.Bval))
b = uint32(obj.Bool2int(cmp.Val.U.Bval))
}
} else if Eqtype(a.Type, n.Type) {
cmp.Right = a
evconst(&cmp)
b = uint32(bool2int(cmp.Val.U.Bval))
b = uint32(obj.Bool2int(cmp.Val.U.Bval))
}
if b != 0 {
......
......@@ -8,13 +8,6 @@ import (
"strings"
)
func bool2int(b bool) int {
if b {
return 1
}
return 0
}
func (n *Node) Line() string {
return obj.Linklinefmt(Ctxt, int(n.Lineno), false, false)
}
......
......@@ -829,7 +829,7 @@ func stacksplit(ctxt *obj.Link, p *obj.Prog, framesize int32, noctxt bool) *obj.
if ctxt.Cursym.Cfunc != 0 {
p.To.Sym = obj.Linklookup(ctxt, "runtime.morestackc", 0)
} else {
p.To.Sym = ctxt.Symmorestack[bool2int(noctxt)]
p.To.Sym = ctxt.Symmorestack[obj.Bool2int(noctxt)]
}
// BLS start
......
// Copyright 2015 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package arm
func bool2int(b bool) int {
if b {
return 1
}
return 0
}
......@@ -831,7 +831,7 @@ func regoff(ctxt *obj.Link, a *obj.Addr) uint32 {
func ispcdisp(v int32) int {
/* pc-relative addressing will reach? */
return bool2int(v >= -0xfffff && v <= 0xfffff && (v&3) == 0)
return obj.Bool2int(v >= -0xfffff && v <= 0xfffff && (v&3) == 0)
}
func isaddcon(v int64) int {
......@@ -842,14 +842,14 @@ func isaddcon(v int64) int {
if (v & 0xFFF) == 0 {
v >>= 12
}
return bool2int(v <= 0xFFF)
return obj.Bool2int(v <= 0xFFF)
}
func isbitcon(v uint64) int {
/* fancy bimm32 or bimm64? */
// TODO(aram):
return 0
// return bool2int(findmask(v) != nil || (v>>32) == 0 && findmask(v|(v<<32)) != nil)
// return obj.Bool2int(findmask(v) != nil || (v>>32) == 0 && findmask(v|(v<<32)) != nil)
}
func autoclass(l int64) int {
......@@ -2188,7 +2188,7 @@ func asmout(ctxt *obj.Link, p *obj.Prog, o *Optab, out []uint32) {
case 24: /* mov/mvn Rs,Rd -> add $0,Rs,Rd or orr Rs,ZR,Rd */
rf := int(p.From.Reg)
rt := int(p.To.Reg)
s := bool2int(rf == REGSP || rt == REGSP)
s := obj.Bool2int(rf == REGSP || rt == REGSP)
if p.As == AMVN || p.As == AMVNW {
if s != 0 {
ctxt.Diag("illegal SP reference\n%v", p)
......
......@@ -583,7 +583,7 @@ func preprocess(ctxt *obj.Link, cursym *obj.LSym) {
}
if !(p.From3.Offset&obj.NOSPLIT != 0) {
p = stacksplit(ctxt, p, ctxt.Autosize, bool2int(cursym.Text.From3.Offset&obj.NEEDCTXT == 0)) // emit split check
p = stacksplit(ctxt, p, ctxt.Autosize, obj.Bool2int(cursym.Text.From3.Offset&obj.NEEDCTXT == 0)) // emit split check
}
aoffset = ctxt.Autosize
......
// Copyright 2015 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package arm64
func bool2int(b bool) int {
if b {
return 1
}
return 0
}
......@@ -758,7 +758,7 @@ func stacksplit(ctxt *obj.Link, p *obj.Prog, framesize int32, noctxt bool) *obj.
if ctxt.Cursym.Cfunc != 0 {
p.To.Sym = obj.Linklookup(ctxt, "runtime.morestackc", 0)
} else {
p.To.Sym = ctxt.Symmorestack[bool2int(noctxt)]
p.To.Sym = ctxt.Symmorestack[obj.Bool2int(noctxt)]
}
// BR start
......
// Copyright 2015 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package ppc64
func bool2int(b bool) int {
if b {
return 1
}
return 0
}
......@@ -641,3 +641,10 @@ var Anames = []string{
"VARDEF",
"VARKILL",
}
func Bool2int(b bool) int {
if b {
return 1
}
return 0
}
......@@ -2985,7 +2985,7 @@ func doasm(ctxt *obj.Link, p *obj.Prog) {
f3t := int(p.F3t) * Ymax
tt := int(p.Tt) * Ymax
xo := bool2int(o.op[0] == 0x0f)
xo := obj.Bool2int(o.op[0] == 0x0f)
z := 0
var a *obj.Addr
var l int
......
......@@ -990,7 +990,7 @@ func stacksplit(ctxt *obj.Link, p *obj.Prog, framesize int32, textarg int32, noc
if ctxt.Cursym.Cfunc != 0 {
p.To.Sym = obj.Linklookup(ctxt, "runtime.morestackc", 0)
} else {
p.To.Sym = ctxt.Symmorestack[bool2int(noctxt)]
p.To.Sym = ctxt.Symmorestack[obj.Bool2int(noctxt)]
}
p = obj.Appendp(ctxt, p)
......
// Copyright 2015 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package x86
func bool2int(b bool) int {
if b {
return 1
}
return 0
}
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