source: sources/src/port_dependency.cc @ 32

Last change on this file since 32 was 27, checked in by buchmann, 16 years ago

SystemCASS now uses autoconf/automake to build the API. Regression tests still
use the old Makefiles.
(thanks to Nicolas Pouillon)

The library directory no longer is "lib-arch-system". The directory now is "lib-linux". Everyone needs to pay attention about SYSTEMCASS environment variable.

Changes:

  • system header includes
  • Add includes to config.h (generated by autoconf/automake)
  • test:
    • linux preprocessor macro instead of _WIN32
    • CONFIG_DEBUG instead of DEBUG

Removes:

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