Mercurial > hg > GearsTemplate
changeset 259:195518ab62fc
fix type gathering pattern match in generate_stub.pl
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Sat, 28 Jan 2017 12:37:22 +0900 |
parents | cd3486e4ba70 |
children | 6b5444bbea8a |
files | src/parallel_execution/CMakeLists.txt src/parallel_execution/SingleLinkedStack.cbc src/parallel_execution/context.h src/parallel_execution/generate_context.pl src/parallel_execution/generate_stub.pl |
diffstat | 5 files changed, 48 insertions(+), 43 deletions(-) [+] |
line wrap: on
line diff
--- a/src/parallel_execution/CMakeLists.txt Fri Jan 27 21:20:07 2017 +0900 +++ b/src/parallel_execution/CMakeLists.txt Sat Jan 28 12:37:22 2017 +0900 @@ -18,7 +18,7 @@ string(REGEX REPLACE "(.*).cbc" "c/\\1.c" j ${i}) add_custom_command ( OUTPUT ${j} - DEPENDS ${i} + DEPENDS ${i} COMMAND "perl" "generate_stub.pl" "-o" ${j} ${i} ) else(${i} MATCHES "\\.cbc")
--- a/src/parallel_execution/SingleLinkedStack.cbc Fri Jan 27 21:20:07 2017 +0900 +++ b/src/parallel_execution/SingleLinkedStack.cbc Sat Jan 28 12:37:22 2017 +0900 @@ -1,33 +1,33 @@ -#include "context.h" -#include "origin_cs.h" +#include "../context.h" +#include "../origin_cs.h" #include <stdio.h> -typedef struct SingleLinkedStack { - struct Element* top; -} SingleLinkedStack; +// typedef struct SingleLinkedStack { +// struct Element* top; +// } SingleLinkedStack; -Stack* createSingleLinkedStack() { +Stack* createSingleLinkedStack(struct Context *context) { struct Stack* stack = new Stack(); struct SingleLinkedStack* singleLinkedStack = new SingleLinkedStack(); - stack->stack = singleLinkedStack; + stack->stack = (union Data*)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; + stack->push = C_pushSingleLinkedStack; + stack->pop = C_popSingleLinkedStack; + stack->pop2 = C_pop2SingleLinkedStack; + stack->get = C_getSingleLinkedStack; + stack->get2 = C_get2SingleLinkedStack; + stack->isEmpty = C_isEmptySingleLinkedStack; + stack->clear = C_clearSingleLinkedStack; return stack; } void printStack1(union Data* data) { - struct Node* node = &data->element.data->node; + struct Node* node = &data->Element.data->Node; if (node == NULL) { printf("NULL"); } else { printf("key = %d ,", node->key); - printStack1((union Data*)data->element.next); + printStack1((union Data*)data->Element.next); } }
--- a/src/parallel_execution/context.h Fri Jan 27 21:20:07 2017 +0900 +++ b/src/parallel_execution/context.h Sat Jan 28 12:37:22 2017 +0900 @@ -86,7 +86,7 @@ long size; struct Queue* wait; // tasks waiting this dataGear } meta; - struct Context context; + struct Context Context; struct Time { enum Code next; double time; @@ -253,5 +253,7 @@ } Ods; }; // union Data end this is necessary for context generator +typedef union Data Data; + #include "c/typedefData.h" #endif
--- a/src/parallel_execution/generate_context.pl Fri Jan 27 21:20:07 2017 +0900 +++ b/src/parallel_execution/generate_context.pl Sat Jan 28 12:37:22 2017 +0900 @@ -64,6 +64,7 @@ my %codeGear; my %dataGear; +# gather module Information for code table initialization for (@ARGV) { next if (/context.c/); &getStubInfo($_); @@ -71,7 +72,8 @@ my (%mCodeGear) = (%codeGear); -while (<*.c>) { +# anyway we gather all Gears Information +while (<*.c test/*.c>) { next if (/context.c/); &getStubInfo($_); } @@ -154,6 +156,7 @@ open my $fd,">","$ddir/enumData.h" or die("can't open $ddir/enumData.h $!"); print $fd "enum DataType {\n"; + print $fd " D_Code,\n"; for my $data ( sort keys %dataGear ) { print $fd " D_${data},\n"; }
--- a/src/parallel_execution/generate_stub.pl Fri Jan 27 21:20:07 2017 +0900 +++ b/src/parallel_execution/generate_stub.pl Sat Jan 28 12:37:22 2017 +0900 @@ -32,7 +32,6 @@ } my %var; -my %type; my %code; my %dataGearVar; my %dataGear; @@ -46,11 +45,12 @@ open my $fd,"<",$filename or die("can't open $filename $!"); while (<$fd>) { if (! $inTypedef) { - if (/^typedef struct (\w+) {/) { + if (/^typedef struct (\w+)/) { $inTypedef = 1; $name = $1; $dataGear{$name} = $_; - $code{$name} = []; + $var{$name} = {}; + $code{$name} = {}; } elsif (/^(\w+)\* create(\w+)\(/) { if (defined $interface) { die "duplicate interface $interface\n"; @@ -65,18 +65,10 @@ } # gather type name and type $dataGear{$name} .= $_; - if (/(\w+);$/ and !/^} (\w+)/) { - my $tmp = $1 . "\n"; - if (/{/) { - $tmp = "{" . $'; - $tmp =~ s/;$//; - } - $var{$name} .= $tmp; - $tmp = $`; - $tmp =~ s/^\s*//; - $type{$name} .= $tmp . "\n"; + if (/^\s*(.*)\s+(\w+);$/ ) { + $var{$name}->{$2} = $1; } elsif (/\_\_code (\w+)\(/) { - push $code{$name}, $1; + $code{$name}->{$1} = 1; } if (/^}/) { $inTypedef = 0; @@ -96,18 +88,21 @@ my($codeGearName, $varName, $typeName, $typeField, $interface) = @_; push @{$dataGearVar{$codeGearName}},$varName; if ($typeField ne $varName) { - $dataGearName{$codeGearName} .= "\t$typeName* $varName = ($typeName*)GearImpl(context, $typeName, $varName);\n"; - # print STDOUT "$codeGearName \t$typeName* $varName = ($typeName*)GearImpl(context, $typeName, $varName);\n"; + $dataGearName{$codeGearName} .= "\t$typeName* $varName = ($typeName*)GearImpl(context, $interface, $varName);\n"; } else { - for my $ivar ($var{$interface}) { + for my $ivar (keys %{$var{$interface}}) { if ($varName eq $ivar) { $dataGearName{$codeGearName} .= "\t$typeName* $varName = Gearef(context, $interface)->$varName;\n"; - # print STDOUT "$codeGearName \t$typeName* $varName = Gearef(context, $interface)->$varName;\n"; + return; + } + } + for my $cName (keys %{$code{$interface}}) { + if ($varName eq $cName) { + $dataGearName{$codeGearName} .= "\tenum Code $varName = Gearef(context, $interface)->$varName;\n"; return; } } $dataGearName{$codeGearName} .= "\t$typeName* $varName = Gearef(context, $typeName)->$typeField;\n"; - # print STDOUT "$codeGearName \t$typeName* $varName = Gearef(context, $typeName)->$typeField;\n"; } } @@ -128,6 +123,11 @@ $i++; } } + if ( $fn =~ m=(.*)/[^/]+$= ) { + if (! -d $1) { + mkdir $1; + } + } open my $fd,">",$fn or die("can't write $fn $!"); my $prevCodeGearName; @@ -158,7 +158,7 @@ } $prevCodeGearName = $codeGearName; $dataGearVar{$codeGearName} = []; - my $newArgs = ""; + my $newArgs = "struct Context *context,"; while($args) { if ($args =~ s/(^\s*,\s*)//) { $newArgs .= $1; @@ -177,6 +177,7 @@ my $typeField = lcfirst($typeName); &generateStubArgs($codeGearName, $varName, $typeName, $typeField, $interface); } + &generateStubArgs($codeGearName, $next, "Code", $next, $interface); } elsif ($args =~ s/^(struct|union) (\w+)(\*)+\s(\w+)//) { my $structType = $1; my $typeName = $2; @@ -203,12 +204,11 @@ my $args = $2; print $fd "${prev}goto meta(context, next);\n"; next; + } else { + s/new\s+(\w+)\(\)/\&ALLOCATE(context, \1)->\1/g; # replacing new } - print $fd $_; - next; - } # gather type name and type - if (/^}/) { + } elsif (/^}/) { $inTypedef = 0; } print $fd $_;