source: sources/src/methodprocess_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: 4.5 KB
Line 
1/*------------------------------------------------------------\
2|                                                             |
3| Tool    :                  systemcass                       |
4|                                                             |
5| File    :           methodprocess_dependency.cc             |
6|                                                             |
7| Author  :                 Buchmann Richard                  |
8|                                                             |
9| Date    :                   22_11_2005                      |
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 <cassert>
37#include <iostream>
38#include <fstream>
39
40#include "methodprocess_dependency.h"
41#include "simplify_string.h"
42#include "sc_module.h"
43
44#ifdef HAVE_CONFIG_H
45#include "config.h"
46#endif
47
48using namespace std;
49namespace sc_core {
50
51string get_name(const method_process_t * method) {
52    assert(method != NULL);
53    const sc_module *module = method->module;
54    assert(module != NULL);
55    const char * module_name = module->name();
56    const char * function_name = method->name;
57
58    string name = module_name;
59    name += "_";
60    name += function_name;
61    return name;
62}
63
64
65static bool dot_write(ofstream & o, const SignalDependencyGraph & sig) {
66    // Preparing data
67    typedef map < const equi_t *, const method_process_t *>table_t;
68    table_t table;
69
70    // For each arrow, add destination node into table
71    SignalDependencyGraph::const_iterator sig_it;
72    for (sig_it = sig.begin(); sig_it != sig.end(); ++sig_it) {
73        const SignalDependency & sd = *sig_it;
74        const equi_t * equi = sd.destination;
75        const method_process_t * method = sd.method;
76        table[equi] = method;
77    }
78
79    // Printing into dot file
80    string s;
81    SignalDependencyGraph::const_iterator it;
82    for (it = sig.begin(); it != sig.end(); ++it) {
83        const SignalDependency & sd = *it;
84        const equi_t * source_equi = sd.source;
85        assert(source_equi != NULL);
86        const method_process_t * source_method = table[source_equi];
87        if (source_method == NULL) {
88            continue;
89        }
90        string source_method_name = get_name(source_method);
91        string source_equi_name = get_name(*source_equi);
92        const method_process_t *destination_method = sd.method;
93        string destination_method_name = get_name(destination_method);
94        o << "edge [label=" << simplify_name(source_equi_name.c_str(), s) << "];\n";
95        o << simplify_name(source_method_name.c_str(), s);
96        o << " -> ";
97        o << simplify_name(destination_method_name.c_str(), s);
98        o << ";\n";
99    }
100}
101
102
103bool MethodProcessDependencyGraph2dot(const char * name, const SignalDependencyGraph & sig) {
104    if (!name) {
105        return false;
106    }
107    string filename;
108    filename = name;
109    filename += ".dot";
110    ofstream o;
111    o.open(filename.c_str(), ios::out | ios::trunc);
112    if (o.is_open() == false) {
113        return false;
114    }
115    o << "strict digraph " << name << " {\n";
116    dot_write(o, sig);
117    // Closing dot file
118    o << "}\n";
119    o.close();
120    if (dump_stage) {
121        cerr << "MethodProcess dependency graph written into '" << filename << "'.\n";
122    }
123    return true;
124}
125
126} // end of sc_core namespace
127
128/*
129# Local Variables:
130# tab-width: 4;
131# c-basic-offset: 4;
132# c-file-offsets:((innamespace . 0)(inline-open . 0));
133# indent-tabs-mode: nil;
134# End:
135#
136# vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4
137*/
Note: See TracBrowser for help on using the repository browser.