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 "assert.h" |
---|
46 | #include "internal.h" |
---|
47 | |
---|
48 | using namespace std; |
---|
49 | |
---|
50 | namespace sc_core { |
---|
51 | |
---|
52 | /* |
---|
53 | static |
---|
54 | const char* |
---|
55 | get_parent_name (const sc_object &obj) |
---|
56 | { |
---|
57 | const sc_object *parent = NULL;//get_parent_object (obj); |
---|
58 | if (parent == NULL) |
---|
59 | return ""; |
---|
60 | return parent->basename (); |
---|
61 | } |
---|
62 | */ |
---|
63 | |
---|
64 | typedef set<const char*> node_set_t; |
---|
65 | node_set_t node_set; |
---|
66 | |
---|
67 | static |
---|
68 | void |
---|
69 | print_edge (ostream &o) |
---|
70 | { |
---|
71 | typedef map<const char*, const char*> edge_t; |
---|
72 | edge_t edges; |
---|
73 | const equi_list_t &eq_list = get_equi_list (); |
---|
74 | equi_list_t::const_iterator jt; |
---|
75 | for (jt = eq_list.begin (); jt != eq_list.end (); ++jt) |
---|
76 | { |
---|
77 | const equi_t &eq = (*jt); |
---|
78 | sc_port_base *out = get_out_port (eq); |
---|
79 | if (out == NULL) |
---|
80 | continue; |
---|
81 | if (is_clock (*out)) |
---|
82 | continue; |
---|
83 | const sc_module &out_mod = out->get_module (); |
---|
84 | const char *out_mod_name = out_mod.basename (); |
---|
85 | equi_t::const_iterator it; |
---|
86 | for (it = eq.begin (); it != eq.end (); ++it) |
---|
87 | { |
---|
88 | const entity &in_entity = *it; |
---|
89 | sc_object *in_obj = in_entity.object; |
---|
90 | ASSERT(in_obj != NULL); |
---|
91 | const sc_module *in_parent = NULL; |
---|
92 | switch (in_entity.type) { |
---|
93 | case entity::PORT : |
---|
94 | in_parent = &(in_entity.port->get_module ()); |
---|
95 | if (&out_mod == in_parent) |
---|
96 | continue; |
---|
97 | break; |
---|
98 | case entity::SIGNAL : |
---|
99 | default : |
---|
100 | continue; |
---|
101 | } |
---|
102 | edges[out_mod_name] = in_parent->basename (); |
---|
103 | node_set.insert(out_mod_name); |
---|
104 | node_set.insert(in_parent->basename ()); |
---|
105 | } |
---|
106 | } |
---|
107 | #if 0 |
---|
108 | const equi_t &signal_eq = *(eq_list.begin ()); |
---|
109 | const char *signal_name = get_name (signal_eq); |
---|
110 | o << "edge [label=\"" << signal_name << "\"]\n"; |
---|
111 | #endif |
---|
112 | edge_t::const_iterator i; |
---|
113 | for (i = edges.begin (); i != edges.end (); ++i) |
---|
114 | { |
---|
115 | o << i->first |
---|
116 | << " -> " |
---|
117 | << i->second |
---|
118 | << ";\n"; |
---|
119 | } |
---|
120 | } |
---|
121 | |
---|
122 | static void print_node (ostream&, const vector<sc_object*>&); |
---|
123 | |
---|
124 | static |
---|
125 | void |
---|
126 | print_node (ostream &o, |
---|
127 | const sc_object &obj) |
---|
128 | { |
---|
129 | const vector<sc_object*> &obj_list = get_child_objects (obj); |
---|
130 | bool subgraph = (obj_list.empty() == false); |
---|
131 | // && (get_parent_object (obj) != NULL); |
---|
132 | if (subgraph) { |
---|
133 | const char *name = obj.basename (); |
---|
134 | o << "subgraph \"cluster" << name << "\" {\n" |
---|
135 | << "label=\"" << name << "\";\n"; |
---|
136 | print_node (o, obj_list); |
---|
137 | o << "}\n"; |
---|
138 | } /*else*/ { |
---|
139 | // if (obj.kind () == sc_module::kind_string) |
---|
140 | if (node_set.find (obj.basename ()) != node_set.end()) |
---|
141 | o << obj.basename () << endl; |
---|
142 | } |
---|
143 | } |
---|
144 | |
---|
145 | static |
---|
146 | void |
---|
147 | print_node (ostream &o, |
---|
148 | const vector<sc_object*> &obj_list) |
---|
149 | { |
---|
150 | vector<sc_object*>::const_iterator it; |
---|
151 | for (it = obj_list.begin(); it != obj_list.end(); ++it) |
---|
152 | { |
---|
153 | sc_object *obj = *it; |
---|
154 | print_node (o, *obj); |
---|
155 | } |
---|
156 | } |
---|
157 | |
---|
158 | bool |
---|
159 | module_hierarchy2dot (const char *name) |
---|
160 | { |
---|
161 | if (!name) |
---|
162 | return false; |
---|
163 | string filename; |
---|
164 | filename = name; |
---|
165 | filename += ".dot"; |
---|
166 | ofstream o; |
---|
167 | o.open (filename.c_str(),ios::out | ios::trunc); |
---|
168 | if (o.is_open () == false) |
---|
169 | return false; |
---|
170 | o << "strict digraph " << name << " {\n"; |
---|
171 | o << "node [shape=box];\n"; |
---|
172 | print_edge (o); |
---|
173 | print_node (o,sc_get_top_level_objects ()); |
---|
174 | o << "}\n"; |
---|
175 | o.close (); |
---|
176 | return true; |
---|
177 | } |
---|
178 | |
---|
179 | } // end of sc_core namespace |
---|
180 | |
---|