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