[1] | 1 | /*------------------------------------------------------------\ |
---|
| 2 | | | |
---|
| 3 | | Tool : systemcass | |
---|
| 4 | | | |
---|
| 5 | | File : graph_signals.cc | |
---|
| 6 | | | |
---|
| 7 | | Author : Buchmann Richard | |
---|
| 8 | | | |
---|
| 9 | | Date : 22_09_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 | /* |
---|
| 37 | * $Log: graph_signals.cc,v $ |
---|
| 38 | * Revision 1.7 2006/06/12 14:02:04 buchmann |
---|
| 39 | * - Now sort transition and generation functions by fonction pointer |
---|
| 40 | * (Thank to Nicolas Pouillon) |
---|
| 41 | * - Add Nicolas Pouillon as contributor into splash screen |
---|
| 42 | * - Rename files and classes from "dependancy" to "dependency". |
---|
| 43 | * - Add some references to bibliography file |
---|
| 44 | * - Add licence note to every files |
---|
| 45 | * - Rename "module graph" to "process graph" |
---|
| 46 | * - Now dump module graph when using --t option and CASS scheduling at the same |
---|
| 47 | * time |
---|
| 48 | * |
---|
| 49 | * Bug fixes : |
---|
| 50 | * - check user time ( != 0) before computing simulation performance |
---|
| 51 | * - Remove reinterpret_cast (for pending write) because of unexpected results |
---|
| 52 | * - Add ASSERT in trace functions |
---|
| 53 | * |
---|
| 54 | * Revision 1.6 2005/10/12 10:01:00 buchmann |
---|
| 55 | * Bug fix : |
---|
| 56 | * - test to avoid malloc(0) |
---|
| 57 | * |
---|
| 58 | * Remove : |
---|
| 59 | * - unused variable |
---|
| 60 | * |
---|
| 61 | * Revision 1.5 2005/09/14 14:08:24 buchmann |
---|
| 62 | * Add Werror flag to compile the debug library. |
---|
| 63 | * Split sc_clock implementation from sc_port to sc_clock. |
---|
| 64 | * Add a helper message to write mealy functions avoiding combinational cycle. |
---|
| 65 | * |
---|
| 66 | * Bug fix : |
---|
| 67 | * - cvs rules is no longer circular |
---|
| 68 | * - bit2string |
---|
| 69 | * - port binding (sc_in to sc_out) |
---|
| 70 | * - error message from FSM rules checker |
---|
| 71 | * - sc_time copy operator |
---|
| 72 | * |
---|
| 73 | * Code cleaning : |
---|
| 74 | * - remove duplicated code (entity.cc and sc_port.cc) |
---|
| 75 | * - remove duplicated declarations (internal_ext.h and internal.h) |
---|
| 76 | * |
---|
| 77 | * Revision 1.4 2005/06/22 09:15:03 buchmann |
---|
| 78 | * Add some *_ext.h files to split internal implementation from API interface. |
---|
| 79 | * |
---|
| 80 | * Add -Wunused to detect unused functions. |
---|
| 81 | * |
---|
| 82 | * Include directory now contains API interface file only. |
---|
| 83 | * |
---|
| 84 | * Declar all the implementation/interface inside sc_core namespace as LRM 2.1 |
---|
| 85 | * advices. |
---|
| 86 | * |
---|
| 87 | * Remove casc namespace. |
---|
| 88 | * |
---|
| 89 | * Clean up dead code segments. |
---|
| 90 | * |
---|
| 91 | * Add hexadecimal dumping support. |
---|
| 92 | * |
---|
| 93 | * Add empty implementation of functions for object hierarchy traversal. (LRM 2.1) |
---|
| 94 | * |
---|
| 95 | * Bug fixes : |
---|
| 96 | * - reference return of the following functions : operators =, |=, &= and so on. |
---|
| 97 | * - range functions now return an sc_int_subref instead of an int. |
---|
| 98 | * |
---|
| 99 | * Revision 1.3 2005/03/25 14:33:01 buchmann |
---|
| 100 | * Typo : |
---|
| 101 | * - dependAncy -> dependEncy |
---|
| 102 | * |
---|
| 103 | * sc_initialize : |
---|
| 104 | * - Use a hash table to speed up elaboration step. (x40 faster) |
---|
| 105 | * |
---|
| 106 | * Tracing : |
---|
| 107 | * - check for modification BEFORE building bit string. |
---|
| 108 | * - use sprintf instead std string concatenation. |
---|
| 109 | * |
---|
| 110 | * Revision 1.2 2005/01/20 09:15:12 buchmann |
---|
| 111 | * add following functions to sc_uint classes : |
---|
| 112 | * - operator [] |
---|
| 113 | * - range (left,right) |
---|
| 114 | * |
---|
| 115 | * support to port dependancy declarations. |
---|
| 116 | * print used precompiled options in verbose mode. |
---|
| 117 | * use pedantic flag. |
---|
| 118 | * add some rules to generate documentations. |
---|
| 119 | * |
---|
| 120 | * Revision 1.1 2004/09/27 14:40:14 buchmann |
---|
| 121 | * bug fix : |
---|
| 122 | * - allow the use of user-defined structs in sc_signal/sc_in/sc_out/sc_inout |
---|
| 123 | * - use sc_dt namespace like official SystemC engine |
---|
| 124 | * |
---|
| 125 | * add : |
---|
| 126 | * - dump the signal/port/module dependancy graph in dot format |
---|
| 127 | * |
---|
| 128 | * Graph library is now splitted from the SystemCASS specific code. |
---|
| 129 | * |
---|
| 130 | */ |
---|
| 131 | |
---|
[12] | 132 | #include <cstdio> |
---|
[1] | 133 | #include <map> |
---|
| 134 | |
---|
| 135 | #include "graph_signals.h" |
---|
| 136 | #include "signal_dependency.h" |
---|
| 137 | #include "sc_sensitive.h" |
---|
| 138 | #include "sc_module.h" |
---|
| 139 | #include "sc_port.h" |
---|
| 140 | |
---|
| 141 | using namespace std; |
---|
| 142 | |
---|
| 143 | namespace sc_core { |
---|
| 144 | |
---|
| 145 | #if 0 |
---|
| 146 | static |
---|
| 147 | ostream& operator << (ostream& o, |
---|
| 148 | const Vertex &v) |
---|
| 149 | { |
---|
| 150 | equi_t* m = (equi_t*)(v.data); |
---|
| 151 | if (v.arcs == NULL) |
---|
| 152 | o << get_name(*m) << "\n"; |
---|
| 153 | Arc *a; |
---|
| 154 | for (a = v.arcs; a; a = a->next) |
---|
| 155 | { |
---|
| 156 | equi_t* m2 = (equi_t*)(a->tip->data); |
---|
| 157 | o << get_name(*m) << "->" |
---|
| 158 | << get_name(*m2) << "\n"; |
---|
| 159 | } |
---|
| 160 | return o; |
---|
| 161 | |
---|
| 162 | } |
---|
| 163 | |
---|
| 164 | static |
---|
| 165 | ostream& |
---|
| 166 | operator << (ostream &o, |
---|
| 167 | const Graph &g) |
---|
| 168 | { |
---|
| 169 | Vertex *v; |
---|
| 170 | int i = 1; |
---|
| 171 | for (v = g.vertices; v < g.vertices + g.n; ++v) { |
---|
| 172 | o << i++ << " : " << *v; |
---|
| 173 | } |
---|
| 174 | return o; |
---|
| 175 | } |
---|
| 176 | #endif |
---|
| 177 | |
---|
| 178 | typedef std::map<const equi_t*, Vertex*> nodes_set_t; |
---|
| 179 | |
---|
| 180 | void |
---|
| 181 | create_arcs (const SignalDependencyGraph& sig_g, nodes_set_t& s) |
---|
| 182 | { |
---|
| 183 | SignalDependencyGraph::const_iterator j; |
---|
| 184 | for (j = sig_g.begin(); j != sig_g.end(); ++j) { |
---|
| 185 | new_arc (s[j->source],s[j->destination]); |
---|
| 186 | } |
---|
| 187 | } |
---|
| 188 | |
---|
| 189 | void |
---|
| 190 | create_vertices_list (Graph *g, nodes_set_t& s) |
---|
| 191 | { |
---|
| 192 | Vertex *v = g->vertices; |
---|
| 193 | if (v == NULL) |
---|
| 194 | return; |
---|
| 195 | nodes_set_t::iterator j; |
---|
| 196 | for (j = s.begin(); j != s.end(); ++j) |
---|
| 197 | { |
---|
| 198 | v->data = (void*) (j->first); |
---|
| 199 | j->second = v++; |
---|
| 200 | } |
---|
| 201 | } |
---|
| 202 | |
---|
| 203 | nodes_set_t* |
---|
| 204 | create_nodes_set (const SignalDependencyGraph& sig_g) |
---|
| 205 | { |
---|
| 206 | /* Create a signal set */ |
---|
| 207 | nodes_set_t &s = *(new nodes_set_t); |
---|
| 208 | |
---|
| 209 | SignalDependencyGraph::const_iterator j; |
---|
| 210 | for (j = sig_g.begin(); j != sig_g.end(); ++j) |
---|
| 211 | { |
---|
| 212 | s[j->source] = NULL; |
---|
| 213 | s[j->destination] = NULL; |
---|
| 214 | } |
---|
| 215 | return &s; |
---|
| 216 | } |
---|
| 217 | |
---|
| 218 | /* Construit le graph de dépendance des signaux de Mealy */ |
---|
| 219 | /* g = Mealy signal dependancy graph */ |
---|
| 220 | Graph *makegraph(const SignalDependencyGraph& sig_g) |
---|
| 221 | { |
---|
| 222 | int n = 0; /* Number of vertices */ |
---|
| 223 | Graph *g; |
---|
| 224 | //Vertex *v; |
---|
| 225 | |
---|
| 226 | /* Create node set */ |
---|
| 227 | nodes_set_t *sig_s = create_nodes_set (sig_g); |
---|
| 228 | |
---|
| 229 | /* Compute the number of vertices in the graph */ |
---|
| 230 | n = sig_s->size(); |
---|
| 231 | |
---|
| 232 | /* Create the graph */ |
---|
| 233 | g = gb_new_graph(n); |
---|
| 234 | |
---|
| 235 | /* Associate the netlist elements to the graph vertices, and vice-versa */ |
---|
| 236 | // v = g->vertices; |
---|
| 237 | |
---|
| 238 | /* Create the node set */ |
---|
| 239 | create_vertices_list (g,*sig_s); |
---|
| 240 | |
---|
| 241 | /* initialisation des vertices */ |
---|
| 242 | create_arcs (sig_g,*sig_s); |
---|
| 243 | |
---|
| 244 | delete sig_s; |
---|
| 245 | #if 0 |
---|
| 246 | cerr << *g << "\n"; |
---|
| 247 | #endif |
---|
| 248 | return g; |
---|
| 249 | } |
---|
| 250 | |
---|
| 251 | } // end of sc_core namespace |
---|
| 252 | |
---|