]> Cypherpunks repositories - gostls13.git/commitdiff
[dev.regabi] cmd/compile: fix ir.Dump for []*CaseClause, etc
authorMatthew Dempsky <mdempsky@google.com>
Tue, 5 Jan 2021 06:58:24 +0000 (22:58 -0800)
committerMatthew Dempsky <mdempsky@google.com>
Tue, 5 Jan 2021 07:36:40 +0000 (07:36 +0000)
Dump uses reflection to print IR nodes, and it only knew how to print
out the Nodes slice type itself. This CL adds support for printing any
slice whose element type implements Node, such as SwitchStmt and
SelectStmt's clause lists.

Change-Id: I2fd8defe11868b564d1d389ea3cd9b8abcefac62
Reviewed-on: https://go-review.googlesource.com/c/go/+/281537
Trust: Matthew Dempsky <mdempsky@google.com>
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
src/cmd/compile/internal/ir/fmt.go

index 92ea160a28bf312da54bedc95ca93b1f6aed2e83..a4e769f508b09de304569413532e2443d27aba14 100644 (file)
@@ -1237,10 +1237,25 @@ func dumpNode(w io.Writer, n Node, depth int) {
                                fmt.Fprintf(w, "%+v-%s", n.Op(), name)
                        }
                        dumpNodes(w, val, depth+1)
+               default:
+                       if vf.Kind() == reflect.Slice && vf.Type().Elem().Implements(nodeType) {
+                               if vf.Len() == 0 {
+                                       continue
+                               }
+                               if name != "" {
+                                       indent(w, depth)
+                                       fmt.Fprintf(w, "%+v-%s", n.Op(), name)
+                               }
+                               for i, n := 0, vf.Len(); i < n; i++ {
+                                       dumpNode(w, vf.Index(i).Interface().(Node), depth+1)
+                               }
+                       }
                }
        }
 }
 
+var nodeType = reflect.TypeOf((*Node)(nil)).Elem()
+
 func dumpNodes(w io.Writer, list Nodes, depth int) {
        if len(list) == 0 {
                fmt.Fprintf(w, " <nil>")