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