diff --git a/src/cmd/compile/internal/gc/ssa.go b/src/cmd/compile/internal/gc/ssa.go index d423c3268da..e0e49e8a8db 100644 --- a/src/cmd/compile/internal/gc/ssa.go +++ b/src/cmd/compile/internal/gc/ssa.go @@ -339,7 +339,7 @@ func buildssa(fn *Node, worker int) *ssa.Func { s.softFloat = s.config.SoftFloat if printssa { - s.f.HTMLWriter = ssa.NewHTMLWriter(ssaDumpFile, s.f.Frontend(), name, ssaDumpCFG) + s.f.HTMLWriter = ssa.NewHTMLWriter(ssaDumpFile, s.f, ssaDumpCFG) // TODO: generate and print a mapping from nodes to values and blocks dumpSourcesColumn(s.f.HTMLWriter, fn) s.f.HTMLWriter.WriteAST("AST", astBuf) @@ -471,7 +471,7 @@ func dumpSourcesColumn(writer *ssa.HTMLWriter, fn *Node) { fname := Ctxt.PosTable.Pos(fn.Pos).Filename() targetFn, err := readFuncLines(fname, fn.Pos.Line(), fn.Func.Endlineno.Line()) if err != nil { - writer.Logger.Logf("cannot read sources for function %v: %v", fn, err) + writer.Logf("cannot read sources for function %v: %v", fn, err) } // Read sources of inlined functions. @@ -487,7 +487,7 @@ func dumpSourcesColumn(writer *ssa.HTMLWriter, fn *Node) { fname := Ctxt.PosTable.Pos(fi.Pos).Filename() fnLines, err := readFuncLines(fname, fi.Pos.Line(), elno.Line()) if err != nil { - writer.Logger.Logf("cannot read sources for function %v: %v", fi, err) + writer.Logf("cannot read sources for inlined function %v: %v", fi, err) continue } inlFns = append(inlFns, fnLines) diff --git a/src/cmd/compile/internal/ssa/compile.go b/src/cmd/compile/internal/ssa/compile.go index 9ec4252def2..3da3b8985f5 100644 --- a/src/cmd/compile/internal/ssa/compile.go +++ b/src/cmd/compile/internal/ssa/compile.go @@ -55,7 +55,7 @@ func Compile(f *Func) { if f.Log() { printFunc(f) } - f.HTMLWriter.WriteFunc("start", "start", f) + f.HTMLWriter.WritePhase("start", "start") if BuildDump != "" && BuildDump == f.Name { f.dumpFile("build") } @@ -111,7 +111,7 @@ func Compile(f *Func) { f.Logf(" pass %s end %s\n", p.name, stats) printFunc(f) } - f.HTMLWriter.WriteFunc(phaseName, fmt.Sprintf("%s %s", phaseName, stats), f) + f.HTMLWriter.WritePhase(phaseName, fmt.Sprintf("%s %s", phaseName, stats)) } if p.time || p.mem { // Surround timing information w/ enough context to allow comparisons. diff --git a/src/cmd/compile/internal/ssa/html.go b/src/cmd/compile/internal/ssa/html.go index 66fff88d7c0..1b083917dc3 100644 --- a/src/cmd/compile/internal/ssa/html.go +++ b/src/cmd/compile/internal/ssa/html.go @@ -18,8 +18,8 @@ import ( ) type HTMLWriter struct { - Logger w io.WriteCloser + Func *Func path string dot *dotWriter prevHash []byte @@ -27,22 +27,37 @@ type HTMLWriter struct { pendingTitles []string } -func NewHTMLWriter(path string, logger Logger, funcname, cfgMask string) *HTMLWriter { +func NewHTMLWriter(path string, f *Func, cfgMask string) *HTMLWriter { out, err := os.OpenFile(path, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0644) if err != nil { - logger.Fatalf(src.NoXPos, "%v", err) + f.Fatalf("%v", err) } pwd, err := os.Getwd() if err != nil { - logger.Fatalf(src.NoXPos, "%v", err) + f.Fatalf("%v", err) } - html := HTMLWriter{w: out, Logger: logger, path: filepath.Join(pwd, path)} - html.dot = newDotWriter(cfgMask) - html.start(funcname) + html := HTMLWriter{ + w: out, + Func: f, + path: filepath.Join(pwd, path), + dot: newDotWriter(cfgMask), + } + html.start() return &html } -func (w *HTMLWriter) start(name string) { +// Fatalf reports an error and exits. +func (w *HTMLWriter) Fatalf(msg string, args ...interface{}) { + fe := w.Func.Frontend() + fe.Fatalf(src.NoXPos, msg, args...) +} + +// Logf calls the (w *HTMLWriter).Func's Logf method passing along a msg and args. +func (w *HTMLWriter) Logf(msg string, args ...interface{}) { + w.Func.Logf(msg, args...) +} + +func (w *HTMLWriter) start() { if w == nil { return } @@ -703,7 +718,7 @@ function toggleDarkMode() { `) w.WriteString("
") w.WriteString("