source: sources/src/sc_main.cc @ 35

Last change on this file since 35 was 35, checked in by buchmann, 15 years ago

Code cleanup.

Add --dynamiclink option to systemcass executable.

File size: 11.2 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#include <cassert>
42
43#include "internal.h"
44#include "global_functions.h"
45#include "sc_ver.h"
46#include "sc_module.h"
47#include "sc_signal.h" // pending_write_vector
48#include "dump_dot.h"
49#include "dump_used_options.h"
50#include "dump_used_env.h"
51
52#ifdef HAVE_CONFIG_H
53#include "config.h"
54#endif
55
56//
57using namespace std;
58using namespace sc_core;
59//
60typedef list<sc_module* >         module_list_t;
61
62//
63namespace sc_core {
64
65bool        check_port_dependencies = false;
66#ifdef CONFIG_DEFAULT_RUNTIME_COMPILATION
67bool        dynamic_link_of_scheduling_code = true;
68#else
69bool        dynamic_link_of_scheduling_code = false;
70#endif
71bool        dump_netlist_info       = false;
72bool        dump_funclist_info      = false;
73bool        dump_stage              = false;
74bool        dump_all_graph          = false;
75const char* dump_module_hierarchy   = NULL;
76bool        edit_schedule           = false;
77bool        keep_generated_code     = false;
78bool        nobanner                = false;
79bool        noinitialization        = false;
80bool        nosimulation            = false;
81bool        notrace                 = false;
82bool        print_schedule          = false;
83bool        print_user_resources    = false;
84char*       save_on_exit            = NULL;
85int         scheduling_method       = NO_SCHEDULING;
86bool        use_sensitivity_list    = false;
87bool        use_port_dependency     = false;
88
89static
90void 
91print_splash_screen ()
92{
93  // Display once
94  if (nobanner == false)
95        cerr << get_splash_screen ();
96  nobanner = true;
97}
98
99static
100void
101check_parameters ()
102{
103  if (dump_all_graph) {
104    if (use_port_dependency)
105      cerr << "SystemCASS will dump signal dependency graph.\n";
106    else
107      cerr << "SystemCASS will dump module dependency graph.\n";
108  }
109  if (!use_port_dependency && check_port_dependencies)
110    cerr << "Warning : unable to check port dependencies.\n";
111  if (!use_port_dependency)
112  {
113    use_sensitivity_list = true;
114    scheduling_method = CASS_SCHEDULING;
115  }
116  switch (scheduling_method) {
117  case CASS_SCHEDULING :
118    assert(use_port_dependency == false);
119    break;
120  case BUCHMANN_SCHEDULING :
121  case MOUCHARD_SCHEDULING :
122    if (!use_port_dependency) {
123    cerr << "Error : "
124            "The choosen scheduling needs port dependencies informations\n";
125    exit (31);
126    }
127    break;
128  default :
129    cerr << "Error : You need to choose one of the available scheduling :\n"
130         << "- Almost static scheduling like CASS (use sensitivity list)\n"
131         << "- Simple static scheduling (use port dependencies)\n"
132         << "- Entirely static scheduling (use port dependencies)\n";
133    exit (33);
134  }
135  assert(use_port_dependency || use_sensitivity_list);
136}
137
138void
139apply_parameters (int &argc, char ** &argv)
140{
141#ifdef KEEP_GENERATED_CODE // supprimer scheduling-XXXXXX.cc
142  keep_generated_code = true;
143#endif
144#ifdef DUMP_NETLIST_INFO
145  dump_netlist_info = true;
146#endif
147#ifdef DUMP_FUNCLIST_INFO
148  dump_funclist_info = true;
149#endif
150#ifdef DUMP_STAGE
151  dump_stage = true;
152#endif
153#ifdef DUMP_COMBINATIONAL_LIST2DOT
154  dump_all_graph = true;
155#endif
156#ifdef PRINT_SCHEDULE
157  print_schedule = true;
158#endif   
159#ifdef USE_PORT_DEPENDENCY
160  use_port_dependency = true;
161#endif
162  // parse the command line
163  int i;
164  for (i = 1; i < argc; ++i)
165    {
166    if (argv[i][0] == '-')
167      {
168      if (argv[i][1] == '-')
169        {
170        switch (argv[i][2])
171          {
172          case 'h' : 
173            print_splash_screen ();
174            cerr << "Usage : " 
175                 << 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"
176                 << "Thoses options are processed by SystemCASS library. All the remaining options are passed to sc_main.\n"
177                 << "sc_main function retrieves last parameters.\n"
178                 << "a       : almost static scheduling (use sensitivity list instead of port dependency information)\n"
179                 << "c       : print schedule at simulation time (stderr)\n"
180                 << "d       : check port dependencies (stderr)\n"
181                 << "edit    : edit schedule before simulation (run $EDITOR or vim by default)\n"
182                 << "f       : print function list (stderr)\n"
183                 << "h       : display help screen and exit (stdout)\n"
184                 << "i       : print instances list, signals list and statistics if available (stderr)\n"
185                 << "k       : dump generated scheduling code (generated_by_systemcass/scheduling-xx.cc)\n"
186                 << "m       : Mouchard's static scheduling (use port dependency information instead of sensitivity list)\n"
187                 << "modules filename : dump module hierarchy graph into specified dot file (tons of bugs inside)\n"
188                 << "nobanner: do not print SystemCASS splash screen\n"
189                 << "dynamiclink: dynamically link the scheduling code\n"
190                 << "nosim   : run until elaboration stage. Don't simulate\n"
191                 << "notrace : disable all tracing functions\n"
192                 << "p       : entirely static scheduling (use port dependency information instead of sensitivity list)\n"
193                 << "s       : print stage (stderr)\n"
194                 << "save_on_exit <name> : save simulation state saved into <name> file when SystemCASS exits (SOCVIEW format)\n"
195            /* WARNING : we can't avoid destructors execution before saving */
196                 << "t       : dump either module graph, or signal dependency graph, signal order, and module evalutation order into dot files\n"
197                 << "tracestart n : start tracing functions at #n cycle\n"
198                 << "usage   : print user time elapsed (sec), simulation cycles done (cycles), and simulator performance (cycles/second) (stderr)\n"
199                 << "v       : print internal SystemCASS kernel options (stderr)\n";
200            noinitialization = true;
201            nosimulation = true;
202            continue;
203          case 'v' : 
204            print_splash_screen ();
205            cerr << get_used_options  () << "\n";
206            cerr << get_used_env () << "\n";
207            continue;
208          case 'u' : 
209            if (strcmp (argv[i]+2, "usage") == 0)
210              print_user_resources = true;
211            else
212              break;
213            continue;
214          case 'i' :
215            dump_netlist_info = true;
216            continue;
217          case 'f' :
218            dump_funclist_info = true;
219            continue;
220          case 's' :
221            if (strcmp (argv[i]+2, "save_on_exit") == 0)
222              save_on_exit = argv[++i];
223            else
224              dump_stage = true;
225            continue;
226          case 'c' :
227            print_schedule = true;
228            continue;
229          case 'd' :
230            if (strcmp (argv[i]+2, "dynamiclink") == 0)
231              dynamic_link_of_scheduling_code = true;
232            else
233              check_port_dependencies = true;
234            continue;
235          case 'e' :
236            if (strcmp (argv[i]+2, "edit") == 0)
237              edit_schedule = true;
238            else
239              break;
240            continue;
241          case 'k' :
242            keep_generated_code = true;
243            continue;
244          case 't' :
245            if (strcmp (argv[i]+2, "tracestart") == 0) {
246              ++i;
247              istringstream iss (argv[i]);
248              iss >> trace_start;
249              trace_start <<= 1;
250//              trace_start = strtoll (argv[i],0,10) << 1;
251//              trace_start = atoll (argv[i]) << 1;
252            } else {
253              dump_all_graph = true;
254            }
255            continue;
256          case 'm' :
257            if (strcmp (argv[i]+2, "modules") == 0) {
258              ++i;
259              dump_module_hierarchy = argv[i];
260              continue;
261            } else if (strcmp (argv[i]+2, "m") == 0) {
262              use_port_dependency = true;
263              scheduling_method = MOUCHARD_SCHEDULING;
264              continue;
265            }
266            break;
267          case 'n' :
268            if (strcmp (argv[i]+2, "nobanner") == 0) {
269              nobanner = true;
270            } else if (strcmp (argv[i]+2, "nodynamiclink") == 0) {
271              dynamic_link_of_scheduling_code = false;
272            } else if (strcmp (argv[i]+2, "nosim") == 0) {
273              nosimulation = true;
274            } else if (strcmp (argv[i]+2, "notrace") == 0) {
275              notrace = true;
276            } else
277              break;
278            continue;
279          case 'a' :
280            use_sensitivity_list = true;
281            scheduling_method = CASS_SCHEDULING;
282            continue;
283          case 'p' :
284            use_port_dependency = true;
285            scheduling_method = BUCHMANN_SCHEDULING;
286            continue;
287          default :
288            break;
289          }
290        break;
291        }
292      } 
293      break;
294    }
295 
296  // erase SystemCASS options from the command line and give it to the sc_main
297  if (i != 1)
298    {
299    int j = 1;
300    while (i < argc)
301      {
302      argv[j++] = argv[i++];
303      }
304    argc = j;
305    }
306#if 0
307  cerr << "The user command line length is " << argc << ".\n";
308#endif
309}
310
311
312} // end of namespace
313
314using namespace sc_core;
315
316int 
317main(int   argc, 
318     char* argv[])
319{
320  apply_parameters    (argc, argv);
321  print_splash_screen ();
322  check_parameters ();
323  if (noinitialization)
324  {
325    return 255;
326  }
327  int ret = sc_main(argc, argv);
328        free (pending_write_vector);
329  close_systemcass ();
330  if (have_to_stop)
331  {
332    cerr << "'sc_stop' function was called. Exit code : 1\n";
333    return 1;
334  }
335  return ret;
336}
337
Note: See TracBrowser for help on using the repository browser.