]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: more String methods for prove types
authorAustin Clements <austin@google.com>
Tue, 9 Jan 2018 19:45:30 +0000 (14:45 -0500)
committerAustin Clements <austin@google.com>
Thu, 8 Mar 2018 22:25:23 +0000 (22:25 +0000)
These aid in debugging.

Change-Id: Ieb38c996765f780f6103f8c3292639d408c25123
Reviewed-on: https://go-review.googlesource.com/87476
Run-TryBot: Austin Clements <austin@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Reviewed-by: Keith Randall <khr@golang.org>
src/cmd/compile/fmt_test.go
src/cmd/compile/internal/ssa/prove.go

index 03e6e2ee4cc9682badb7e6af45f838bc4ea40c7c..578a0bfb20fb168f170c53486ba5fa199aef02fc 100644 (file)
@@ -707,6 +707,7 @@ var knownFormats = map[string]string{
        "uint %04x":        "",
        "uint %5d":         "",
        "uint %d":          "",
+       "uint %x":          "",
        "uint16 %d":        "",
        "uint16 %v":        "",
        "uint16 %x":        "",
index ecf0412377979661a1340e77b3a9f736def73b73..448a92ae579fd6039c1daa746e00bd439bb84633 100644 (file)
@@ -45,6 +45,18 @@ const (
        gt
 )
 
+var relationStrings = [...]string{
+       0: "none", lt: "<", eq: "==", lt | eq: "<=",
+       gt: ">", gt | lt: "!=", gt | eq: ">=", gt | eq | lt: "any",
+}
+
+func (r relation) String() string {
+       if r < relation(len(relationStrings)) {
+               return relationStrings[r]
+       }
+       return fmt.Sprintf("relation(%d)", uint(r))
+}
+
 // domain represents the domain of a variable pair in which a set
 // of relations is known.  For example, relations learned for unsigned
 // pairs cannot be transferred to signed pairs because the same bit
@@ -58,6 +70,30 @@ const (
        boolean
 )
 
+var domainStrings = [...]string{
+       "signed", "unsigned", "pointer", "boolean",
+}
+
+func (d domain) String() string {
+       s := ""
+       for i, ds := range domainStrings {
+               if d&(1<<uint(i)) != 0 {
+                       if len(s) != 0 {
+                               s += "|"
+                       }
+                       s += ds
+                       d &^= 1 << uint(i)
+               }
+       }
+       if d != 0 {
+               if len(s) != 0 {
+                       s += "|"
+               }
+               s += fmt.Sprintf("0x%x", uint(d))
+       }
+       return s
+}
+
 type pair struct {
        v, w *Value // a pair of values, ordered by ID.
        // v can be nil, to mean the zero value.