source: sources/src/module_hierarchy2dot.cc

Last change on this file was 59, checked in by meunier, 7 years ago
  • Fixed memory leaks
  • Fixed indentation in some files
File size: 5.3 KB
Line 
1/*------------------------------------------------------------\
2  |                                                             |
3  | Tool    :                  systemcass                       |
4  |                                                             |
5  | File    :                  module_hierarchy2dot.cc          |
6  |                                                             |
7  | Author  :                 Buchmann Richard                  |
8  |                                                             |
9  | Date    :                   26_01_2006                      |
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 <vector>
37#include <map>
38#include <set>
39#include <fstream>
40#include "module_hierarchy.h"
41#include "module_hierarchy2dot.h"
42#include "sc_fwd.h"
43#include "sc_signal.h"
44#include "entity.h"
45#include <cassert>
46#include "internal.h"
47#ifdef HAVE_CONFIG_H
48#include "config.h"
49#endif
50
51using namespace std;
52
53namespace sc_core {
54
55typedef set<const char*> node_set_t;
56node_set_t node_set;
57
58static void print_edge (ostream &o)
59{
60    typedef map<const char*, const char*> edge_t;
61    edge_t edges;
62    const equi_list_t &eq_list = get_equi_list ();
63    equi_list_t::const_iterator jt;
64    for (jt = eq_list.begin (); jt != eq_list.end (); ++jt)
65    {
66        const equi_t & eq = (*jt);
67        sc_port_base * out   = get_out_port (eq);
68        if (out == NULL) {
69            continue;
70        }
71        if (is_clock(*out)) {
72            continue;
73        }
74        const sc_module &out_mod = out->get_module ();
75        const char *out_mod_name = out_mod.basename ();
76        equi_t::const_iterator it;
77        for (it = eq.begin (); it != eq.end (); ++it)
78        {
79            const entity &in_entity  = *it;
80            sc_object    *in_obj     = in_entity.object;
81            assert(in_obj != NULL);
82            const sc_module *in_parent = NULL;
83            switch (in_entity.type) {
84                case entity::PORT :
85                    in_parent = &(in_entity.port->get_module ());
86                    if (&out_mod == in_parent) {
87                        continue;
88                    }
89                    break;
90                case entity::SIGNAL :
91                default :
92                    continue;
93            }
94            edges[out_mod_name] = in_parent->basename ();
95            node_set.insert(out_mod_name);
96            node_set.insert(in_parent->basename ());
97        }
98    }
99#if 0
100    const equi_t &signal_eq = *(eq_list.begin ());
101    const char *signal_name = get_name (signal_eq);
102    o << "edge [label=\"" << signal_name << "\"]\n";
103#endif
104    edge_t::const_iterator i;
105    for (i = edges.begin (); i != edges.end (); ++i)
106    {
107        o << i->first
108          << " -> " 
109          << i->second
110          << ";\n";
111    }
112}
113
114static void print_node (ostream&, const vector<sc_object*>&);
115
116static
117    void
118print_node (ostream         &o,
119        const sc_object &obj)
120{
121    const vector<sc_object*> &obj_list = get_child_objects (obj);
122    bool subgraph = (obj_list.empty() == false);
123    //                  && (get_parent_object (obj) != NULL);
124    if (subgraph) {
125        const char *name = obj.basename ();
126        o << "subgraph \"cluster" << name << "\" {\n"
127            << "label=\"" << name << "\";\n";
128        print_node (o, obj_list);
129        o << "}\n";
130    } /*else*/ {
131        //    if (obj.kind () == sc_module::kind_string)
132        if (node_set.find (obj.basename ()) != node_set.end()) {
133            o << obj.basename () << endl;
134        }
135    }
136}
137
138static
139    void
140print_node (ostream                  &o,
141        const vector<sc_object*> &obj_list)
142{
143    vector<sc_object*>::const_iterator it;
144    for (it = obj_list.begin(); it != obj_list.end(); ++it)
145    {
146        sc_object *obj = *it;
147        print_node (o, *obj);
148    }
149}
150
151    bool
152module_hierarchy2dot (const char *name)
153{
154    if (!name) {
155        return false;
156    }
157    string filename;
158    filename =  name;
159    filename += ".dot";
160    ofstream o;
161    o.open (filename.c_str(),ios::out | ios::trunc);
162    if (o.is_open () == false) {
163        return false;
164    }
165    o << "strict digraph " << name << " {\n";
166    o << "node [shape=box];\n";
167    print_edge (o);
168    print_node (o,sc_get_top_level_objects ());
169    o << "}\n";
170    o.close ();
171    return true;
172}
173
174} // end of sc_core namespace
175
Note: See TracBrowser for help on using the repository browser.