source: branches/with_autoconf/src/signal_dependency.cc @ 8

Last change on this file since 8 was 8, checked in by nipo, 16 years ago

Checkin autotools magic

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