Mercurial > hg > Members > Moririn
changeset 249:afa1e02e4386
fix generate stub
author | mir3636 |
---|---|
date | Wed, 25 Jan 2017 18:41:50 +0900 |
parents | 1ede5390cda2 |
children | 8a8963ce9858 |
files | src/parallel_execution/Stack.cbc src/parallel_execution/generate_stub.pl |
diffstat | 2 files changed, 94 insertions(+), 28 deletions(-) [+] |
line wrap: on
line diff
--- a/src/parallel_execution/Stack.cbc Wed Jan 25 16:55:53 2017 +0900 +++ b/src/parallel_execution/Stack.cbc Wed Jan 25 18:41:50 2017 +0900 @@ -1,9 +1,9 @@ -typedef struct Stack { +typedef struct Stack<Impl>{ union Data* stack; union Data* data; union Data* data1; enum Code whenEmpty; - enum Code clear; + __code clear(Impl* stack,__code next(...)); enum Code push; enum Code pop; enum Code pop2; @@ -12,3 +12,26 @@ enum Code get2; enum 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 16:55:53 2017 +0900 +++ b/src/parallel_execution/generate_stub.pl Wed Jan 25 18:41:50 2017 +0900 @@ -15,11 +15,11 @@ system "mkdir d"; while (<*.cbc>) { - &getDataGear($_); + my $fn = $_; + &getDataGear($fn); + &generateDataGear($fn); } -&generateDataGear(); - sub getDataGear { my ($filename) = @_; open my $fd,"<",$filename or die("can't open $filename $!"); @@ -29,24 +29,31 @@ $inTypedef = 1; $name = $1; $dataGear{$name} = $_; - } - if (/^\_\_code (\w+)/) { + } elsif (/^(\w+)\* create(\w+)\(/) { + if (defined $interface) { + die "duplicate interface $interface\n"; + } + $interface = $1; + $implimentation = $2; + } elsif (/^\_\_code (\w+)/) { $codeGearName = $1; - while (/struct (\w+)\*\s(\w+)/g) { - $tmp = lcfirst($1); - if ($tmp ne $2) { - $tmp = ucfirst($2); - $dataGearName{$codeGearName} .= "\t\t(" . $1 . "*)GearImpl(context, " . $tmp . ", " . $2 . ")"; + $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"; } else { - $dataGearName{$codeGearName} .= "\t\tGearef(context, " . $1 . ")"; - $dataGearName{$codeGearName} .= ",\n"; + push @$dataGearVar{$codeGearName},$3; + $dataGearName{$codeGearName} .= "\t$2* $3 = Gearef(context, " . $2 . ")->$3;\n"; } } - next; } next; } + # gather type name and type $dataGear{$name} .= $_; if (/(\w+);$/ and !/^} (\w+)/) { $tmp = $1 . "\n"; @@ -66,21 +73,57 @@ } sub generateDataGear { - 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"; + my ($filename) = @_; + my $fn = $filename; + $fn =~ s/\.cbc/.c/; + open my $in,"<",$filename or die("can't open $filename $!"); + open my $fd,">",$fn or die("can't write $fn $!"); + my $prevCodeGearName; + while (<$in>) { + if (! $inTypedef) { + if (/^typedef struct (\w+) {/) { + $inTypedef = 1; + } elsif (/^\_\_code (\w+)/) { + my $codeGearName = $1; + 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"; + } + $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 { + } + } + } + next; + } + # gather type name and type + if (/^}/) { + $inTypedef = 0; + } } - 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"; - } +# 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"; +# } - open my $fd,">","d/stub.h" or die("can't open d/stub.h $!"); for my $codeGearName ( sort keys %dataGearName ) { print $fd "__code ", $codeGearName ,"_stub (struct Context* context) {\n"; print $fd "\tgoto " . $codeGearName . "(";