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

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

Checkin autotools magic

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