[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Module dependency graph
From: |
thi |
Subject: |
Re: Module dependency graph |
Date: |
Fri, 23 Mar 2001 18:42:24 -0800 |
From: Keisuke Nishida <address@hidden>
Date: Tue, 13 Mar 2001 21:19:53 -0500
This is a little tool that generates a diagram of Guile's
module dependency.
[code snipped]
eep! you can't post perl in a guile mailing list and get away with it!
below is a translation... will end up being incorporated into GUMM
sooner or later (or maybe (ice-9 wool-navel-gather-gazing) :-).
this program also handles `use-modules' top-level forms and avoids
false-positives inherent in a regexp-based approach. i didn't actually
download the DOT program, so if you could hint me the appropriate syntax
for a different line style, i will extend this to handle autoloads, etc.
[guile-sources added to cc; please remove in replies where inappropriate.]
thi
_________________________________
#!/bin/sh
exec guile -s $0 "$@" # -*- scheme -*-
!#
;;; Copyright (C) 2001 Thien-Thi Nguyen
;;; This program is part of ttn-do, released under GNU GPL v2 with ABSOLUTELY
;;; NO WARRANTY. See http://www.gnu.org/copyleft/gpl.txt for details.
(use-modules (ice-9 regex) (ttn echo) (ttn ftw) (ttn eformat))
(activate-eformat)
(define ec ";") ; end command
(define default-module '(guile)) ; hmmm
;; Header
(for-each echo '("digraph use2dot {"
" label = \"Guile Module Dependencies\";"
" rankdir = LR;"
" size = \"7.5,10\";"
" ratio = fill;"
" nodesep = \"0.05\";"))
(define (grok-n-spew filename)
(let* ((p (open-file filename "r"))
(next (lambda () (read p)))
(curmod #f)
(spew (lambda (module use)
(echo #[ "${module}" -> "${use}"$ec]))))
(let loop ((form (next)))
(or (eof-object? form)
(begin
(and (list? form)
(case (car form)
((define-module)
(let ((module (cadr form)))
(set! curmod module)
(let loop ((ls form))
(or (null? ls)
(null? (cdr ls))
(if (eq? ':use-module (car ls))
(begin (spew module (cadr ls))
(loop (cddr ls)))
(loop (cdr ls)))))))
((use-modules)
(let ((module (or curmod default-module)))
(for-each (lambda (use) (spew module use))
(cdr form))))))
(loop (next)))))))
;; Body
(for-each (lambda (file)
(ftw file (lambda (filename statinfo flag)
(and (eq? 'regular flag)
(string-match "\\.scm$" filename)
(grok-n-spew filename))
#t)))
(let ((ls (cdr (command-line))))
(cond ((null? ls) '("."))
(else ls))))
;; Footer
(echo "}")
(deactivate-eformat)
;;; use2dot ends here