Mercurial > hg > GearsTemplate
changeset 250:8a8963ce9858
fix generate_stub
author | mir3636 |
---|---|
date | Wed, 25 Jan 2017 21:22:56 +0900 |
parents | afa1e02e4386 |
children | 0ab52d6e2fd9 |
files | src/parallel_execution/Stack.cbc src/parallel_execution/generate_stub.pl |
diffstat | 2 files changed, 86 insertions(+), 82 deletions(-) [+] |
line wrap: on
line diff
--- a/src/parallel_execution/Stack.cbc Wed Jan 25 18:41:50 2017 +0900 +++ b/src/parallel_execution/Stack.cbc Wed Jan 25 21:22:56 2017 +0900 @@ -2,36 +2,14 @@ union Data* stack; union Data* data; union Data* data1; - enum Code whenEmpty; + __code whenEmpty(...); __code clear(Impl* stack,__code next(...)); - enum Code push; - enum Code pop; - enum Code pop2; - enum Code isEmpty; - enum Code get; - enum Code get2; - enum Code next; + __code push(Impl* stack,union Data* data, __code next(...)); + __code pop(Impl* stack, __code next(union Data*, ...)); + __code pop2(Impl* stack, union Data** data, union Data** data1, __code next(union Data**, union Data**, ...)); + __code isEmpty(Impl* stack, __code next(...), __code whenEmpty(...)); + __code get(Impl* stack, union Data** data, __code next(...)); + __code get2(Impl* stack,..., __code next(...)); + __code next(...); } Stack; -__code clear(Impl* stack,__code next(...)) { -} - -__code pushSingleLinkedStack(struct SingleLinkedStack* stack,union Data* data, __code next(...)) { -} - -__code popSingleLinkedStack(struct SingleLinkedStack* stack, __code next(..., union Data*)) { -} - -__code pop2SingleLinkedStack(struct SingleLinkedStack* stack, union Data** data, union Data** data1, __code next(..., union Data**, union Data**)) { -} - -__code getSingleLinkedStack(struct SingleLinkedStack* stack, union Data** data, __code next(...)) { -} - -__code get2SingleLinkedStack(struct SingleLinkedStack* stack,..., __code next(...)) { -} - -__code isEmptySingleLinkedStack(struct SingleLinkedStack* stack, __code next(...), __code whenEmpty(...)) { -} - -
--- a/src/parallel_execution/generate_stub.pl Wed Jan 25 18:41:50 2017 +0900 +++ b/src/parallel_execution/generate_stub.pl Wed Jan 25 21:22:56 2017 +0900 @@ -1,5 +1,7 @@ #!/usr/bin/perl +use strict; + # interface.cbc # typedef struct Worker { # int id; @@ -11,17 +13,22 @@ # struct Queue* tasks; # } Worker; -system "rm -rf d"; -system "mkdir d"; - while (<*.cbc>) { my $fn = $_; &getDataGear($fn); &generateDataGear($fn); } +my %var; +my %type; +my %code; +my %dataGearVar; +my %dataGear; +my %dataGearName; + sub getDataGear { my ($filename) = @_; + my ($interface, $implementation, $codeGearName, $name, $inTypedef); open my $fd,"<",$filename or die("can't open $filename $!"); while (<$fd>) { if (! $inTypedef) { @@ -34,29 +41,43 @@ die "duplicate interface $interface\n"; } $interface = $1; - $implimentation = $2; + $implementation = $2; + if ( -f "$interface.cbc") { + &getDataGear("$interface.cbc"); + } } elsif (/^\_\_code (\w+)/) { $codeGearName = $1; $dataGearVar{$codeGearName} = []; - while (/(struct|union) (\w+)\*\s(\w+)/g) { - $tmp = lcfirst($2); - if ($tmp ne $3) { - $tmp = ucfirst($3); - push @$dataGearVar{$codeGearName},$tmp; - $dataGearName{$codeGearName} .= "\t$2* $tmp = (" . $2 . "*)GearImpl(context, " . $tmp . ", " . $3 . ")"; - $dataGearName{$codeGearName} .= ",\n"; + args:while (/(struct|union) (\w+)\*\s(\w+)/g) { + my $structType = $1; + my $typeName = $2; + my $varName = $3; + my $typeField = lcfirst($typeName); + push @{$dataGearVar{$codeGearName}},$varName; + if ($typeField ne $varName) { + $dataGearName{$codeGearName} .= "\t$typeName* $varName = (" . $typeName . "*)GearImpl(context, " . $varName . ", " . $varName . ");\n"; } else { - push @$dataGearVar{$codeGearName},$3; - $dataGearName{$codeGearName} .= "\t$2* $3 = Gearef(context, " . $2 . ")->$3;\n"; + for my $ivar ( $var{$interface}) { + if ($varName eq $ivar) { + $dataGearName{$codeGearName} .= "\t$typeName* $varName = Gearef(context, $interface)->$varName;\n"; + next args; + } + } + $dataGearName{$codeGearName} .= "\t$typeName* $varName = Gearef(context, " . $typeName . ")->$typeField;\n"; } } + $dataGearName{$codeGearName} .= "\tgoto $codeGearName(context"; + for my $arg ( @{$dataGearVar{$codeGearName}}) { + $dataGearName{$codeGearName} .= ", $arg"; + } + $dataGearName{$codeGearName} .= ");"; } next; } # gather type name and type $dataGear{$name} .= $_; if (/(\w+);$/ and !/^} (\w+)/) { - $tmp = $1 . "\n"; + my $tmp = $1 . "\n"; if (/{/) { $tmp = "{" . $'; $tmp =~ s/;$//; @@ -65,73 +86,78 @@ $tmp = $`; $tmp =~ s/^\s*//; $type{$name} .= $tmp . "\n"; - } + } elsif (/\_\_code (\w+)\(/) { + push $code{$name}, $1; + } if (/^}/) { $inTypedef = 0; } } } +sub generateStub { + my($fd,$prevCodeGearName) = @_; + print $fd "__code ", $prevCodeGearName ,"_stub (struct Context* context) {\n"; + print $fd $dataGearName{$codeGearName}; + print $fd "\n} \n\n"; + $stub{$prevCodeGearName."_stub"} = 1; +} + sub generateDataGear { my ($filename) = @_; - my $fn = $filename; - $fn =~ s/\.cbc/.c/; + my $fn1 = $filename; + $fn1 =~ s/\.cbc/.c/; open my $in,"<",$filename or die("can't open $filename $!"); + my $i = 1; + my $fn = $fn1; + while ( -f $fn) { + $fn = "$fn1.$i"; + $i++; + } open my $fd,">",$fn or die("can't write $fn $!"); my $prevCodeGearName; + my $inTypedef = 0; + my %stub; while (<$in>) { if (! $inTypedef) { if (/^typedef struct (\w+) {/) { $inTypedef = 1; } elsif (/^\_\_code (\w+)/) { my $codeGearName = $1; + if ($codeGearName =~ /_stub$/) { + $stub{$codeGearName} = 1; + print $fd $_; + next; + } if (defined $prevCodeGearName) { - print $fd "__code ", $prevCodeGearName ,"_stub (struct Context* context) {\n"; - print $fd "\tgoto " . $prevcodeGearName . "("; - #print $fd "\tgoto " . $prevcodeGearName . "(context,\n"; - print $fd substr($dataGearName{$codeGearName},2,-2); - print $fd "); \n} \n\n"; + if (defined $stub{$prevCodeGearName."_stub"}) { + undef $prevCodeGearName; + print $fd $_; + next; + } + &generateStub; } $prevCodeGearName = $codeGearName; - while (s/\_\_code next\(\.\.\.([^)]*)/enum Code next/) { - } - while (/(struct|union) (\w+)\*\s(\w+)/g) { - my $tmp = lcfirst($2); - if ($tmp ne $3) { - $tmp = ucfirst($3); - } else { - } - } + } elsif (/^(.*)goto next\(\.\.\.(.*)\);/) { + my $prev = $1; + my $args = $2; + print $fd "${prev}goto meta(context, next);\n"; + next; } + print $fd $_; next; } # gather type name and type if (/^}/) { $inTypedef = 0; } + print $fd $_; } -# open my $fd,">","d/extern.h" or die("can't open d/extern.h $!"); -# for my $name ( sort keys %dataGear ) { -# print $fd $dataGear{$name},"\n"; -# } -# print $fd "\n"; -# -# open my $fd,">","d/type.h" or die("can't open d/stub.h $!"); -# for my $name ( sort keys %dataGear ) { -# print $fd $var{$name},"\n"; -# } -# for my $name ( sort keys %dataGear ) { -# print $fd $type{$name},"\n"; -# } - - for my $codeGearName ( sort keys %dataGearName ) { - print $fd "__code ", $codeGearName ,"_stub (struct Context* context) {\n"; - print $fd "\tgoto " . $codeGearName . "("; - #print $fd "\tgoto " . $codeGearName . "(context,\n"; - print $fd substr($dataGearName{$codeGearName},2,-2); - print $fd "); \n} \n\n"; + if (defined $prevCodeGearName) { + if (!defined $stub{$prevCodeGearName."_stub"}) { + &generateStub; + } } - print $fd "\n"; } # end