Mercurial > hg > GearsTemplate
changeset 194:081607dcf893
create generate_stub.pl
author | mir3636 |
---|---|
date | Fri, 16 Dec 2016 19:40:42 +0900 |
parents | af4dec989aa1 |
children | bd96dffaa76a 119c035e0e36 |
files | src/parallel_execution/SingleLinkedStack.cbc src/parallel_execution/Stack.cbc src/parallel_execution/context.h src/parallel_execution/generate_stub.pl src/parallel_execution/rb_tree.cbc src/parallel_execution/stack.cbc src/parallel_execution/stack.h |
diffstat | 7 files changed, 209 insertions(+), 171 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/parallel_execution/SingleLinkedStack.cbc Fri Dec 16 19:40:42 2016 +0900 @@ -0,0 +1,112 @@ +#include "context.h" +#include "origin_cs.h" +#include <stdio.h> + +typedef struct SingleLinkedStack { + struct Element* top; +} SingleLinkedStack; + +Stack* createSingleLinkedStack() { + struct Stack* stack = new Stack(); + struct SingleLinkedStack* singleLinkedStack = new SingleLinkedStack(); + stack->stack = singleLinkedStack; + singleLinkedStack->top = NULL; + stack->push = pushSingleLinkedStack; + stack->pop = popSingleLinkedStack; + stack->pop2 = pop2SingleLinkedStack; + stack->get = getSingleLinkedStack; + stack->get2 = get2SingleLinkedStack; + stack->isEmpty = isEmptySingleLinkedStack; + stack->clear = clearSingleLinkedStack; + return stack; +} + +void printStack1(union Data* data) { + struct Node* node = &data->element.data->node; + if (node == NULL) { + printf("NULL"); + } else { + printf("key = %d ,", node->key); + printStack1((union Data*)data->element.next); + } +} + +void printStack(union Data* data) { + printStack1(data); + printf("\n"); +} + +__code clearSingleLinkedStack(struct SingleLinkedStack* stack,__code next(...)) { + stack->top = NULL; + goto next(...); +} + +__code pushSingleLinkedStack(struct SingleLinkedStack* stack,union Data* data, __code next(...)) { + Element* element = new Element(); + element->next = stack->top; + element->data = data; + stack->top = element; + goto next(...); +} + +__code popSingleLinkedStack(struct SingleLinkedStack* stack, __code next(..., union Data*)) { + union Data* data; + if (stack->top) { + *data = stack->top->data; + stack->top = stack->top->next; + } else { + *data = NULL; + } + goto next(..., data); +} + +__code pop2SingleLinkedStack(struct SingleLinkedStack* stack, union Data** data, union Data** data1, __code next(..., union Data**, union Data**)) { + if (stack->top) { + *data = stack->top->data; + stack->top = stack->top->next; + } else { + *data = NULL; + } + if (stack->top) { + *data1 = stack->top->data; + stack->top = stack->top->next; + } else { + *data1 = NULL; + } + goto next(..., data, data1); +} + + +__code getSingleLinkedStack(struct SingleLinkedStack* stack, union Data** data, __code next(...)) { + if (stack->top) + *data = stack->top->data; + else + *data = NULL; + goto next(...); +} + +__code get2SingleLinkedStack(struct SingleLinkedStack* stack,..., __code next(...)) { + union Data* data, *data1; + + if (stack->top) { + data = stack->top->data; + if (stack->top->next) { + data1 = stack->top->next->data; + } else { + data1 = NULL; + } + } else { + data = NULL; + data1 = NUll; + } + goto next(data, data1, ...); +} + +__code isEmptySingleLinkedStack(struct SingleLinkedStack* stack, __code next(...), __code whenEmpty(...)) { + if (stack->top) + goto next(...); + else + goto whenEmpty(...); +} + +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/parallel_execution/Stack.cbc Fri Dec 16 19:40:42 2016 +0900 @@ -0,0 +1,14 @@ +typedef struct Stack { + union Data* stack; + union Data* data; + union Data* data1; + enum Code whenEmpty; + enum Code clear; + enum Code push; + enum Code pop; + enum Code pop2; + enum Code isEmpty; + enum Code get; + enum Code get2; + enum Code next; +} Stack;
--- a/src/parallel_execution/context.h Fri Dec 16 17:56:39 2016 +0900 +++ b/src/parallel_execution/context.h Fri Dec 16 19:40:42 2016 +0900 @@ -145,26 +145,26 @@ enum Code get; enum Code get2; enum Code next; - } stack; + } Stack; // Stack implementations struct SingleLinkedStack { struct Element* top; - } singleLinkedStack; + } SingleLinkedStack; struct ArrayStack { int size; int limit; struct Element* array; - } arrayStack; + } ArrayStack; // Stack implementation end struct Element { union Data* data; struct Element* next; - } element; + } Element; struct Array { int index; int prefix; int* array; - } array; + } Array; struct Tree { union Data* tree; struct Node* node;
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/parallel_execution/generate_stub.pl Fri Dec 16 19:40:42 2016 +0900 @@ -0,0 +1,50 @@ +#!/usr/bin/perl + +# interface.cbc +# typedef struct Worker { +# int id; +# struct Context* contexts; +# enum Code execute; +# enum Code taskSend; +# enum Code taskRecive; +# enum Code shutdown; +# struct Queue* tasks; +# } Worker; + +system "rm -rf d"; +system "mkdir d"; + +while (<*.cbc>) { + &getDataGear($_); +} + +&generateDataGear(); + +sub getDataGear { + my ($filename) = @_; + open my $fd,"<",$filename or die("can't open $filename $!"); + while (<$fd>) { + if (! $inTypedef) { + if (/^typedef struct (\w+) {/) { + $inTypedef = 1; + $name = $1; + $dataGear{$name} = $_; + } + next; + } + $dataGear{$name} .= $_; + if (/^}/) { + $inTypedef = 0; + } + } +} + +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"; + } + print $fd "\n"; +} + +# end
--- a/src/parallel_execution/rb_tree.cbc Fri Dec 16 17:56:39 2016 +0900 +++ b/src/parallel_execution/rb_tree.cbc Fri Dec 16 19:40:42 2016 +0900 @@ -5,58 +5,41 @@ extern enum Relational compare(struct Node* node1, struct Node* node2); -typedef struct Stack { - union Data* stack; - union Data* data; - union Data* data1; - enum Code whenEmpty; - - enum Code clear; - enum Code push; - enum Code pop; - enum Code pop2; - enum Code isEmpty; - enum Code get; - enum Code get2; - enum Code next; -} Stack; - typedef struct Tree { - union Data* tree - enum Code put; - enum Code get; - enum Code remove; - enum Code next; + union Data* tree; + struct Node* node; + enum Code put; + enum Code get; + enum Code remove; + enum Code clear; + enum Code next; } Tree; -typedef struct Traverse { - struct Node* root; - struct Node* current; - struct Node* previous; - struct Node* newNode; - struct Node* parent; - struct Node* grandparent; - struct Stack* nodeStack; - int result; -} Traverse; +typedef struct RedBlackTree { + struct Node* root; + struct Node* current; // reading node of original tree + struct Node* previous; // parent of reading node of original tree + struct Node* newNode; // writing node of new tree + struct Node* parent; + struct Node* grandparent; + struct Stack* nodeStack; + int result; +} RedBlackTree; typedef struct RotateTree { - enum Code next; - struct Traverse* traverse; - struct Tree* tree; -} RotateTree; + enum Code next; + struct RedBlackTree* traverse; + struct Tree* tree; +} rotateTree; typedef struct Node { - int key; // comparable data segment - union Data* value; - struct Node* left; - struct Node* right; - // need to balancing - enum Color { - Red, - Black, - } color; -} Node; + int key; // comparable data segment + union Data* value; + struct Node* left; + struct Node* right; + // need to balancing + enum Color { Red, Black, } color; +} node; void printTree1(union Data* data) { struct Node* node = &data->node;
--- a/src/parallel_execution/stack.cbc Fri Dec 16 17:56:39 2016 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,113 +0,0 @@ -#include "context.h" -#include "stack.h" -#include "origin_cs.h" -#include <stdio.h> - -typedef struct SingleLinkedStack { - struct Element* top; -} SingleLinkedStack; - -Stack* createSingleLinkedStack() { - struct Stack* stack = new Stack(); - struct SingleLinkedStack* singleLinkedStack = new SingleLinkedStack(); - stack->stack = singleLinkedStack; - singleLinkedStack->top = NULL; - stack->push = pushSingleLinkedStack; - stack->pop = popSingleLinkedStack; - stack->pop2 = pop2SingleLinkedStack; - stack->get = getSingleLinkedStack; - stack->get2 = get2SingleLinkedStack; - stack->isEmpty = isEmptySingleLinkedStack; - stack->clear = clearSingleLinkedStack; - return stack; -} - -void printStack1(union Data* data) { - struct Node* node = &data->element.data->node; - if (node == NULL) { - printf("NULL"); - } else { - printf("key = %d ,", node->key); - printStack1((union Data*)data->element.next); - } -} - -void printStack(union Data* data) { - printStack1(data); - printf("\n"); -} - -__code clearSingleLinkedStack(struct SingleLinkedStack* stack,__code next(...)) { - stack->top = NULL; - goto next(...); -} - -__code pushSingleLinkedStack(struct SingleLinkedStack* stack,union Data* data, __code next(...)) { - Element* element = new Element(); - element->next = stack->top; - element->data = data; - stack->top = element; - goto next(...); -} - -__code popSingleLinkedStack(struct SingleLinkedStack* stack, __code next(..., union Data*)) { - union Data* data; - if (stack->top) { - *data = stack->top->data; - stack->top = stack->top->next; - } else { - *data = NULL; - } - goto next(..., data); -} - -__code pop2SingleLinkedStack(struct SingleLinkedStack* stack, union Data** data, union Data** data1, __code next(..., union Data**, union Data**)) { - if (stack->top) { - *data = stack->top->data; - stack->top = stack->top->next; - } else { - *data = NULL; - } - if (stack->top) { - *data1 = stack->top->data; - stack->top = stack->top->next; - } else { - *data1 = NULL; - } - goto next(..., data, data1); -} - - -__code getSingleLinkedStack(struct SingleLinkedStack* stack, union Data** data, __code next(...)) { - if (stack->top) - *data = stack->top->data; - else - *data = NULL; - goto next(...); -} - -__code get2SingleLinkedStack(struct SingleLinkedStack* stack,..., __code next(...)) { - union Data* data, *data1; - - if (stack->top) { - data = stack->top->data; - if (stack->top->next) { - data1 = stack->top->next->data; - } else { - data1 = NULL; - } - } else { - data = NULL; - data1 = NUll; - } - goto next(data, data1, ...); -} - -__code isEmptySingleLinkedStack(struct SingleLinkedStack* stack, __code next(...), __code whenEmpty(...)) { - if (stack->top) - goto next(...); - else - goto whenEmpty(...); -} - -
--- a/src/parallel_execution/stack.h Fri Dec 16 17:56:39 2016 +0900 +++ b/src/parallel_execution/stack.h Fri Dec 16 19:40:42 2016 +0900 @@ -1,9 +1,1 @@ extern union Data* createSingleLinkedStack(struct Context* context); - -extern __code pushSingleLinkedStack_stub(struct Context* context) ; -extern __code popSingleLinkedStack_stub(struct Context* context) ; -extern __code pop2SingleLinkedStack_stub(struct Context* context) ; -extern __code getSingleLinkedStack_stub(struct Context* context) ; -extern __code get2SingleLinkedStack_stub(struct Context* context) ; -extern __code isEmptySingleLinkedStack_stub(struct Context* context) ; -extern __code clearSingleLinkedStack_stub(struct Context* context) ;