changeset 385:c1512f358c37

add getCodeGear to generate_stub.pl
author mir3636
date Tue, 25 Jul 2017 21:19:54 +0900
parents ee5d2b1685d7
children 89a9e9c14498
files src/parallel_execution/generate_stub.pl src/parallel_execution/test/stack_test.c
diffstat 2 files changed, 97 insertions(+), 69 deletions(-) [+]
line wrap: on
line diff
--- a/src/parallel_execution/generate_stub.pl	Tue Jul 25 16:43:19 2017 +0900
+++ b/src/parallel_execution/generate_stub.pl	Tue Jul 25 21:19:54 2017 +0900
@@ -100,41 +100,24 @@
                 if ( -f "$interface.cbc") {
                     &getDataGear("$interface.cbc");
                 }
+            } elsif (/^(\s)*(\w+)\-\>(\w+)\s\=\s\((.*)\)create(\w+)\((\w+)\);$/) {
+                #my $intfn = ucfirst($2);
+                my $impln = $5;
+                if ( -f "$impln.cbc") {
+                    &getCodeGear("$impln.cbc");
+                }
             }
             next;
         }
         # gather type name and type
         $dataGear{$name} .= $_;
-	if (/^\s*(.*)\s+(\w+);$/ ) {
+        if (/^\s*(.*)\s+(\w+);$/ ) {
             my $ttype = $1;
             my $tname = $2;
             if ($ttype =~ /^(union|struct) (\w+)/) {
                 $ttype = $2;
             }
             $var{$name}->{$tname} = $ttype;
-        } 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;
@@ -142,6 +125,44 @@
     }
 }
 
