Mercurial > hg > GearsTemplate
comparison src/parallel_execution/generate_stub.pl @ 398:fc4fcd441700
Fix spanwTasks
author | Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Tue, 29 Aug 2017 01:01:44 +0900 |
parents | c43ec0e3fa84 |
children | 394e38952c80 |
comparison
equal
deleted
inserted
replaced
397:c43ec0e3fa84 | 398:fc4fcd441700 |
---|---|
325 } | 325 } |
326 # continuation case | 326 # continuation case |
327 if ($args =~ s/^(\s)*\_\_code\s+(\w+)\(([^)]*)\)//) { | 327 if ($args =~ s/^(\s)*\_\_code\s+(\w+)\(([^)]*)\)//) { |
328 my $next = $2; | 328 my $next = $2; |
329 my @args = split(/,/,$3); | 329 my @args = split(/,/,$3); |
330 if ( &generateStubArgs($codeGearName, $next, "Code", $next, $interface,0) ) { | 330 if (&generateStubArgs($codeGearName, $next, "Code", $next, $interface,0) ) { |
331 $newArgs .= "enum Code $next"; | 331 $newArgs .= "enum Code $next"; |
332 } | 332 } |
333 # analyze continuation arguments | 333 # analyze continuation arguments |
334 # output arguments are defined in the Interface take the pointer of these | 334 # output arguments are defined in the Interface take the pointer of these |
335 # output arguments are put into the Interface DataGear just before the goto | 335 # output arguments are put into the Interface DataGear just before the goto |
420 my $nextCodeGear = pop(@dataGears); | 420 my $nextCodeGear = pop(@dataGears); |
421 my $inputCount = $codeGear{$codeGearName}->{'input'}; | 421 my $inputCount = $codeGear{$codeGearName}->{'input'}; |
422 my $outputCount = $codeGear{$codeGearName}->{'output'}; | 422 my $outputCount = $codeGear{$codeGearName}->{'output'}; |
423 if (! $inParGoto) { | 423 if (! $inParGoto) { |
424 $inParGoto = 1; | 424 $inParGoto = 1; |
425 my $initTasks = << "EOFEOF"; | 425 print $fd "${prev}struct SingleLinkedQueue* queue = &context->tasks->queue->SingleLinkedQueue;\n"; |
426 ${prev}struct Context** tasks = (struct Context**)ALLOC_ARRAY(context, Context, ?); | 426 print $fd "${prev}struct Element* element;\n"; |
427 ${prev}int taskCount = 0; | 427 print $fd "${prev}struct Context* task;\n"; |
428 EOFEOF | 428 } |
429 print $fd $initTasks; | |
430 } | |
431 | |
432 my $initTask = << "EOFEOF"; | 429 my $initTask = << "EOFEOF"; |
433 ${prev}struct Context* task = NEW(struct Context); | 430 ${prev}task = NEW(struct Context); |
434 ${prev}initContext(task); | 431 ${prev}initContext(task); |
435 ${prev}task->next = C_$codeGearName; | 432 ${prev}task->next = C_$codeGearName; |
436 ${prev}task->idgCount = $inputCount; | 433 ${prev}task->idgCount = $inputCount; |
437 ${prev}task->idg = task->dataNum; | 434 ${prev}task->idg = task->dataNum; |
438 ${prev}task->maxIdg = task->idg + $inputCount; | 435 ${prev}task->maxIdg = task->idg + $inputCount; |
439 ${prev}task->odg = task->maxIdg; | 436 ${prev}task->odg = task->maxIdg; |
440 ${prev}task->maxOdg = task->odg + $outputCount; | 437 ${prev}task->maxOdg = task->odg + $outputCount; |
441 EOFEOF | 438 EOFEOF |
442 print $fd $initTask; | 439 print $fd $initTask; |
443 for my $i (0..$inputCount-1) { | 440 for my $i (0..$inputCount-1) { |
444 print $fd "${prev}task->data[task->idg+$i] = (union Data*)@dataGears[$i];\n"; | 441 print $fd "${prev}task->data[task->idg+$i] = (union Data*)@dataGears[$i];\n"; |
445 } | 442 } |
446 | 443 |
447 for my $i (0..$outputCount-1) { | 444 for my $i (0..$outputCount-1) { |
448 print $fd "${prev}task->data[task->odg+$i] = (union Data*)@dataGears[$inputCount+$i];\n"; | 445 print $fd "${prev}task->data[task->odg+$i] = (union Data*)@dataGears[$inputCount+$i];\n"; |
449 } | 446 } |
450 | 447 my $putTask = << "EOFEOF"; |
451 print $fd "${prev}tasks[taskCount] = task;\n"; | 448 ${prev}element = &ALLOCATE(context, Element)->Element; |
452 print $fd "${prev}taskCount++;\n"; | 449 ${prev}element->next = NULL; |
450 ${prev}element->data = (union Data*)task; | |
451 ${prev}if (queue->last) { | |
452 ${prev} Element* last = queue->last; | |
453 ${prev} last->next = element; | |
454 ${prev} queue->last = element; | |
455 ${prev}} else { | |
456 ${prev} queue->top = element; | |
457 ${prev} queue->last = element; | |
458 ${prev}} | |
459 EOFEOF | |
460 print $fd $putTask; | |
453 next; | 461 next; |
454 } elsif (/^(.*)goto (\w+)\((.*)\);/) { | 462 } elsif (/^(.*)goto (\w+)\((.*)\);/) { |
455 # handling goto statement | 463 # handling goto statement |
456 # convert it to the meta call form with two arugments, that is context and enum Code | 464 # convert it to the meta call form with two arugments, that is context and enum Code |
457 my $prev = $1; | 465 my $prev = $1; |
468 for my $arg ( @{$outputArgs{$codeGearName}->{$next}} ) { | 476 for my $arg ( @{$outputArgs{$codeGearName}->{$next}} ) { |
469 my $v = shift(@args); | 477 my $v = shift(@args); |
470 print $fd "\t*O_$arg = $v;\n"; | 478 print $fd "\t*O_$arg = $v;\n"; |
471 } | 479 } |
472 if ($inParGoto) { | 480 if ($inParGoto) { |
473 print $fd "${prev}taskManager->contexts = tasks;\n"; | 481 print $fd "${prev}taskManager->tasks = context->tasks;\n"; |
474 print $fd "${prev}goto par_meta(context, Gearef(context, TaskManager)->taskManager->TaskManager.spawnTasks, $next);\n"; | 482 print $fd "${prev}taskManager->next1 = C_$next;\n"; |
483 print $fd "${prev}goto par_meta(context, Gearef(context, TaskManager)->taskManager->TaskManager.spawnTasks, C_$next);\n"; | |
475 } else { | 484 } else { |
476 print $fd "${prev}goto meta(context, $next);\n"; | 485 print $fd "${prev}goto meta(context, $next);\n"; |
477 } | 486 } |
478 next; | 487 next; |
479 } | 488 } |
480 if ($inParGoto) { | 489 if ($inParGoto) { |
481 print $fd "${prev}taskManager->contexts = tasks;\n"; | 490 print $fd "${prev}taskManager->tasks = context->tasks;\n"; |
482 print $fd "${prev}goto par_meta(context, Gearef(context, TaskManager)->taskManager->TaskManager.spawnTasks, $next);\n"; | 491 print $fd "${prev}taskManager->next1 = C_$next;\n"; |
492 print $fd "${prev}goto par_meta(context, Gearef(context, TaskManager)->taskManager->TaskManager.spawnTasks, C_$next);\n"; | |
483 next; | 493 next; |
484 } | 494 } |
495 } elsif(/^}/) { | |
496 $inParGoto = 0; | |
485 } | 497 } |
486 else { | 498 else { |
487 s/new\s+(\w+)\(\)/\&ALLOCATE(context, \1)->\1/g; # replacing new | 499 s/new\s+(\w+)\(\)/\&ALLOCATE(context, \1)->\1/g; # replacing new |
488 } | 500 } |
489 # gather type name and type | 501 # gather type name and type |
490 } elsif (/^}/) { | 502 } elsif (/^}/) { |
491 $inParGoto = 0; | |
492 $inStub = 0; | 503 $inStub = 0; |
493 $inTypedef = 0; | 504 $inTypedef = 0; |
494 } | 505 } |
495 print $fd $_; | 506 print $fd $_; |
496 } | 507 } |