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