source: sources/src/port_dependency.cc @ 65

Last change on this file since 65 was 52, checked in by meunier, 11 years ago

Code formatting in all source files.

File size: 5.7 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
41#include "port_dependency.h"
42#include "simplify_string.h"
43#include "sc_fwd.h"
44#include "sc_object.h"
45#include "sc_module.h"
46#include "sc_port.h"
47#include "sc_ver_ext.h"
48
49#ifdef HAVE_CONFIG_H
50#include "config.h"
51#endif
52
53using namespace std;
54
55namespace sc_core {
56
57static PortDependencyGraph aPortDependencyGraph;
58
59const PortDependencyGraph & get_port_dependency_graph() {
60    return aPortDependencyGraph;
61}
62
63
64static void check_port_dependency_declaration(const sc_port_base * a, const sc_port_base& b) {
65    const sc_module & moduleA = a->get_module();
66    const sc_module & moduleB = b.get_module();
67    if (check_port_dependencies && (&moduleA != &moduleB)) {
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        }
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        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        cerr << "Error : Port dependency declaration in '"
91            << module_name_stack.back () << "' constructor is wrong.\n" 
92            << "The dependency of '" << a->name () << "' and '" << b.name ()
93            << "' should be linked to a SC_METHOD.\n";         
94        exit(165); //17092005);
95    }
96}
97
98
99void set_port_dependency(const sc_port_base * a, const sc_port_base & b) {
100    check_port_dependency_declaration(a,b);
101    PortDependency p;
102    p.method = method_process_list.back();
103    p.source = a;
104    p.destination = &b;
105    aPortDependencyGraph.push_back(p);
106#ifdef DUMP_PORT_DEPENDENCY
107    if (a) {
108        cerr << "'" << ((sc_object&)b).name()
109            << "' depends on '" 
110            << ((sc_object*)a)->name() 
111            << "' in '" << p.method->name << "' function.\n";
112    }
113    else {
114        cerr << "'" << ((sc_object&)b).name()
115            << "' doesn't depend on anything"
116            << " in '" << p.method->name << "' function.\n";
117    }
118#endif
119}
120
121
122static void dot_write (ofstream & o, const PortDependencyGraph & g) {
123    string s;
124    PortDependencyGraph::const_iterator it;
125    for (it = g.begin (); it != g.end (); ++it) {
126        if (it->source == NULL) {
127            continue;
128        }
129        const char * name;
130        name = ((sc_object *)it->source)->name();
131        o << simplify_name(name,s);
132        o << " -> ";
133        name = ((sc_object *)it->destination)->name();
134        o << simplify_name(name,s);
135        o << "\n";
136    }
137}
138
139
140bool PortDependencyGraph2dot (const char * name, const PortDependencyGraph & g) {
141    if (!name) {
142        return false;
143    }
144    string filename;
145    filename = name;
146    filename += ".dot";
147    ofstream o;
148    o.open(filename.c_str(),ios::out | ios::trunc);
149    if (o.is_open () == false) {
150        return false;
151    }
152    o << "// Port dependency graph\n"
153        "// Generated by "
154        << sc_version () << "\n";
155    o << "strict digraph " << name << " {\n";
156    dot_write (o,g);
157    o << "}\n";
158    o.close ();
159    if (dump_stage) {
160        cerr << "Port Dependency Graph written into '" << filename << "'.\n";
161    }
162    return true;
163}
164
165} // end of sc_core namespace
166
167/*
168# Local Variables:
169# tab-width: 4;
170# c-basic-offset: 4;
171# c-file-offsets:((innamespace . 0)(inline-open . 0));
172# indent-tabs-mode: nil;
173# End:
174#
175# vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4
176*/
177
Note: See TracBrowser for help on using the repository browser.