1
2
3
4
5 package noder
6
7 import (
8 "sync"
9
10 "cmd/compile/internal/base"
11 "cmd/compile/internal/ir"
12 "cmd/compile/internal/syntax"
13 "cmd/compile/internal/types2"
14 )
15
16
17
18 func MatchASTDump(fn *syntax.FuncDecl) bool {
19 if len(base.Debug.AstDump) == 0 {
20 return false
21 }
22 if fn.Name == nil {
23 return false
24 }
25 return matchForDump(fn, base.Ctxt.Pkgpath)
26 }
27
28
29
30
31
32
33 func matchForDump(fn *syntax.FuncDecl, pkgPath string) bool {
34 return ir.MatchPkgFn(pkgPath, fn.Name.Value, base.Debug.AstDump)
35 }
36
37 func escapedFileName(fn *syntax.FuncDecl, suffix string) string {
38 return ir.EscapedFileName(base.Ctxt.Pkgpath+"."+fn.Name.Value, suffix)
39 }
40
41 var mu sync.Mutex
42 var htmlWriters = make(map[*syntax.FuncDecl]*HTMLWriter)
43 var orderedFuncs = []*syntax.FuncDecl{}
44
45
46 func DumpNodeHTML(pkg *types2.Package, file *syntax.File, info *types2.Info, fn *syntax.FuncDecl, why string, n syntax.Node) {
47 mu.Lock()
48 defer mu.Unlock()
49 w, ok := htmlWriters[fn]
50 if !ok {
51 name := escapedFileName(fn, ".syntax.html")
52 w = NewHTMLWriter(pkg, file, info, name, fn, "")
53 htmlWriters[fn] = w
54 orderedFuncs = append(orderedFuncs, fn)
55 }
56 w.WritePhase(why, why)
57 }
58
59
60 func CloseHTMLWriters() {
61 mu.Lock()
62 defer mu.Unlock()
63 for _, fn := range orderedFuncs {
64 if w, ok := htmlWriters[fn]; ok {
65 w.Close("Writing html syntax output for %s to %s\n", w.pkgFuncName(), w.Path())
66 delete(htmlWriters, fn)
67 }
68 }
69 orderedFuncs = nil
70 }
71
View as plain text