aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/compile/internal/ssa/print.go
diff options
context:
space:
mode:
authorMichael Matloob <matloob@google.com>2015-05-30 13:17:12 -0400
committerKeith Randall <khr@golang.org>2015-06-03 04:35:55 +0000
commitbd95412d23e80d779062abe0798b8e7d85fcc138 (patch)
tree9c80855aa439ea77426dd65a4eb2e5b802a64958 /src/cmd/compile/internal/ssa/print.go
parenta9cec30fdcc549282e0a5d520edb2eaf60f3061a (diff)
downloadgo-bd95412d23e80d779062abe0798b8e7d85fcc138.tar.gz
go-bd95412d23e80d779062abe0798b8e7d85fcc138.zip
[dev.ssa] cmd/compile/internal/ssa: add a String() method to Func
The string method has the same output as printFunc. Change-Id: Iab2ebc17a3d6418edfeb7b585e4f251e7a11f399 Reviewed-on: https://go-review.googlesource.com/10552 Reviewed-by: Keith Randall <khr@golang.org>
Diffstat (limited to 'src/cmd/compile/internal/ssa/print.go')
-rw-r--r--src/cmd/compile/internal/ssa/print.go41
1 files changed, 28 insertions, 13 deletions
diff --git a/src/cmd/compile/internal/ssa/print.go b/src/cmd/compile/internal/ssa/print.go
index eeea30d970..b9a958c18e 100644
--- a/src/cmd/compile/internal/ssa/print.go
+++ b/src/cmd/compile/internal/ssa/print.go
@@ -4,15 +4,30 @@
package ssa
-import "fmt"
+import (
+ "bytes"
+ "fmt"
+ "io"
+ "os"
+)
func printFunc(f *Func) {
- fmt.Print(f.Name)
- fmt.Print(" ")
- fmt.Println(f.Type)
+ fprintFunc(os.Stdout, f)
+}
+
+func (f *Func) String() string {
+ var buf bytes.Buffer
+ fprintFunc(&buf, f)
+ return buf.String()
+}
+
+func fprintFunc(w io.Writer, f *Func) {
+ fmt.Fprint(w, f.Name)
+ fmt.Fprint(w, " ")
+ fmt.Fprintln(w, f.Type)
printed := make([]bool, f.NumValues())
for _, b := range f.Blocks {
- fmt.Printf(" b%d:\n", b.ID)
+ fmt.Fprintf(w, " b%d:\n", b.ID)
n := 0
// print phis first since all value cycles contain a phi
@@ -20,8 +35,8 @@ func printFunc(f *Func) {
if v.Op != OpPhi {
continue
}
- fmt.Print(" ")
- fmt.Println(v.LongString())
+ fmt.Fprint(w, " ")
+ fmt.Fprintln(w, v.LongString())
printed[v.ID] = true
n++
}
@@ -39,25 +54,25 @@ func printFunc(f *Func) {
continue outer
}
}
- fmt.Print(" ")
- fmt.Println(v.LongString())
+ fmt.Fprint(w, " ")
+ fmt.Fprintln(w, v.LongString())
printed[v.ID] = true
n++
}
if m == n {
- fmt.Println("dependency cycle!")
+ fmt.Fprintln(w, "dependency cycle!")
for _, v := range b.Values {
if printed[v.ID] {
continue
}
- fmt.Print(" ")
- fmt.Println(v.LongString())
+ fmt.Fprint(w, " ")
+ fmt.Fprintln(w, v.LongString())
printed[v.ID] = true
n++
}
}
}
- fmt.Println(" " + b.LongString())
+ fmt.Fprintln(w, " "+b.LongString())
}
}