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 | // |
---|
57 | using namespace std; |
---|
58 | using namespace sc_core; |
---|
59 | // |
---|
60 | typedef list<sc_module* > module_list_t; |
---|
61 | |
---|
62 | // |
---|
63 | namespace sc_core { |
---|
64 | |
---|
65 | bool check_port_dependencies = false; |
---|
66 | #ifdef CONFIG_DEFAULT_RUNTIME_COMPILATION |
---|
67 | bool dynamic_link_of_scheduling_code = true; |
---|
68 | #else |
---|
69 | bool dynamic_link_of_scheduling_code = false; |
---|
70 | #endif |
---|
71 | bool dump_netlist_info = false; |
---|
72 | bool dump_funclist_info = false; |
---|
73 | bool dump_stage = false; |
---|
74 | bool dump_all_graph = false; |
---|
75 | const char* dump_module_hierarchy = NULL; |
---|
76 | bool edit_schedule = false; |
---|
77 | bool keep_generated_code = false; |
---|
78 | bool nobanner = false; |
---|
79 | bool noinitialization = false; |
---|
80 | bool nosimulation = false; |
---|
81 | bool notrace = false; |
---|
82 | bool print_schedule = false; |
---|
83 | bool print_user_resources = false; |
---|
84 | char* save_on_exit = NULL; |
---|
85 | int scheduling_method = NO_SCHEDULING; |
---|
86 | bool use_sensitivity_list = false; |
---|
87 | bool use_port_dependency = false; |
---|
88 | |
---|
89 | #ifdef _OPENMP |
---|
90 | bool use_openmp = true; |
---|
91 | #else |
---|
92 | bool use_openmp = false; |
---|
93 | #endif |
---|
94 | |
---|
95 | const char *HELP_STRING = \ |
---|
96 | "\n" |
---|
97 | "--a\n" |
---|
98 | " almost static scheduling (use sensitivity list instead of port\n" |
---|
99 | " dependency information\n" |
---|
100 | "\n" |
---|
101 | "--c\n" |
---|
102 | " print schedule at simulation time (stderr)\n" |
---|
103 | "\n" |
---|
104 | "--d\n" |
---|
105 | " check port dependencies (stderr)\n" |
---|
106 | "\n" |
---|
107 | "--edit\n" |
---|
108 | " edit schedule before simulation (run $EDITOR or vim by default)\n" |
---|
109 | "\n" |
---|
110 | "--f\n" |
---|
111 | " print function list (stderr)\n" |
---|
112 | "\n" |
---|
113 | "--h\n" |
---|
114 | " display help screen and exit (stdout)\n" |
---|
115 | "\n" |
---|
116 | "--i\n" |
---|
117 | " print instances list, signals list and statistics if available (stderr)\n" |
---|
118 | "\n" |
---|
119 | "--k\n" |
---|
120 | " dump generated scheduling code\n" |
---|
121 | " (generated_by_systemcass/scheduling-xx.cc)\n" |
---|
122 | "\n" |
---|
123 | "--m\n" |
---|
124 | " Mouchard's static scheduling (use port dependency information instead\n" |
---|
125 | " of sensitivity list)\n" |
---|
126 | "\n" |
---|
127 | "--modules <filename>\n" |
---|
128 | " dump module hierarchy graph into specified dot file (tons of bugs\n" |
---|
129 | " inside)\n" |
---|
130 | "\n" |
---|
131 | "--nobanner\n" |
---|
132 | " do not print SystemCASS splash screen\n" |
---|
133 | "\n" |
---|
134 | "--dynamiclink\n" |
---|
135 | " dynamically link the scheduling code\n" |
---|
136 | "\n" |
---|
137 | "--nosim\n" |
---|
138 | " run until elaboration stage. Don't simulate\n" |
---|
139 | "\n" |
---|
140 | "--notrace\n" |
---|
141 | " disable all tracing functions\n" |
---|
142 | "\n" |
---|
143 | "--p\n" |
---|
144 | " entirely static scheduling (use port dependency information instead of\n" |
---|
145 | " sensitivity list)\n" |
---|
146 | "\n" |
---|
147 | "--s\n" |
---|
148 | " print stage (stderr)\n" |
---|
149 | "\n" |
---|
150 | "--save_on_exit <name>\n" |
---|
151 | " save simulation state saved into <name> file when SystemCASS exits\n" |
---|
152 | " (SOCVIEW format)\n" |
---|
153 | "\n" |
---|
154 | /* WARNING : we can't avoid destructors execution before saving */ |
---|
155 | "--t\n" |
---|
156 | " dump either module graph, or signal dependency graph, signal order,\n" |
---|
157 | " and module evalutation order into dot files\n" |
---|
158 | "\n" |
---|
159 | "--tracestart <n>\n" |
---|
160 | " start tracing functions at #n cycle\n" |
---|
161 | "\n" |
---|
162 | "--usage\n" |
---|
163 | " print user time elapsed (sec), simulation cycles done (cycles),\n" |
---|
164 | " and simulator performance (cycles/second) (stderr)\n" |
---|
165 | "\n" |
---|
166 | "--v\n" |
---|
167 | " print internal SystemCASS kernel options (stderr)\n" |
---|
168 | "\n"; |
---|
169 | |
---|
170 | |
---|
171 | static |
---|
172 | void |
---|
173 | print_splash_screen () |
---|
174 | { |
---|
175 | // Display once |
---|
176 | if (nobanner == false) |
---|
177 | cerr << get_splash_screen (); |
---|
178 | nobanner = true; |
---|
179 | } |
---|
180 | |
---|
181 | static |
---|
182 | void |
---|
183 | check_parameters () |
---|
184 | { |
---|
185 | if (dump_all_graph) { |
---|
186 | if (use_port_dependency) |
---|
187 | cerr << "SystemCASS will dump signal dependency graph.\n"; |
---|
188 | else |
---|
189 | cerr << "SystemCASS will dump module dependency graph.\n"; |
---|
190 | } |
---|
191 | if (!use_port_dependency && check_port_dependencies) |
---|
192 | cerr << "Warning : unable to check port dependencies.\n"; |
---|
193 | if (!use_port_dependency) |
---|
194 | { |
---|
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 | void |
---|
221 | apply_parameters (int &argc, char ** &argv) |
---|
222 | { |
---|
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 | { |
---|
248 | if (argv[i][0] == '-') |
---|
249 | { |
---|
250 | if (argv[i][1] == '-') |
---|
251 | { |
---|
252 | switch (argv[i][2]) |
---|
253 | { |
---|
254 | case 'h' : |
---|
255 | print_splash_screen (); |
---|
256 | cerr << "Usage : " |
---|
257 | << 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" |
---|
258 | << "Thoses options are processed by SystemCASS library. All the remaining options are passed to sc_main.\n" |
---|
259 | << "sc_main function retrieves last parameters.\n" |
---|
260 | << HELP_STRING; |
---|
261 | noinitialization = true; |
---|
262 | nosimulation = true; |
---|
263 | continue; |
---|
264 | case 'v' : |
---|
265 | print_splash_screen (); |
---|
266 | cerr << get_used_options () << "\n"; |
---|
267 | cerr << get_used_env () << "\n"; |
---|
268 | cerr << sc_version () << "\n\n"; |
---|
269 | exit (0); |
---|
270 | case 'u' : |
---|
271 | if (strcmp (argv[i]+2, "usage") == 0) |
---|
272 | print_user_resources = true; |
---|
273 | else |
---|
274 | break; |
---|
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 | else |
---|
286 | dump_stage = true; |
---|
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 | else |
---|
295 | check_port_dependencies = true; |
---|
296 | continue; |
---|
297 | case 'e' : |
---|
298 | if (strcmp (argv[i]+2, "edit") == 0) |
---|
299 | edit_schedule = true; |
---|
300 | else |
---|
301 | break; |
---|
302 | continue; |
---|
303 | case 'k' : |
---|
304 | keep_generated_code = true; |
---|
305 | continue; |
---|
306 | case 't' : |
---|
307 | if (strcmp (argv[i]+2, "tracestart") == 0) { |
---|
308 | ++i; |
---|
309 | istringstream iss (argv[i]); |
---|
310 | iss >> trace_start; |
---|
311 | trace_start <<= 1; |
---|
312 | // trace_start = strtoll (argv[i],0,10) << 1; |
---|
313 | // trace_start = atoll (argv[i]) << 1; |
---|
314 | } else { |
---|
315 | dump_all_graph = true; |
---|
316 | } |
---|
317 | continue; |
---|
318 | case 'm' : |
---|
319 | if (strcmp (argv[i]+2, "modules") == 0) { |
---|
320 | ++i; |
---|
321 | dump_module_hierarchy = argv[i]; |
---|
322 | continue; |
---|
323 | } else if (strcmp (argv[i]+2, "m") == 0) { |
---|
324 | use_port_dependency = true; |
---|
325 | scheduling_method = MOUCHARD_SCHEDULING; |
---|
326 | continue; |
---|
327 | } |
---|
328 | break; |
---|
329 | case 'n' : |
---|
330 | if (strcmp (argv[i]+2, "nobanner") == 0) { |
---|
331 | nobanner = true; |
---|
332 | } else if (strcmp (argv[i]+2, "nodynamiclink") == 0) { |
---|
333 | dynamic_link_of_scheduling_code = false; |
---|
334 | } else if (strcmp (argv[i]+2, "nosim") == 0) { |
---|
335 | nosimulation = true; |
---|
336 | } else if (strcmp (argv[i]+2, "notrace") == 0) { |
---|
337 | notrace = true; |
---|
338 | } else |
---|
339 | break; |
---|
340 | continue; |
---|
341 | case 'a' : |
---|
342 | use_sensitivity_list = true; |
---|
343 | scheduling_method = CASS_SCHEDULING; |
---|
344 | continue; |
---|
345 | case 'p' : |
---|
346 | use_port_dependency = true; |
---|
347 | scheduling_method = BUCHMANN_SCHEDULING; |
---|
348 | continue; |
---|
349 | default : |
---|
350 | break; |
---|
351 | } |
---|
352 | break; |
---|
353 | } |
---|
354 | } |
---|
355 | break; |
---|
356 | } |
---|
357 | |
---|
358 | // erase SystemCASS options from the command line and give it to the sc_main |
---|
359 | if (i != 1) |
---|
360 | { |
---|
361 | int j = 1; |
---|
362 | while (i < argc) |
---|
363 | { |
---|
364 | argv[j++] = argv[i++]; |
---|
365 | } |
---|
366 | argc = j; |
---|
367 | } |
---|
368 | #if 0 |
---|
369 | cerr << "The user command line length is " << argc << ".\n"; |
---|
370 | #endif |
---|
371 | } |
---|
372 | |
---|
373 | |
---|
374 | } // end of namespace |
---|
375 | |
---|
376 | using namespace sc_core; |
---|
377 | |
---|
378 | int |
---|
379 | main(int argc, |
---|
380 | char* argv[]) |
---|
381 | { |
---|
382 | apply_parameters (argc, argv); |
---|
383 | print_splash_screen (); |
---|
384 | check_parameters (); |
---|
385 | |
---|
386 | if (noinitialization) |
---|
387 | { |
---|
388 | return 255; |
---|
389 | } |
---|
390 | |
---|
391 | int ret = sc_main(argc, argv); |
---|
392 | free (pending_write_vector); |
---|
393 | close_systemcass (); |
---|
394 | |
---|
395 | if (have_to_stop) |
---|
396 | { |
---|
397 | cerr << "'sc_stop' function was called. Exit code : 1\n"; |
---|
398 | return 1; |
---|
399 | } |
---|
400 | |
---|
401 | return ret; |
---|
402 | } |
---|
403 | |
---|