Ignore:
Timestamp:
Jan 22, 2013, 4:23:22 PM (11 years ago)
Author:
meunier
Message:

Code formatting in all source files.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sources/src/signal_dependency.cc

    r27 r52  
    4343#include "sc_module.h"
    4444#include "sc_ver_ext.h"
     45
    4546#ifdef HAVE_CONFIG_H
    4647#include "config.h"
     
    5152namespace sc_core {
    5253
    53 bool
    54 SignalDependency::operator < (const SignalDependency &b) const
    55 {
    56         if (source < b.source)
    57                 return true;
    58         if (destination < b.destination)
    59                 return true;
    60         return false;
    61 }
    62 
    63 static
    64 void
    65 txt_write (ofstream &o, const component_list_t &l)
    66 {
    67         component_list_t::const_iterator it;
    68         for (it = l.begin (); it != l.end (); ++it)
    69         {
    70                 o << get_name(*((equi_t*)(*it))) << " ";
    71         }
    72 }
    73 
    74 static
    75 void
    76 txt_write (ofstream &o, const strong_component_list_t &l)
    77 {
    78         strong_component_list_t::const_iterator it;
    79         for (it = l.begin (); it != l.end (); ++it)
    80         {
    81                 txt_write (o,**it);
    82                 o <<  "\n";
    83         }
    84 }
    85 
    86 bool
    87 SignalDependencyOrder2txt (const char *name,
    88                            const strong_component_list_t&l)
    89 {
    90         if (!name)
    91                 return false;
    92         string filename;
    93         filename =  name;
    94         filename += ".txt";
    95         ofstream o;
    96   o.open (filename.c_str(),ios::out | ios::trunc);
    97         if (o.is_open () == false)
    98                 return false;
    99         txt_write (o,l);
    100         o.close ();
    101         return true;
    102        
    103 }
    104 
    105 static
    106 void
    107 dot_write (ofstream &o, const SignalDependencyGraph &g)
    108 {
    109         string s;
    110         SignalDependencyGraph::const_iterator it;
    111         for (it = g.begin (); it != g.end (); ++it)
    112         {
    113                 string name;
    114                 name = it->method->module->name();
    115                 name += "_";
    116                 name += it->method->name;
    117                 o << "edge [label="
    118       << simplify_name(name.c_str(),s)
    119       << "];\n";
    120     const equi_t *equi = it->source;
    121                 name = get_name (*equi);
    122                 o << simplify_name(name.c_str(),s);
    123                 o       << " -> ";
    124     equi = it->destination;
    125                 name = get_name (*equi);
    126                 o << simplify_name(name.c_str(),s);
    127           o << ";\n";
    128         }
    129 }
    130 
    131 bool
    132 SignalDependencyGraph2dot (const char *name,
    133                            const SignalDependencyGraph& g)
    134 {
    135         if (!name)
    136                 return false;
    137         string filename;
    138         filename =  name;
    139         filename += ".dot";
    140         ofstream o;
    141   o.open (filename.c_str(),ios::out | ios::trunc);
    142         if (o.is_open () == false)
    143                 return false;
    144         o << "// Signal dependency graph\n"
    145        "// Generated by "
    146     << sc_version () << "\n";
    147         o << "strict digraph " << name << " {\n";
    148         dot_write (o,g);
    149         o << "}\n";
    150         o.close ();
    151   if (dump_stage)
    152     cerr << "Signal Dependency Graph written into '"
    153          << filename << "'.\n";
    154         return true;
    155 }
    156 
    157 SignalDependencyGraph*
    158 MakeSignalDependencyGraph (const PortDependencyGraph& g)
    159 {
    160   if (dump_stage)
    161           cerr << "Making signal dependency graph...\n";
    162 
    163         SignalDependencyGraph *sig_g = new SignalDependencyGraph ();
    164         PortDependencyGraph::const_iterator it;
    165         for (it = g.begin(); it != g.end(); ++it)
    166         {
    167                 SignalDependency s;
    168                 s.method = it->method;
    169                 const sc_interface *inter;
    170                 inter = it->source;
    171                 if (inter)
    172                         s.source = &(get_equi (*inter));
    173                 else
    174                         continue;
    175                 inter = it->destination;
    176                 s.destination = &(get_equi (*inter));
    177                 sig_g->insert(s);
    178         }
    179         return sig_g;
    180 }
    181 
    182 
    183 static
    184 bool
    185 is_in (const equi_t &e, const method_process_t &m)
    186 {
    187   const tab_t *pt = e.begin ()->interface->get_pointer ();
    188   const sensitivity_list_t &sens = m.sensitivity_list;
    189   sensitivity_list_t::const_iterator it;
    190   for (it = sens.begin (); it != sens.end (); ++it)
    191   {
    192     const sc_event &event = *it;
    193     if (pt == event.get_interface().get_pointer ())
    194       return true;
    195   }
    196         return false;
    197 }
    198 
    199 static
    200 bool
    201 is_valid (const SignalDependency &s)
    202 {
    203 #if 0
    204   cerr << "'" << get_name (*(s.destination)) << "'"
    205        << " depends on '" << get_name (*(s.source)) << "'"
    206        << " in the module '" << s.method->module->name() << "'\n";
    207   return true;
    208 #endif
    209         if (is_in (*(s.source), *(s.method)))
    210     return true;
    211   const char *src = get_name (*(s.source));
    212   cerr << "'" << get_name (*(s.destination)) << "'"
    213        << " depends on '" << src << "'"
    214        << " in the module '" << s.method->module->name() << "'"
    215        << " but '" << src << "' is not in the sensitivity_list.\n";
    216   return false;
    217 }
    218 
    219 bool
    220 Check (const SignalDependencyGraph &g)
    221 {
    222         SignalDependencyGraph::const_iterator it;
    223         for (it = g.begin(); it != g.end(); ++it)
    224         {
    225                 const SignalDependency &s = (*it);
    226     if (!is_valid (s))
    227       return false;
    228   } 
    229   return true;
    230 }
    231 
    232 static
    233 bool
    234 is_in (const equi_t &e, const SignalDependencyGraph &g)
    235 {
    236   SignalDependencyGraph::const_iterator it;
    237   for (it = g.begin (); it != g.end (); ++it)
    238   {
    239     const SignalDependency &s = *it;
    240     if (&e == s.source)
    241       return true;
    242   }
    243         return false;
    244 }
    245 
    246 static
    247 bool
    248 is_in (const sensitivity_list_t &sens, const SignalDependencyGraph &g)
    249 {
    250   sensitivity_list_t::const_iterator it;
    251   for (it = sens.begin (); it != sens.end (); ++it)
    252   {
    253     const sc_event     &event = *it;
    254     const sc_interface &i     = event.get_interface();
    255     const equi_t       &equi  = get_equi (i);
    256                 if (is_clock (i))
    257       continue;
    258     if (!is_in (equi, g)) {
    259       cerr << "'" << get_name(equi) << "'"
    260            << " is in the sensitivity list of ";
    261       return false;
    262     }
    263   }
    264   return true;
    265 }
    266 
    267 bool
    268 Check       (const method_process_list_t &ml,
    269              const SignalDependencyGraph &g)
    270 {
    271         method_process_list_t::const_iterator it;
    272         for (it = ml.begin(); it != ml.end(); ++it)
    273         {
    274                 const method_process_t   &m = *(*it);
    275     const sensitivity_list_t &sens = m.sensitivity_list;
    276                 if (!is_in (sens, g))
    277     {
    278       cerr << "'" << m.module->name() << "' module instance "
    279            << "but any output port doesn't depend on this input.\n";
    280       return false;
    281     }
    282   } 
    283   return true;
    284 }
     54bool SignalDependency::operator < (const SignalDependency & b) const {
     55    if (source < b.source) {
     56        return true;
     57    }
     58    if (destination < b.destination) {
     59        return true;
     60    }
     61    return false;
     62}
     63
     64
     65static void txt_write(ofstream & o, const component_list_t & l) {
     66    component_list_t::const_iterator it;
     67    for (it = l.begin(); it != l.end(); ++it) {
     68        o << get_name(*((equi_t *) (*it))) << " ";
     69    }
     70}
     71
     72
     73static void txt_write(ofstream & o, const strong_component_list_t & l) {
     74    strong_component_list_t::const_iterator it;
     75    for (it = l.begin(); it != l.end(); ++it) {
     76        txt_write(o, **it);
     77        o <<  "\n";
     78    }
     79}
     80
     81
     82bool SignalDependencyOrder2txt(const char * name, const strong_component_list_t & l) {
     83    if (!name) {
     84        return false;
     85    }
     86    string filename;
     87    filename =  name;
     88    filename += ".txt";
     89    ofstream o;
     90    o.open(filename.c_str(),ios::out | ios::trunc);
     91    if (!o.is_open()) {
     92        return false;
     93    }
     94    txt_write(o, l);
     95    o.close();
     96    return true;
     97}
     98
     99
     100static void dot_write(ofstream & o, const SignalDependencyGraph & g) {
     101    string s;
     102    SignalDependencyGraph::const_iterator it;
     103    for (it = g.begin(); it != g.end(); ++it) {
     104        string name;
     105        name = it->method->module->name();
     106        name += "_";
     107        name += it->method->name;
     108        o << "edge [label="
     109            << simplify_name(name.c_str(), s)
     110            << "];\n";
     111        const equi_t * equi = it->source;
     112        name = get_name(*equi);
     113        o << simplify_name(name.c_str(), s);
     114        o << " -> ";
     115        equi = it->destination;
     116        name = get_name(*equi);
     117        o << simplify_name(name.c_str(), s);
     118        o << ";\n";
     119    }
     120}
     121
     122
     123bool SignalDependencyGraph2dot(const char * name, const SignalDependencyGraph & g) {
     124    if (!name) {
     125        return false;
     126    }
     127    string filename;
     128    filename =  name;
     129    filename += ".dot";
     130    ofstream o;
     131    o.open(filename.c_str(),ios::out | ios::trunc);
     132    if (!o.is_open()) {
     133        return false;
     134    }
     135    o << "// Signal dependency graph\n"
     136        "// Generated by "
     137        << sc_version() << "\n";
     138    o << "strict digraph " << name << " {\n";
     139    dot_write(o, g);
     140    o << "}\n";
     141    o.close();
     142    if (dump_stage) {
     143        cerr << "Signal Dependency Graph written into '"
     144            << filename << "'.\n";
     145    }
     146    return true;
     147}
     148
     149
     150SignalDependencyGraph * MakeSignalDependencyGraph(const PortDependencyGraph & g) {
     151    if (dump_stage) {
     152        cerr << "Making signal dependency graph...\n";
     153    }
     154
     155    SignalDependencyGraph * sig_g = new SignalDependencyGraph();
     156    PortDependencyGraph::const_iterator it;
     157    for (it = g.begin(); it != g.end(); ++it) {
     158        SignalDependency s;
     159        s.method = it->method;
     160        const sc_interface * inter;
     161        inter = it->source;
     162        if (inter) {
     163            s.source = &(get_equi(*inter));
     164        }
     165        else {
     166            continue;
     167        }
     168        inter = it->destination;
     169        s.destination = &(get_equi(*inter));
     170        sig_g->insert(s);
     171    }
     172    return sig_g;
     173}
     174
     175
     176static bool is_in(const equi_t & e, const method_process_t & m) {
     177    const tab_t * pt = e.begin()->interface->get_pointer();
     178    const sensitivity_list_t & sens = m.sensitivity_list;
     179    sensitivity_list_t::const_iterator it;
     180    for (it = sens.begin(); it != sens.end(); ++it) {
     181        const sc_event & event = *it;
     182        if (pt == event.get_interface().get_pointer()) {
     183            return true;
     184        }
     185    }
     186    return false;
     187}
     188
     189
     190static bool is_valid(const SignalDependency & s) {
     191    if (dump_stage) {
     192    cerr << "'" << get_name (*(s.destination)) << "'"
     193        << " depends on '" << get_name (*(s.source)) << "'"
     194        << " in the module '" << s.method->module->name() << "'\n";
     195    }
     196    if (is_in(*(s.source), *(s.method))) {
     197        return true;
     198    }
     199   
     200    const char * src = get_name(*(s.source));
     201    cerr << "'" << get_name(*(s.destination)) << "'"
     202        << " depends on '" << src << "'"
     203        << " in the module '" << s.method->module->name() << "'"
     204        << " but '" << src << "' is not in the sensitivity_list.\n";
     205    return false;
     206}
     207
     208
     209bool Check(const SignalDependencyGraph & g) {
     210    SignalDependencyGraph::const_iterator it;
     211    for (it = g.begin(); it != g.end(); ++it) {
     212        const SignalDependency &s = (*it);
     213        if (!is_valid(s)) {
     214            return false;
     215        }
     216
     217    } 
     218    return true;
     219}
     220
     221
     222static bool is_in(const equi_t & e, const SignalDependencyGraph & g) {
     223    SignalDependencyGraph::const_iterator it;
     224    for (it = g.begin(); it != g.end(); ++it) {
     225        const SignalDependency & s = *it;
     226        if (&e == s.source) {
     227            return true;
     228        }
     229
     230    }
     231    return false;
     232}
     233
     234
     235static bool is_in(const sensitivity_list_t & sens, const SignalDependencyGraph & g) {
     236    sensitivity_list_t::const_iterator it;
     237    for (it = sens.begin(); it != sens.end(); ++it) {
     238        const sc_event & event = *it;
     239        const sc_interface & i = event.get_interface();
     240        const equi_t & equi = get_equi(i);
     241        if (is_clock(i)) {
     242            continue;
     243        }
     244        if (!is_in(equi, g)) {
     245            cerr << "'" << get_name(equi) << "' is in the sensitivity list of ";
     246            return false;
     247        }
     248    }
     249    return true;
     250}
     251
     252
     253bool Check(const method_process_list_t & ml, const SignalDependencyGraph & g) {
     254    method_process_list_t::const_iterator it;
     255    for (it = ml.begin(); it != ml.end(); ++it) {
     256        const method_process_t & m = *(*it);
     257        const sensitivity_list_t & sens = m.sensitivity_list;
     258        if (!is_in(sens, g)) {
     259            cerr << "'" << m.module->name() << "' module instance "
     260                 << "but any output port doesn't depend on this input.\n";
     261            return false;
     262        }
     263    } 
     264    return true;
     265}
     266
    285267
    286268} // end of sc_core namespace
    287269
     270/*
     271# Local Variables:
     272# tab-width: 4;
     273# c-basic-offset: 4;
     274# c-file-offsets:((innamespace . 0)(inline-open . 0));
     275# indent-tabs-mode: nil;
     276# End:
     277#
     278# vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4
     279*/
     280
Note: See TracChangeset for help on using the changeset viewer.