source: latest/src/port_dependency.cc @ 1

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

Initial import from CVS repository

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