Changeset 52 for sources/src/gen_code.cc
- Timestamp:
- Jan 22, 2013, 4:23:22 PM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sources/src/gen_code.cc
r47 r52 1 1 /*------------------------------------------------------------\ 2 | |3 | Tool : systemcass |4 | |5 | File : gen_code.cc |6 | |7 | Author : Taktak Sami |8 | Buchmann Richard |9 | |10 | Date : 09_07_2004 |11 | |12 \------------------------------------------------------------*/2 | | 3 | Tool : systemcass | 4 | | 5 | File : gen_code.cc | 6 | | 7 | Author : Taktak Sami | 8 | Buchmann Richard | 9 | | 10 | Date : 09_07_2004 | 11 | | 12 \------------------------------------------------------------*/ 13 13 14 14 /* … … 34 34 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 35 35 */ 36 36 37 #if defined(__linux__) 37 38 #include <linux/limits.h> … … 39 40 #include <windows.h> 40 41 #endif 42 41 43 #include <cstring> 42 44 #include <cstdio> … … 50 52 #include "sc_ver.h" 51 53 #include "process_dependency.h" 54 52 55 #ifdef HAVE_CONFIG_H 53 56 #include "config.h" … … 67 70 namespace sc_core { 68 71 69 static void PrintCall(std::ostream &, const method_process_t &);70 static void open_temp(std::ofstream &, char *);72 static void PrintCall(std::ostream &, const method_process_t &); 73 static void open_temp(std::ofstream &, char *); 71 74 typedef void (*CASC_ENTRY_FUNC) (void *); 72 typedef union { unsigned long long int integer; SC_ENTRY_FUNC pmf; CASC_ENTRY_FUNC pf; } fct;73 74 const char * 75 get_pmf_type () 76 { 77 switch (sizeof (SC_ENTRY_FUNC)) { 78 case 4: 79 // G4 pointer-to-member-function style 80 return "unsigned long int";81 case 8:82 // PCpointer-to-member-function style83 return "unsigned longlong int";84 default:85 cerr << "Internal Error : Unsupported pointer-to-member-function"86 "(size: " << sizeof (SC_ENTRY_FUNC) << ").\n"87 "Please try --nodynamiclink option.\n";88 exit(21072009);89 };90 } 91 92 static 93 ostream& operator << (ostream &o, const SC_ENTRY_FUNC &f) 94 { 95 register fct p; 96 p.integer = 0; 97 p.pmf = f; 98 return o << "0x" << hex << p.integer << "ULL";99 } 100 101 static 102 void 103 PrintCall (std::ostream &o, 104 const method_process_t &m) 105 {106 SC_ENTRY_FUNC func= m.func;107 if (print_schedule)108 o << " fprintf(stderr,\"evaluation de "109 << m.module->name() << "->" << m.name << "()\\n\");\n";110 o << " p.integer = " << func << ";\n";75 typedef union { 76 unsigned long long int integer; 77 SC_ENTRY_FUNC pmf; 78 CASC_ENTRY_FUNC pf; 79 } fct; 80 81 82 const char * get_pmf_type() { 83 switch (sizeof(SC_ENTRY_FUNC)) { 84 case 4: 85 // G4 pointer-to-member-function style 86 return "unsigned long int"; 87 case 8: 88 // PC pointer-to-member-function style 89 return "unsigned long long int"; 90 default: 91 cerr << 92 "Internal Error : Unsupported pointer-to-member-function" 93 "(size: " << sizeof(SC_ENTRY_FUNC) << ").\n" 94 "Please try --nodynamiclink option.\n"; 95 exit(21072009); 96 }; 97 } 98 99 100 static ostream & operator <<(ostream & o, const SC_ENTRY_FUNC & f) { 101 register fct p; 102 p.integer = 0; 103 p.pmf = f; 104 return o << "0x" << hex << p.integer << "ULL"; 105 } 106 107 108 static void PrintCall(std::ostream & o, const method_process_t & m) { 109 SC_ENTRY_FUNC func = m.func; 110 if (print_schedule) { 111 o << " fprintf(stderr,\"evaluation de " << m.module->name() << "->" << m.name << "()\\n\");\n"; 112 } 113 o << " p.integer = " << func << ";\n"; 111 114 #ifdef CPP_CALL 112 o << " (((sc_module*)(" << m.module << "))->*(p.pmf)) (); /* " 113 << m.module->name () << "->" << m.name << "() */\n"; 115 o << " (((sc_module*)(" << m.module << "))->*(p.pmf)) (); /* " << m.module->name() << "->" << m.name << "() */\n"; 114 116 #else 115 o << " p.pf((void *)" 116 << m.module << "); /* " 117 << m.module->name () << "->" << m.name << "() */\n"; 118 #endif 119 } 120 121 static 122 bool 123 is_exist (const char *temp) 124 { 125 #if 0 126 cerr << "testing " << temp << "\n"; 127 #endif 128 ifstream o; 129 o.open (temp,ios::in); 130 if (o.is_open () == false) 131 return false; 132 #if 0 133 cerr << "opened\n"; 134 cerr << "peek : " << (int) o.peek() << endl; 135 #endif 136 if (o.peek () == -1) 137 return false; 138 return true; 139 } 140 141 static 142 void 143 open_temp (ofstream &o, 144 char *temp) 145 { 146 /* 147 srand (time (NULL)); 148 int r = rand () % 1000; 149 */ 150 pid_t pid = getpid(); 151 int r = -1; 152 do { 153 sprintf (temp, "%s/scheduling-%d-%x.cc", temporary_dir, pid, ++r); 154 } while (is_exist (temp)); 155 156 o.open (temp,ios::out); 157 if (o.is_open () == false) 158 { 159 cerr << "Error : Unable to open a file to write scheduling code.\n"; 160 exit (30032005); 161 } 162 117 o << " p.pf((void *)" << m.module << "); /* " << m.module->name() << "->" << m.name << "() */\n"; 118 #endif 119 } 120 121 122 static bool is_exist(const char * temp) { 123 ifstream o; 124 o.open(temp, ios::in); 125 if (o.is_open() == false) { 126 return false; 127 } 128 if (o.peek() == -1) { 129 return false; 130 } 131 return true; 132 } 133 134 135 static void open_temp(ofstream & o, char * temp) { 136 /* 137 srand (time (NULL)); 138 int r = rand () % 1000; 139 */ 140 pid_t pid = getpid(); 141 int r = -1; 142 do { 143 sprintf(temp, "%s/scheduling-%d-%x.cc", temporary_dir, pid, ++r); 144 } while (is_exist(temp)); 145 146 o.open(temp, ios::out); 147 if (o.is_open() == false) { 148 cerr << "Error : Unable to open a file to write scheduling code.\n"; 149 exit(30032005); 150 } 163 151 #ifdef CONFIG_DEBUG 164 cerr << "opened temporary filename : " << temp << "\n"; 165 #endif 166 167 sprintf (temp, "scheduling-%d-%x", pid, r++); 168 } 169 170 static 171 char * 172 gen_transition (ofstream &o, 173 method_process_list_t &transition_func_list) 174 { 175 // transitions 176 o << "\ninline void transition(void)\n{\n"; 177 if (transition_func_list.empty () == false) { 178 o << " /* fonctions de transition */\n" 179 << " register fct p;\n"; 180 method_process_list_t::iterator mm; 181 for( mm = transition_func_list.begin(); mm != transition_func_list.end(); ++mm) 182 { 183 PrintCall (o, **mm); 184 } 185 } 186 o << "}\n"; 187 } 188 189 static 190 char * 191 gen_moore (ofstream &o, 192 method_process_list_t &moore_func_list) 193 { 194 // Moore generations (sequential functions) 195 o << "\ninline void moore_generation (void)\n{\n"; 196 if (moore_func_list.empty () == false) { 197 o << " /* fonctions de generation de Moore */\n" 198 << " register fct p;\n"; 199 method_process_list_t::reverse_iterator mm; 200 for( mm = moore_func_list.rbegin(); mm != moore_func_list.rend(); ++mm) 201 { 202 PrintCall (o, **mm); 203 } 204 } 205 o << " \n}\n"; 206 } 207 208 static 209 char * 210 gen_mealy (ofstream &o, 211 strong_component_list_t &strongcomponents) 212 { 213 // Mealy generations (combinational functions only) 214 o << "\nextern void mealy_generation (void)\n{\n"; 215 if (strongcomponents.empty ()) 216 return NULL; 217 o << " register fct p;\n" 218 << "\n\n /* fonctions de mealy */\n"; 152 cerr << "opened temporary filename : " << temp << "\n"; 153 #endif 154 sprintf(temp, "scheduling-%d-%x", pid, r++); 155 } 156 157 158 static char * gen_transition(ofstream & o, method_process_list_t & transition_func_list) { 159 // transitions 160 o << "\ninline void transition(void)\n{\n"; 161 if (transition_func_list.empty() == false) { 162 o << " /* fonctions de transition */\n" << " register fct p;\n"; 163 method_process_list_t::iterator mm; 164 for (mm = transition_func_list.begin(); mm != transition_func_list.end(); ++mm) { 165 PrintCall(o, **mm); 166 } 167 } 168 o << "}\n"; 169 } 170 171 172 static char * gen_moore(ofstream & o, method_process_list_t & moore_func_list) { 173 // Moore generations (sequential functions) 174 o << "\ninline void moore_generation (void)\n{\n"; 175 if (moore_func_list.empty() == false) { 176 o << " /* fonctions de generation de Moore */\n" 177 << " register fct p;\n"; 178 method_process_list_t::reverse_iterator mm; 179 for (mm = moore_func_list.rbegin(); 180 mm != moore_func_list.rend(); ++mm) { 181 PrintCall(o, **mm); 182 } 183 } 184 o << " \n}\n"; 185 } 186 187 188 static char * gen_mealy(ofstream & o, strong_component_list_t & strongcomponents) { 189 // Mealy generations (combinational functions only) 190 o << "\nextern void mealy_generation (void)\n{\n"; 191 if (strongcomponents.empty()) { 192 return NULL; 193 } 194 o << " register fct p;\n" << "\n\n /* fonctions de mealy */\n"; 219 195 #ifdef NO_STATIC_SCHEDULE 220 o << "\n do {\n unstable = 0;\n"; 221 #endif 222 strong_component_list_t::iterator ss; 223 for ( ss = strongcomponents.begin(); ss != strongcomponents.end(); ++ss) { 224 if ( (*ss)->size() == 1) { 225 /* un seul element dans le strong component */ 226 method_process_t *m = (method_process_t*)(*((*ss)->begin ())); 227 PrintCall (o, *m); 228 continue; 229 } else { 230 /* plusieurs elements dans le strong component */ 196 o << "\n do {\n unstable = 0;\n"; 197 #endif 198 strong_component_list_t::iterator ss; 199 for (ss = strongcomponents.begin(); ss != strongcomponents.end(); ++ss) { 200 if ((*ss)->size() == 1) { 201 /* un seul element dans le strong component */ 202 method_process_t *m = (method_process_t *) (*((*ss)->begin())); 203 PrintCall(o, *m); 204 continue; 205 } 206 else { 207 /* plusieurs elements dans le strong component */ 231 208 #ifndef NO_STATIC_SCHEDULE 232 o << "\n do {\n unstable = 0;\n";233 #endif 234 component_list_t::reverse_iterator rev_mm;235 for(rev_mm = (*ss)->rbegin(); rev_mm != (*ss)->rend(); ++rev_mm) {236 method_process_t *m = (method_process_t*) *rev_mm;237 PrintCall(o, *m);238 }209 o << "\n do {\n unstable = 0;\n"; 210 #endif 211 component_list_t::reverse_iterator rev_mm; 212 for (rev_mm = (*ss)->rbegin(); rev_mm != (*ss)->rend(); ++rev_mm) { 213 method_process_t * m = (method_process_t *) * rev_mm; 214 PrintCall(o, *m); 215 } 239 216 #ifndef NO_STATIC_SCHEDULE 240 o << " } while ( unstable );\n\n";241 #endif 242 }243 }217 o << " } while ( unstable );\n\n"; 218 #endif 219 } 220 } 244 221 #ifdef NO_STATIC_SCHEDULE 245 o << " } while ( unstable );\n\n";222 o << " } while ( unstable );\n\n"; 246 223 #else 247 o << "\tunstable = 0;\n"; 248 #endif 249 } 250 251 static 252 char * 253 gen_mealy (ofstream &o, 254 ProcessDependencyList &mealy_func_list) 255 { 256 // Mealy generations (combinational functions only) 257 o << "\nextern void mealy_generation (void)\n{\n"; 258 o << " register fct p;\n" 259 << "\n\n /* fonctions de mealy */\n"; 260 ProcessDependencyList::iterator it; 261 for (it = mealy_func_list.begin(); it != mealy_func_list.end(); ++it) 262 { 263 const method_process_t *m = *it; 264 PrintCall (o, *m); 265 } 266 } 267 268 char * 269 gen_scheduling_code_for_dynamic_link ( 270 method_process_list_t &transition_func_list, 271 method_process_list_t &moore_func_list, 272 strong_component_list_t &strongcomponents) 273 { 274 if (dump_stage) 275 cerr << "Generating C code for scheduling...\n"; 276 277 // open temporary file 278 ofstream o; 279 char base_name[PATH_MAX]; 280 open_temp (o, base_name); 281 282 if (! o.good ()) { 283 perror("scheduling: open file\n"); 284 exit(-1); 285 } 286 287 o << "// generated by " << sc_version () << endl 288 << "#include <casc.h>\n\n" 289 << "#include <cstdio>\n\n" 290 // << "#include <iostream>\n\n" 291 << "namespace sc_core {\n" 292 << " typedef void (sc_module::*SC_ENTRY_FUNC)();\n" 293 << " typedef void (*CASC_ENTRY_FUNC)(void *);\n"; 294 295 const char *pmf_type = get_pmf_type (); 296 297 o << " typedef union { " 298 << pmf_type 299 << " integer; SC_ENTRY_FUNC pmf; CASC_ENTRY_FUNC pf; } fct;\n"; 300 301 gen_transition (o, transition_func_list); 302 gen_moore (o, moore_func_list); 303 gen_mealy (o, strongcomponents); 304 305 o << " \n}\n"; 306 o << "\n} // end of sc_core namespace\n"; 307 308 o.flush (); 309 o.close (); 310 311 // add "cc" extension 312 char file_name[PATH_MAX]; 313 strncpy(file_name, base_name, PATH_MAX); 314 file_name[strlen (base_name)] = '\0'; 315 strcat(file_name, ".cc"); 316 rename (base_name, file_name); 317 318 if (edit_schedule) 319 run_schedule_editor (file_name); 320 321 if (dump_stage) 322 cerr << "Generating C code for scheduling done.\n"; 323 324 return strdup(base_name); 325 } 326 327 char * 328 gen_scheduling_code_for_dynamic_link ( 329 method_process_list_t &transition_func_list, 330 method_process_list_t &moore_func_list, 331 ProcessDependencyList &mealy_func_list) 332 { 333 if (dump_stage) 334 cerr << "Generating C code for scheduling...\n"; 335 336 // open temporary file 337 ofstream o; 338 char base_name[PATH_MAX]; 339 open_temp (o, base_name); 340 341 if (! o.good ()) { 342 perror("scheduling: open file\n"); 343 exit(-1); 344 } 345 346 o << "// generated by " << sc_version () << endl 347 << "#include <casc.h>\n\n" 348 << "#include <cstdio>\n\n" 349 // << "#include <iostream>\n\n" 350 << "namespace sc_core {\n" 351 << " typedef void (sc_module::*SC_ENTRY_FUNC)();\n" 352 << " typedef void (*CASC_ENTRY_FUNC)(void *);\n" 353 << " typedef union { unsigned long long int integer; SC_ENTRY_FUNC pmf; CASC_ENTRY_FUNC pf; } fct;\n"; 354 355 gen_transition (o, transition_func_list); 356 gen_moore (o, moore_func_list); 357 gen_mealy (o, mealy_func_list); 358 359 o << "\n}\n"; 360 o << "\n} // end of sc_core namespace\n"; 361 362 o.flush (); 363 o.close (); 364 365 // add "cc" extension 366 char file_name[PATH_MAX]; 367 strncpy(file_name, base_name, PATH_MAX); 368 file_name[strlen (base_name)] = '\0'; 369 strcat(file_name, ".cc"); 370 rename (base_name, file_name); 371 372 if (edit_schedule) 373 run_schedule_editor (file_name); 374 375 if (dump_stage) 376 cerr << "Generating C code for scheduling done.\n"; 377 378 return strdup(base_name); 379 } 224 o << "\tunstable = 0;\n"; 225 #endif 226 } 227 228 229 static char * gen_mealy(ofstream & o, ProcessDependencyList & mealy_func_list) { 230 // Mealy generations (combinational functions only) 231 o << "\nextern void mealy_generation (void)\n{\n"; 232 o << " register fct p;\n" << "\n\n /* fonctions de mealy */\n"; 233 ProcessDependencyList::iterator it; 234 for (it = mealy_func_list.begin(); it != mealy_func_list.end(); ++it) { 235 const method_process_t * m = *it; 236 PrintCall(o, *m); 237 } 238 } 239 240 241 char * gen_scheduling_code_for_dynamic_link(method_process_list_t & 242 transition_func_list, 243 method_process_list_t & 244 moore_func_list, 245 strong_component_list_t & 246 strongcomponents) { 247 if (dump_stage) { 248 cerr << "Generating C code for scheduling...\n"; 249 } 250 251 // open temporary file 252 ofstream o; 253 char base_name[PATH_MAX]; 254 open_temp(o, base_name); 255 256 if (!o.good()) { 257 perror("scheduling: open file\n"); 258 exit(-1); 259 } 260 261 o << "// generated by " << sc_version() << endl 262 << "#include <casc.h>\n\n" << "#include <cstdio>\n\n" 263 // << "#include <iostream>\n\n" 264 << "namespace sc_core {\n" 265 << " typedef void (sc_module::*SC_ENTRY_FUNC)();\n" 266 << " typedef void (*CASC_ENTRY_FUNC)(void *);\n"; 267 268 const char * pmf_type = get_pmf_type(); 269 270 o << " typedef union { " 271 << pmf_type 272 << " integer; SC_ENTRY_FUNC pmf; CASC_ENTRY_FUNC pf; } fct;\n"; 273 274 gen_transition(o, transition_func_list); 275 gen_moore(o, moore_func_list); 276 gen_mealy(o, strongcomponents); 277 278 o << " \n}\n"; 279 o << "\n} // end of sc_core namespace\n"; 280 281 o.flush(); 282 o.close(); 283 284 // add "cc" extension 285 char file_name[PATH_MAX]; 286 strncpy(file_name, base_name, PATH_MAX); 287 file_name[strlen(base_name)] = '\0'; 288 strcat(file_name, ".cc"); 289 rename(base_name, file_name); 290 291 if (edit_schedule) { 292 run_schedule_editor(file_name); 293 } 294 295 if (dump_stage) { 296 cerr << "Generating C code for scheduling done.\n"; 297 } 298 299 return strdup(base_name); 300 } 301 302 303 char * gen_scheduling_code_for_dynamic_link(method_process_list_t & 304 transition_func_list, 305 method_process_list_t & 306 moore_func_list, 307 ProcessDependencyList & 308 mealy_func_list) { 309 if (dump_stage) { 310 cerr << "Generating C code for scheduling...\n"; 311 } 312 313 // open temporary file 314 ofstream o; 315 char base_name[PATH_MAX]; 316 open_temp(o, base_name); 317 318 if (!o.good()) { 319 perror("scheduling: open file\n"); 320 exit(-1); 321 } 322 323 o << "// generated by " << sc_version() << endl 324 << "#include <casc.h>\n\n" << "#include <cstdio>\n\n" 325 << "namespace sc_core {\n" 326 << " typedef void (sc_module::*SC_ENTRY_FUNC)();\n" 327 << " typedef void (*CASC_ENTRY_FUNC)(void *);\n" 328 << 329 " typedef union { unsigned long long int integer; SC_ENTRY_FUNC pmf; CASC_ENTRY_FUNC pf; } fct;\n"; 330 331 gen_transition(o, transition_func_list); 332 gen_moore(o, moore_func_list); 333 gen_mealy(o, mealy_func_list); 334 335 o << "\n}\n"; 336 o << "\n} // end of sc_core namespace\n"; 337 338 o.flush(); 339 o.close(); 340 341 // add "cc" extension 342 char file_name[PATH_MAX]; 343 strncpy(file_name, base_name, PATH_MAX); 344 file_name[strlen(base_name)] = '\0'; 345 strcat(file_name, ".cc"); 346 rename(base_name, file_name); 347 348 if (edit_schedule) { 349 run_schedule_editor(file_name); 350 } 351 352 if (dump_stage) { 353 cerr << "Generating C code for scheduling done.\n"; 354 } 355 356 return strdup(base_name); 357 } 358 380 359 381 360 /* base_name est la base du nom du fichier C++ 382 361 * casc_cflags est une string qui correspond à $(INCLUDE) d'un Makefile 383 362 */ 384 void 385 compile_code (const char *base_name, 386 const char *casc_cflags2) 387 { 388 if (dump_stage) 389 cerr << "Compiling C/C++ code for scheduling...\n"; 390 char compil_str[512]; 391 const char *compiler = getenv ("CXX"); 392 const char *systemc_dir = getenv ("SYSTEMCASS"); 393 // const char *target_arch = getenv ("TARGET_ARCH"); 394 const char *default_compiler = 363 void compile_code(const char * base_name, const char * casc_cflags2) { 364 if (dump_stage) { 365 cerr << "Compiling C/C++ code for scheduling...\n"; 366 } 367 char compil_str[512]; 368 const char * compiler = getenv("CXX"); 369 const char * systemc_dir = getenv("SYSTEMCASS"); 370 const char * default_compiler = 395 371 #ifdef CPP_CALL 396 "g++";372 "g++"; 397 373 #else 398 374 "gcc"; 399 375 #endif 400 376 401 compiler = (compiler == NULL)?default_compiler:compiler; 402 if (systemc_dir == NULL) { 403 systemc_dir = getenv ("SYSTEMC"); 377 compiler = (compiler == NULL) ? default_compiler : compiler; 404 378 if (systemc_dir == NULL) { 405 cerr << "Error : set SYSTEMCASS or SYSTEMC environnement variable " 406 "to the SYSTEMCASS directory.\n"; 407 exit (-1); 408 } 409 } 410 //target_arch = (target_arch == NULL)?"":target_arch; 411 412 char target_name[128]; 413 char source_name[128]; 414 sprintf (target_name, "%s.lo", base_name); 415 sprintf (source_name, "%s.cc", base_name); 416 417 if (keep_generated_code) 418 { 419 char lg_cde[256]; 420 sprintf (lg_cde, "mkdir -p %s", generated_files_dir); 421 system(lg_cde); 422 sprintf(lg_cde, "cp %s/%s %s/", 423 temporary_dir, source_name, generated_files_dir); 424 if (dump_stage) 425 cerr << "$ " << lg_cde << "\n"; 426 system(lg_cde); 427 sprintf(lg_cde, "(cd %s ; indent %s)", 428 generated_files_dir, source_name); 429 if (dump_stage) 430 cerr << "$ " << lg_cde << "\n"; 431 system(lg_cde); 432 } 433 /* ******* */ 434 /* COMPILE */ 435 /* ******* */ 436 const char *commandline_template = 379 systemc_dir = getenv("SYSTEMC"); 380 if (systemc_dir == NULL) { 381 cerr << "Error : set SYSTEMCASS or SYSTEMC environnement variable to the SYSTEMCASS directory.\n"; 382 exit(-1); 383 } 384 } 385 386 char target_name[128]; 387 char source_name[128]; 388 sprintf(target_name, "%s.lo", base_name); 389 sprintf(source_name, "%s.cc", base_name); 390 391 if (keep_generated_code) { 392 char lg_cde[256]; 393 sprintf(lg_cde, "mkdir -p %s", generated_files_dir); 394 system(lg_cde); 395 sprintf(lg_cde, "cp %s/%s %s/", temporary_dir, source_name, generated_files_dir); 396 if (dump_stage) { 397 cerr << "$ " << lg_cde << "\n"; 398 } 399 system(lg_cde); 400 sprintf(lg_cde, "(cd %s ; indent %s)", generated_files_dir, source_name); 401 if (dump_stage) { 402 cerr << "$ " << lg_cde << "\n"; 403 } 404 system(lg_cde); 405 } 406 /* ******* */ 407 /* COMPILE */ 408 /* ******* */ 409 const char * commandline_template = 437 410 #if defined(CONFIG_OS_DARWIN) 438 "(cd %s ;" " %s %s -DSCHEDULING_BY_CASC -I%s/include -fno-common -dynamic -o %s -c %s)" 411 "(cd %s ;" 412 " %s %s -DSCHEDULING_BY_CASC -I%s/include -fno-common -dynamic -o %s -c %s)" 439 413 #elif defined(CONFIG_OS_LINUX) 440 "(cd %s ; libtool --mode=compile %s %s -DSCHEDULING_BY_CASC -I%s/include -shared -o %s -c %s)"414 "(cd %s ; libtool --mode=compile %s %s -DSCHEDULING_BY_CASC -I%s/include -shared -o %s -c %s)" 441 415 #else 442 "(cd %s ;" " %s %s -DSCHEDULING_BY_CASC -I%s/include -dynamiclib -o %s -c %s)" 443 #endif 444 ; 445 446 string cflags = casc_cflags; 447 if (use_openmp) 448 cflags += " -fopenmp"; 449 450 sprintf(compil_str, 451 commandline_template, 452 temporary_dir, 453 compiler, 454 cflags.c_str(), 455 systemc_dir, 456 target_name, 457 source_name); 458 459 if (dump_stage) 460 cerr << "Executing command : " << compil_str << "\n"; 461 462 if (system(compil_str)) { 463 perror("compil : system"); 464 exit(-1); 465 } 466 467 /* **** */ 468 /* LINK */ 469 /* **** */ 470 sprintf (target_name, "%s.la", base_name); 416 "(cd %s ;" 417 " %s %s -DSCHEDULING_BY_CASC -I%s/include -dynamiclib -o %s -c %s)" 418 #endif 419 ; 420 421 string cflags = casc_cflags; 422 if (use_openmp) { 423 cflags += " -fopenmp"; 424 } 425 426 sprintf(compil_str, commandline_template, temporary_dir, compiler, cflags.c_str(), systemc_dir, target_name, source_name); 427 428 if (dump_stage) { 429 cerr << "Executing command : " << compil_str << "\n"; 430 } 431 432 if (system(compil_str)) { 433 perror("compil : system"); 434 exit(-1); 435 } 436 437 /* **** */ 438 /* LINK */ 439 /* **** */ 440 sprintf(target_name, "%s.la", base_name); 471 441 472 442 #ifdef CONFIG_OS_LINUX 473 sprintf(source_name, "%s.lo", base_name);474 sprintf(compil_str, "(cd %s ; pwd ; libtool --mode=link %s %s -module -shared -o %s %s -rpath /tmp)", /* -L. -L%s/lib-%s */475 temporary_dir, compiler, casc_cflags, /*systemc_dir, target_arch,*/476 target_name, source_name);443 sprintf(source_name, "%s.lo", base_name); 444 sprintf(compil_str, "(cd %s ; pwd ; libtool --mode=link %s %s -module -shared -o %s %s -rpath /tmp)", /* -L. -L%s/lib-%s */ 445 temporary_dir, compiler, casc_cflags, /*systemc_dir, target_arch, */ 446 target_name, source_name); 477 447 #else 478 sprintf (source_name, "%s.o", base_name); 479 sprintf(compil_str, "(cd %s ; pwd ; libtool -dynamic -o %s %s)", 480 temporary_dir, target_name, source_name); 481 #endif 482 483 if (dump_stage) 484 cerr << "Executing command : " << compil_str << "\n"; 485 486 if (system(compil_str)) { 487 perror("compil : system"); 488 exit(-1); 489 } 490 491 /* 492 sprintf(compil_str, "(cd %s ; rm -f %s.o %s.lo)", 493 temporary_dir, base_name, base_name); 494 if (dump_stage) 495 cerr << "$ " << compil_str << "\n"; 496 */ 497 498 system(compil_str); 499 if (dump_stage) 500 cerr << "Compiling done.\n"; 501 } 448 sprintf(source_name, "%s.o", base_name); 449 sprintf(compil_str, "(cd %s ; pwd ; libtool -dynamic -o %s %s)", temporary_dir, target_name, source_name); 450 #endif 451 452 if (dump_stage) { 453 cerr << "Executing command : " << compil_str << "\n"; 454 } 455 456 if (system(compil_str)) { 457 perror("compil : system"); 458 exit(-1); 459 } 460 461 system(compil_str); 462 if (dump_stage) { 463 cerr << "Compiling done.\n"; 464 } 465 } 466 502 467 503 468 /* ******************************** … … 505 470 */ 506 471 struct function_call { 507 fct *function;508 void **instance;509 intfunc_number;472 fct * function; 473 void ** instance; 474 int func_number; 510 475 }; 511 476 static function_call pf[3]; 512 477 513 void 514 get_function_call (function_call &pf, 515 method_process_list_t &func_list) 516 { 517 pf.func_number = func_list.size (); 518 pf.function = (fct*) malloc (sizeof (fct) * pf.func_number); 519 pf.instance = (void**) malloc (sizeof (void*) * pf.func_number); 520 method_process_list_t::iterator mm; 521 int i; 522 for (mm = func_list.begin(), i = 0; mm != func_list.end(); ++mm, ++i) 523 { 524 const method_process_t *mp = *mm; 525 pf.function[i].pmf = (mp->func); 526 pf.instance[i] = (void*)(mp->module); 527 } 528 } 529 530 void 531 get_function_call (function_call &pf, 532 ProcessDependencyList &func_list) 533 { 534 pf.func_number = func_list.size (); 535 pf.function = (fct*) malloc (sizeof (fct) * pf.func_number); 536 pf.instance = (void**) malloc (sizeof (void*) * pf.func_number); 537 ProcessDependencyList::iterator it; 538 int i; 539 for (i = 0, it = func_list.begin(); it != func_list.end(); ++it, ++i) 540 { 541 const method_process_t *mp = *it; 542 pf.function[i].pmf = (mp->func); 543 pf.instance[i] = (void*)(mp->module); 544 } 545 } 546 547 void 548 gen_scheduling_code_for_static_func ( 549 method_process_list_t &transition_func_list, 550 method_process_list_t &moore_func_list, 551 ProcessDependencyList &mealy_func_list) 552 { 553 if (dump_stage) 554 cerr << "Generating scheduling...\n"; 555 556 get_function_call (pf[0], transition_func_list); 557 get_function_call (pf[1], moore_func_list); 558 get_function_call (pf[2], mealy_func_list); 559 560 if (dump_stage) 561 cerr << "Generating scheduling done.\n"; 562 } 563 564 void 565 call_functions (function_call &fc) 566 { 567 int n = fc.func_number; 568 int i; 569 for (i = 0; i < n; ++i) 570 { 571 #if 0 //defined(CONFIG_DEBUG) 572 sc_module *m = (sc_module*)(fc.instance[i]); 573 cerr << m->name () << endl; 574 #endif 575 fc.function[i].pf (fc.instance[i]); 576 } 577 } 578 579 void 580 call_functions_in_parallel (function_call &fc) 581 { 582 int n = fc.func_number; 583 int i; 584 #pragma omp parallel for 585 for (i = 0; i < n; ++i) 586 { 587 #if 0 //defined(CONFIG_DEBUG) 588 sc_module *m = (sc_module*)(fc.instance[i]); 589 cerr << m->name () << endl; 590 cerr << "thread #" << omp_get_thread_num () << endl; 591 #endif 592 fc.function[i].pf (fc.instance[i]); 593 } 594 } 595 596 void static_mealy_generation () 597 { 598 call_functions (pf[2]); 599 } 600 601 void static_simulate_1_cycle (void) 602 { 603 call_functions (pf[0]); // transition 604 update (); 605 call_functions_in_parallel (pf[1]); // moore generation 606 call_functions (pf[2]); // mealy generation 607 } 478 479 void get_function_call(function_call & pf, method_process_list_t & func_list) { 480 pf.func_number = func_list.size(); 481 pf.function = (fct *) malloc(sizeof(fct) * pf.func_number); 482 pf.instance = (void **) malloc(sizeof(void *) * pf.func_number); 483 method_process_list_t::iterator mm; 484 int i; 485 for (mm = func_list.begin(), i = 0; mm != func_list.end(); ++mm, ++i) { 486 const method_process_t * mp = *mm; 487 pf.function[i].pmf = (mp->func); 488 pf.instance[i] = (void *) (mp->module); 489 } 490 } 491 492 493 void get_function_call(function_call & pf, ProcessDependencyList & func_list) { 494 pf.func_number = func_list.size(); 495 pf.function = (fct *) malloc(sizeof(fct) * pf.func_number); 496 pf.instance = (void **) malloc(sizeof(void *) * pf.func_number); 497 ProcessDependencyList::iterator it; 498 int i; 499 for (i = 0, it = func_list.begin(); it != func_list.end(); ++it, ++i) { 500 const method_process_t * mp = *it; 501 pf.function[i].pmf = (mp->func); 502 pf.instance[i] = (void *) (mp->module); 503 } 504 } 505 506 507 void gen_scheduling_code_for_static_func(method_process_list_t & 508 transition_func_list, 509 method_process_list_t & 510 moore_func_list, 511 ProcessDependencyList & 512 mealy_func_list) { 513 if (dump_stage) { 514 cerr << "Generating scheduling...\n"; 515 } 516 517 get_function_call(pf[0], transition_func_list); 518 get_function_call(pf[1], moore_func_list); 519 get_function_call(pf[2], mealy_func_list); 520 521 if (dump_stage) { 522 cerr << "Generating scheduling done.\n"; 523 } 524 } 525 526 527 void call_functions(function_call & fc) { 528 int n = fc.func_number; 529 int i; 530 for (i = 0; i < n; ++i) { 531 #if 0 532 //defined(CONFIG_DEBUG) 533 sc_module *m = (sc_module *) (fc.instance[i]); 534 cerr << m->name() << endl; 535 #endif 536 fc.function[i].pf(fc.instance[i]); 537 } 538 } 539 540 541 void call_functions_in_parallel(function_call & fc) { 542 int n = fc.func_number; 543 int i; 544 #pragma omp parallel for 545 for (i = 0; i < n; ++i) { 546 #if 0 547 //defined(CONFIG_DEBUG) 548 sc_module *m = (sc_module *) (fc.instance[i]); 549 cerr << m->name() << endl; 550 cerr << "thread #" << omp_get_thread_num() << endl; 551 #endif 552 fc.function[i].pf(fc.instance[i]); 553 } 554 } 555 556 557 void static_mealy_generation() { 558 call_functions(pf[2]); 559 } 560 561 562 void static_simulate_1_cycle(void) { 563 call_functions(pf[0]); // transition 564 update(); 565 call_functions_in_parallel(pf[1]); // moore generation 566 call_functions(pf[2]); // mealy generation 567 } 568 608 569 609 570 /* *************************************** … … 611 572 */ 612 573 613 static method_process_list_t 574 static method_process_list_t func_list[2]; 614 575 static strong_component_list_t quasistatic_list; 615 576 616 static 617 void 618 Call (const method_process_t &m) 619 { 620 sc_module *mod = m.module; 621 SC_ENTRY_FUNC func = m.func; 622 // CASC_ENTRY_FUNC func = reinterpret_cast<CASC_ENTRY_FUNC> (m.func); 623 (mod->*func) (); 624 } 625 626 void quasistatic_mealy_generation () 627 { 628 strong_component_list_t::iterator ss; 629 for ( ss = quasistatic_list.begin(); ss != quasistatic_list.end(); ++ss) { 630 if ( (*ss)->size() == 1) { 631 /* un seul element dans le strong component */ 632 method_process_t *m = (method_process_t*)(*((*ss)->begin ())); 633 Call (*m); 634 continue; 635 } else { 636 /* plusieurs elements dans le strong component */ 637 do { 638 unstable = 0; 639 component_list_t::reverse_iterator rev_mm; 640 for( rev_mm = (*ss)->rbegin(); rev_mm != (*ss)->rend(); ++rev_mm) { 641 method_process_t *m = (method_process_t*) *rev_mm; 642 Call (*m); 643 } 644 } while ( unstable ); 645 } 646 } 647 } 648 649 void quasistatic_simulate_1_cycle (void) 650 { 651 method_process_list_t::iterator mm; 652 for( mm = func_list[0].begin(); mm != func_list[0].end(); ++mm) 653 { 654 method_process_t &m = **mm; 655 Call (m); 656 } 657 update (); 658 for( mm = func_list[1].begin(); mm != func_list[1].end(); ++mm) 659 { 660 method_process_t &m = **mm; 661 Call (m); 662 } 663 quasistatic_mealy_generation (); 664 } 665 666 void 667 gen_scheduling_code_for_quasistatic_func ( 668 method_process_list_t &transition_func_list, 669 method_process_list_t &moore_func_list, 670 strong_component_list_t &mealy_func_list) 671 { 672 if (dump_stage) 673 cerr << "Generating quasi static scheduling...\n"; 674 675 func_list[0] = transition_func_list; 676 func_list[1] = moore_func_list; 677 quasistatic_list = mealy_func_list; 678 679 if (dump_stage) 680 cerr << "Generating quasi static scheduling done.\n"; 577 static void Call(const method_process_t & m) { 578 sc_module * mod = m.module; 579 SC_ENTRY_FUNC func = m.func; 580 // CASC_ENTRY_FUNC func = reinterpret_cast<CASC_ENTRY_FUNC> (m.func); 581 (mod->*func) (); 582 } 583 584 585 void quasistatic_mealy_generation() { 586 strong_component_list_t::iterator ss; 587 for (ss = quasistatic_list.begin(); ss != quasistatic_list.end(); ++ss) { 588 if ((*ss)->size() == 1) { 589 /* un seul element dans le strong component */ 590 method_process_t * m = (method_process_t *) (*((*ss)->begin())); 591 Call(*m); 592 continue; 593 } 594 else { 595 /* plusieurs elements dans le strong component */ 596 do { 597 unstable = 0; 598 component_list_t::reverse_iterator rev_mm; 599 for (rev_mm = (*ss)->rbegin(); rev_mm != (*ss)->rend(); ++rev_mm) { 600 method_process_t * m = (method_process_t *) * rev_mm; 601 Call(*m); 602 } 603 } while (unstable); 604 } 605 } 606 } 607 608 609 void quasistatic_simulate_1_cycle(void) { 610 method_process_list_t::iterator mm; 611 for (mm = func_list[0].begin(); mm != func_list[0].end(); ++mm) { 612 method_process_t & m = **mm; 613 Call(m); 614 } 615 update(); 616 for (mm = func_list[1].begin(); mm != func_list[1].end(); ++mm) { 617 method_process_t & m = **mm; 618 Call(m); 619 } 620 quasistatic_mealy_generation(); 621 } 622 623 624 void gen_scheduling_code_for_quasistatic_func(method_process_list_t & 625 transition_func_list, 626 method_process_list_t & 627 moore_func_list, 628 strong_component_list_t & 629 mealy_func_list) { 630 if (dump_stage) { 631 cerr << "Generating quasi static scheduling...\n"; 632 } 633 634 func_list[0] = transition_func_list; 635 func_list[1] = moore_func_list; 636 quasistatic_list = mealy_func_list; 637 638 if (dump_stage) { 639 cerr << "Generating quasi static scheduling done.\n"; 640 } 681 641 } 682 642 } // end of sc_core namespace 683 643 684 644 645 /* 646 # Local Variables: 647 # tab-width: 4; 648 # c-basic-offset: 4; 649 # c-file-offsets:((innamespace . 0)(inline-open . 0)); 650 # indent-tabs-mode: nil; 651 # End: 652 # 653 # vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 654 */
Note: See TracChangeset
for help on using the changeset viewer.