changeset 418:a74bec89c198

generate main
author mir3636
date Fri, 06 Oct 2017 14:39:36 +0900
parents eec6553a2aa6
children 3789144f972e
files src/parallel_execution/RedBlackTree.cbc src/parallel_execution/generate_stub.pl
diffstat 2 files changed, 22 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/src/parallel_execution/RedBlackTree.cbc	Thu Oct 05 17:00:48 2017 +0900
+++ b/src/parallel_execution/RedBlackTree.cbc	Fri Oct 06 14:39:36 2017 +0900
@@ -7,7 +7,7 @@
 Tree* createRedBlackTree(struct Context* context) {
     struct Tree* tree = new Tree();
     struct RedBlackTree* redBlackTree = new RedBlackTree();
-    tree->tree = (union Data*)createRedBlackTree;
+    tree->tree = (union Data*)redBlackTree;
     redBlackTree->root = NULL;
     redBlackTree->nodeStack = (union Data*)createSingleLinkedStack(context);
     tree->put = C_putRedBlackTree;
@@ -45,11 +45,9 @@
     if (root) {
         tree->current = root;
         tree->result = compare(tree->current, node);
-        // goto replaceNode(tree, tree->nodeStack);
-        goto meta(context, C_replaceNode);
+        goto replaceNode(tree, tree->nodeStack);
     }
-    // goto insertNode(tree, tree->nodeStack, node);
-    goto meta(context, C_insertNode);
+    goto insertNode(tree, tree->nodeStack, node);
 }
 
 __code replaceNode(struct RedBlackTree* tree, struct Stack* nodeStack) {
--- a/src/parallel_execution/generate_stub.pl	Thu Oct 05 17:00:48 2017 +0900
+++ b/src/parallel_execution/generate_stub.pl	Fri Oct 06 14:39:36 2017 +0900
@@ -278,13 +278,16 @@
     my $inTypedef = 0;
     my $inStub = 0;
     my $inParGoto = 0;
+    my $inMain = 0 ;
     my %stub;
     my $codeGearName;
 
     while (<$in>) {
-        if (! $inTypedef && ! $inStub) {
+        if (! $inTypedef && ! $inStub && ! $inMain) {
             if (/^typedef struct (\w+) {/) {
                 $inTypedef = 1;
+            } elsif (/^int main\((.*)\) {/) {
+                $inMain = 1;
             } elsif (/^\_\_code (\w+)\((.*)\)(.*)/) {
                 $codeGearName = $1;
                 my $args = $2;
@@ -513,9 +516,23 @@
                 s/new\s+(\w+)\(\)/\&ALLOCATE(context, \1)->\1/g;   # replacing new
             }
             # gather type name and type
-        } elsif (/^}/) {
+        } elsif ($inMain) {
+            if (/^(.*)goto start_code\(main_context\);/) {
+                next;
+            } elsif (/^(.*)goto (\w+)\((.*)\);/) {
+                my $prev = $1;
+                my $next = $2;
+                print $fd "${prev}struct Context* main_context = NEW(struct Context);\n";
+                print $fd "${prev}initContext(main_context);\n";
+                print $fd "${prev}main_context->next = C_$next;\n";
+                print $fd "${prev}goto start_code(main_context);\n";
+                next;
+            }
+        }
+        if (/^}/) {
             $inStub = 0;
             $inTypedef = 0;
+            $inMain = 0;
         }
         print $fd $_;
     }