source: sources/src/graph_signals.cc @ 8

Last change on this file since 8 was 1, checked in by buchmann, 17 years ago

Initial import from CVS repository

File size: 7.0 KB
Line 
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
142using namespace std;
143
144namespace sc_core {
145
146#if 0
147static
148ostream& operator << (ostream&      o,
149                      const Vertex &v)
150{
151        equi_t* m = (equi_t*)(v.data);
152  if (v.arcs == NULL)
153          o << get_name(*m) << "\n";
154  Arc *a;
155  for (a = v.arcs; a; a = a->next)
156        {
157          equi_t* m2 = (equi_t*)(a->tip->data);
158          o << get_name(*m) << "->"
159                  << get_name(*m2) << "\n";
160        }
161  return o;
162
163}
164
165static
166ostream&
167operator << (ostream     &o,
168             const Graph &g)
169{
170  Vertex *v;
171  int     i = 1;
172  for (v = g.vertices; v < g.vertices + g.n; ++v) {
173    o << i++ << " : " << *v;
174  }
175  return o;
176}
177#endif
178
179typedef std::map<const equi_t*, Vertex*> nodes_set_t;
180
181void
182create_arcs (const SignalDependencyGraph& sig_g, nodes_set_t& s)
183{
184  SignalDependencyGraph::const_iterator j;
185  for (j = sig_g.begin(); j != sig_g.end(); ++j) { 
186    new_arc (s[j->source],s[j->destination]);
187  }
188}
189
190void
191create_vertices_list (Graph *g, nodes_set_t& s)
192{
193        Vertex *v = g->vertices;
194  if (v == NULL)
195    return;
196  nodes_set_t::iterator j;
197  for (j = s.begin(); j != s.end(); ++j) 
198  {
199                v->data   = (void*) (j->first);
200                j->second = v++;
201        }       
202}
203
204nodes_set_t*
205create_nodes_set (const SignalDependencyGraph& sig_g)
206{
207        /* Create a signal set */
208        nodes_set_t &s = *(new nodes_set_t);
209
210  SignalDependencyGraph::const_iterator j;
211  for (j = sig_g.begin(); j != sig_g.end(); ++j) 
212  {
213                s[j->source] = NULL;
214                s[j->destination] = NULL;
215  }
216        return &s;
217}
218
219/* Construit le graph de dépendance des signaux de Mealy */
220/* g = Mealy signal dependancy graph */
221Graph *makegraph(const SignalDependencyGraph& sig_g)
222{
223  int         n = 0; /* Number of vertices */
224  Graph      *g;
225  //Vertex     *v;
226 
227        /* Create node set */
228        nodes_set_t *sig_s = create_nodes_set (sig_g);
229
230  /* Compute the number of vertices in the graph */
231  n = sig_s->size();
232 
233  /* Create the graph */
234  g = gb_new_graph(n);
235
236  /* Associate the netlist elements to the graph vertices, and vice-versa */
237//  v = g->vertices;
238
239        /* Create the node set */
240  create_vertices_list (g,*sig_s);
241
242  /* initialisation des vertices */
243        create_arcs (sig_g,*sig_s);
244
245        delete sig_s;
246#if 0
247        cerr << *g << "\n";
248#endif
249  return g;
250}   
251
252} // end of sc_core namespace
253
Note: See TracBrowser for help on using the repository browser.