Ignore:
Timestamp:
Feb 6, 2017, 11:35:42 AM (7 years ago)
Author:
meunier
Message:
  • Fixed memory leaks
  • Fixed indentation in some files
File:
1 edited

Legend:

Unmodified
Added
Removed
  • sources/src/module_hierarchy2dot.cc

    r27 r59  
    11/*------------------------------------------------------------\
    2 |                                                             |
    3 | Tool    :                  systemcass                       |
    4 |                                                             |
    5 | File    :                  module_hierarchy2dot.cc          |
    6 |                                                             |
    7 | Author  :                 Buchmann Richard                  |
    8 |                                                             |
    9 | Date    :                   26_01_2006                      |
    10 |                                                             |
    11 \------------------------------------------------------------*/
     2  |                                                             |
     3  | Tool    :                  systemcass                       |
     4  |                                                             |
     5  | File    :                  module_hierarchy2dot.cc          |
     6  |                                                             |
     7  | Author  :                 Buchmann Richard                  |
     8  |                                                             |
     9  | Date    :                   26_01_2006                      |
     10  |                                                             |
     11  \------------------------------------------------------------*/
    1212
    1313/*
     
    5353namespace sc_core {
    5454
    55 /*
    56 static
    57 const char*
    58 get_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 
    6755typedef set<const char*> node_set_t;
    6856node_set_t node_set;
    6957
    70 static
    71 void
    72 print_edge (ostream &o)
     58static void print_edge (ostream &o)
    7359{
    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)
     60    typedef map<const char*, const char*> edge_t;
     61    edge_t edges;
     62    const equi_list_t &eq_list = get_equi_list ();
     63    equi_list_t::const_iterator jt;
     64    for (jt = eq_list.begin (); jt != eq_list.end (); ++jt)
    9065    {
    91       const entity &in_entity  = *it;
    92       sc_object    *in_obj     = in_entity.object;
    93       assert(in_obj != NULL);
    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 ());
     66        const equi_t & eq = (*jt);
     67        sc_port_base * out   = get_out_port (eq);
     68        if (out == NULL) {
     69            continue;
     70        }
     71        if (is_clock(*out)) {
     72            continue;
     73        }
     74        const sc_module &out_mod = out->get_module ();
     75        const char *out_mod_name = out_mod.basename ();
     76        equi_t::const_iterator it;
     77        for (it = eq.begin (); it != eq.end (); ++it)
     78        {
     79            const entity &in_entity  = *it;
     80            sc_object    *in_obj     = in_entity.object;
     81            assert(in_obj != NULL);
     82            const sc_module *in_parent = NULL;
     83            switch (in_entity.type) {
     84                case entity::PORT :
     85                    in_parent = &(in_entity.port->get_module ());
     86                    if (&out_mod == in_parent) {
     87                        continue;
     88                    }
     89                    break;
     90                case entity::SIGNAL :
     91                default :
     92                    continue;
     93            }
     94            edges[out_mod_name] = in_parent->basename ();
     95            node_set.insert(out_mod_name);
     96            node_set.insert(in_parent->basename ());
     97        }
    10898    }
    109   }
    11099#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";
     100    const equi_t &signal_eq = *(eq_list.begin ());
     101    const char *signal_name = get_name (signal_eq);
     102    o << "edge [label=\"" << signal_name << "\"]\n";
    114103#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   }
     104    edge_t::const_iterator i;
     105    for (i = edges.begin (); i != edges.end (); ++i)
     106    {
     107        o << i->first
     108          << " -> "
     109          << i->second
     110          << ";\n";
     111    }
    123112}
    124113
     
    126115
    127116static
    128 void
     117    void
    129118print_node (ostream         &o,
    130             const sc_object &obj)
     119        const sc_object &obj)
    131120{
    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   }
     121    const vector<sc_object*> &obj_list = get_child_objects (obj);
     122    bool subgraph = (obj_list.empty() == false);
     123    //                  && (get_parent_object (obj) != NULL);
     124    if (subgraph) {
     125        const char *name = obj.basename ();
     126        o << "subgraph \"cluster" << name << "\" {\n"
     127            << "label=\"" << name << "\";\n";
     128        print_node (o, obj_list);
     129        o << "}\n";
     130    } /*else*/ {
     131        //    if (obj.kind () == sc_module::kind_string)
     132        if (node_set.find (obj.basename ()) != node_set.end()) {
     133            o << obj.basename () << endl;
     134        }
     135    }
    146136}
    147137
    148138static
    149 void
     139    void
    150140print_node (ostream                  &o,
    151             const vector<sc_object*> &obj_list)
     141        const vector<sc_object*> &obj_list)
    152142{
    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   }
     143    vector<sc_object*>::const_iterator it;
     144    for (it = obj_list.begin(); it != obj_list.end(); ++it)
     145    {
     146        sc_object *obj = *it;
     147        print_node (o, *obj);
     148    }
    159149}
    160150
    161 bool
     151    bool
    162152module_hierarchy2dot (const char *name)
    163153{
    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;
     154    if (!name) {
     155        return false;
     156    }
     157    string filename;
     158    filename =  name;
     159    filename += ".dot";
     160    ofstream o;
     161    o.open (filename.c_str(),ios::out | ios::trunc);
     162    if (o.is_open () == false) {
     163        return false;
     164    }
     165    o << "strict digraph " << name << " {\n";
     166    o << "node [shape=box];\n";
     167    print_edge (o);
     168    print_node (o,sc_get_top_level_objects ());
     169    o << "}\n";
     170    o.close ();
     171    return true;
    180172}
    181173
Note: See TracChangeset for help on using the changeset viewer.