]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: a rule's line number is at its ->
authorKeith Randall <khr@golang.org>
Tue, 26 Apr 2016 21:09:58 +0000 (14:09 -0700)
committerKeith Randall <khr@golang.org>
Tue, 26 Apr 2016 23:09:00 +0000 (23:09 +0000)
Let's define the line number of a multiline rule as the line
number on which the -> appears.  This helps make the rule
cover analysis look a bit nicer.

Change-Id: I4ac4c09f2240285976590ecfd416bc4c05e78946
Reviewed-on: https://go-review.googlesource.com/22473
Reviewed-by: Josh Bleecher Snyder <josharian@gmail.com>
src/cmd/compile/internal/ssa/gen/rulegen.go

index 02a5da2a5adc2a54b1fa1372b9508a91004c940e..5f7d1cf984c96743b01afe253f2be7b04ae4db7f 100644 (file)
@@ -91,6 +91,7 @@ func genRules(arch arch) {
        scanner := bufio.NewScanner(text)
        rule := ""
        var lineno int
+       var ruleLineno int // line number of "->"
        for scanner.Scan() {
                lineno++
                line := scanner.Text()
@@ -107,6 +108,9 @@ func genRules(arch arch) {
                if !strings.Contains(rule, "->") {
                        continue
                }
+               if ruleLineno == 0 {
+                       ruleLineno = lineno
+               }
                if strings.HasSuffix(rule, "->") {
                        continue
                }
@@ -117,13 +121,14 @@ func genRules(arch arch) {
                if op[len(op)-1] == ')' {
                        op = op[:len(op)-1] // rule has only opcode, e.g. (ConstNil) -> ...
                }
-               loc := fmt.Sprintf("%s.rules:%d", arch.name, lineno)
+               loc := fmt.Sprintf("%s.rules:%d", arch.name, ruleLineno)
                if isBlock(op, arch) {
                        blockrules[op] = append(blockrules[op], Rule{rule: rule, loc: loc})
                } else {
                        oprules[op] = append(oprules[op], Rule{rule: rule, loc: loc})
                }
                rule = ""
+               ruleLineno = 0
        }
        if err := scanner.Err(); err != nil {
                log.Fatalf("scanner failed: %v\n", err)