Overview
Context
Changes
Modified utils/plot-code.scm
from [060b469cc0]
to [c6dc12eb7d].
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
|
-
+
+
+
+
|
#!/mfs/pkgs/chicken/4.8.0.5/bin/csi -nbq
(use regex srfi-69)
(use regex srfi-69 srfi-13)
(define targs (string-split (cadddr (argv)) ","))
(define files (cddddr (argv)))
(define filedat-defns (make-hash-table))
(define filedat-usages (make-hash-table))
(define defn-rx (regexp "^\\s*\\(define\\s+\\(([^\\s\\)]+).*"))
(define all-regexs (make-hash-table))
(define all-fns '())
(define (print-err . data)
(with-output-to-port (current-error-port)
(lambda ()
(apply print data))))
(print-err "Making graph for files: " (string-intersperse targs ", "))
(print-err "Looking at files: " (string-intersperse files ", "))
;; Gather the functions
;;
(for-each
(lambda (fname)
(print-err "Processing file " fname)
(with-input-from-file fname
|
︙ | | |
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
|
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
|
-
-
-
+
+
+
+
+
+
+
+
-
+
-
+
-
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
+
+
+
+
+
+
-
+
|
(for-each
(lambda (fnname)
(hash-table-set! all-regexs fnname (regexp (conc "^(|.*[^a-zA-Z]+)" fnname "([^a-zA-Z]+|)$"))))
(cons "toplevel" all-fns))
(define breadcrumbs (make-hash-table))
(print-err "Make the quick check regex")
(define have-function-rx (regexp (conc "(" (string-intersperse all-fns "|")
")")))
(define (have-function inl)
(let loop ((hed (car all-fns))
(tal (cdr all-fns)))
(if (string-contains inl hed)
#t
(if (null? tal)
#f
(loop (car tal)(cdr tal))))))
(define (look-for-all-calls inl fnname)
(if (string-search have-function-rx inl)
(if (have-function inl) ;; (string-search have-function-rx inl)
(let loop ((hed (car all-fns))
(tal (cdr all-fns))
(res '()))
(let ((match (string-match (hash-table-ref all-regexs fnname) inl)))
(let ((match (string-match (hash-table-ref all-regexs hed) inl)))
(if match
(let ((newres (cons hed res)))
(if (not (null? tal))
(if (null? tal)
newres
(loop (car tal)
(cdr tal)
newres)))
(if (null? tal)
res
(loop (car tal)(cdr tal) res)))))
'()))
;; Gather the usages
(print "digraph G {")
(define curr-cluster-num 0)
(define function-calls '())
(for-each
(lambda (fname)
(let ((last-func #f))
(print-err "Processing file " fname)
(print "subgraph cluster_" curr-cluster-num " {")
(set! curr-cluster-num (+ curr-cluster-num 1))
(with-input-from-file fname
(lambda ()
(with-output-to-port (current-error-port)
(lambda ()
(print "Analyzing file " fname)))
(print "label=\"" fname "\";")
(let loop ((inl (read-line))
(fnname "toplevel"))
(if (not (eof-object? inl))
(let ((match (string-match defn-rx inl)))
(if match
(let ((func-name (cadr match)))
(print "\"" func-name "\";")
(hash-table-set! breadcrumbs func-name #t)
(loop (read-line)
func-name))
(let ((calls (look-for-all-calls inl fnname)))
(print-err "Processing file " fname)
(print "subgraph cluster_" curr-cluster-num " {")
(set! curr-cluster-num (+ curr-cluster-num 1))
(with-input-from-file fname
(lambda ()
(with-output-to-port (current-error-port)
(lambda ()
(print "Analyzing file " fname)))
(print "label=\"" fname "\";")
(let loop ((inl (read-line))
(fnname "toplevel")
(allcalls '()))
(if (eof-object? inl)
(begin
(set! function-calls (cons (list fnname allcalls) function-calls))
(for-each
(lambda (call-name)
(hash-table-set! breadcrumbs call-name #t))
allcalls)
(print-err "function: " fnname " allcalls: " allcalls))
(let ((match (string-match defn-rx inl)))
(if match
(let ((func-name (cadr match)))
(if last-func
(print "\"" func-name "\" -> \"" last-func "\";")
(print "\"" func-name "\";"))
(set! last-func func-name)
(hash-table-set! breadcrumbs func-name #t)
(loop (read-line)
func-name
allcalls))
(let ((calls (look-for-all-calls inl fnname)))
(if (not (null? calls))
(set! function-calls (cons (list fnname calls) function-calls)))
;; (print "Function: " fnname " calls: " calls))
(loop (read-line) fnname))))))))
(print "}"))
(loop (read-line) fnname (append allcalls calls)))))))))
(print "}")))
targs)
(print-err "breadcrumbs: " (hash-table-keys breadcrumbs))
(print-err "function-calls: " function-calls)
(for-each
(lambda (function-call)
(print-err "function-call: " function-call)
(let ((fnname (car function-call))
(calls (cadr function-call)))
(for-each
(lambda (callname)
(print (if (hash-table-ref/default breadcrumbs callname #f) "" "// ")
"\"" fnname "\" -> \"" callname "\";"))
calls)))
function-calls)
(print "}")
;; (exit)
(exit)
|