From 60651a1bc8540d9144e69fc71065f4994dfb0bbc Mon Sep 17 00:00:00 2001 From: Josh Bleecher Snyder Date: Wed, 22 Jan 2020 09:59:24 -0800 Subject: [PATCH] cmd/compile: add rule location to some rulegen logging MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit This requires threading location information through varCount. This provides much more useful error messages. Change-Id: If5ff942cbbbf386724eda15a523c181c137fac20 Reviewed-on: https://go-review.googlesource.com/c/go/+/216221 Run-TryBot: Josh Bleecher Snyder TryBot-Result: Gobot Gobot Reviewed-by: Daniel Martí --- src/cmd/compile/internal/ssa/gen/rulegen.go | 22 ++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/cmd/compile/internal/ssa/gen/rulegen.go b/src/cmd/compile/internal/ssa/gen/rulegen.go index 2e5f3d24f3..0d51458f60 100644 --- a/src/cmd/compile/internal/ssa/gen/rulegen.go +++ b/src/cmd/compile/internal/ssa/gen/rulegen.go @@ -945,13 +945,13 @@ func genBlockRewrite(rule Rule, arch arch, data blockData) *RuleRewrite { // genMatch returns the variable whose source position should be used for the // result (or "" if no opinion), and a boolean that reports whether the match can fail. func genMatch(rr *RuleRewrite, arch arch, match string, pregenTop bool) (pos, checkOp string) { - cnt := varCount(rr.match, rr.cond) + cnt := varCount(rr) return genMatch0(rr, arch, match, "v", cnt, pregenTop) } func genMatch0(rr *RuleRewrite, arch arch, match, v string, cnt map[string]int, pregenTop bool) (pos, checkOp string) { if match[0] != '(' || match[len(match)-1] != ')' { - log.Fatalf("non-compound expr in genMatch0: %q", match) + log.Fatalf("%s: non-compound expr in genMatch0: %q", rr.loc, match) } op, oparch, typ, auxint, aux, args := parseValue(match, arch, rr.loc) @@ -1443,14 +1443,14 @@ func expandOr(r string) []string { } // varCount returns a map which counts the number of occurrences of -// Value variables in the s-expression "match" and the Go expression "cond". -func varCount(match, cond string) map[string]int { +// Value variables in the s-expression rr.match and the Go expression rr.cond. +func varCount(rr *RuleRewrite) map[string]int { cnt := map[string]int{} - varCount1(match, cnt) - if cond != "" { - expr, err := parser.ParseExpr(cond) + varCount1(rr.loc, rr.match, cnt) + if rr.cond != "" { + expr, err := parser.ParseExpr(rr.cond) if err != nil { - log.Fatalf("failed to parse cond %q: %v", cond, err) + log.Fatalf("%s: failed to parse cond %q: %v", rr.loc, rr.cond, err) } ast.Inspect(expr, func(n ast.Node) bool { if id, ok := n.(*ast.Ident); ok { @@ -1462,7 +1462,7 @@ func varCount(match, cond string) map[string]int { return cnt } -func varCount1(m string, cnt map[string]int) { +func varCount1(loc, m string, cnt map[string]int) { if m[0] == '<' || m[0] == '[' || m[0] == '{' { return } @@ -1476,11 +1476,11 @@ func varCount1(m string, cnt map[string]int) { cnt[name]++ } if expr[0] != '(' || expr[len(expr)-1] != ')' { - log.Fatalf("non-compound expr in commute1: %q", expr) + log.Fatalf("%s: non-compound expr in varCount1: %q", loc, expr) } s := split(expr[1 : len(expr)-1]) for _, arg := range s[1:] { - varCount1(arg, cnt) + varCount1(loc, arg, cnt) } } -- 2.50.0