From 88e47187c165e477a189049094e5e988b7651a6a Mon Sep 17 00:00:00 2001 From: Josh Bleecher Snyder Date: Wed, 15 Mar 2017 22:43:40 -0700 Subject: [PATCH] cmd/compile: relocate code from config.go to func.go 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 TryBot-Result: Gobot Gobot Reviewed-by: Brad Fitzpatrick --- src/cmd/compile/internal/ssa/config.go | 84 -------------------------- src/cmd/compile/internal/ssa/func.go | 82 +++++++++++++++++++++++++ 2 files changed, 82 insertions(+), 84 deletions(-) diff --git a/src/cmd/compile/internal/ssa/config.go b/src/cmd/compile/internal/ssa/config.go index 589b7c9b1e..30ee9b45ff 100644 --- a/src/cmd/compile/internal/ssa/config.go +++ b/src/cmd/compile/internal/ssa/config.go @@ -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 -} diff --git a/src/cmd/compile/internal/ssa/func.go b/src/cmd/compile/internal/ssa/func.go index 8682467053..733e2abe1b 100644 --- a/src/cmd/compile/internal/ssa/func.go +++ b/src/cmd/compile/internal/ssa/func.go @@ -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 +} -- 2.48.1