Skip to content

Commit 44e20b6

Browse files
committed
cmd/compile: more String methods for prove types
These aid in debugging. Change-Id: Ieb38c996765f780f6103f8c3292639d408c25123 Reviewed-on: https://go-review.googlesource.com/87476 Run-TryBot: Austin Clements <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Brad Fitzpatrick <[email protected]> Reviewed-by: Keith Randall <[email protected]>
1 parent 491f409 commit 44e20b6

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

src/cmd/compile/fmt_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -707,6 +707,7 @@ var knownFormats = map[string]string{
707707
"uint %04x": "",
708708
"uint %5d": "",
709709
"uint %d": "",
710+
"uint %x": "",
710711
"uint16 %d": "",
711712
"uint16 %v": "",
712713
"uint16 %x": "",

src/cmd/compile/internal/ssa/prove.go

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,18 @@ const (
4545
gt
4646
)
4747

48+
var relationStrings = [...]string{
49+
0: "none", lt: "<", eq: "==", lt | eq: "<=",
50+
gt: ">", gt | lt: "!=", gt | eq: ">=", gt | eq | lt: "any",
51+
}
52+
53+
func (r relation) String() string {
54+
if r < relation(len(relationStrings)) {
55+
return relationStrings[r]
56+
}
57+
return fmt.Sprintf("relation(%d)", uint(r))
58+
}
59+
4860
// domain represents the domain of a variable pair in which a set
4961
// of relations is known. For example, relations learned for unsigned
5062
// pairs cannot be transferred to signed pairs because the same bit
@@ -58,6 +70,30 @@ const (
5870
boolean
5971
)
6072

73+
var domainStrings = [...]string{
74+
"signed", "unsigned", "pointer", "boolean",
75+
}
76+
77+
func (d domain) String() string {
78+
s := ""
79+
for i, ds := range domainStrings {
80+
if d&(1<<uint(i)) != 0 {
81+
if len(s) != 0 {
82+
s += "|"
83+
}
84+
s += ds
85+
d &^= 1 << uint(i)
86+
}
87+
}
88+
if d != 0 {
89+
if len(s) != 0 {
90+
s += "|"
91+
}
92+
s += fmt.Sprintf("0x%x", uint(d))
93+
}
94+
return s
95+
}
96+
6197
type pair struct {
6298
v, w *Value // a pair of values, ordered by ID.
6399
// v can be nil, to mean the zero value.

0 commit comments

Comments
 (0)