]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile/internal/gc: move intLiteral to gc.Node
authorDave Cheney <dave@cheney.net>
Fri, 18 Sep 2015 08:56:47 +0000 (18:56 +1000)
committerDave Cheney <dave@cheney.net>
Sat, 19 Sep 2015 04:38:02 +0000 (04:38 +0000)
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/14744
Reviewed-by: Aram Hăvărneanu <aram@mgk.ro>
Reviewed-by: Dave Cheney <dave@cheney.net>
Run-TryBot: Dave Cheney <dave@cheney.net>
TryBot-Result: Gobot Gobot <gobot@golang.org>

src/cmd/compile/internal/arm64/gsubr.go
src/cmd/compile/internal/gc/const.go
src/cmd/compile/internal/mips64/gsubr.go
src/cmd/compile/internal/ppc64/gsubr.go

index 11214789f571111ebe6ccd52571b2b78b5d14ec9..50ff29bf8f3c7ffa1c52e56cef4814d1892a0d1f 100644 (file)
@@ -467,30 +467,18 @@ hard:
        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.
 // It synthesizes some multiple-instruction sequences
 // so the front end can stay simpler.
 func gins(as int, f, t *gc.Node) *obj.Prog {
        if as >= obj.A_ARCHSPECIFIC {
-               if x, ok := intLiteral(f); ok {
+               if x, ok := f.IntLiteral(); ok {
                        ginscon(as, x, t)
                        return nil // caller must not use
                }
        }
        if as == arm64.ACMP {
-               if x, ok := intLiteral(t); ok {
+               if x, ok := t.IntLiteral(); ok {
                        ginscon2(as, f, x)
                        return nil // caller must not use
                }
index e7559c206e5a0490d7ddb485544f4fbb80c6d5f6..71b582b739651c8572f02b6a97618588bf707147 100644 (file)
@@ -10,6 +10,19 @@ import (
        "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.
 // n must be an integer constant.
 func (n *Node) Int() int64 {
index 4ef928c8264276564972147793497ef37fc137f9..dde05c4a512dfa6fd6d403f4a72c6c4d9610473f 100644 (file)
@@ -545,30 +545,18 @@ hard:
        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.
 // It synthesizes some multiple-instruction sequences
 // so the front end can stay simpler.
 func gins(as int, f, t *gc.Node) *obj.Prog {
        if as >= obj.A_ARCHSPECIFIC {
-               if x, ok := intLiteral(f); ok {
+               if x, ok := f.IntLiteral(); ok {
                        ginscon(as, x, t)
                        return nil // caller must not use
                }
        }
        if as == ppc64.ACMP || as == ppc64.ACMPU {
-               if x, ok := intLiteral(t); ok {
+               if x, ok := t.IntLiteral(); ok {
                        ginscon2(as, f, x)
                        return nil // caller must not use
                }
index 4ef928c8264276564972147793497ef37fc137f9..dde05c4a512dfa6fd6d403f4a72c6c4d9610473f 100644 (file)
@@ -545,30 +545,18 @@ hard:
        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.
 // It synthesizes some multiple-instruction sequences
 // so the front end can stay simpler.
 func gins(as int, f, t *gc.Node) *obj.Prog {
        if as >= obj.A_ARCHSPECIFIC {
-               if x, ok := intLiteral(f); ok {
+               if x, ok := f.IntLiteral(); ok {
                        ginscon(as, x, t)
                        return nil // caller must not use
                }
        }
        if as == ppc64.ACMP || as == ppc64.ACMPU {
-               if x, ok := intLiteral(t); ok {
+               if x, ok := t.IntLiteral(); ok {
                        ginscon2(as, f, x)
                        return nil // caller must not use
                }