Mercurial > hg > GearsTemplate
diff src/parallel_execution/generate_stub.pl @ 461:6b71cf5b1c22
Change Interface files from cbc to header
author | Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Wed, 20 Dec 2017 17:54:15 +0900 |
parents | 3025d00eb87d |
children | 8d7e5d48cad3 |
line wrap: on
line diff
--- a/src/parallel_execution/generate_stub.pl Sat Dec 16 06:04:32 2017 +0900 +++ b/src/parallel_execution/generate_stub.pl Wed Dec 20 17:54:15 2017 +0900 @@ -26,7 +26,7 @@ } } -for my $fn (@ARGV) { +for my $fn (@ARGV) { next if ($fn !~ /\.cbc$/); &getDataGear($fn); &generateDataGear($fn); @@ -95,19 +95,13 @@ $generic{$name} = []; } elsif (/^(\w+)(\*)+ create(\w+)\(/) { if (defined $interface) { - die "duplicate interface $interface\n"; + die "duplicate interface $interface\n"; } $interface = $1; $implementation = $3; if ( -f "$interface.cbc") { &getDataGear("$interface.cbc"); } - } elsif (/\s*\=\s*(.*)create(\w+)\((.*)\);$/) { - #my $intfn = ucfirst($2); - my $impln = $2; - if ( -f "$impln.cbc") { - &getCodeGear("$impln.cbc"); - } } elsif(/^(.*)par goto (\w+)\((.*)\)/) { my $codeGearName = $2; if ($filename =~ /^(.*)\/(.*)/) { @@ -116,6 +110,14 @@ if ( -f "$codeGearName.cbc") { &getCodeGear("$codeGearName.cbc"); } + } elsif(/^#include "(.*)"/) { + # interface include + my $interfaceHeader = $1; + next if ($interfaceHeader =~ /context.h/); + if (-f $interfaceHeader) { + &getDataGear("$interfaceHeader"); + &getCodeGear("$interfaceHeader"); + } } next; } @@ -133,6 +135,7 @@ $inTypedef = 0; } } + } sub getCodeGear { @@ -143,26 +146,28 @@ if (/^(\w+)(\*)+ create(\w+)\(/) { $name = $1; $impln = $3; + } elsif(/^typedef struct (.*)<.*>\s*{/) { + $name = $1; } if (defined $name) { - if (/^\_\_code (\w+)$impln\((.*)\)(.*)/) { + if (/^\s*\_\_code (\w+)\((.*)\);/) { my $args = $2; my $method = $1; $code{$name}->{$method} = []; while($args) { - if ($args =~ s/(^\s*,\s*)//) { - } + # replace comma + $args =~ s/(^\s*,\s*)//; # continuation case if ($args =~ s/^(\s)*\_\_code\s+(\w+)\(([^)]*)\)//) { my $next = $2; my @args = split(/,/,$3); - push(@{$code{$name}->{$method}},"\_\_code $next"); - } elsif ($args =~ s/^(struct|union) (\w+)(\*)+\s(\w+)//) { + push(@{$code{$name}->{$method}},"\_\_code $next"); + } elsif ($args =~ s/^(struct|union)?\s*(\w+)(\*)?+\s(\w+)//) { my $structType = $1; my $typeName = $2; my $varName = $4; my $typeField = lcfirst($typeName); - push(@{$code{$name}->{$method}},"$typeName $varName"); + push(@{$code{$name}->{$method}},"$typeName $varName"); } elsif ($args =~ s/(.*,)//) { } else { last; @@ -207,7 +212,7 @@ sub generateStubArgs { my($codeGearName, $varName, $typeName, $typeField, $interface,$output) = @_; - my $varname1 = $output?"O_$varName":$varName; + my $varname1 = $output?"O_$varName":$varName; for my $n ( @{$dataGearVar{$codeGearName}} ) { # we already have it return 0 if ( $n eq $varname1); @@ -219,7 +224,7 @@ $dataGearName{$codeGearName} .= "\t$typeName* $varName = ($typeName*)GearImpl(context, $interface, $varName);\n"; } else { for my $ivar (keys %{$var{$interface}}) { - # input data gear field + # input data gear field if ($varName eq $ivar) { if ($typeName eq $var{$interface}->{$ivar}) { if ($output) { @@ -358,7 +363,7 @@ $newArgs .= $&; # assuming no duplicate &generateStubArgs($codeGearName, $varName, $typeName, $typeField, $interface,0); } elsif ($args =~ s/(.*,)//) { - $newArgs .= $1; + $newArgs .= $1; } else { $newArgs .= $args; last; @@ -379,7 +384,7 @@ } next; } elsif (/^(.*)goto (\w+)\-\>(\w+)\((.*)\);/) { - # handling goto statement + # handling goto statement # convert it to the meta call form with two arugments, that is context and enum Code my $prev = $1; my $next = $2; @@ -418,7 +423,7 @@ } else { print $fd "\tGearef(context, $ntype)->$pName = C_$arg;\n"; } - } elsif ($pType =~ s/Data$//){ + } elsif ($pType =~ s/Data$//){ print $fd "\tGearef(context, $ntype)->$pName = (union Data*) $arg;\n"; } else { print $fd "\tGearef(context, $ntype)->$pName = $arg;\n"; @@ -432,141 +437,141 @@ # convert it to the parallel my $prev = $1; my $codeGearName = $2; - my $args = $3; + my $args = $3; my $inputCount = $codeGear{$codeGearName}->{'input'}; my $outputCount = $codeGear{$codeGearName}->{'output'}; my @iterateCounts; # parse examples 'par goto(.., iterate(10), exit);' - if ($args =~ /iterate\((.*)?\),/) { - @iterateCounts = split(/,/,$1);; - $inputCount--; - } - # replace iterate keyword - $args =~ s/iterate\((.*)?\),//; - my @dataGears = split(/,\s*/, $args); - my $nextCodeGear = pop(@dataGears); - if (! $inParGoto) { - $inParGoto = 1; - print $fd "${prev}struct Element* element;\n"; - } - my $initTask = << "EOFEOF"; - ${prev}context->task = NEW(struct Context); - ${prev}initContext(context->task); - ${prev}context->task->next = C_$codeGearName; - ${prev}context->task->idgCount = $inputCount; - ${prev}context->task->idg = context->task->dataNum; - ${prev}context->task->maxIdg = context->task->idg + $inputCount; - ${prev}context->task->odg = context->task->maxIdg; - ${prev}context->task->maxOdg = context->task->odg + $outputCount; + if ($args =~ /iterate\((.*)?\),/) { + @iterateCounts = split(/,/,$1);; + $inputCount--; + } + # replace iterate keyword + $args =~ s/iterate\((.*)?\),//; + my @dataGears = split(/,\s*/, $args); + my $nextCodeGear = pop(@dataGears); + if (! $inParGoto) { + $inParGoto = 1; + print $fd "${prev}struct Element* element;\n"; + } + my $initTask = << "EOFEOF"; + ${prev}context->task = NEW(struct Context); + ${prev}initContext(context->task); + ${prev}context->task->next = C_$codeGearName; + ${prev}context->task->idgCount = $inputCount; + ${prev}context->task->idg = context->task->dataNum; + ${prev}context->task->maxIdg = context->task->idg + $inputCount; + ${prev}context->task->odg = context->task->maxIdg; + ${prev}context->task->maxOdg = context->task->odg + $outputCount; EOFEOF - print $fd $initTask; - if (@iterateCounts) { - print $fd "${prev}context->task->iterate = 0;\n"; - my $len = @iterateCounts; - if ($len == 1) { - print $fd "${prev}context->task->iterator = createMultiDimIterator(context, $iterateCounts[0], 1, 1);\n"; - } elsif ($len == 2) { - print $fd "${prev}context->task->iterator = createMultiDimIterator(context, $iterateCounts[0], $iterateCounts[1], 1);\n"; - } elsif ($len == 3) { - print $fd "${prev}context->task->iterator = createMultiDimIterator(context, $iterateCounts[0], $iterateCounts[1], $iterateCounts[2]);\n"; - } - } - for my $dataGear (@dataGears) { - print $fd "${prev}GET_META($dataGear)->wait = createSynchronizedQueue(context);\n"; - } - for my $i (0..$inputCount-1) { - print $fd "${prev}context->task->data[context->task->idg+$i] = (union Data*)@dataGears[$i];\n"; - } + print $fd $initTask; + if (@iterateCounts) { + print $fd "${prev}context->task->iterate = 0;\n"; + my $len = @iterateCounts; + if ($len == 1) { + print $fd "${prev}context->task->iterator = createMultiDimIterator(context, $iterateCounts[0], 1, 1);\n"; + } elsif ($len == 2) { + print $fd "${prev}context->task->iterator = createMultiDimIterator(context, $iterateCounts[0], $iterateCounts[1], 1);\n"; + } elsif ($len == 3) { + print $fd "${prev}context->task->iterator = createMultiDimIterator(context, $iterateCounts[0], $iterateCounts[1], $iterateCounts[2]);\n"; + } + } + for my $dataGear (@dataGears) { + print $fd "${prev}GET_META($dataGear)->wait = createSynchronizedQueue(context);\n"; + } + for my $i (0..$inputCount-1) { + print $fd "${prev}context->task->data[context->task->idg+$i] = (union Data*)@dataGears[$i];\n"; + } - for my $i (0..$outputCount-1) { - print $fd "${prev}context->task->data[context->task->odg+$i] = (union Data*)@dataGears[$inputCount+$i];\n"; - } - my $putTask = << "EOFEOF"; - ${prev}element = &ALLOCATE(context, Element)->Element; - ${prev}element->next = NULL; - ${prev}element->data = (union Data*)context->task; - ${prev}context->tasks->queue->SingleLinkedQueue.last->next = element; - ${prev}context->tasks->queue->SingleLinkedQueue.last = element; + for my $i (0..$outputCount-1) { + print $fd "${prev}context->task->data[context->task->odg+$i] = (union Data*)@dataGears[$inputCount+$i];\n"; + } + my $putTask = << "EOFEOF"; + ${prev}element = &ALLOCATE(context, Element)->Element; + ${prev}element->next = NULL; + ${prev}element->data = (union Data*)context->task; + ${prev}context->tasks->queue->SingleLinkedQueue.last->next = element; + ${prev}context->tasks->queue->SingleLinkedQueue.last = element; EOFEOF - print $fd $putTask; - next; - } elsif (/^(.*)goto (\w+)\((.*)\);/) { - # handling goto statement - # convert it to the meta call form with two arugments, that is context and enum Code - my $prev = $1; - my $next = $2; - my @args = split(/, /,$3); - my $v = 0; - for my $n ( @{$dataGearVar{$codeGearName}} ) { - # continuation arguments - $v = 1 if ( $n eq $next); - } - if ($v || defined $code{$interface}->{$next}) { - # write continuation's arguments into the interface arguments - # we may need a commit for a shared DataGear - for my $arg ( @{$outputArgs{$codeGearName}->{$next}} ) { - my $v = shift(@args); - print $fd "\t*O_$arg = $v;\n"; - } - if ($inParGoto) { - print $fd "${prev}taskManager->tasks = context->tasks;\n"; - print $fd "${prev}taskManager->next1 = C_$next;\n"; - print $fd "${prev}goto meta(context, C_$next);\n"; - } else { - print $fd "${prev}goto meta(context, $next);\n"; - } - next; - } - if ($inParGoto) { - print $fd "${prev}taskManager->tasks = context->tasks;\n"; - print $fd "${prev}taskManager->next1 = C_$next;\n"; - print $fd "${prev}goto meta(context, C_$next);\n"; - next; - } elsif ($next eq "meta") { - print $fd $_; - next; - } else { - print $fd "${prev}goto meta(context, C_$next);\n"; - next; - } - } elsif(/^.*(struct|union)?\s(\w+)\*\s(\w+)\s?[=;]/) { - my $type = $2; - my $varName = $3; - $localVarType{$varName} = $type; - s/new\s+(\w+)\(\)/\&ALLOCATE(context, \1)->\1/g; # replacing new - } - elsif(/^}/) { - $inParGoto = 0; - } else { - s/new\s+(\w+)\(\)/\&ALLOCATE(context, \1)->\1/g; # replacing new - } - # gather type name and type - } elsif ($inMain) { - if (/^(.*)goto start_code\(main_context\);/) { - print $fd $_; - next; - } elsif (/^(.*)goto (\w+)\((.*)\);/) { - my $prev = $1; - my $next = $2; - print $fd "${prev}struct Context* main_context = NEW(struct Context);\n"; - print $fd "${prev}initContext(main_context);\n"; - print $fd "${prev}main_context->next = C_$next;\n"; - print $fd "${prev}goto start_code(main_context);\n"; - next; - } - } - if (/^}/) { - $inStub = 0; - $inTypedef = 0; - $inMain = 0; - } - print $fd $_; - } - if (defined $prevCodeGearName) { - if (!defined $stub{$prevCodeGearName."_stub"}) { - $stub{$prevCodeGearName."_stub"} = &generateStub($fd,$prevCodeGearName,$dataGearName{$codeGearName}); - } - } + print $fd $putTask; + next; + } elsif (/^(.*)goto (\w+)\((.*)\);/) { + # handling goto statement + # convert it to the meta call form with two arugments, that is context and enum Code + my $prev = $1; + my $next = $2; + my @args = split(/, /,$3); + my $v = 0; + for my $n ( @{$dataGearVar{$codeGearName}} ) { + # continuation arguments + $v = 1 if ( $n eq $next); + } + if ($v || defined $code{$interface}->{$next}) { + # write continuation's arguments into the interface arguments + # we may need a commit for a shared DataGear + for my $arg ( @{$outputArgs{$codeGearName}->{$next}} ) { + my $v = shift(@args); + print $fd "\t*O_$arg = $v;\n"; + } + if ($inParGoto) { + print $fd "${prev}taskManager->tasks = context->tasks;\n"; + print $fd "${prev}taskManager->next1 = C_$next;\n"; + print $fd "${prev}goto meta(context, C_$next);\n"; + } else { + print $fd "${prev}goto meta(context, $next);\n"; + } + next; + } + if ($inParGoto) { + print $fd "${prev}taskManager->tasks = context->tasks;\n"; + print $fd "${prev}taskManager->next1 = C_$next;\n"; + print $fd "${prev}goto meta(context, C_$next);\n"; + next; + } elsif ($next eq "meta") { + print $fd $_; + next; + } else { + print $fd "${prev}goto meta(context, C_$next);\n"; + next; + } + } elsif(/^.*(struct|union)?\s(\w+)\*\s(\w+)\s?[=;]/) { + my $type = $2; + my $varName = $3; + $localVarType{$varName} = $type; + s/new\s+(\w+)\(\)/\&ALLOCATE(context, \1)->\1/g; # replacing new + } + elsif(/^}/) { + $inParGoto = 0; + } else { + s/new\s+(\w+)\(\)/\&ALLOCATE(context, \1)->\1/g; # replacing new + } + # gather type name and type + } elsif ($inMain) { + if (/^(.*)goto start_code\(main_context\);/) { + print $fd $_; + next; + } elsif (/^(.*)goto (\w+)\((.*)\);/) { + my $prev = $1; + my $next = $2; + print $fd "${prev}struct Context* main_context = NEW(struct Context);\n"; + print $fd "${prev}initContext(main_context);\n"; + print $fd "${prev}main_context->next = C_$next;\n"; + print $fd "${prev}goto start_code(main_context);\n"; + next; + } + } + if (/^}/) { + $inStub = 0; + $inTypedef = 0; + $inMain = 0; + } + print $fd $_; + } + if (defined $prevCodeGearName) { + if (!defined $stub{$prevCodeGearName."_stub"}) { + $stub{$prevCodeGearName."_stub"} = &generateStub($fd,$prevCodeGearName,$dataGearName{$codeGearName}); + } + } } # end