]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: relocate code from config.go to func.go
authorJosh Bleecher Snyder <josharian@gmail.com>
Thu, 16 Mar 2017 05:43:40 +0000 (22:43 -0700)
committerJosh Bleecher Snyder <josharian@gmail.com>
Fri, 17 Mar 2017 05:21:53 +0000 (05:21 +0000)
This is a follow-up to CL 38167.
Pure code movement.

Change-Id: I13e58f7eac6718c77076d89e13fc721a5205ec57
Reviewed-on: https://go-review.googlesource.com/38322
Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
src/cmd/compile/internal/ssa/config.go
src/cmd/compile/internal/ssa/func.go

index 589b7c9b1ef3c54a845931f77f0ae5a2564a53f7..30ee9b45ffdf67edeb0337f79fe3e297f5b83fdd 100644 (file)
@@ -7,11 +7,8 @@ package ssa
 import (
        "cmd/internal/obj"
        "cmd/internal/src"
-       "crypto/sha1"
-       "fmt"
        "os"
        "strconv"
-       "strings"
 )
 
 // A Config holds readonly compilation information.
@@ -318,84 +315,3 @@ func (c *Config) Error(pos src.XPos, msg string, args ...interface{})  { c.fe.Er
 func (c *Config) Warnl(pos src.XPos, msg string, args ...interface{})  { c.fe.Warnl(pos, msg, args...) }
 func (c *Config) Debug_checknil() bool                                 { return c.fe.Debug_checknil() }
 func (c *Config) Debug_wb() bool                                       { return c.fe.Debug_wb() }
-
-func (f *Func) logDebugHashMatch(evname, name string) {
-       if f.logfiles == nil {
-               f.logfiles = make(map[string]*os.File)
-       }
-       file := f.logfiles[evname]
-       if file == nil {
-               file = os.Stdout
-               tmpfile := os.Getenv("GSHS_LOGFILE")
-               if tmpfile != "" {
-                       var ok error
-                       file, ok = os.Create(tmpfile)
-                       if ok != nil {
-                               f.Fatalf("could not open hash-testing logfile %s", tmpfile)
-                       }
-               }
-               f.logfiles[evname] = file
-       }
-       s := fmt.Sprintf("%s triggered %s\n", evname, name)
-       file.WriteString(s)
-       file.Sync()
-}
-
-// DebugHashMatch returns true if environment variable evname
-// 1) is empty (this is a special more-quickly implemented case of 3)
-// 2) is "y" or "Y"
-// 3) is a suffix of the sha1 hash of name
-// 4) is a suffix of the environment variable
-//    fmt.Sprintf("%s%d", evname, n)
-//    provided that all such variables are nonempty for 0 <= i <= n
-// Otherwise it returns false.
-// When true is returned the message
-//  "%s triggered %s\n", evname, name
-// is printed on the file named in environment variable
-//  GSHS_LOGFILE
-// or standard out if that is empty or there is an error
-// opening the file.
-func (f *Func) DebugHashMatch(evname, name string) bool {
-       evhash := os.Getenv(evname)
-       if evhash == "" {
-               return true // default behavior with no EV is "on"
-       }
-       if evhash == "y" || evhash == "Y" {
-               f.logDebugHashMatch(evname, name)
-               return true
-       }
-       if evhash == "n" || evhash == "N" {
-               return false
-       }
-       // Check the hash of the name against a partial input hash.
-       // We use this feature to do a binary search to
-       // find a function that is incorrectly compiled.
-       hstr := ""
-       for _, b := range sha1.Sum([]byte(name)) {
-               hstr += fmt.Sprintf("%08b", b)
-       }
-
-       if strings.HasSuffix(hstr, evhash) {
-               f.logDebugHashMatch(evname, name)
-               return true
-       }
-
-       // Iteratively try additional hashes to allow tests for multi-point
-       // failure.
-       for i := 0; true; i++ {
-               ev := fmt.Sprintf("%s%d", evname, i)
-               evv := os.Getenv(ev)
-               if evv == "" {
-                       break
-               }
-               if strings.HasSuffix(hstr, evv) {
-                       f.logDebugHashMatch(ev, name)
-                       return true
-               }
-       }
-       return false
-}
-
-func DebugNameMatch(evname, name string) bool {
-       return os.Getenv(evname) == name
-}
index 86824670536eda50bc57c8456e10d7984f9533ff..733e2abe1bad19065c0d671043e9f30d0f3fe100 100644 (file)
@@ -6,6 +6,7 @@ package ssa
 
 import (
        "cmd/internal/src"
+       "crypto/sha1"
        "fmt"
        "math"
        "os"
@@ -526,3 +527,84 @@ func (f *Func) invalidateCFG() {
        f.cachedSdom = nil
        f.cachedLoopnest = nil
 }
+
+// DebugHashMatch returns true if environment variable evname
+// 1) is empty (this is a special more-quickly implemented case of 3)
+// 2) is "y" or "Y"
+// 3) is a suffix of the sha1 hash of name
+// 4) is a suffix of the environment variable
+//    fmt.Sprintf("%s%d", evname, n)
+//    provided that all such variables are nonempty for 0 <= i <= n
+// Otherwise it returns false.
+// When true is returned the message
+//  "%s triggered %s\n", evname, name
+// is printed on the file named in environment variable
+//  GSHS_LOGFILE
+// or standard out if that is empty or there is an error
+// opening the file.
+func (f *Func) DebugHashMatch(evname, name string) bool {
+       evhash := os.Getenv(evname)
+       if evhash == "" {
+               return true // default behavior with no EV is "on"
+       }
+       if evhash == "y" || evhash == "Y" {
+               f.logDebugHashMatch(evname, name)
+               return true
+       }
+       if evhash == "n" || evhash == "N" {
+               return false
+       }
+       // Check the hash of the name against a partial input hash.
+       // We use this feature to do a binary search to
+       // find a function that is incorrectly compiled.
+       hstr := ""
+       for _, b := range sha1.Sum([]byte(name)) {
+               hstr += fmt.Sprintf("%08b", b)
+       }
+
+       if strings.HasSuffix(hstr, evhash) {
+               f.logDebugHashMatch(evname, name)
+               return true
+       }
+
+       // Iteratively try additional hashes to allow tests for multi-point
+       // failure.
+       for i := 0; true; i++ {
+               ev := fmt.Sprintf("%s%d", evname, i)
+               evv := os.Getenv(ev)
+               if evv == "" {
+                       break
+               }
+               if strings.HasSuffix(hstr, evv) {
+                       f.logDebugHashMatch(ev, name)
+                       return true
+               }
+       }
+       return false
+}
+
+func (f *Func) logDebugHashMatch(evname, name string) {
+       if f.logfiles == nil {
+               f.logfiles = make(map[string]*os.File)
+       }
+       file := f.logfiles[evname]
+       if file == nil {
+               file = os.Stdout
+               tmpfile := os.Getenv("GSHS_LOGFILE")
+               if tmpfile != "" {
+                       var ok error
+                       file, ok = os.Create(tmpfile)
+                       if ok != nil {
+                               f.Fatalf("could not open hash-testing logfile %s", tmpfile)
+                       }
+               }
+               f.logfiles[evname] = file
+       }
+       s := fmt.Sprintf("%s triggered %s\n", evname, name)
+       file.WriteString(s)
+       file.Sync()
+}
+
+func DebugNameMatch(evname, name string) bool {
+       return os.Getenv(evname) == name
+}