]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: add rule location to some rulegen logging
authorJosh Bleecher Snyder <josharian@gmail.com>
Wed, 22 Jan 2020 17:59:24 +0000 (09:59 -0800)
committerJosh Bleecher Snyder <josharian@gmail.com>
Fri, 21 Feb 2020 04:25:16 +0000 (04:25 +0000)
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 <josharian@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Daniel Martí <mvdan@mvdan.cc>
src/cmd/compile/internal/ssa/gen/rulegen.go

index 2e5f3d24f3dac295e558410c1d8de2bb27d13153..0d51458f60bfd5e5cf433a076d35ba0b8c44d5e7 100644 (file)
@@ -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)
        }
 }