[1] | 1 | /*------------------------------------------------------------\ |
---|
[52] | 2 | | | |
---|
| 3 | | Tool : systemcass | |
---|
| 4 | | | |
---|
| 5 | | File : dump_dot.cc | |
---|
| 6 | | | |
---|
| 7 | | Author : Buchmann Richard | |
---|
| 8 | | | |
---|
| 9 | | Date : 09_07_2004 | |
---|
| 10 | | | |
---|
| 11 | \------------------------------------------------------------*/ |
---|
[1] | 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 <fstream> |
---|
| 37 | #include "dump_dot.h" |
---|
| 38 | #include "sc_module.h" |
---|
| 39 | #include "sc_port.h" |
---|
| 40 | #include "simplify_string.h" |
---|
| 41 | #include "sc_ver.h" // sc_version |
---|
[27] | 42 | #ifdef HAVE_CONFIG_H |
---|
| 43 | #include "config.h" |
---|
| 44 | #endif |
---|
[1] | 45 | |
---|
[52] | 46 | typedef std::list<sc_core::sc_port_base *> port_list_t; |
---|
| 47 | |
---|
[1] | 48 | using namespace std; |
---|
| 49 | |
---|
| 50 | namespace sc_core { |
---|
| 51 | |
---|
[4] | 52 | using namespace sc_dt; |
---|
| 53 | |
---|
[1] | 54 | // Build a port list owned by the module mod |
---|
[52] | 55 | static void get_out_port_list(const sc_module & mod, port_list_t & pl) { |
---|
| 56 | port2module_t::iterator i; |
---|
| 57 | for (i = port2module.begin(); i != port2module.end(); ++i) { |
---|
| 58 | if ((i->second == &mod) && (i->first)) { |
---|
| 59 | pl.push_back((sc_port_base *) (i->first)); |
---|
| 60 | } |
---|
| 61 | } |
---|
[1] | 62 | } |
---|
| 63 | |
---|
[52] | 64 | static void dump_dot(ofstream & o, method_process_t & m) { |
---|
| 65 | port_list_t port_list; |
---|
| 66 | get_out_port_list(*(m.module), port_list); |
---|
| 67 | port_list_t::iterator op; |
---|
| 68 | for (op = port_list.begin(); op != port_list.end(); ++op) { |
---|
| 69 | sensitivity_list_t::iterator ip; |
---|
| 70 | for (ip = m.sensitivity_list.begin(); ip != m.sensitivity_list.end(); ++ip) { |
---|
| 71 | if (is_clock(ip->get_interface())) { |
---|
| 72 | continue; |
---|
| 73 | } |
---|
| 74 | const char * in = get_name(ip->get_interface().get_pointer()); |
---|
| 75 | const char * out = (*op)->name(); |
---|
| 76 | string s; |
---|
| 77 | o << simplify_name(in, s); |
---|
| 78 | o << "->"; |
---|
| 79 | o << simplify_name(out, s); |
---|
| 80 | o << ";\n"; |
---|
| 81 | } |
---|
| 82 | } |
---|
[1] | 83 | } |
---|
| 84 | |
---|
[52] | 85 | |
---|
| 86 | static void dump_all(ofstream & o, method_process_list_t & lm) { |
---|
| 87 | method_process_list_t::iterator it; |
---|
| 88 | for (it = lm.begin(); it != lm.end(); ++it) { |
---|
| 89 | dump_dot(o, **it); |
---|
| 90 | } |
---|
[1] | 91 | } |
---|
| 92 | |
---|
[52] | 93 | |
---|
| 94 | static void dump_all(ofstream & o, const Vertex & v) { |
---|
| 95 | if (v.arcs == NULL) { |
---|
| 96 | return; |
---|
| 97 | } |
---|
| 98 | Arc * a; |
---|
| 99 | for (a = v.arcs; a != NULL; a = a->next) { |
---|
| 100 | method_process_t * m = (method_process_t *) v.data; |
---|
| 101 | method_process_t * m2 = (method_process_t *) a->tip->data; |
---|
| 102 | o << m->module->name(); |
---|
| 103 | o << " -> " << m2->module->name() << "\n"; |
---|
| 104 | } |
---|
[1] | 105 | } |
---|
| 106 | |
---|
[52] | 107 | |
---|
| 108 | static void dump_all(ofstream & o, Graph & g) { |
---|
| 109 | Vertex *v; |
---|
| 110 | for (v = g.vertices; v < g.vertices + g.n; v++) { |
---|
| 111 | dump_all(o, *v); |
---|
| 112 | } |
---|
[1] | 113 | } |
---|
| 114 | |
---|
[52] | 115 | |
---|
| 116 | bool SignalDependancyGraph2dot(const char * name, method_process_list_t & lm) { |
---|
| 117 | if (!name) { |
---|
| 118 | return false; |
---|
| 119 | } |
---|
| 120 | string filename; |
---|
| 121 | filename = name; |
---|
| 122 | filename += ".dot"; |
---|
| 123 | ofstream o; |
---|
| 124 | o.open(filename.c_str(), ios::out | ios::trunc); |
---|
| 125 | if (o.is_open() == false) { |
---|
| 126 | return false; |
---|
| 127 | } |
---|
| 128 | o << "// Signal dependency graph\n" |
---|
| 129 | "// Generated by " << sc_version() << "\n"; |
---|
| 130 | o << "strict digraph " << name << " {\n"; |
---|
| 131 | dump_all(o, lm); |
---|
| 132 | o << "}\n"; |
---|
| 133 | o.close(); |
---|
| 134 | return true; |
---|
[1] | 135 | } |
---|
| 136 | |
---|
| 137 | |
---|
| 138 | |
---|
[52] | 139 | bool FctDependancyGraph2dot(const char * name, Graph * g) { |
---|
| 140 | if (!name) { |
---|
| 141 | return false; |
---|
| 142 | } |
---|
| 143 | if (!g) { |
---|
| 144 | return false; |
---|
| 145 | } |
---|
| 146 | string filename; |
---|
| 147 | filename = name; |
---|
| 148 | filename += ".dot"; |
---|
| 149 | ofstream o; |
---|
| 150 | o.open(filename.c_str(), ios::out | ios::trunc); |
---|
| 151 | if (o.is_open() == false) { |
---|
| 152 | return false; |
---|
| 153 | } |
---|
| 154 | o << "// Function dependency graph\n" |
---|
| 155 | "// Generated by " << sc_version() << "\n"; |
---|
| 156 | o << "digraph " << name << " {\n"; |
---|
| 157 | dump_all(o, *g); |
---|
| 158 | o << "}\n"; |
---|
| 159 | o.close(); |
---|
| 160 | return true; |
---|
[1] | 161 | } |
---|
| 162 | |
---|
| 163 | } // end of sc_core namespace |
---|
| 164 | |
---|
[52] | 165 | /* |
---|
| 166 | # Local Variables: |
---|
| 167 | # tab-width: 4; |
---|
| 168 | # c-basic-offset: 4; |
---|
| 169 | # c-file-offsets:((innamespace . 0)(inline-open . 0)); |
---|
| 170 | # indent-tabs-mode: nil; |
---|
| 171 | # End: |
---|
| 172 | # |
---|
| 173 | # vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 |
---|
| 174 | */ |
---|