source: sources/src/sc_main.cc @ 60

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