Mercurial > hg > Members > Moririn
comparison src/parallel_execution/generate_stub.pl @ 364:a0a3301bac4d
Add Time interface
author | Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Thu, 29 Jun 2017 18:04:33 +0900 |
parents | d93dceb84c75 |
children | 51b7e4eb9ade |
comparison
equal
deleted
inserted
replaced
363:3aab69fc4c28 | 364:a0a3301bac4d |
---|---|
36 my %dataGearVar; | 36 my %dataGearVar; |
37 my %outputVar; # output var initializer | 37 my %outputVar; # output var initializer |
38 my %outputArgs; # continuation's output variables | 38 my %outputArgs; # continuation's output variables |
39 my %dataGear; | 39 my %dataGear; |
40 my %dataGearName; | 40 my %dataGearName; |
41 my %generic; | |
42 my %dataGearVarType; | |
43 my $implementation; | 41 my $implementation; |
44 my $interface; | 42 my $interface; |
45 | |
46 # interface definision | |
47 # | |
48 # typedef struct Stack<Type, Impl>{ | |
49 # Type* stack; | |
50 # Type* data; | |
51 # Type* data1; | |
52 # __code whenEmpty(...); | |
53 # __code clear(Impl* stack,__code next(...)); | |
54 # __code push(Impl* stack,Type* data, __code next(...)); | |
55 # __code pop(Impl* stack, __code next(Type*, ...)); | |
56 # __code pop2(Impl* stack, Type** data, Type** data1, __code next(Type**, Type**, ...)); | |
57 # __code isEmpty(Impl* stack, __code next(...), __code whenEmpty(...)); | |
58 # __code get(Impl* stack, Type** data, __code next(...)); | |
59 # __code get2(Impl* stack,..., __code next(...)); | |
60 # __code next(...); | |
61 # } Stack; | |
62 # | |
63 # calling example | |
64 # | |
65 # goto nodeStack->push((union Data*)node, stackTest3); | |
66 # | |
67 # generated meta level code | |
68 # | |
69 # Gearef(context, Stack)->stack = nodeStack->stack; | |
70 # Gearef(context, Stack)->data = (union Data*)node; | |
71 # Gearef(context, Stack)->next = C_stackTest3; | |
72 # goto meta(context, nodeStack->push); | |
73 | 43 |
74 sub getDataGear { | 44 sub getDataGear { |
75 my ($filename) = @_; | 45 my ($filename) = @_; |
76 my ($codeGearName, $name, $inTypedef); | 46 my ($codeGearName, $name, $inTypedef); |
77 open my $fd,"<",$filename or die("can't open $filename $!"); | 47 open my $fd,"<",$filename or die("can't open $filename $!"); |
78 while (<$fd>) { | 48 while (<$fd>) { |
79 if (! $inTypedef) { | 49 if (! $inTypedef) { |
80 if (/^typedef struct (\w+)\s*<(.*)>/) { | 50 if (/^typedef struct (\w+)/) { |
81 $inTypedef = 1; | 51 $inTypedef = 1; |
82 $name = $1; | 52 $name = $1; |
83 $dataGear{$name} = $_; | 53 $dataGear{$name} = $_; |
84 $var{$name} = {}; | 54 $var{$name} = {}; |
85 $code{$name} = {}; | 55 $code{$name} = {}; |
86 $generic{$name} = \split(/,/,$2); | |
87 } elsif (/^typedef struct (\w+)/) { | |
88 $inTypedef = 1; | |
89 $name = $1; | |
90 $dataGear{$name} = $_; | |
91 $var{$name} = {}; | |
92 $code{$name} = {}; | |
93 $generic{$name} = []; | |
94 } elsif (/^(\w+)(\*)+ create(\w+)\(/) { | 56 } elsif (/^(\w+)(\*)+ create(\w+)\(/) { |
95 if (defined $interface) { | 57 if (defined $interface) { |
96 die "duplicate interface $interface\n"; | 58 die "duplicate interface $interface\n"; |
97 } | 59 } |
98 $interface = $1; | 60 $interface = $1; |
110 my $tname = $2; | 72 my $tname = $2; |
111 if ($ttype =~ /^(union|struct) (\w+)/) { | 73 if ($ttype =~ /^(union|struct) (\w+)/) { |
112 $ttype = $2; | 74 $ttype = $2; |
113 } | 75 } |
114 $var{$name}->{$tname} = $ttype; | 76 $var{$name}->{$tname} = $ttype; |
115 } elsif (/^\_\_code (\w+)\((.*)\)(.*)/) { | 77 } elsif (/\_\_code (\w+)\(/) { |
116 my $args = $2; | 78 $code{$name}->{$1} = 1; |
117 my $method = $1; | |
118 $code{$name}->{$method} = []; | |
119 while($args) { | |
120 if ($args =~ s/(^\s*,\s*)//) { | |
121 } | |
122 # continuation case | |
123 if ($args =~ s/^(\s)*\_\_code\s+(\w+)\(([^)]*)\)//) { | |
124 my $next = $2; | |
125 my @args = split(/,/,$3); | |
126 push(@{$code{$name}->{$method}},$next); | |
127 } elsif ($args =~ s/^(struct|union) (\w+)(\*)+\s(\w+)//) { | |
128 my $structType = $1; | |
129 my $typeName = $2; | |
130 my $varName = $4; | |
131 my $typeField = lcfirst($typeName); | |
132 push(@{$code{$name}->{$method}},$varName); | |
133 } elsif ($args =~ s/(.*,)//) { | |
134 } else { | |
135 last; | |
136 } | |
137 } | |
138 } | 79 } |
139 if (/^}/) { | 80 if (/^}/) { |
140 $inTypedef = 0; | 81 $inTypedef = 0; |
141 } | 82 } |
142 } | 83 } |
156 for my $n ( @{$dataGearVar{$codeGearName}} ) { | 97 for my $n ( @{$dataGearVar{$codeGearName}} ) { |
157 # we already have it | 98 # we already have it |
158 return 0 if ( $n eq $varname1); | 99 return 0 if ( $n eq $varname1); |
159 } | 100 } |
160 push @{$dataGearVar{$codeGearName}}, $varname1; | 101 push @{$dataGearVar{$codeGearName}}, $varname1; |
161 push @{$dataGearVarType{$codeGearName}}, $typeName; | |
162 if ($typeName eq $implementation) { | 102 if ($typeName eq $implementation) { |
163 # get implementation | 103 # get implementation |
164 $dataGearName{$codeGearName} .= "\t$typeName* $varName = ($typeName*)GearImpl(context, $interface, $varName);\n"; | 104 $dataGearName{$codeGearName} .= "\t$typeName* $varName = ($typeName*)GearImpl(context, $interface, $varName);\n"; |
165 } else { | 105 } else { |
166 for my $ivar (keys %{$var{$interface}}) { | 106 for my $ivar (keys %{$var{$interface}}) { |
311 # output data var can be use before write | 251 # output data var can be use before write |
312 # it should be initialze by gearef | 252 # it should be initialze by gearef |
313 print $fd $outputVar{$codeGearName}; | 253 print $fd $outputVar{$codeGearName}; |
314 } | 254 } |
315 next; | 255 next; |
316 } elsif (/^(.*)goto (\w+)\-\>(\w+)\((.*)\);/) { | |
317 # handling goto statement | |
318 # convert it to the meta call form with two arugments, that is context and enum Code | |
319 my $prev = $1; | |
320 my $next = $2; | |
321 my $method = $3; | |
322 my @args = split(/,/,$4); | |
323 my @types = @{$dataGearVarType{$codeGearName}}; | |
324 my $ntype; | |
325 for my $v (@{$dataGearVar{$codeGearName}}) { | |
326 my $t = shift @types; | |
327 if ($v eq $next) { | |
328 $ntype = $t; | |
329 } | |
330 } | |
331 print $fd "\tGearef(context, $ntype)->$next = $next->$next;\n"; | |
332 # Put interface argument | |
333 my $prot = $code{$ntype}->{$method}; | |
334 for my $arg (@args) { | |
335 my $p = shift @$prot; | |
336 next if ($p eq $arg); | |
337 print $fd "\tGearef(context, $ntype)->$p = $arg;\n"; | |
338 } | |
339 print $fd "${prev}goto meta(context, $next->$next->$ntype.$method);\n"; | |
340 next; | |
341 } elsif (/^(.*)goto (\w+)\((.*)\);/) { | 256 } elsif (/^(.*)goto (\w+)\((.*)\);/) { |
342 # handling goto statement | 257 # handling goto statement |
343 # convert it to the meta call form with two arugments, that is context and enum Code | 258 # convert it to the meta call form with two arugments, that is context and enum Code |
344 my $prev = $1; | 259 my $prev = $1; |
345 my $next = $2; | 260 my $next = $2; |