source: branches/with_autoconf/src/sc_main.cc @ 20

Last change on this file since 20 was 20, checked in by nipo, 15 years ago

Sync up with trunk changes

File size: 11.1 KB
Line 
1/*------------------------------------------------------------\
2|                                                             |
3| Tool    :                  systemcass                       |
4|                                                             |
5| File    :                   sc_main.cc                      |
6|                                                             |
7| Author  :                 Buchmann Richard                  |
8|                           Taktak Sami                       |
9|                                                             |
10| Date    :                   09_07_2004                      |
11|                                                             |
12\------------------------------------------------------------*/
13
14/*
15 * This file is part of the Disydent Project
16 * Copyright (C) Laboratoire UPMC/LIP6
17 * Universite Pierre et Marie Curie
18 *
19 * Home page          : http://www-asim.lip6.fr/disydent
20 * E-mail             : mailto:richard.buchmann@lip6.fr
21 *
22 * This library is free software; you  can redistribute it and/or modify it
23 * under the terms  of the GNU Library General Public  License as published
24 * by the Free Software Foundation; either version 2 of the License, or (at
25 * your option) any later version.
26 *
27 * Disydent is distributed  in the hope  that it  will be
28 * useful, but WITHOUT  ANY WARRANTY; without even the  implied warranty of
29 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
30 * Public License for more details.
31 *
32 * You should have received a copy  of the GNU General Public License along
33 * with the GNU C Library; see the  file COPYING. If not, write to the Free
34 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
35 */
36
37#include <sstream>
38#include <list>
39#include <set>
40#include <cstring> // strcmp
41
42#include "internal.h"
43#include "global_functions.h"
44#include "sc_ver.h"
45#include "sc_module.h"
46#include "sc_signal.h" // pending_write_vector
47#include "dump_dot.h"
48#include "dump_used_options.h"
49#include "dump_used_env.h"
50#include <cassert>
51#ifdef HAVE_CONFIG_H
52#include "config.h"
53#endif
54
55//
56using namespace std;
57using namespace sc_core;
58//
59typedef list<sc_module* >         module_list_t;
60
61//
62namespace sc_core {
63
64bool        check_port_dependencies = false;
65#ifdef CONFIG_DEFAULT_RUNTIME_COMPILATION
66bool        dynamic_link_of_scheduling_code = true;
67#else
68bool        dynamic_link_of_scheduling_code = false;
69#endif
70bool        dump_netlist_info       = false;
71bool        dump_funclist_info      = false;
72bool        dump_stage              = false;
73bool        dump_all_graph          = false;
74const char* dump_module_hierarchy   = NULL;
75bool        edit_schedule           = false;
76bool        keep_generated_code     = false;
77bool        nobanner                = false;
78bool        noinitialization        = false;
79bool        nosimulation            = false;
80bool        notrace                 = false;
81bool        print_schedule          = false;
82bool        print_user_resources    = false;
83char*       save_on_exit            = NULL;
84int         scheduling_method       = NO_SCHEDULING;
85bool        use_sensitivity_list    = false;
86bool        use_port_dependency     = false;
87
88static
89void 
90print_splash_screen ()
91{
92  // Display once
93  if (nobanner == false)
94        cerr << get_splash_screen ();
95  nobanner = true;
96}
97
98static
99void
100check_parameters ()
101{
102  if (dump_all_graph) {
103    if (use_port_dependency)
104      cerr << "SystemCASS will dump signal dependency graph.\n";
105    else
106      cerr << "SystemCASS will dump module dependency graph.\n";
107  }
108  if (!use_port_dependency && check_port_dependencies)
109    cerr << "Warning : unable to check port dependencies.\n";
110  if (!use_port_dependency)
111  {
112    use_sensitivity_list = true;
113    scheduling_method = CASS_SCHEDULING;
114  }
115  switch (scheduling_method) {
116  case CASS_SCHEDULING :
117    assert(use_port_dependency == false);
118    break;
119  case BUCHMANN_SCHEDULING :
120  case MOUCHARD_SCHEDULING :
121    if (!use_port_dependency) {
122    cerr << "Error : "
123            "The choosen scheduling needs port dependencies informations\n";
124    exit (31);
125    }
126    break;
127  default :
128    cerr << "Error : You need to choose one of the available scheduling :\n"
129         << "- Almost static scheduling like CASS (use sensitivity list)\n"
130         << "- Simple static scheduling (use port dependencies)\n"
131         << "- Entirely static scheduling (use port dependencies)\n";
132    exit (33);
133  }
134  assert(use_port_dependency || use_sensitivity_list);
135}
136
137void
138apply_parameters (int &argc, char ** &argv)
139{
140#ifdef KEEP_GENERATED_CODE // supprimer scheduling-XXXXXX.cc
141  keep_generated_code = true;
142#endif
143#ifdef DUMP_NETLIST_INFO
144  dump_netlist_info = true;
145#endif
146#ifdef DUMP_FUNCLIST_INFO
147  dump_funclist_info = true;
148#endif
149#ifdef DUMP_STAGE
150  dump_stage = true;
151#endif
152#ifdef DUMP_COMBINATIONAL_LIST2DOT
153  dump_all_graph = true;
154#endif
155#ifdef PRINT_SCHEDULE
156  print_schedule = true;
157#endif   
158#ifdef USE_PORT_DEPENDENCY
159  use_port_dependency = true;
160#endif
161  // parse the command line
162  int i;
163  for (i = 1; i < argc; ++i)
164    {
165    if (argv[i][0] == '-')
166      {
167      if (argv[i][1] == '-')
168        {
169        switch (argv[i][2])
170          {
171          case 'h' : 
172            print_splash_screen ();
173            cerr << "Usage : " 
174                 << argv[0] << " [--c] [--edit] [--d] [--f] [--h] [--i] [--k] [--modules filename] [--nobanner] [--nodynamiclink] [--nosim] [--notrace] [--s] [--t] [--tracestart n] [--usage] [--v] [--p|m|a] [others parameters processed by sc_main]\n"
175                 << "Thoses options are processed by SystemCASS library. All the remaining options are passed to sc_main.\n"
176                 << "sc_main function retrieves last parameters.\n"
177                 << "a       : almost static scheduling (use sensitivity list instead of port dependency information)\n"
178                 << "c       : print schedule at simulation time (stderr)\n"
179                 << "d       : check port dependencies (stderr)\n"
180                 << "edit    : edit schedule before simulation (run $EDITOR or vim by default)\n"
181                 << "f       : print function list (stderr)\n"
182                 << "h       : display help screen and exit (stdout)\n"
183                 << "i       : print instances list, signals list and statistics if available (stderr)\n"
184                 << "k       : dump generated scheduling code (generated_by_systemcass/scheduling-xx.cc)\n"
185                 << "m       : Mouchard's static scheduling (use port dependency information instead of sensitivity list)\n"
186                 << "modules filename : dump module hierarchy graph into specified dot file (tons of bugs inside)\n"
187                 << "nobanner: do not print SystemCASS splash screen\n"
188                 << "nodynamiclink: do not link dynamically scheduling code\n"
189                 << "nosim   : run until elaboration stage. Don't simulate\n"
190                 << "notrace : disable all tracing functions\n"
191                 << "p       : entirely static scheduling (use port dependency information instead of sensitivity list)\n"
192                 << "s       : print stage (stderr)\n"
193                 << "save_on_exit <name> : save simulation state saved into <name> file when SystemCASS exits (SOCVIEW format)\n"
194            /* WARNING : we can't avoid destructors execution before saving */
195                 << "t       : dump either module graph, or signal dependency graph, signal order, and module evalutation order into dot files\n"
196                 << "tracestart n : start tracing functions at #n cycle\n"
197                 << "usage   : print user time elapsed (sec), simulation cycles done (cycles), and simulator performance (cycles/second) (stderr)\n"
198                 << "v       : print internal SystemCASS kernel options (stderr)\n";
199            noinitialization = true;
200            nosimulation = true;
201            continue;
202          case 'v' : 
203            print_splash_screen ();
204            cerr << get_used_options  () << "\n";
205            cerr << get_used_env () << "\n";
206            continue;
207          case 'u' : 
208            if (strcmp (argv[i]+2, "usage") == 0)
209              print_user_resources = true;
210            else
211              break;
212            continue;
213          case 'i' :
214            dump_netlist_info = true;
215            continue;
216          case 'f' :
217            dump_funclist_info = true;
218            continue;
219          case 's' :
220            if (strcmp (argv[i]+2, "save_on_exit") == 0)
221              save_on_exit = argv[++i];
222            else
223              dump_stage = true;
224            continue;
225          case 'c' :
226            print_schedule = true;
227            continue;
228          case 'e' :
229            if (strcmp (argv[i]+2, "edit") == 0)
230              edit_schedule = true;
231            else
232              break;
233            continue;
234          case 'k' :
235            keep_generated_code = true;
236            continue;
237          case 't' :
238            if (strcmp (argv[i]+2, "tracestart") == 0) {
239              ++i;
240              istringstream iss (argv[i]);
241              iss >> trace_start;
242              trace_start <<= 1;
243//              trace_start = strtoll (argv[i],0,10) << 1;
244//              trace_start = atoll (argv[i]) << 1;
245            } else {
246              dump_all_graph = true;
247            }
248            continue;
249          case 'm' :
250            if (strcmp (argv[i]+2, "modules") == 0) {
251              ++i;
252              dump_module_hierarchy = argv[i];
253              continue;
254            } else if (strcmp (argv[i]+2, "m") == 0) {
255              use_port_dependency = true;
256              scheduling_method = MOUCHARD_SCHEDULING;
257              continue;
258            }
259            break;
260          case 'n' :
261            if (strcmp (argv[i]+2, "nobanner") == 0) {
262              nobanner = true;
263            } else if (strcmp (argv[i]+2, "nodynamiclink") == 0) {
264              dynamic_link_of_scheduling_code = false;
265            } else if (strcmp (argv[i]+2, "nosim") == 0) {
266              nosimulation = true;
267            } else if (strcmp (argv[i]+2, "notrace") == 0) {
268              notrace = true;
269            } else
270              break;
271            continue;
272          case 'a' :
273            use_sensitivity_list = true;
274            scheduling_method = CASS_SCHEDULING;
275            continue;
276          case 'p' :
277            use_port_dependency = true;
278            scheduling_method = BUCHMANN_SCHEDULING;
279            continue;
280          case 'd' :
281            check_port_dependencies = true;
282            continue;
283          default :
284            break;
285          }
286        break;
287        }
288      } 
289      break;
290    }
291 
292  // erase SystemCASS options from the command line and give it to the sc_main
293  if (i != 1)
294    {
295    int j = 1;
296    while (i < argc)
297      {
298      argv[j++] = argv[i++];
299      }
300    argc = j;
301    }
302#if 0
303  cerr << "The user command line length is " << argc << ".\n";
304#endif
305}
306
307
308} // end of namespace
309
310using namespace sc_core;
311
312int 
313main(int   argc, 
314     char* argv[])
315{
316  apply_parameters    (argc, argv);
317  print_splash_screen ();
318  check_parameters ();
319  if (noinitialization)
320  {
321    return 255;
322  }
323  int ret = sc_main(argc, argv);
324        free (pending_write_vector);
325  close_systemcass ();
326  if (have_to_stop)
327  {
328    cerr << "'sc_stop' function was called. Exit code : 1\n";
329    return 1;
330  }
331  return ret;
332}
333
Note: See TracBrowser for help on using the repository browser.