]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile/internal: better AST line highlight in ssa.html
authorZheng Xu <zheng.xu@arm.com>
Wed, 1 Sep 2021 05:48:48 +0000 (13:48 +0800)
committerCherry Mui <cherryyz@google.com>
Fri, 10 Sep 2021 14:03:35 +0000 (14:03 +0000)
We tend to set div class with the line number in HTML AST nodes. So that
the AST nodes can be highlighted with corresponding source and ssa ir.

The pure AST text dump is created first. And then it is parsed and
written to the HTML file.

CL 275785 changed the format of the line information in AST node dump,
which makes the HTMLWriter fail to parse the line information.

This CL updates the code in HTMLWriter to align with the format of AST
node dump.

Fix #48133

Change-Id: I2b56fc5e3e9771456d91f22caf23a427c235eb12
Reviewed-on: https://go-review.googlesource.com/c/go/+/347269
Reviewed-by: Cherry Mui <cherryyz@google.com>
Trust: Than McIntosh <thanm@google.com>

src/cmd/compile/internal/ir/fmt.go
src/cmd/compile/internal/ssa/html.go

index 22fbf3997585afc3dabc059a90f88daf53106dd6..a99cb5ed9872c31c2cab22dbfa86b0b139b78e4b 100644 (file)
@@ -1147,6 +1147,7 @@ func dumpNodeHeader(w io.Writer, n Node) {
                        }
                        // TODO(mdempsky): Print line pragma details too.
                        file := filepath.Base(pos.Filename())
+                       // Note: this output will be parsed by ssa/html.go:(*HTMLWriter).WriteAST. Keep in sync.
                        fmt.Fprintf(w, "%s:%d:%d", file, pos.Line(), pos.Col())
                }
        }
index 6fd898636cd6ceff0eb015a2261e3a7048020d12..d9a78b396243beb32e912549f89a83ef72c692a5 100644 (file)
@@ -903,15 +903,12 @@ func (w *HTMLWriter) WriteAST(phase string, buf *bytes.Buffer) {
                        if strings.HasPrefix(l, "buildssa") {
                                escaped = fmt.Sprintf("<b>%v</b>", l)
                        } else {
-                               // Parse the line number from the format l(123).
-                               idx := strings.Index(l, " l(")
-                               if idx != -1 {
-                                       subl := l[idx+3:]
-                                       idxEnd := strings.Index(subl, ")")
-                                       if idxEnd != -1 {
-                                               if _, err := strconv.Atoi(subl[:idxEnd]); err == nil {
-                                                       lineNo = subl[:idxEnd]
-                                               }
+                               // Parse the line number from the format file:line:col.
+                               // See the implementation in ir/fmt.go:dumpNodeHeader.
+                               sl := strings.Split(l, ":")
+                               if len(sl) >= 3 {
+                                       if _, err := strconv.Atoi(sl[len(sl)-2]); err == nil {
+                                               lineNo = sl[len(sl)-2]
                                        }
                                }
                                escaped = html.EscapeString(l)