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