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