source: sources/src/port_dependency.cc @ 26

Last change on this file since 26 was 17, checked in by buchmann, 16 years ago

Fix :

  • add missing system header includes
File size: 5.2 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 <cstring>
37#include <list>
38#include <iostream>
39#include <fstream>
40#include "port_dependency.h"
41#include "simplify_string.h"
42#include "sc_fwd.h"
43#include "sc_object.h"
44#include "sc_module.h"
45#include "sc_port.h"
46#include "sc_ver_ext.h"
47
48using namespace std;
49
50namespace sc_core {
51
52static PortDependencyGraph aPortDependencyGraph;
53
54const PortDependencyGraph& 
55get_port_dependency_graph ()
56{
57        return aPortDependencyGraph;
58}
59
60static
61void
62check_port_dependency_declaration (const sc_port_base* a, 
63                                   const sc_port_base& b)
64{
65  const sc_module &moduleA = a->get_module ();
66  const sc_module &moduleB = b.get_module  ();
67  if (check_port_dependencies && (&moduleA != &moduleB))
68  {
69    const char *module_nameA = moduleA.basename ();
70    const char *module_nameB = moduleB.basename ();
71    if (strlen (module_nameA) == 0)
72      module_nameA = "<top level>";
73    cerr << "Error : Port dependency declaration in '"
74         << module_name_stack.back () << "' constructor is wrong.\n" 
75         << "'" << a->name () << "' and '" << b.name ()
76         << "' are ports of two differents modules ("
77         << module_nameA << " and " 
78         << module_nameB << "). "
79         << "You can't declare any port dependency like that.\n";
80    exit (37); //15092005);
81  }
82  if (module_name_stack.empty ())
83  {
84    cerr << "Error : Port dependency declaration is wrong.\n" 
85         << "The dependency declaration of '" 
86         << a->name () << "' and '" << b.name ()
87         << "' is not in any sc_module constructor.\n";
88    exit (16092005);
89  }
90  if (method_process_list.empty ())
91  {
92    cerr << "Error : Port dependency declaration in '"
93         << module_name_stack.back () << "' constructor is wrong.\n" 
94         << "The dependency of '" << a->name () << "' and '" << b.name ()
95         << "' should be linked to a SC_METHOD.\n";         
96    exit(165); //17092005);
97  }
98}
99
100void 
101set_port_dependency          (const sc_port_base* a, 
102                              const sc_port_base& b)
103{
104  check_port_dependency_declaration (a,b);
105        PortDependency p;
106        p.method = method_process_list.back();
107        p.source = a;
108        p.destination = &b;
109        aPortDependencyGraph.push_back (p);
110#if DUMP_PORT_DEPENDENCY
111        if (a) {
112                cerr << "'" << ((sc_object&)b).name()
113             << "' depends on '" 
114                           << ((sc_object*)a)->name () 
115         << "' in '" << p.method->name << "' function.\n";
116        } else
117                cerr << "'" << ((sc_object&)b).name()
118             << "' doesn't depend on anything"
119         << " in '" << p.method->name << "' function.\n";
120#endif
121}
122
123static
124void
125dot_write (ofstream &o, const PortDependencyGraph &g)
126{
127        string s;
128        PortDependencyGraph::const_iterator it;
129        for (it = g.begin (); it != g.end (); ++it)
130        {
131                if (it->source == NULL)
132                        continue;
133                const char *name;
134                name = ((sc_object*)it->source)->name();
135                o << simplify_name(name,s);
136                o       << " -> ";
137                name = ((sc_object*)it->destination)->name();
138                o << simplify_name(name,s);
139          o << "\n";
140        }
141}
142
143bool
144PortDependencyGraph2dot (const char *name,
145                         const PortDependencyGraph& g)
146{
147        if (!name)
148                return false;
149        string filename;
150        filename =  name;
151        filename += ".dot";
152        ofstream o;
153  o.open (filename.c_str(),ios::out | ios::trunc);
154        if (o.is_open () == false)
155                return false;
156        o << "// Port dependency graph\n"
157       "// Generated by "
158    << sc_version () << "\n";
159        o << "strict digraph " << name << " {\n";
160        dot_write (o,g);
161        o << "}\n";
162        o.close ();
163  if (dump_stage)
164    cerr << "Port Dependency Graph written into '" 
165         << filename << "'.\n";
166        return true;
167}
168
169} // end of sc_core namespace
170
Note: See TracBrowser for help on using the repository browser.