source: sources/src/module_hierarchy2dot.cc @ 52

Last change on this file since 52 was 27, checked in by buchmann, 16 years ago

SystemCASS now uses autoconf/automake to build the API. Regression tests still
use the old Makefiles.
(thanks to Nicolas Pouillon)

The library directory no longer is "lib-arch-system". The directory now is "lib-linux". Everyone needs to pay attention about SYSTEMCASS environment variable.

Changes:

  • system header includes
  • Add includes to config.h (generated by autoconf/automake)
  • test:
    • linux preprocessor macro instead of _WIN32
    • CONFIG_DEBUG instead of DEBUG

Removes:

  • Makefile
  • guess_endianness.cc
  • guess_os.sh
  • assert.h (we now use standard assert.h)
  • Options.def
File size: 5.0 KB
RevLine 
[1]1/*------------------------------------------------------------\
2|                                                             |
3| Tool    :                  systemcass                       |
4|                                                             |
5| File    :                  module_hierarchy2dot.cc          |
6|                                                             |
7| Author  :                 Buchmann Richard                  |
8|                                                             |
9| Date    :                   26_01_2006                      |
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 <vector>
37#include <map>
38#include <set>
39#include <fstream>
40#include "module_hierarchy.h"
41#include "module_hierarchy2dot.h"
42#include "sc_fwd.h"
43#include "sc_signal.h"
44#include "entity.h"
[27]45#include <cassert>
[1]46#include "internal.h"
[27]47#ifdef HAVE_CONFIG_H
48#include "config.h"
49#endif
[1]50
51using namespace std;
52
53namespace sc_core {
54
55/*
56static
57const char*
58get_parent_name (const sc_object &obj)
59{
60  const sc_object *parent = NULL;//get_parent_object (obj);
61  if (parent == NULL)
62    return "";
63  return parent->basename ();
64}
65*/
66
67typedef set<const char*> node_set_t;
68node_set_t node_set;
69
70static
71void
72print_edge (ostream &o)
73{
74  typedef map<const char*, const char*> edge_t;
75  edge_t edges;
76  const equi_list_t &eq_list = get_equi_list ();
77  equi_list_t::const_iterator jt;
78  for (jt = eq_list.begin (); jt != eq_list.end (); ++jt)
79  {
80    const equi_t &eq = (*jt);
81    sc_port_base *out   = get_out_port (eq);
82    if (out == NULL)
83      continue;
84    if (is_clock (*out))
85      continue;
86    const sc_module &out_mod = out->get_module ();
87    const char *out_mod_name = out_mod.basename ();
88    equi_t::const_iterator it;
89    for (it = eq.begin (); it != eq.end (); ++it)
90    {
91      const entity &in_entity  = *it;
92      sc_object    *in_obj     = in_entity.object;
[27]93      assert(in_obj != NULL);
[1]94      const sc_module *in_parent = NULL;
95      switch (in_entity.type) {
96      case entity::PORT :
97        in_parent = &(in_entity.port->get_module ());
98        if (&out_mod == in_parent)
99          continue;
100        break;
101      case entity::SIGNAL :
102      default :
103        continue;
104      }
105      edges[out_mod_name] = in_parent->basename ();
106      node_set.insert(out_mod_name);
107      node_set.insert(in_parent->basename ());
108    }
109  }
110#if 0
111  const equi_t &signal_eq = *(eq_list.begin ());
112  const char *signal_name = get_name (signal_eq);
113  o << "edge [label=\"" << signal_name << "\"]\n";
114#endif
115  edge_t::const_iterator i;
116  for (i = edges.begin (); i != edges.end (); ++i)
117  {
118    o << i->first
119      << " -> " 
120      << i->second
121      << ";\n";
122  }
123}
124
125static void print_node (ostream&, const vector<sc_object*>&);
126
127static
128void
129print_node (ostream         &o,
130            const sc_object &obj)
131{
132  const vector<sc_object*> &obj_list = get_child_objects (obj);
133  bool subgraph = (obj_list.empty() == false);
134//                  && (get_parent_object (obj) != NULL);
135  if (subgraph) {
136    const char *name = obj.basename ();
137    o << "subgraph \"cluster" << name << "\" {\n"
138      << "label=\"" << name << "\";\n";
139    print_node (o, obj_list);
140    o << "}\n";
141  } /*else*/ {
142//    if (obj.kind () == sc_module::kind_string)
143    if (node_set.find (obj.basename ()) != node_set.end())
144      o << obj.basename () << endl;
145  }
146}
147
148static
149void
150print_node (ostream                  &o,
151            const vector<sc_object*> &obj_list)
152{
153  vector<sc_object*>::const_iterator it;
154  for (it = obj_list.begin(); it != obj_list.end(); ++it)
155  {
156    sc_object *obj = *it;
157    print_node (o, *obj);
158  }
159}
160
161bool
162module_hierarchy2dot (const char *name)
163{
164        if (!name)
165                return false;
166        string filename;
167        filename =  name;
168        filename += ".dot";
169        ofstream o;
170  o.open (filename.c_str(),ios::out | ios::trunc);
171        if (o.is_open () == false)
172                return false;
173        o << "strict digraph " << name << " {\n";
174  o << "node [shape=box];\n";
175  print_edge (o);
176        print_node (o,sc_get_top_level_objects ());
177        o << "}\n";
178        o.close ();
179        return true;
180}
181
182} // end of sc_core namespace
183
Note: See TracBrowser for help on using the repository browser.