source: sources/src/methodprocess_dependency.cc @ 3

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

Initial import from CVS repository

File size: 4.2 KB
Line 
1/*------------------------------------------------------------\
2|                                                             |
3| Tool    :                  systemcass                       |
4|                                                             |
5| File    :           methodprocess_dependency.cc             |
6|                                                             |
7| Author  :                 Buchmann Richard                  |
8|                                                             |
9| Date    :                   22_11_2005                      |
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 "assert.h"
37#include "methodprocess_dependency.h"
38#include "simplify_string.h"
39#include "sc_module.h"
40#include <iostream>
41#include <fstream>
42
43using namespace std;
44namespace sc_core {
45
46string
47get_name (const method_process_t *method)
48{
49  ASSERT(method != NULL);
50  const sc_module *module = method->module;
51  ASSERT(module != NULL);
52  const char *module_name = module->name ();
53  const char *function_name = method->name;
54 
55  string name = module_name;
56  name += "_";
57  name += function_name;
58  return name;
59}
60
61static
62bool
63dot_write (ofstream &o,
64           const SignalDependencyGraph &sig)
65{
66  // Preparing data
67  typedef map<const equi_t *, const method_process_t *> table_t;
68  table_t table;
69 
70  // For each arrow, add destination node into table
71        SignalDependencyGraph::const_iterator sig_it;
72        for (sig_it = sig.begin (); sig_it != sig.end (); ++sig_it)
73  {
74    const SignalDependency &sd     = *sig_it;
75    const equi_t           *equi   = sd.destination;
76          const method_process_t *method = sd.method;
77    table[equi] = method;
78  }
79
80  // Printing into dot file
81        string s;
82  SignalDependencyGraph::const_iterator it;
83  for (it = sig.begin (); it != sig.end (); ++it)
84  {
85    const SignalDependency &sd = *it;
86    const equi_t           *source_equi     = sd.source;
87    ASSERT(source_equi != NULL);
88          const method_process_t *source_method   = table[source_equi];
89    if (source_method == NULL)
90      continue;
91    string                  source_method_name = get_name (source_method);
92    string                  source_equi_name = get_name (*source_equi);
93          const method_process_t *destination_method = sd.method;
94    string                  destination_method_name = get_name (destination_method);
95                o << "edge [label="
96      << simplify_name(source_equi_name.c_str(),s)
97      << "];\n";
98                o << simplify_name(source_method_name.c_str(),s);
99                o       << " -> ";
100                o << simplify_name(destination_method_name.c_str(),s);
101          o << ";\n";
102  }
103}
104
105bool 
106MethodProcessDependencyGraph2dot (const char *name,
107                                  const SignalDependencyGraph& sig)
108{
109        if (!name)
110                return false;
111        string filename;
112        filename =  name;
113        filename += ".dot";
114        ofstream o;
115  o.open (filename.c_str(),ios::out | ios::trunc);
116        if (o.is_open () == false)
117                return false;
118        o << "strict digraph " << name << " {\n";
119        dot_write (o,sig);
120  // Closing dot file
121        o << "}\n";
122        o.close ();
123  if (dump_stage)
124    cerr << "MethodProcess dependency graph written into '" 
125         << filename << "'.\n";
126        return true;
127}
128
129} // end of sc_core namespace
130
Note: See TracBrowser for help on using the repository browser.