+sub getCodeGear {
+    my ($filename) = @_;
+    open my $fd,"<",$filename or die("can't open $filename $!");
+    my ($name,$impln);
+    while (<$fd>) {
+        if (/^(\w+)(\*)+ create(\w+)\(/) {
+            $name = $1;
+            $impln = $3;
+        }
+        if (defined $name) {
+            if (/^\_\_code (\w+)$impln\((.*)\)(.*)/) {
+                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;
+                    }
+                }
+            }
+        }
+    }
+}
+
 sub generateStub {
     my($fd,$prevCodeGearName,$dataGearName) = @_;
     print $fd "__code ", $prevCodeGearName ,"_stub(struct Context* context) {\n";
@@ -331,10 +352,12 @@
                 print $fd "\tGearef(context, $ntype)->$next = $next->$next;\n";
                 # Put interface argument 
                 my $prot = $code{$ntype}->{$method};
+                my $i = 1;
                 for my $arg (@args) {
-                    my $p = shift @$prot;
-                    next if ($p eq $arg);
+                    my $p = @$prot[$i];
+                    next if ( $p eq $arg);
                     print $fd "\tGearef(context, $ntype)->$p = $arg;\n";
+                    $i++;
                 }
                 print $fd "${prev}goto meta(context, $next->$next->$ntype.$method);\n";
                 next;
--- a/src/parallel_execution/test/stack_test.c	Tue Jul 25 16:43:19 2017 +0900
+++ b/src/parallel_execution/test/stack_test.c	Tue Jul 25 21:19:54 2017 +0900
@@ -1,62 +1,67 @@
-#include "../context.h"
+#include "../../context.h"
 #include <assert.h>
 
-__code stack_test1(struct Context* context, struct Task* task, struct Stack* stack) {
-    task->code = C_stack_test1;
-    stack->next = C_stack_test2;
-    stack->data = (union Data*)task;
+__code stackTest1(struct Context *context,struct Stack* stack) {
+    stack->stack = (union Data*)createSingleLinkedStack(context);
+    Node* node = &ALLOCATE(context, Node)->Node;
+    node->color = Red;
+	Gearef(context, Stack)->stack = stack->stack;
+	Gearef(context, Stack)->data = node;
+	Gearef(context, Stack)->next =  stackTest2;
     goto meta(context, stack->stack->Stack.push);
 }
 
-__code stack_test1_stub(struct Context* context) {
-    Task* task = &ALLOCATE(context, Task)->Task;
-    Stack* stack = createSingleLinkedStack(context);
-    assert(stack->stack->SingleLinkedStack.top == NULL);
-    context->data[D_Stack]->Stack.stack = (union Data*)stack;
-    goto stack_test1(context,
-            task,
-            &context->data[D_Stack]->Stack);
-}
+__code stackTest1_stub(struct Context* context) {
+	Stack* stack = Gearef(context, Stack);
+	goto stackTest1(context, stack);
+} 
 
-__code stack_test2(struct Context* context, struct Task* task, struct Stack* stack) {
-    task->code = C_stack_test2;
-    stack->next = C_stack_test3;
-    stack->data = (union Data*)task;
+__code stackTest2(struct Context *context,struct Stack* stack) {
+    Node* node = &ALLOCATE(context, Node)->Node;
+    node->color = Black;
+	Gearef(context, Stack)->stack = stack->stack;
+	Gearef(context, Stack)->data = node;
+	Gearef(context, Stack)->next =  stackTest3;
     goto meta(context, stack->stack->Stack.push);
 }
 
-__code stack_test2_stub(struct Context* context) {
-    assert(context->data[D_Stack]->Stack.stack->Stack.stack->SingleLinkedStack.top->data->Task.code == C_stack_test1);
-    Task* task = &ALLOCATE(context, Task)->Task;
-    goto stack_test2(context,
-            task,
-            &context->data[D_Stack]->Stack);
+__code stackTest2_stub(struct Context* context) {
+    SingleLinkedStack* singleLinkedStack = &stack->stack->Stack.stack->SingleLinkedStack;
+    assert(singleLinkedStack->top->data->Node.color == Red);
+    Stack* stack = Gearef(context, Stack);
+    goto stackTest2(context, stack);
 }
 
-__code stack_test3(struct Context* context, struct Stack* stack) {
-    stack->next = C_stack_test4;
+__code stackTest3(struct Context *context,struct Stack* stack) {
+	Gearef(context, Stack)->stack = stack->stack;
+	Gearef(context, Stack)->next = assert3;
     goto meta(context, stack->stack->Stack.pop);
 }
 
-__code stack_test3_stub(struct Context* context) {
-    assert(context->data[D_Stack]->Stack.stack->Stack.stack->SingleLinkedStack.top->data->Task.code == C_stack_test2);
-    goto stack_test3(context,
-            &context->data[D_Stack]->Stack);
-}
+__code stackTest3_stub(struct Context* context) {
+    /*
+        assert on stack implementation
+    */
+    SingleLinkedStack* singleLinkedStack = &stack->stack->Stack.stack->SingleLinkedStack;
+    assert(singleLinkedStack->top->data->Node.color == Black);
+    Stack* stack = Gearef(context, Stack);
+    goto stackTest3(context, stack);
+} 
 
-__code stack_test4(struct Context* context) {
-    goto meta(context, C_exit_code);
-}
-
-__code stack_test4_stub(struct Context* context) {
-    assert(context->data[D_Stack]->Stack.data->Task.code == C_stack_test2);
-    assert(context->data[D_Stack]->Stack.stack->Stack.stack->SingleLinkedStack.top->data->Task.code == C_stack_test1);
-    goto stack_test4(context);
+__code assert3(struct Context *context,struct Node* node, struct Stack* stack) {
+    /*
+        assert in normal level
+    */
+    assert(node->color == Red);
+    goto exit_code(0);
 }
 
 int main(int argc, char const* argv[]) {
-    struct Context* main_context = NEW(struct Context);
-    initContext(main_context);
-    main_context->next = C_stack_test1;
-    goto start_code(main_context);
+    goto stackTest1();
 }
+__code assert3_stub(struct Context* context) {
+	Node* node = Gearef(context, Node);
+	Stack* stack = Gearef(context, Stack);
+	goto assert3(context, node, stack);
+} 
+