source: sources/src/sc_main.cc @ 52

Last change on this file since 52 was 52, checked in by meunier, 11 years ago

Code formatting in all source files.

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