1 | /*------------------------------------------------------------\ |
---|
2 | | | |
---|
3 | | Tool : systemcass | |
---|
4 | | | |
---|
5 | | File : dump_dot.cc | |
---|
6 | | | |
---|
7 | | Author : Buchmann Richard | |
---|
8 | | | |
---|
9 | | Date : 09_07_2004 | |
---|
10 | | | |
---|
11 | \------------------------------------------------------------*/ |
---|
12 | |
---|
13 | /* |
---|
14 | * This file is part of the Disydent Project |
---|
15 | * Copyright (C) Laboratoire LIP6 - Département ASIM |
---|
16 | * Universite Pierre et Marie Curie |
---|
17 | * |
---|
18 | * Home page : http://www-asim.lip6.fr/disydent |
---|
19 | * E-mail : mailto:richard.buchmann@lip6.fr |
---|
20 | * |
---|
21 | * This library is free software; you can redistribute it and/or modify it |
---|
22 | * under the terms of the GNU Library General Public License as published |
---|
23 | * by the Free Software Foundation; either version 2 of the License, or (at |
---|
24 | * your option) any later version. |
---|
25 | * |
---|
26 | * Disydent is distributed in the hope that it will be |
---|
27 | * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
28 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General |
---|
29 | * Public License for more details. |
---|
30 | * |
---|
31 | * You should have received a copy of the GNU General Public License along |
---|
32 | * with the GNU C Library; see the file COPYING. If not, write to the Free |
---|
33 | * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
---|
34 | */ |
---|
35 | |
---|
36 | #include <fstream> |
---|
37 | #include "dump_dot.h" |
---|
38 | #include "sc_module.h" |
---|
39 | #include "sc_port.h" |
---|
40 | #include "simplify_string.h" |
---|
41 | #include "sc_ver.h" // sc_version |
---|
42 | #ifdef HAVE_CONFIG_H |
---|
43 | #include "config.h" |
---|
44 | #endif |
---|
45 | |
---|
46 | typedef std::list<sc_core::sc_port_base*> port_list_t; |
---|
47 | using namespace std; |
---|
48 | |
---|
49 | namespace sc_core { |
---|
50 | |
---|
51 | using namespace sc_dt; |
---|
52 | |
---|
53 | // Build a port list owned by the module mod |
---|
54 | static void |
---|
55 | get_out_port_list (const sc_module &mod, port_list_t &pl) |
---|
56 | { |
---|
57 | port2module_t::iterator i; |
---|
58 | for (i = port2module.begin (); i != port2module.end (); ++i) { |
---|
59 | if ((i->second == &mod) && (i->first)) { |
---|
60 | pl.push_back ((sc_port_base*)(i->first)); |
---|
61 | } |
---|
62 | } |
---|
63 | } |
---|
64 | |
---|
65 | static void |
---|
66 | dump_dot (ofstream &o, method_process_t &m) |
---|
67 | { |
---|
68 | port_list_t port_list; |
---|
69 | get_out_port_list (*(m.module),port_list); |
---|
70 | port_list_t::iterator op; |
---|
71 | for (op = port_list.begin (); op != port_list.end (); ++op) |
---|
72 | { |
---|
73 | sensitivity_list_t::iterator ip; |
---|
74 | for (ip = m.sensitivity_list.begin(); ip != m.sensitivity_list.end();++ip) |
---|
75 | { |
---|
76 | if (is_clock (ip->get_interface())) |
---|
77 | continue; |
---|
78 | const char *in = get_name (ip->get_interface().get_pointer()); |
---|
79 | const char *out = (*op)->name (); |
---|
80 | string s; |
---|
81 | o << simplify_name(in,s); |
---|
82 | o << "->"; |
---|
83 | o << simplify_name(out,s); |
---|
84 | o << ";\n"; |
---|
85 | } |
---|
86 | } |
---|
87 | } |
---|
88 | |
---|
89 | static void |
---|
90 | dump_all (ofstream &o, method_process_list_t &lm) |
---|
91 | { |
---|
92 | method_process_list_t::iterator it; |
---|
93 | for (it = lm.begin (); it != lm.end (); ++it) |
---|
94 | dump_dot (o,**it); |
---|
95 | } |
---|
96 | |
---|
97 | static void |
---|
98 | dump_all (ofstream &o, const Vertex & v) |
---|
99 | { |
---|
100 | if (v.arcs == NULL) |
---|
101 | return; |
---|
102 | Arc *a; |
---|
103 | for (a = v.arcs; a; a = a->next) |
---|
104 | { |
---|
105 | method_process_t *m = (method_process_t*)v.data; |
---|
106 | method_process_t *m2 = (method_process_t*)a->tip->data; |
---|
107 | o << m->module->name (); |
---|
108 | o << " -> " |
---|
109 | << m2->module->name () |
---|
110 | << "\n"; |
---|
111 | } |
---|
112 | } |
---|
113 | |
---|
114 | static void |
---|
115 | dump_all (ofstream &o, Graph &g) |
---|
116 | { |
---|
117 | Vertex *v; |
---|
118 | for (v = g.vertices; v < g.vertices + g.n; v++) |
---|
119 | { |
---|
120 | dump_all (o,*v); |
---|
121 | } |
---|
122 | } |
---|
123 | |
---|
124 | bool |
---|
125 | SignalDependancyGraph2dot (const char *name, method_process_list_t &lm) |
---|
126 | { |
---|
127 | if (!name) |
---|
128 | return false; |
---|
129 | string filename; |
---|
130 | filename = name; |
---|
131 | filename += ".dot"; |
---|
132 | ofstream o; |
---|
133 | o.open (filename.c_str(),ios::out | ios::trunc); |
---|
134 | if (o.is_open () == false) |
---|
135 | return false; |
---|
136 | o << "// Signal dependency graph\n" |
---|
137 | "// Generated by " |
---|
138 | << sc_version () << "\n"; |
---|
139 | o << "strict digraph " << name << " {\n"; |
---|
140 | dump_all (o,lm); |
---|
141 | o << "}\n"; |
---|
142 | o.close (); |
---|
143 | return true; |
---|
144 | } |
---|
145 | |
---|
146 | |
---|
147 | |
---|
148 | bool |
---|
149 | FctDependancyGraph2dot (const char *name, Graph *g) |
---|
150 | { |
---|
151 | if (!name) |
---|
152 | return false; |
---|
153 | if (!g) |
---|
154 | return false; |
---|
155 | string filename; |
---|
156 | filename = name; |
---|
157 | filename += ".dot"; |
---|
158 | ofstream o; |
---|
159 | o.open (filename.c_str(),ios::out | ios::trunc); |
---|
160 | if (o.is_open () == false) |
---|
161 | return false; |
---|
162 | o << "// Function dependency graph\n" |
---|
163 | "// Generated by " |
---|
164 | << sc_version () << "\n"; |
---|
165 | o << "digraph " << name << " {\n"; |
---|
166 | dump_all (o,*g); |
---|
167 | o << "}\n"; |
---|
168 | o.close (); |
---|
169 | return true; |
---|
170 | } |
---|
171 | |
---|
172 | } // end of sc_core namespace |
---|
173 | |
---|