source: latest/src/dump_dot.cc @ 1

Last change on this file since 1 was 1, checked in by buchmann, 17 years ago

Initial import from CVS repository

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