1 | /*------------------------------------------------------------\ |
---|
2 | | | |
---|
3 | | Tool : systemcass | |
---|
4 | | | |
---|
5 | | File : port_dependency.cc | |
---|
6 | | | |
---|
7 | | Author : Buchmann Richard | |
---|
8 | | | |
---|
9 | | Date : 21_09_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 <set> |
---|
37 | #include <iostream> |
---|
38 | #include <fstream> |
---|
39 | #include "signal_dependency.h" |
---|
40 | #include "simplify_string.h" |
---|
41 | #include "sc_fwd.h" |
---|
42 | #include "sc_port.h" |
---|
43 | #include "sc_module.h" |
---|
44 | #include "sc_ver_ext.h" |
---|
45 | |
---|
46 | using namespace std; |
---|
47 | |
---|
48 | namespace sc_core { |
---|
49 | |
---|
50 | bool |
---|
51 | SignalDependency::operator < (const SignalDependency &b) const |
---|
52 | { |
---|
53 | if (source < b.source) |
---|
54 | return true; |
---|
55 | if (destination < b.destination) |
---|
56 | return true; |
---|
57 | return false; |
---|
58 | } |
---|
59 | |
---|
60 | static |
---|
61 | void |
---|
62 | txt_write (ofstream &o, const component_list_t &l) |
---|
63 | { |
---|
64 | component_list_t::const_iterator it; |
---|
65 | for (it = l.begin (); it != l.end (); ++it) |
---|
66 | { |
---|
67 | o << get_name(*((equi_t*)(*it))) << " "; |
---|
68 | } |
---|
69 | } |
---|
70 | |
---|
71 | static |
---|
72 | void |
---|
73 | txt_write (ofstream &o, const strong_component_list_t &l) |
---|
74 | { |
---|
75 | strong_component_list_t::const_iterator it; |
---|
76 | for (it = l.begin (); it != l.end (); ++it) |
---|
77 | { |
---|
78 | txt_write (o,**it); |
---|
79 | o << "\n"; |
---|
80 | } |
---|
81 | } |
---|
82 | |
---|
83 | bool |
---|
84 | SignalDependencyOrder2txt (const char *name, |
---|
85 | const strong_component_list_t&l) |
---|
86 | { |
---|
87 | if (!name) |
---|
88 | return false; |
---|
89 | string filename; |
---|
90 | filename = name; |
---|
91 | filename += ".txt"; |
---|
92 | ofstream o; |
---|
93 | o.open (filename.c_str(),ios::out | ios::trunc); |
---|
94 | if (o.is_open () == false) |
---|
95 | return false; |
---|
96 | txt_write (o,l); |
---|
97 | o.close (); |
---|
98 | return true; |
---|
99 | |
---|
100 | } |
---|
101 | |
---|
102 | static |
---|
103 | void |
---|
104 | dot_write (ofstream &o, const SignalDependencyGraph &g) |
---|
105 | { |
---|
106 | string s; |
---|
107 | SignalDependencyGraph::const_iterator it; |
---|
108 | for (it = g.begin (); it != g.end (); ++it) |
---|
109 | { |
---|
110 | string name; |
---|
111 | name = it->method->module->name(); |
---|
112 | name += "_"; |
---|
113 | name += it->method->name; |
---|
114 | o << "edge [label=" |
---|
115 | << simplify_name(name.c_str(),s) |
---|
116 | << "];\n"; |
---|
117 | const equi_t *equi = it->source; |
---|
118 | name = get_name (*equi); |
---|
119 | o << simplify_name(name.c_str(),s); |
---|
120 | o << " -> "; |
---|
121 | equi = it->destination; |
---|
122 | name = get_name (*equi); |
---|
123 | o << simplify_name(name.c_str(),s); |
---|
124 | o << ";\n"; |
---|
125 | } |
---|
126 | } |
---|
127 | |
---|
128 | bool |
---|
129 | SignalDependencyGraph2dot (const char *name, |
---|
130 | const SignalDependencyGraph& g) |
---|
131 | { |
---|
132 | if (!name) |
---|
133 | return false; |
---|
134 | string filename; |
---|
135 | filename = name; |
---|
136 | filename += ".dot"; |
---|
137 | ofstream o; |
---|
138 | o.open (filename.c_str(),ios::out | ios::trunc); |
---|
139 | if (o.is_open () == false) |
---|
140 | return false; |
---|
141 | o << "// Signal dependency graph\n" |
---|
142 | "// Generated by " |
---|
143 | << sc_version () << "\n"; |
---|
144 | o << "strict digraph " << name << " {\n"; |
---|
145 | dot_write (o,g); |
---|
146 | o << "}\n"; |
---|
147 | o.close (); |
---|
148 | if (dump_stage) |
---|
149 | cerr << "Signal Dependency Graph written into '" |
---|
150 | << filename << "'.\n"; |
---|
151 | return true; |
---|
152 | } |
---|
153 | |
---|
154 | SignalDependencyGraph* |
---|
155 | MakeSignalDependencyGraph (const PortDependencyGraph& g) |
---|
156 | { |
---|
157 | if (dump_stage) |
---|
158 | cerr << "Making signal dependency graph...\n"; |
---|
159 | |
---|
160 | SignalDependencyGraph *sig_g = new SignalDependencyGraph (); |
---|
161 | PortDependencyGraph::const_iterator it; |
---|
162 | for (it = g.begin(); it != g.end(); ++it) |
---|
163 | { |
---|
164 | SignalDependency s; |
---|
165 | s.method = it->method; |
---|
166 | const sc_interface *inter; |
---|
167 | inter = it->source; |
---|
168 | if (inter) |
---|
169 | s.source = &(get_equi (*inter)); |
---|
170 | else |
---|
171 | continue; |
---|
172 | inter = it->destination; |
---|
173 | s.destination = &(get_equi (*inter)); |
---|
174 | sig_g->insert(s); |
---|
175 | } |
---|
176 | return sig_g; |
---|
177 | } |
---|
178 | |
---|
179 | |
---|
180 | static |
---|
181 | bool |
---|
182 | is_in (const equi_t &e, const method_process_t &m) |
---|
183 | { |
---|
184 | const tab_t *pt = e.begin ()->interface->get_pointer (); |
---|
185 | const sensitivity_list_t &sens = m.sensitivity_list; |
---|
186 | sensitivity_list_t::const_iterator it; |
---|
187 | for (it = sens.begin (); it != sens.end (); ++it) |
---|
188 | { |
---|
189 | const sc_event &event = *it; |
---|
190 | if (pt == event.get_interface().get_pointer ()) |
---|
191 | return true; |
---|
192 | } |
---|
193 | return false; |
---|
194 | } |
---|
195 | |
---|
196 | static |
---|
197 | bool |
---|
198 | is_valid (const SignalDependency &s) |
---|
199 | { |
---|
200 | #if 0 |
---|
201 | cerr << "'" << get_name (*(s.destination)) << "'" |
---|
202 | << " depends on '" << get_name (*(s.source)) << "'" |
---|
203 | << " in the module '" << s.method->module->name() << "'\n"; |
---|
204 | return true; |
---|
205 | #endif |
---|
206 | if (is_in (*(s.source), *(s.method))) |
---|
207 | return true; |
---|
208 | const char *src = get_name (*(s.source)); |
---|
209 | cerr << "'" << get_name (*(s.destination)) << "'" |
---|
210 | << " depends on '" << src << "'" |
---|
211 | << " in the module '" << s.method->module->name() << "'" |
---|
212 | << " but '" << src << "' is not in the sensitivity_list.\n"; |
---|
213 | return false; |
---|
214 | } |
---|
215 | |
---|
216 | bool |
---|
217 | Check (const SignalDependencyGraph &g) |
---|
218 | { |
---|
219 | SignalDependencyGraph::const_iterator it; |
---|
220 | for (it = g.begin(); it != g.end(); ++it) |
---|
221 | { |
---|
222 | const SignalDependency &s = (*it); |
---|
223 | if (!is_valid (s)) |
---|
224 | return false; |
---|
225 | } |
---|
226 | return true; |
---|
227 | } |
---|
228 | |
---|
229 | static |
---|
230 | bool |
---|
231 | is_in (const equi_t &e, const SignalDependencyGraph &g) |
---|
232 | { |
---|
233 | SignalDependencyGraph::const_iterator it; |
---|
234 | for (it = g.begin (); it != g.end (); ++it) |
---|
235 | { |
---|
236 | const SignalDependency &s = *it; |
---|
237 | if (&e == s.source) |
---|
238 | return true; |
---|
239 | } |
---|
240 | return false; |
---|
241 | } |
---|
242 | |
---|
243 | static |
---|
244 | bool |
---|
245 | is_in (const sensitivity_list_t &sens, const SignalDependencyGraph &g) |
---|
246 | { |
---|
247 | sensitivity_list_t::const_iterator it; |
---|
248 | for (it = sens.begin (); it != sens.end (); ++it) |
---|
249 | { |
---|
250 | const sc_event &event = *it; |
---|
251 | const sc_interface &i = event.get_interface(); |
---|
252 | const equi_t &equi = get_equi (i); |
---|
253 | if (is_clock (i)) |
---|
254 | continue; |
---|
255 | if (!is_in (equi, g)) { |
---|
256 | cerr << "'" << get_name(equi) << "'" |
---|
257 | << " is in the sensitivity list of "; |
---|
258 | return false; |
---|
259 | } |
---|
260 | } |
---|
261 | return true; |
---|
262 | } |
---|
263 | |
---|
264 | bool |
---|
265 | Check (const method_process_list_t &ml, |
---|
266 | const SignalDependencyGraph &g) |
---|
267 | { |
---|
268 | method_process_list_t::const_iterator it; |
---|
269 | for (it = ml.begin(); it != ml.end(); ++it) |
---|
270 | { |
---|
271 | const method_process_t &m = *(*it); |
---|
272 | const sensitivity_list_t &sens = m.sensitivity_list; |
---|
273 | if (!is_in (sens, g)) |
---|
274 | { |
---|
275 | cerr << "'" << m.module->name() << "' module instance " |
---|
276 | << "but any output port doesn't depend on this input.\n"; |
---|
277 | return false; |
---|
278 | } |
---|
279 | } |
---|
280 | return true; |
---|
281 | } |
---|
282 | |
---|
283 | } // end of sc_core namespace |
---|
284 | |
---|