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 "methodprocess_dependency.h" |
---|
38 | #include "simplify_string.h" |
---|
39 | #include "sc_module.h" |
---|
40 | #include <iostream> |
---|
41 | #include <fstream> |
---|
42 | #ifdef HAVE_CONFIG_H |
---|
43 | #include "config.h" |
---|
44 | #endif |
---|
45 | |
---|
46 | using namespace std; |
---|
47 | namespace sc_core { |
---|
48 | |
---|
49 | string |
---|
50 | get_name (const method_process_t *method) |
---|
51 | { |
---|
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 | static |
---|
65 | bool |
---|
66 | dot_write (ofstream &o, |
---|
67 | const SignalDependencyGraph &sig) |
---|
68 | { |
---|
69 | // Preparing data |
---|
70 | typedef map<const equi_t *, const method_process_t *> table_t; |
---|
71 | table_t table; |
---|
72 | |
---|
73 | // For each arrow, add destination node into table |
---|
74 | SignalDependencyGraph::const_iterator sig_it; |
---|
75 | for (sig_it = sig.begin (); sig_it != sig.end (); ++sig_it) |
---|
76 | { |
---|
77 | const SignalDependency &sd = *sig_it; |
---|
78 | const equi_t *equi = sd.destination; |
---|
79 | const method_process_t *method = sd.method; |
---|
80 | table[equi] = method; |
---|
81 | } |
---|
82 | |
---|
83 | // Printing into dot file |
---|
84 | string s; |
---|
85 | SignalDependencyGraph::const_iterator it; |
---|
86 | for (it = sig.begin (); it != sig.end (); ++it) |
---|
87 | { |
---|
88 | const SignalDependency &sd = *it; |
---|
89 | const equi_t *source_equi = sd.source; |
---|
90 | assert(source_equi != NULL); |
---|
91 | const method_process_t *source_method = table[source_equi]; |
---|
92 | if (source_method == NULL) |
---|
93 | continue; |
---|
94 | string source_method_name = get_name (source_method); |
---|
95 | string source_equi_name = get_name (*source_equi); |
---|
96 | const method_process_t *destination_method = sd.method; |
---|
97 | string destination_method_name = get_name (destination_method); |
---|
98 | o << "edge [label=" |
---|
99 | << simplify_name(source_equi_name.c_str(),s) |
---|
100 | << "];\n"; |
---|
101 | o << simplify_name(source_method_name.c_str(),s); |
---|
102 | o << " -> "; |
---|
103 | o << simplify_name(destination_method_name.c_str(),s); |
---|
104 | o << ";\n"; |
---|
105 | } |
---|
106 | } |
---|
107 | |
---|
108 | bool |
---|
109 | MethodProcessDependencyGraph2dot (const char *name, |
---|
110 | const SignalDependencyGraph& sig) |
---|
111 | { |
---|
112 | if (!name) |
---|
113 | return false; |
---|
114 | string filename; |
---|
115 | filename = name; |
---|
116 | filename += ".dot"; |
---|
117 | ofstream o; |
---|
118 | o.open (filename.c_str(),ios::out | ios::trunc); |
---|
119 | if (o.is_open () == false) |
---|
120 | return false; |
---|
121 | o << "strict digraph " << name << " {\n"; |
---|
122 | dot_write (o,sig); |
---|
123 | // Closing dot file |
---|
124 | o << "}\n"; |
---|
125 | o.close (); |
---|
126 | if (dump_stage) |
---|
127 | cerr << "MethodProcess dependency graph written into '" |
---|
128 | << filename << "'.\n"; |
---|
129 | return true; |
---|
130 | } |
---|
131 | |
---|
132 | } // end of sc_core namespace |
---|
133 | |
---|