1 | /*------------------------------------------------------------\ |
---|
2 | | | |
---|
3 | | Tool : systemcass | |
---|
4 | | | |
---|
5 | | File : graph_signals.cc | |
---|
6 | | | |
---|
7 | | Author : Buchmann Richard | |
---|
8 | | | |
---|
9 | | Date : 22_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 | /* |
---|
37 | * $Log: graph_signals.cc,v $ |
---|
38 | * Revision 1.7 2006/06/12 14:02:04 buchmann |
---|
39 | * - Now sort transition and generation functions by fonction pointer |
---|
40 | * (Thank to Nicolas Pouillon) |
---|
41 | * - Add Nicolas Pouillon as contributor into splash screen |
---|
42 | * - Rename files and classes from "dependancy" to "dependency". |
---|
43 | * - Add some references to bibliography file |
---|
44 | * - Add licence note to every files |
---|
45 | * - Rename "module graph" to "process graph" |
---|
46 | * - Now dump module graph when using --t option and CASS scheduling at the same |
---|
47 | * time |
---|
48 | * |
---|
49 | * Bug fixes : |
---|
50 | * - check user time ( != 0) before computing simulation performance |
---|
51 | * - Remove reinterpret_cast (for pending write) because of unexpected results |
---|
52 | * - Add ASSERT in trace functions |
---|
53 | * |
---|
54 | * Revision 1.6 2005/10/12 10:01:00 buchmann |
---|
55 | * Bug fix : |
---|
56 | * - test to avoid malloc(0) |
---|
57 | * |
---|
58 | * Remove : |
---|
59 | * - unused variable |
---|
60 | * |
---|
61 | * Revision 1.5 2005/09/14 14:08:24 buchmann |
---|
62 | * Add Werror flag to compile the debug library. |
---|
63 | * Split sc_clock implementation from sc_port to sc_clock. |
---|
64 | * Add a helper message to write mealy functions avoiding combinational cycle. |
---|
65 | * |
---|
66 | * Bug fix : |
---|
67 | * - cvs rules is no longer circular |
---|
68 | * - bit2string |
---|
69 | * - port binding (sc_in to sc_out) |
---|
70 | * - error message from FSM rules checker |
---|
71 | * - sc_time copy operator |
---|
72 | * |
---|
73 | * Code cleaning : |
---|
74 | * - remove duplicated code (entity.cc and sc_port.cc) |
---|
75 | * - remove duplicated declarations (internal_ext.h and internal.h) |
---|
76 | * |
---|
77 | * Revision 1.4 2005/06/22 09:15:03 buchmann |
---|
78 | * Add some *_ext.h files to split internal implementation from API interface. |
---|
79 | * |
---|
80 | * Add -Wunused to detect unused functions. |
---|
81 | * |
---|
82 | * Include directory now contains API interface file only. |
---|
83 | * |
---|
84 | * Declar all the implementation/interface inside sc_core namespace as LRM 2.1 |
---|
85 | * advices. |
---|
86 | * |
---|
87 | * Remove casc namespace. |
---|
88 | * |
---|
89 | * Clean up dead code segments. |
---|
90 | * |
---|
91 | * Add hexadecimal dumping support. |
---|
92 | * |
---|
93 | * Add empty implementation of functions for object hierarchy traversal. (LRM 2.1) |
---|
94 | * |
---|
95 | * Bug fixes : |
---|
96 | * - reference return of the following functions : operators =, |=, &= and so on. |
---|
97 | * - range functions now return an sc_int_subref instead of an int. |
---|
98 | * |
---|
99 | * Revision 1.3 2005/03/25 14:33:01 buchmann |
---|
100 | * Typo : |
---|
101 | * - dependAncy -> dependEncy |
---|
102 | * |
---|
103 | * sc_initialize : |
---|
104 | * - Use a hash table to speed up elaboration step. (x40 faster) |
---|
105 | * |
---|
106 | * Tracing : |
---|
107 | * - check for modification BEFORE building bit string. |
---|
108 | * - use sprintf instead std string concatenation. |
---|
109 | * |
---|
110 | * Revision 1.2 2005/01/20 09:15:12 buchmann |
---|
111 | * add following functions to sc_uint classes : |
---|
112 | * - operator [] |
---|
113 | * - range (left,right) |
---|
114 | * |
---|
115 | * support to port dependancy declarations. |
---|
116 | * print used precompiled options in verbose mode. |
---|
117 | * use pedantic flag. |
---|
118 | * add some rules to generate documentations. |
---|
119 | * |
---|
120 | * Revision 1.1 2004/09/27 14:40:14 buchmann |
---|
121 | * bug fix : |
---|
122 | * - allow the use of user-defined structs in sc_signal/sc_in/sc_out/sc_inout |
---|
123 | * - use sc_dt namespace like official SystemC engine |
---|
124 | * |
---|
125 | * add : |
---|
126 | * - dump the signal/port/module dependancy graph in dot format |
---|
127 | * |
---|
128 | * Graph library is now splitted from the SystemCASS specific code. |
---|
129 | * |
---|
130 | */ |
---|
131 | |
---|
132 | #include <stdio.h> |
---|
133 | #include <map> |
---|
134 | #include <string> |
---|
135 | |
---|
136 | #include "graph_signals.h" |
---|
137 | #include "signal_dependency.h" |
---|
138 | #include "sc_sensitive.h" |
---|
139 | #include "sc_module.h" |
---|
140 | #include "sc_port.h" |
---|
141 | #ifdef HAVE_CONFIG_H |
---|
142 | #include "config.h" |
---|
143 | #endif |
---|
144 | |
---|
145 | using namespace std; |
---|
146 | |
---|
147 | namespace sc_core { |
---|
148 | |
---|
149 | #if 0 |
---|
150 | static |
---|
151 | ostream& operator << (ostream& o, |
---|
152 | const Vertex &v) |
---|
153 | { |
---|
154 | equi_t* m = (equi_t*)(v.data); |
---|
155 | if (v.arcs == NULL) |
---|
156 | o << get_name(*m) << "\n"; |
---|
157 | Arc *a; |
---|
158 | for (a = v.arcs; a; a = a->next) |
---|
159 | { |
---|
160 | equi_t* m2 = (equi_t*)(a->tip->data); |
---|
161 | o << get_name(*m) << "->" |
---|
162 | << get_name(*m2) << "\n"; |
---|
163 | } |
---|
164 | return o; |
---|
165 | |
---|
166 | } |
---|
167 | |
---|
168 | static |
---|
169 | ostream& |
---|
170 | operator << (ostream &o, |
---|
171 | const Graph &g) |
---|
172 | { |
---|
173 | Vertex *v; |
---|
174 | int i = 1; |
---|
175 | for (v = g.vertices; v < g.vertices + g.n; ++v) { |
---|
176 | o << i++ << " : " << *v; |
---|
177 | } |
---|
178 | return o; |
---|
179 | } |
---|
180 | #endif |
---|
181 | |
---|
182 | typedef std::map<const equi_t*, Vertex*> nodes_set_t; |
---|
183 | |
---|
184 | void |
---|
185 | create_arcs (const SignalDependencyGraph& sig_g, nodes_set_t& s) |
---|
186 | { |
---|
187 | SignalDependencyGraph::const_iterator j; |
---|
188 | for (j = sig_g.begin(); j != sig_g.end(); ++j) { |
---|
189 | new_arc (s[j->source],s[j->destination]); |
---|
190 | } |
---|
191 | } |
---|
192 | |
---|
193 | void |
---|
194 | create_vertices_list (Graph *g, nodes_set_t& s) |
---|
195 | { |
---|
196 | Vertex *v = g->vertices; |
---|
197 | if (v == NULL) |
---|
198 | return; |
---|
199 | nodes_set_t::iterator j; |
---|
200 | for (j = s.begin(); j != s.end(); ++j) |
---|
201 | { |
---|
202 | v->data = (void*) (j->first); |
---|
203 | j->second = v++; |
---|
204 | } |
---|
205 | } |
---|
206 | |
---|
207 | nodes_set_t* |
---|
208 | create_nodes_set (const SignalDependencyGraph& sig_g) |
---|
209 | { |
---|
210 | /* Create a signal set */ |
---|
211 | nodes_set_t &s = *(new nodes_set_t); |
---|
212 | |
---|
213 | SignalDependencyGraph::const_iterator j; |
---|
214 | for (j = sig_g.begin(); j != sig_g.end(); ++j) |
---|
215 | { |
---|
216 | s[j->source] = NULL; |
---|
217 | s[j->destination] = NULL; |
---|
218 | } |
---|
219 | return &s; |
---|
220 | } |
---|
221 | |
---|
222 | /* Construit le graph de dépendance des signaux de Mealy */ |
---|
223 | /* g = Mealy signal dependancy graph */ |
---|
224 | Graph *makegraph(const SignalDependencyGraph& sig_g) |
---|
225 | { |
---|
226 | int n = 0; /* Number of vertices */ |
---|
227 | Graph *g; |
---|
228 | //Vertex *v; |
---|
229 | |
---|
230 | /* Create node set */ |
---|
231 | nodes_set_t *sig_s = create_nodes_set (sig_g); |
---|
232 | |
---|
233 | /* Compute the number of vertices in the graph */ |
---|
234 | n = sig_s->size(); |
---|
235 | |
---|
236 | /* Create the graph */ |
---|
237 | g = gb_new_graph(n); |
---|
238 | |
---|
239 | /* Associate the netlist elements to the graph vertices, and vice-versa */ |
---|
240 | // v = g->vertices; |
---|
241 | |
---|
242 | /* Create the node set */ |
---|
243 | create_vertices_list (g,*sig_s); |
---|
244 | |
---|
245 | /* initialisation des vertices */ |
---|
246 | create_arcs (sig_g,*sig_s); |
---|
247 | |
---|
248 | delete sig_s; |
---|
249 | #if 0 |
---|
250 | cerr << *g << "\n"; |
---|
251 | #endif |
---|
252 | return g; |
---|
253 | } |
---|
254 | |
---|
255 | } // end of sc_core namespace |
---|
256 | |
---|