Commit 88e47187 authored by Josh Bleecher Snyder's avatar Josh Bleecher Snyder

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 <josharian@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: 's avatarBrad Fitzpatrick <bradfitz@golang.org>
parent a5e3cac8
......@@ -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
}
......@@ -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
}
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