mingw: make simavr compilable with MinGW
[simavr] / doc / tags_to_dot.rb
1 #!/usr/bin/ruby
2 #
3 #       Copyright 2008, 2009 Michel Pollet <buserror@gmail.com>
4 #
5 #       This file is part of simavr.
6 #
7 #       simavr is free software: you can redistribute it and/or modify
8 #       it under the terms of the GNU General Public License as published by
9 #       the Free Software Foundation, either version 3 of the License, or
10 #       (at your option) any later version.
11 #
12 #       simavr is distributed in the hope that it will be useful,
13 #       but WITHOUT ANY WARRANTY; without even the implied warranty of
14 #       MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 #       GNU General Public License for more details.
16 #
17 #       You should have received a copy of the GNU General Public License
18 #       along with simavr.  If not, see <http://www.gnu.org/licenses/>.
19
20 $files = Hash.new
21 $syms = Hash.new
22
23 tags = File.new(ARGV[0])
24
25 key = Array.new
26
27 while !tags.eof?
28         next unless tags.readline.chomp.match(/([^\t]+)\t([^\t]+)\t(.*)\$\/;"\t([^\t]+)/);
29         key[0] = $1;
30         key[1] = $2;
31         key[3] = $3;
32         key[4] = $4;
33
34         next if key[4] == 'm' or key[4] == 't'  or key[4] == 's'  or key[4] == 'e'  or key[4] == 'v';
35         next if key[0].match(/[us]?int[0-9]+_t/);
36         next if key[0] == "ROM_BASED";
37         
38         key[1].gsub!(/.*\/|\.[ch]$/,"");
39         
40         unless $files.key? key[1]
41                 $files[key[1]] = Hash.new
42         end
43         unless $files[key[1]].key? key[0]
44                 $files[key[1]][key[0]] = Hash.new
45                 $syms[key[0]] = key[1]
46         end
47         #puts key[0] + " = '#{key[4]}'"
48 end
49
50 puts "digraph dump { node [shape=rect]; compound=true; nodesep=.1; ranksep=2; rankdir=LR; concentrate=true; "
51
52 modules = Hash.new;
53 links = Array.new;
54
55 1.upto(ARGV.length-1) { |i|
56
57         use = File.new(ARGV[i])
58 #       puts "<<<<<<<<FILE " + ARGV[i]
59         
60         fil = ARGV[i].gsub(/.*\/|\.[ch]$/,"");
61
62         while !use.eof?
63                  
64                 line = use.readline;
65                 next if line.match(/[ \t]*\/\//);
66                 line.gsub!(/[^a-zA-Z0-9_]/, " ");
67                 line.gsub!(/[ \t]+/, " ");
68         #       puts ">>>" + line
69                 words = line.split(/[ \t]+/);
70                 words.each { |w|
71                         if $syms.key? w and $syms[w] != fil
72                                 unless $files[$syms[w]][w].key? fil
73         #                               puts w + " is in " + $syms[w]
74                                         $files[$syms[w]][w][fil] = 1
75                                         
76                                         sym=w
77                                         unless modules.key? fil
78                                                 modules[fil] = Array.new
79                                         end
80                                         modules[fil] +=  [ "\"cc_#{fil}_#{sym}\" [label=\"#{sym}\",color=\"gray\",height=\".08\",style=dotted];" ]
81                                         links += ["\"cc_#{fil}_#{sym}\" -> \"dd_#{$syms[w]}_#{sym}\";"]
82                                 end
83                         end
84                 }
85         end
86 }
87
88 $files.keys.each { |fil|
89 #       puts "File #{fil} ?"
90         $files[fil].keys.each { |sym| 
91         #       puts "\tSym #{sym} : #{$files[fil][sym].length} ?"
92                 if $files[fil][sym].length > 0
93                         unless modules.key? fil
94                                 modules[fil] = Array.new
95                         end
96                         modules[fil] +=  [ "\"dd_#{fil}_#{sym}\" [label=\"#{sym}\"];" ]
97                 end
98         }
99 }
100 modules.keys.each {|fil|
101         puts "\tsubgraph cluster_#{fil} {\n\t\tlabel=\"#{fil}\"; fontsize=\"18\"; "
102         modules[fil].each { |lin|
103                 puts "\t\t#{lin}"
104         }
105         puts "\t}"
106 }
107 links.each { |lin|
108         puts "\t#{lin}"
109 }
110 puts "}"