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