changeset 373:03fdea4ef680

Fix perl script
author Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
date Tue, 11 Jul 2017 18:18:14 +0900
parents d6ce4273e7d1
children fb50cf8aa615
files src/parallel_execution/generate_stub.pl
diffstat 1 files changed, 88 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/src/parallel_execution/generate_stub.pl	Tue Jul 11 17:47:11 2017 +0900
+++ b/src/parallel_execution/generate_stub.pl	Tue Jul 11 18:18:14 2017 +0900
@@ -38,21 +38,59 @@
 my %outputArgs;      # continuation's output variables
 my %dataGear;
 my %dataGearName;
+my %generic;
+my %dataGearVarType;
 my $implementation;
 my $interface;
 
+# interface definision
+#
+# typedef struct Stack<Type, Impl>{
+#         Type* stack;
+#         Type* data;
+#         Type* data1;
+#         __code whenEmpty(...);
+#         __code clear(Impl* stack,__code next(...));
+#         __code push(Impl* stack,Type* data, __code next(...));
+#         __code pop(Impl* stack, __code next(Type*, ...));
+#         __code pop2(Impl* stack, Type** data, Type** data1, __code next(Type**, Type**, ...));
+#         __code isEmpty(Impl* stack, __code next(...), __code whenEmpty(...));
+#         __code get(Impl* stack, Type** data, __code next(...));
+#         __code get2(Impl* stack,..., __code next(...));
+#         __code next(...);
+# } Stack;
+#
+# calling example
+#
+# goto nodeStack->push((union Data*)node, stackTest3);
+#
+# generated meta level code
+#
+# Gearef(context, Stack)->stack = nodeStack->stack;
+# Gearef(context, Stack)->data = (union Data*)node;
+# Gearef(context, Stack)->next = C_stackTest3;
+# goto meta(context, nodeStack->push);
+
 sub getDataGear {
     my ($filename) = @_;
     my ($codeGearName, $name, $inTypedef);
     open my $fd,"<",$filename or die("can't open $filename $!");
     while (<$fd>) {
         if (! $inTypedef) {
-            if (/^typedef struct (\w+)/) {
+            if (/^typedef struct (\w+)\s*<(.*)>/) {
                 $inTypedef = 1;
                 $name = $1;
                 $dataGear{$name} = $_;
                 $var{$name} = {};
                 $code{$name} = {};
+                $generic{$name} = \split(/,/,$2);
+            } elsif (/^typedef struct (\w+)/) {
+                $inTypedef = 1;
+                $name = $1;
+                $dataGear{$name} = $_;
+                $var{$name} = {};
+                $code{$name} = {};
+                $generic{$name} = [];
             } elsif (/^(\w+)(\*)+ create(\w+)\(/) {
                 if (defined $interface) {
                    die "duplicate interface $interface\n"; 
@@ -74,8 +112,29 @@
                 $ttype = $2;
             }
             $var{$name}->{$tname} = $ttype;
-	} elsif (/\_\_code (\w+)\(/) {
-            $code{$name}->{$1} = 1;
+        } elsif (/^\_\_code (\w+)\((.*)\)(.*)/) {
+            my $args = $2;
+            my $method = $1;
+            $code{$name}->{$method} = [];
+            while($args) {
+                if ($args =~ s/(^\s*,\s*)//) {
+                }
+                # continuation case
+                if ($args =~ s/^(\s)*\_\_code\s+(\w+)\(([^)]*)\)//) {
+                    my $next = $2;
+                    my @args = split(/,/,$3);
+                    push(@{$code{$name}->{$method}},$next); 
+                } elsif ($args =~ s/^(struct|union) (\w+)(\*)+\s(\w+)//) {
+                    my $structType = $1;
+                    my $typeName = $2;
+                    my $varName = $4;
+                    my $typeField = lcfirst($typeName);
+                    push(@{$code{$name}->{$method}},$varName); 
+                } elsif ($args =~ s/(.*,)//) {
+                } else {
+                    last;
+                }
+            }
         }
         if (/^}/) {
             $inTypedef = 0;
@@ -99,6 +158,7 @@
         return 0 if ( $n eq $varname1);
     }
     push @{$dataGearVar{$codeGearName}}, $varname1;
+    push @{$dataGearVarType{$codeGearName}}, $typeName;
     if ($typeName eq $implementation) {
         # get implementation
         $dataGearName{$codeGearName} .= "\t$typeName* $varName = ($typeName*)GearImpl(context, $interface, $varName);\n";
@@ -253,6 +313,31 @@
                     print $fd $outputVar{$codeGearName};
                 }
                 next;
+            } elsif (/^(.*)goto (\w+)\-\>(\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 $method = $3;
+                my @args = split(/,/,$4);
+                my @types = @{$dataGearVarType{$codeGearName}};
+                my $ntype;
+                for my $v (@{$dataGearVar{$codeGearName}}) {
+                    my $t = shift @types;
+                    if ($v eq $next) {
+                        $ntype = $t;
+                    }
+                }
+                print $fd "\tGearef(context, $ntype)->$next = $next->$next;\n";
+                # Put interface argument 
+                my $prot = $code{$ntype}->{$method};
+                for my $arg (@args) {
+                    my $p = shift @$prot;
+                    next if ($p eq $arg);
+                    print $fd "\tGearef(context, $ntype)->$p = $arg;\n";
+                }
+                print $fd "${prev}goto meta(context, $next->$next->$ntype.$method);\n";
+                next;
             } elsif (/^(.*)goto (\w+)\((.*)\);/) {
                 # handling goto statement  
                 # convert it to the meta call form with two arugments, that is context and enum Code