Mercurial > hg > GearsTemplate
changeset 527:929aa06a12f9
Generate par goto code gear stub
author | Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Sat, 27 Jan 2018 21:45:58 +0900 |
parents | 8102ef6947a6 |
children | 82ff74c2f162 |
files | src/parallel_execution/examples/calc/add.cbc src/parallel_execution/examples/calc/initIntegerDataGears.cbc src/parallel_execution/examples/calc/mult.cbc src/parallel_execution/generate_stub.pl |
diffstat | 4 files changed, 57 insertions(+), 49 deletions(-) [+] |
line wrap: on
line diff
--- a/src/parallel_execution/examples/calc/add.cbc Thu Jan 25 16:13:01 2018 +0900 +++ b/src/parallel_execution/examples/calc/add.cbc Sat Jan 27 21:45:58 2018 +0900 @@ -1,18 +1,7 @@ #include "../../../context.h" #include <stdio.h> __code add(struct Integer* input1, struct Integer* input2, __code next(struct Integer* output, ...)) { - struct Integer* output = *O_output; output->value = input1->value + input2->value; printf("%d + %d = %d\n", input1->value, input2->value, output->value); - *O_output = output; - goto meta(context, next); + goto next(output, ...); } - -__code add_stub(struct Context* context) { - Integer** O_output = (struct Integer **)&context->data[context->odg]; - goto add(context, - &context->data[context->idg]->Integer, - &context->data[context->idg + 1]->Integer, - context->next, - O_output); -}
--- a/src/parallel_execution/examples/calc/initIntegerDataGears.cbc Thu Jan 25 16:13:01 2018 +0900 +++ b/src/parallel_execution/examples/calc/initIntegerDataGears.cbc Sat Jan 27 21:45:58 2018 +0900 @@ -1,25 +1,8 @@ #include "../../../context.h" #include <stdio.h> __code initIntegerDataGears(__code next(struct Integer* output1, struct Integer* output2, struct Integer* output3, ...)) { - struct Integer* output1 = *O_output1; - struct Integer* output2 = *O_output2; - struct Integer* output3 = *O_output3; output1->value = 1; output2->value = 2; output3->value = 3; - *O_output1 = output1; - *O_output2 = output2; - *O_output3 = output3; - goto meta(context, next); + goto next(output1, output2, output3, ...); } - -__code initIntegerDataGears_stub(struct Context* context) { - Integer** O_output1 = (struct Integer **)&context->data[context->odg]; - Integer** O_output2 = (struct Integer **)&context->data[context->odg+1]; - Integer** O_output3 = (struct Integer **)&context->data[context->odg+2]; - goto initIntegerDataGears(context, - context->next, - O_output1, - O_output2, - O_output3); -}
--- a/src/parallel_execution/examples/calc/mult.cbc Thu Jan 25 16:13:01 2018 +0900 +++ b/src/parallel_execution/examples/calc/mult.cbc Sat Jan 27 21:45:58 2018 +0900 @@ -1,18 +1,7 @@ #include "../../../context.h" #include <stdio.h> __code mult(struct Integer* input1, struct Integer* input2, __code next(struct Integer* output, ...)) { - struct Integer* output = *O_output; output->value = input1->value * input2->value; printf("%d * %d = %d\n", input1->value, input2->value, output->value); - *O_output = output; - goto meta(context, next); + goto next(output, ...); } - -__code mult_stub(struct Context* context) { - Integer** O_output = (struct Integer **)&context->data[context->odg]; - goto mult(context, - &context->data[context->idg]->Integer, - &context->data[context->idg + 1]->Integer, - context->next, - O_output); -}
--- a/src/parallel_execution/generate_stub.pl Thu Jan 25 16:13:01 2018 +0900 +++ b/src/parallel_execution/generate_stub.pl Sat Jan 27 21:45:58 2018 +0900 @@ -118,6 +118,14 @@ &getDataGear("$interfaceHeader"); &getCodeGear("$interfaceHeader"); } + } elsif (/^\_\_code (\w+)\((.*)\)(.*)/) { + my $codeGearName = $1; + if ($filename =~ /^(.*)\/(.*)/) { + $codeGearName = "$1/$codeGearName"; + } + if ( -f "$codeGearName.cbc") { + &getCodeGear("$codeGearName.cbc"); + } } next; } @@ -185,13 +193,22 @@ if ($args =~ s/(^\s*,\s*)//) { } if ($args =~ s/^(\s)*\_\_code\s+(\w+)\((.*?)\)//) { + $codeGear{$codeGearName}->{"code"}->{$2} = "\_\_code"; $inputIncFlag = 0; - $outputCount = split(/,/,$3); - $outputCount--; - } elsif ($args =~ s/^(struct|union)?\s*(\w+)(\*)?+\s(\w+)//) { - if($inputIncFlag) { - $inputCount++; + my @outputs = split(/,/,$3); + for my $output (@outputs) { + if ($output =~ /\s*(struct|union)?\s*(\w+)(\*)?+\s(\w+)/) { + my $type = $2; + my $varName = $4; + $codeGear{$codeGearName}->{"var"}->{$varName} = "$type $outputCount"; + $outputCount++; + } } + } elsif ($args =~ s/^(struct|union)?\s*(\w+)(\*)?+\s(\w+)// && $inputIncFlag) { + my $type = $2; + my $varName = $4; + $codeGear{$codeGearName}->{"var"}->{$varName} = "$type $inputCount"; + $inputCount++; } elsif ($args =~ s/(.*,)//) { } else { last; @@ -224,6 +241,7 @@ # get implementation $dataGearName{$codeGearName} .= "\t$typeName* $varName = ($typeName*)GearImpl(context, $interface, $varName);\n"; } else { + # interface var for my $ivar (keys %{$var{$interface}}) { # input data gear field if ($varName eq $ivar) { @@ -233,12 +251,13 @@ $outputVar{$codeGearName} .= "\t$typeName$ptrType $varName = *O_$varName;\n"; return 1; } - $dataGearName{$codeGearName} .= "\t$typeName$ptrType $varName = Gearef(context, $interface)->$varName;\n"; return 1; } } } + + # interface continuation for my $cName (keys %{$code{$interface}}) { if ($varName eq $cName) { # continuation field @@ -246,6 +265,34 @@ return 1; } } + + # par goto var + for my $var (keys %{$codeGear{$codeGearName}->{"var"}}) { + # input data gear field + if ($varName eq $var) { + my ($type, $count) = split(/\s/, $codeGear{$codeGearName}->{"var"}->{$var}); + if ($typeName eq $type) { + if ($output) { + $dataGearName{$codeGearName} .= "\t$typeName$ptrType* O_$varName = ($typeName $ptrType*)&context->data[context->odg + $count];\n"; + $outputVar{$codeGearName} .= "\t$typeName$ptrType $varName = *O_$varName;\n"; + return 1; + } + $dataGearName{$codeGearName} .= "\t$typeName$ptrType $varName = &context->data[context->idg + $count]->$typeName;\n"; + return 1; + } + } + } + + # par goto continuation + for my $cName (keys %{$codeGear{$codeGearName}->{"code"}}) { + if ($varName eq $cName) { + # continuation field + $dataGearName{$codeGearName} .= "\tenum Code $varName = context->next;\n"; + return 1; + } + } + + # par goto continuation # global or local variable case if ($typeName eq "Code") { $dataGearName{$codeGearName} .= "\tenum $typeName$ptrType $varName = Gearef(context, $interface)->$varName;\n"; @@ -508,7 +555,7 @@ # 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 @args = split(/,/, $3); my $v = 0; for my $n ( @{$dataGearVar{$codeGearName}} ) { # continuation arguments