Commit 3e476827 authored by Dave Cheney's avatar Dave Cheney

cmd/compile/internal/gc: move intLiteral to gc.Node

intLiteral is used by the gins wrappers in arm64, ppc64 and
mips64. Refactor the function to a method on gc.Node and update
the callers to use the common copy.

Change-Id: I2db90d801a9cb18f8526eb921e13daa75ca1cf6f
Reviewed-on: https://go-review.googlesource.com/14744Reviewed-by: default avatarAram Hăvărneanu <aram@mgk.ro>
Reviewed-by: default avatarDave Cheney <dave@cheney.net>
Run-TryBot: Dave Cheney <dave@cheney.net>
TryBot-Result: Gobot Gobot <gobot@golang.org>
parent c742ff6a
...@@ -467,30 +467,18 @@ hard: ...@@ -467,30 +467,18 @@ hard:
return return
} }
func intLiteral(n *gc.Node) (x int64, ok bool) {
switch {
case n == nil:
return
case gc.Isconst(n, gc.CTINT):
return n.Int(), true
case gc.Isconst(n, gc.CTBOOL):
return int64(obj.Bool2int(n.Bool())), true
}
return
}
// gins is called by the front end. // gins is called by the front end.
// It synthesizes some multiple-instruction sequences // It synthesizes some multiple-instruction sequences
// so the front end can stay simpler. // so the front end can stay simpler.
func gins(as int, f, t *gc.Node) *obj.Prog { func gins(as int, f, t *gc.Node) *obj.Prog {
if as >= obj.A_ARCHSPECIFIC { if as >= obj.A_ARCHSPECIFIC {
if x, ok := intLiteral(f); ok { if x, ok := f.IntLiteral(); ok {
ginscon(as, x, t) ginscon(as, x, t)
return nil // caller must not use return nil // caller must not use
} }
} }
if as == arm64.ACMP { if as == arm64.ACMP {
if x, ok := intLiteral(t); ok { if x, ok := t.IntLiteral(); ok {
ginscon2(as, f, x) ginscon2(as, f, x)
return nil // caller must not use return nil // caller must not use
} }
......
...@@ -10,6 +10,19 @@ import ( ...@@ -10,6 +10,19 @@ import (
"strings" "strings"
) )
// IntLiteral returns the Node's literal value as an interger.
func (n *Node) IntLiteral() (x int64, ok bool) {
switch {
case n == nil:
return
case Isconst(n, CTINT):
return n.Int(), true
case Isconst(n, CTBOOL):
return int64(obj.Bool2int(n.Bool())), true
}
return
}
// Int returns n as an int. // Int returns n as an int.
// n must be an integer constant. // n must be an integer constant.
func (n *Node) Int() int64 { func (n *Node) Int() int64 {
......
...@@ -545,30 +545,18 @@ hard: ...@@ -545,30 +545,18 @@ hard:
return return
} }
func intLiteral(n *gc.Node) (x int64, ok bool) {
switch {
case n == nil:
return
case gc.Isconst(n, gc.CTINT):
return n.Int(), true
case gc.Isconst(n, gc.CTBOOL):
return int64(obj.Bool2int(n.Bool())), true
}
return
}
// gins is called by the front end. // gins is called by the front end.
// It synthesizes some multiple-instruction sequences // It synthesizes some multiple-instruction sequences
// so the front end can stay simpler. // so the front end can stay simpler.
func gins(as int, f, t *gc.Node) *obj.Prog { func gins(as int, f, t *gc.Node) *obj.Prog {
if as >= obj.A_ARCHSPECIFIC { if as >= obj.A_ARCHSPECIFIC {
if x, ok := intLiteral(f); ok { if x, ok := f.IntLiteral(); ok {
ginscon(as, x, t) ginscon(as, x, t)
return nil // caller must not use return nil // caller must not use
} }
} }
if as == ppc64.ACMP || as == ppc64.ACMPU { if as == ppc64.ACMP || as == ppc64.ACMPU {
if x, ok := intLiteral(t); ok { if x, ok := t.IntLiteral(); ok {
ginscon2(as, f, x) ginscon2(as, f, x)
return nil // caller must not use return nil // caller must not use
} }
......
...@@ -545,30 +545,18 @@ hard: ...@@ -545,30 +545,18 @@ hard:
return return
} }
func intLiteral(n *gc.Node) (x int64, ok bool) {
switch {
case n == nil:
return
case gc.Isconst(n, gc.CTINT):
return n.Int(), true
case gc.Isconst(n, gc.CTBOOL):
return int64(obj.Bool2int(n.Bool())), true
}
return
}
// gins is called by the front end. // gins is called by the front end.
// It synthesizes some multiple-instruction sequences // It synthesizes some multiple-instruction sequences
// so the front end can stay simpler. // so the front end can stay simpler.
func gins(as int, f, t *gc.Node) *obj.Prog { func gins(as int, f, t *gc.Node) *obj.Prog {
if as >= obj.A_ARCHSPECIFIC { if as >= obj.A_ARCHSPECIFIC {
if x, ok := intLiteral(f); ok { if x, ok := f.IntLiteral(); ok {
ginscon(as, x, t) ginscon(as, x, t)
return nil // caller must not use return nil // caller must not use
} }
} }
if as == ppc64.ACMP || as == ppc64.ACMPU { if as == ppc64.ACMP || as == ppc64.ACMPU {
if x, ok := intLiteral(t); ok { if x, ok := t.IntLiteral(); ok {
ginscon2(as, f, x) ginscon2(as, f, x)
return nil // caller must not use return nil // caller must not use
} }
......
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