Mercurial > hg > Members > Moririn
annotate src/parallel_execution/generate_stub.pl @ 389:d9a7620a1106
handle continuation in stub
author | masataka |
---|---|
date | Sat, 29 Jul 2017 19:35:16 +0900 |
parents | 8940d1451a0d |
children | 2d9c500f263e |
rev | line source |
---|---|
194 | 1 #!/usr/bin/perl |
2 | |
250 | 3 use strict; |
254 | 4 use Getopt::Std; |
250 | 5 |
194 | 6 # interface.cbc |
7 # typedef struct Worker { | |
8 # int id; | |
9 # struct Context* contexts; | |
10 # enum Code execute; | |
11 # enum Code taskSend; | |
12 # enum Code taskRecive; | |
13 # enum Code shutdown; | |
14 # struct Queue* tasks; | |
15 # } Worker; | |
16 | |
255 | 17 our($opt_o,$opt_d,$opt_h); |
18 getopts('o:d:h'); | |
19 | |
20 my $dir = "."; | |
21 if ($opt_d) { | |
22 $dir = $opt_d; | |
23 if (! -d $dir) { | |
24 mkdir $dir; | |
25 } | |
26 } | |
254 | 27 |
28 for my $fn (@ARGV) { | |
255 | 29 next if ($fn !~ /\.cbc$/); |
249 | 30 &getDataGear($fn); |
31 &generateDataGear($fn); | |
194 | 32 } |
33 | |
250 | 34 my %var; |
35 my %code; | |
36 my %dataGearVar; | |
260
6b5444bbea8a
generated stub no comiple errors
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
259
diff
changeset
|
37 my %outputVar; # output var initializer |
6b5444bbea8a
generated stub no comiple errors
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
259
diff
changeset
|
38 my %outputArgs; # continuation's output variables |
250 | 39 my %dataGear; |
40 my %dataGearName; | |
384
ee5d2b1685d7
Fix perlscript
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
383
diff
changeset
|
41 my %generic; |
ee5d2b1685d7
Fix perlscript
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
383
diff
changeset
|
42 my %dataGearVarType; |
253 | 43 my $implementation; |
44 my $interface; | |
250 | 45 |
384
ee5d2b1685d7
Fix perlscript
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
383
diff
changeset
|
46 # interface definision |
ee5d2b1685d7
Fix perlscript
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
383
diff
changeset
|
47 # |
ee5d2b1685d7
Fix perlscript
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
383
diff
changeset
|
48 # typedef struct Stack<Type, Impl>{ |
ee5d2b1685d7
Fix perlscript
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
383
diff
changeset
|
49 # Type* stack; |
ee5d2b1685d7
Fix perlscript
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
383
diff
changeset
|
50 # Type* data; |
ee5d2b1685d7
Fix perlscript
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
383
diff
changeset
|
51 # Type* data1; |
ee5d2b1685d7
Fix perlscript
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
383
diff
changeset
|
52 # __code whenEmpty(...); |
ee5d2b1685d7
Fix perlscript
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
383
diff
changeset
|
53 # __code clear(Impl* stack,__code next(...)); |
ee5d2b1685d7
Fix perlscript
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
383
diff
changeset
|
54 # __code push(Impl* stack,Type* data, __code next(...)); |
ee5d2b1685d7
Fix perlscript
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
383
diff
changeset
|
55 # __code pop(Impl* stack, __code next(Type*, ...)); |
ee5d2b1685d7
Fix perlscript
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
383
diff
changeset
|
56 # __code pop2(Impl* stack, Type** data, Type** data1, __code next(Type**, Type**, ...)); |
ee5d2b1685d7
Fix perlscript
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
383
diff
changeset
|
57 # __code isEmpty(Impl* stack, __code next(...), __code whenEmpty(...)); |
ee5d2b1685d7
Fix perlscript
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
383
diff
changeset
|
58 # __code get(Impl* stack, Type** data, __code next(...)); |
ee5d2b1685d7
Fix perlscript
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
383
diff
changeset
|
59 # __code get2(Impl* stack,..., __code next(...)); |
ee5d2b1685d7
Fix perlscript
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
383
diff
changeset
|
60 # __code next(...); |
ee5d2b1685d7
Fix perlscript
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
383
diff
changeset
|
61 # } Stack; |
ee5d2b1685d7
Fix perlscript
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
383
diff
changeset
|
62 # |
ee5d2b1685d7
Fix perlscript
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
383
diff
changeset
|
63 # calling example |
ee5d2b1685d7
Fix perlscript
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
383
diff
changeset
|
64 # |
ee5d2b1685d7
Fix perlscript
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
383
diff
changeset
|
65 # goto nodeStack->push((union Data*)node, stackTest3); |
ee5d2b1685d7
Fix perlscript
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
383
diff
changeset
|
66 # |
ee5d2b1685d7
Fix perlscript
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
383
diff
changeset
|
67 # generated meta level code |
ee5d2b1685d7
Fix perlscript
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
383
diff
changeset
|
68 # |
ee5d2b1685d7
Fix perlscript
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
383
diff
changeset
|
69 # Gearef(context, Stack)->stack = nodeStack->stack; |
ee5d2b1685d7
Fix perlscript
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
383
diff
changeset
|
70 # Gearef(context, Stack)->data = (union Data*)node; |
ee5d2b1685d7
Fix perlscript
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
383
diff
changeset
|
71 # Gearef(context, Stack)->next = C_stackTest3; |
ee5d2b1685d7
Fix perlscript
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
383
diff
changeset
|
72 # goto meta(context, nodeStack->push); |
ee5d2b1685d7
Fix perlscript
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
383
diff
changeset
|
73 |
194 | 74 sub getDataGear { |
75 my ($filename) = @_; | |
253 | 76 my ($codeGearName, $name, $inTypedef); |
194 | 77 open my $fd,"<",$filename or die("can't open $filename $!"); |
78 while (<$fd>) { | |
79 if (! $inTypedef) { | |
384
ee5d2b1685d7
Fix perlscript
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
383
diff
changeset
|
80 if (/^typedef struct (\w+)\s*<(.*)>/) { |
194 | 81 $inTypedef = 1; |
82 $name = $1; | |
83 $dataGear{$name} = $_; | |
259
195518ab62fc
fix type gathering pattern match in generate_stub.pl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
255
diff
changeset
|
84 $var{$name} = {}; |
195518ab62fc
fix type gathering pattern match in generate_stub.pl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
255
diff
changeset
|
85 $code{$name} = {}; |
384
ee5d2b1685d7
Fix perlscript
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
383
diff
changeset
|
86 $generic{$name} = \split(/,/,$2); |
ee5d2b1685d7
Fix perlscript
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
383
diff
changeset
|
87 } elsif (/^typedef struct (\w+)/) { |
ee5d2b1685d7
Fix perlscript
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
383
diff
changeset
|
88 $inTypedef = 1; |
ee5d2b1685d7
Fix perlscript
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
383
diff
changeset
|
89 $name = $1; |
ee5d2b1685d7
Fix perlscript
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
383
diff
changeset
|
90 $dataGear{$name} = $_; |
ee5d2b1685d7
Fix perlscript
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
383
diff
changeset
|
91 $var{$name} = {}; |
ee5d2b1685d7
Fix perlscript
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
383
diff
changeset
|
92 $code{$name} = {}; |
ee5d2b1685d7
Fix perlscript
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
383
diff
changeset
|
93 $generic{$name} = []; |
269 | 94 } elsif (/^(\w+)(\*)+ create(\w+)\(/) { |
249 | 95 if (defined $interface) { |
96 die "duplicate interface $interface\n"; | |
97 } | |
98 $interface = $1; | |
269 | 99 $implementation = $3; |
250 | 100 if ( -f "$interface.cbc") { |
101 &getDataGear("$interface.cbc"); | |
102 } | |
385 | 103 } elsif (/^(\s)*(\w+)\-\>(\w+)\s\=\s\((.*)\)create(\w+)\((\w+)\);$/) { |
104 #my $intfn = ucfirst($2); | |
105 my $impln = $5; | |
106 if ( -f "$impln.cbc") { | |
107 &getCodeGear("$impln.cbc"); | |
108 } | |
226 | 109 } |
194 | 110 next; |
111 } | |
249 | 112 # gather type name and type |
194 | 113 $dataGear{$name} .= $_; |
385 | 114 if (/^\s*(.*)\s+(\w+);$/ ) { |
280 | 115 my $ttype = $1; |
116 my $tname = $2; | |
117 if ($ttype =~ /^(union|struct) (\w+)/) { | |
118 $ttype = $2; | |
119 } | |
120 $var{$name}->{$tname} = $ttype; | |
250 | 121 } |
194 | 122 if (/^}/) { |
123 $inTypedef = 0; | |
124 } | |
125 } | |
126 } | |
127 | |
385 | 128 sub getCodeGear { |
129 my ($filename) = @_; | |
130 open my $fd,"<",$filename or die("can't open $filename $!"); | |
131 my ($name,$impln); | |
132 while (<$fd>) { | |
133 if (/^(\w+)(\*)+ create(\w+)\(/) { | |
134 $name = $1; | |
135 $impln = $3; | |
136 } | |
137 if (defined $name) { | |
138 if (/^\_\_code (\w+)$impln\((.*)\)(.*)/) { | |
139 my $args = $2; | |
140 my $method = $1; | |
141 $code{$name}->{$method} = []; | |
142 while($args) { | |
143 if ($args =~ s/(^\s*,\s*)//) { | |
144 } | |
145 # continuation case | |
146 if ($args =~ s/^(\s)*\_\_code\s+(\w+)\(([^)]*)\)//) { | |
147 my $next = $2; | |
148 my @args = split(/,/,$3); | |
387 | 149 push(@{$code{$name}->{$method}},"\_\_code $next"); |
385 | 150 } elsif ($args =~ s/^(struct|union) (\w+)(\*)+\s(\w+)//) { |
151 my $structType = $1; | |
152 my $typeName = $2; | |
153 my $varName = $4; | |
154 my $typeField = lcfirst($typeName); | |
387 | 155 push(@{$code{$name}->{$method}},"$typeName $varName"); |
385 | 156 } elsif ($args =~ s/(.*,)//) { |
157 } else { | |
158 last; | |
159 } | |
160 } | |
161 } | |
162 } | |
163 } | |
164 } | |
165 | |
250 | 166 sub generateStub { |
251 | 167 my($fd,$prevCodeGearName,$dataGearName) = @_; |
274 | 168 print $fd "__code ", $prevCodeGearName ,"_stub(struct Context* context) {\n"; |
251 | 169 print $fd $dataGearName; |
250 | 170 print $fd "\n} \n\n"; |
251 | 171 return 1; |
250 | 172 } |
173 | |
253 | 174 sub generateStubArgs { |
260
6b5444bbea8a
generated stub no comiple errors
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
259
diff
changeset
|
175 my($codeGearName, $varName, $typeName, $typeField, $interface,$output) = @_; |
6b5444bbea8a
generated stub no comiple errors
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
259
diff
changeset
|
176 my $varname1 = $output?"O_$varName":$varName; |
6b5444bbea8a
generated stub no comiple errors
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
259
diff
changeset
|
177 for my $n ( @{$dataGearVar{$codeGearName}} ) { |
6b5444bbea8a
generated stub no comiple errors
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
259
diff
changeset
|
178 # we already have it |
6b5444bbea8a
generated stub no comiple errors
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
259
diff
changeset
|
179 return 0 if ( $n eq $varname1); |
6b5444bbea8a
generated stub no comiple errors
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
259
diff
changeset
|
180 } |
6b5444bbea8a
generated stub no comiple errors
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
259
diff
changeset
|
181 push @{$dataGearVar{$codeGearName}}, $varname1; |
384
ee5d2b1685d7
Fix perlscript
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
383
diff
changeset
|
182 push @{$dataGearVarType{$codeGearName}}, $typeName; |
260
6b5444bbea8a
generated stub no comiple errors
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
259
diff
changeset
|
183 if ($typeName eq $implementation) { |
6b5444bbea8a
generated stub no comiple errors
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
259
diff
changeset
|
184 # get implementation |
258 | 185 $dataGearName{$codeGearName} .= "\t$typeName* $varName = ($typeName*)GearImpl(context, $interface, $varName);\n"; |
253 | 186 } else { |
259
195518ab62fc
fix type gathering pattern match in generate_stub.pl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
255
diff
changeset
|
187 for my $ivar (keys %{$var{$interface}}) { |
260
6b5444bbea8a
generated stub no comiple errors
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
259
diff
changeset
|
188 # input data gear field |
253 | 189 if ($varName eq $ivar) { |
280 | 190 if ($typeName eq $var{$interface}->{$ivar}) { |
191 if ($output) { | |
192 $dataGearName{$codeGearName} .= "\t$typeName** O_$varName = &Gearef(context, $interface)->$varName;\n"; | |
193 $outputVar{$codeGearName} .= "\t$typeName* $varName;\n"; | |
194 return 1; | |
195 } | |
196 | |
197 $dataGearName{$codeGearName} .= "\t$typeName* $varName = Gearef(context, $interface)->$varName;\n"; | |
260
6b5444bbea8a
generated stub no comiple errors
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
259
diff
changeset
|
198 return 1; |
6b5444bbea8a
generated stub no comiple errors
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
259
diff
changeset
|
199 } |
253 | 200 } |
201 } | |
259
195518ab62fc
fix type gathering pattern match in generate_stub.pl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
255
diff
changeset
|
202 for my $cName (keys %{$code{$interface}}) { |
195518ab62fc
fix type gathering pattern match in generate_stub.pl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
255
diff
changeset
|
203 if ($varName eq $cName) { |
260
6b5444bbea8a
generated stub no comiple errors
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
259
diff
changeset
|
204 # continuation field |
259
195518ab62fc
fix type gathering pattern match in generate_stub.pl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
255
diff
changeset
|
205 $dataGearName{$codeGearName} .= "\tenum Code $varName = Gearef(context, $interface)->$varName;\n"; |
260
6b5444bbea8a
generated stub no comiple errors
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
259
diff
changeset
|
206 return 1; |
253 | 207 } |
208 } | |
389 | 209 # global or local variable case |
210 if ($typeName eq "Code") { | |
211 $dataGearName{$codeGearName} .= "\tenum $typeName $varName = Gearef(context, $interface)->$varName;\n"; | |
212 return 1; | |
213 } | |
268 | 214 $dataGearName{$codeGearName} .= "\t$typeName* $varName = Gearef(context, $typeName);\n"; |
260
6b5444bbea8a
generated stub no comiple errors
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
259
diff
changeset
|
215 return 1; |
253 | 216 } |
217 } | |
218 | |
194 | 219 sub generateDataGear { |
249 | 220 my ($filename) = @_; |
221 open my $in,"<",$filename or die("can't open $filename $!"); | |
254 | 222 |
223 my $fn; | |
224 if ($opt_o) { | |
225 $fn = $opt_o; | |
226 } else { | |
227 my $fn1 = $filename; | |
228 $fn1 =~ s/\.cbc/.c/; | |
229 my $i = 1; | |
255 | 230 $fn = "$dir/$fn1"; |
254 | 231 while ( -f $fn) { |
255 | 232 $fn = "$dir/$fn1.$i"; |
254 | 233 $i++; |
234 } | |
250 | 235 } |
259
195518ab62fc
fix type gathering pattern match in generate_stub.pl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
255
diff
changeset
|
236 if ( $fn =~ m=(.*)/[^/]+$= ) { |
195518ab62fc
fix type gathering pattern match in generate_stub.pl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
255
diff
changeset
|
237 if (! -d $1) { |
195518ab62fc
fix type gathering pattern match in generate_stub.pl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
255
diff
changeset
|
238 mkdir $1; |
195518ab62fc
fix type gathering pattern match in generate_stub.pl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
255
diff
changeset
|
239 } |
195518ab62fc
fix type gathering pattern match in generate_stub.pl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
255
diff
changeset
|
240 } |
249 | 241 open my $fd,">",$fn or die("can't write $fn $!"); |
254 | 242 |
249 | 243 my $prevCodeGearName; |
250 | 244 my $inTypedef = 0; |
278 | 245 my $inStub = 0; |
250 | 246 my %stub; |
251 | 247 my $codeGearName; |
254 | 248 |
249 | 249 while (<$in>) { |
278 | 250 if (! $inTypedef && ! $inStub) { |
249 | 251 if (/^typedef struct (\w+) {/) { |
252 $inTypedef = 1; | |
253 | 253 } elsif (/^\_\_code (\w+)\((.*)\)(.*)/) { |
251 | 254 $codeGearName = $1; |
253 | 255 my $args = $2; |
256 my $tail = $3; | |
250 | 257 if ($codeGearName =~ /_stub$/) { |
262 | 258 # don't touch already existing stub |
278 | 259 $inStub = 1; |
250 | 260 $stub{$codeGearName} = 1; |
261 print $fd $_; | |
262 next; | |
263 } | |
249 | 264 if (defined $prevCodeGearName) { |
262 | 265 # stub is generated just before next CodeGear |
250 | 266 if (defined $stub{$prevCodeGearName."_stub"}) { |
267 undef $prevCodeGearName; | |
278 | 268 } else { |
269 &generateStub($fd,$prevCodeGearName,$dataGearName{$prevCodeGearName}); | |
270 $stub{$prevCodeGearName."_stub"} = 1; | |
250 | 271 } |
249 | 272 } |
262 | 273 # analyzing CodeGear argument |
274 # these arguments are extract from current context's arugment DataGear Interface | |
275 # and passed to the CodeGear | |
276 # struct Implementaion needs special handling | |
277 # __code next(...) ---> enum Code next | |
253 | 278 $prevCodeGearName = $codeGearName; |
279 $dataGearVar{$codeGearName} = []; | |
260
6b5444bbea8a
generated stub no comiple errors
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
259
diff
changeset
|
280 $outputVar{$codeGearName} = ""; |
6b5444bbea8a
generated stub no comiple errors
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
259
diff
changeset
|
281 $outputArgs{$codeGearName} = {}; |
259
195518ab62fc
fix type gathering pattern match in generate_stub.pl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
255
diff
changeset
|
282 my $newArgs = "struct Context *context,"; |
305 | 283 if ($args=~/^struct Context\s*\*\s*context/) { |
284 $newArgs = ""; | |
285 } | |
253 | 286 while($args) { |
287 if ($args =~ s/(^\s*,\s*)//) { | |
288 $newArgs .= $1; | |
289 } | |
262 | 290 # continuation case |
280 | 291 if ($args =~ s/^(\s)*\_\_code\s+(\w+)\(([^)]*)\)//) { |
292 my $next = $2; | |
293 my @args = split(/,/,$3); | |
260
6b5444bbea8a
generated stub no comiple errors
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
259
diff
changeset
|
294 if ( &generateStubArgs($codeGearName, $next, "Code", $next, $interface,0) ) { |
6b5444bbea8a
generated stub no comiple errors
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
259
diff
changeset
|
295 $newArgs .= "enum Code $next"; |
258 | 296 } |
262 | 297 # analyze continuation arguments |
298 # output arguments are defined in the Interface take the pointer of these | |
299 # output arguments are put into the Interface DataGear just before the goto | |
253 | 300 for my $arg (@args) { |
301 $arg =~ s/^\s*//; | |
260
6b5444bbea8a
generated stub no comiple errors
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
259
diff
changeset
|
302 last if ($arg =~ /\.\.\./); |
253 | 303 $arg =~ s/^(struct|union) (\w+)(\*)+\s(\w+)//; |
304 my $structType = $1; | |
305 my $typeName = $2; | |
306 my $varName = $4; | |
307 my $typeField = lcfirst($typeName); | |
260
6b5444bbea8a
generated stub no comiple errors
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
259
diff
changeset
|
308 push(@{$outputArgs{$codeGearName}->{$next}}, $varName); |
6b5444bbea8a
generated stub no comiple errors
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
259
diff
changeset
|
309 if (&generateStubArgs($codeGearName, $varName, $typeName, $typeField, $interface,1)) { |
6b5444bbea8a
generated stub no comiple errors
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
259
diff
changeset
|
310 $newArgs .= ",$structType $typeName **O_$varName"; |
6b5444bbea8a
generated stub no comiple errors
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
259
diff
changeset
|
311 } |
253 | 312 } |
313 } elsif ($args =~ s/^(struct|union) (\w+)(\*)+\s(\w+)//) { | |
314 my $structType = $1; | |
315 my $typeName = $2; | |
316 my $varName = $4; | |
317 my $typeField = lcfirst($typeName); | |
260
6b5444bbea8a
generated stub no comiple errors
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
259
diff
changeset
|
318 $newArgs .= $&; # assuming no duplicate |
6b5444bbea8a
generated stub no comiple errors
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
259
diff
changeset
|
319 &generateStubArgs($codeGearName, $varName, $typeName, $typeField, $interface,0); |
255 | 320 } elsif ($args =~ s/(.*,)//) { |
321 $newArgs .= $1; | |
322 } else { | |
323 $newArgs .= $args; | |
324 last; | |
253 | 325 } |
326 } | |
262 | 327 # generate goto statement from stub to the CodeGear in the buffer |
253 | 328 $dataGearName{$codeGearName} .= "\tgoto $codeGearName(context"; |
329 for my $arg ( @{$dataGearVar{$codeGearName}}) { | |
330 $dataGearName{$codeGearName} .= ", $arg"; | |
331 } | |
332 $dataGearName{$codeGearName} .= ");"; | |
262 | 333 # generate CodeGear header with new arguments |
253 | 334 print $fd "__code $codeGearName($newArgs)$tail\n"; |
260
6b5444bbea8a
generated stub no comiple errors
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
259
diff
changeset
|
335 if ($outputVar{$codeGearName} ne "") { |
324 | 336 # output data var can be use before write |
337 # it should be initialze by gearef | |
260
6b5444bbea8a
generated stub no comiple errors
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
259
diff
changeset
|
338 print $fd $outputVar{$codeGearName}; |
6b5444bbea8a
generated stub no comiple errors
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
259
diff
changeset
|
339 } |
250 | 340 next; |
384
ee5d2b1685d7
Fix perlscript
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
383
diff
changeset
|
341 } elsif (/^(.*)goto (\w+)\-\>(\w+)\((.*)\);/) { |
ee5d2b1685d7
Fix perlscript
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
383
diff
changeset
|
342 # handling goto statement |
ee5d2b1685d7
Fix perlscript
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
383
diff
changeset
|
343 # convert it to the meta call form with two arugments, that is context and enum Code |
ee5d2b1685d7
Fix perlscript
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
383
diff
changeset
|
344 my $prev = $1; |
ee5d2b1685d7
Fix perlscript
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
383
diff
changeset
|
345 my $next = $2; |
ee5d2b1685d7
Fix perlscript
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
383
diff
changeset
|
346 my $method = $3; |
ee5d2b1685d7
Fix perlscript
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
383
diff
changeset
|
347 my @args = split(/,/,$4); |
ee5d2b1685d7
Fix perlscript
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
383
diff
changeset
|
348 my @types = @{$dataGearVarType{$codeGearName}}; |
ee5d2b1685d7
Fix perlscript
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
383
diff
changeset
|
349 my $ntype; |
ee5d2b1685d7
Fix perlscript
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
383
diff
changeset
|
350 for my $v (@{$dataGearVar{$codeGearName}}) { |
ee5d2b1685d7
Fix perlscript
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
383
diff
changeset
|
351 my $t = shift @types; |
ee5d2b1685d7
Fix perlscript
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
383
diff
changeset
|
352 if ($v eq $next) { |
ee5d2b1685d7
Fix perlscript
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
383
diff
changeset
|
353 $ntype = $t; |
ee5d2b1685d7
Fix perlscript
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
383
diff
changeset
|
354 } |
ee5d2b1685d7
Fix perlscript
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
383
diff
changeset
|
355 } |
ee5d2b1685d7
Fix perlscript
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
383
diff
changeset
|
356 print $fd "\tGearef(context, $ntype)->$next = $next->$next;\n"; |
ee5d2b1685d7
Fix perlscript
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
383
diff
changeset
|
357 # Put interface argument |
ee5d2b1685d7
Fix perlscript
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
383
diff
changeset
|
358 my $prot = $code{$ntype}->{$method}; |
385 | 359 my $i = 1; |
384
ee5d2b1685d7
Fix perlscript
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
383
diff
changeset
|
360 for my $arg (@args) { |
385 | 361 my $p = @$prot[$i]; |
362 next if ( $p eq $arg); | |
387 | 363 $p =~ s/^(.*)\s(\w+)//; |
364 my $pType = $1; | |
365 my $pName = $2; | |
366 $arg =~ s/^(\s)*(\w+)/$2/; | |
367 if ($pType =~ s/\_\_code$//) { | |
368 print $fd "\tGearef(context, $ntype)->$pName = C_$arg;\n"; | |
369 } else { | |
370 print $fd "\tGearef(context, $ntype)->$pName = $arg;\n"; | |
371 } | |
385 | 372 $i++; |
384
ee5d2b1685d7
Fix perlscript
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
383
diff
changeset
|
373 } |
ee5d2b1685d7
Fix perlscript
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
383
diff
changeset
|
374 print $fd "${prev}goto meta(context, $next->$next->$ntype.$method);\n"; |
ee5d2b1685d7
Fix perlscript
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
383
diff
changeset
|
375 next; |
260
6b5444bbea8a
generated stub no comiple errors
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
259
diff
changeset
|
376 } elsif (/^(.*)goto (\w+)\((.*)\);/) { |
278 | 377 # handling goto statement |
262 | 378 # convert it to the meta call form with two arugments, that is context and enum Code |
250 | 379 my $prev = $1; |
260
6b5444bbea8a
generated stub no comiple errors
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
259
diff
changeset
|
380 my $next = $2; |
6b5444bbea8a
generated stub no comiple errors
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
259
diff
changeset
|
381 my @args = split(/,/,$3); |
388 | 382 my $v = 0; |
383 for my $n ( @{$dataGearVar{$codeGearName}} ) { | |
384 # continuation arguments | |
385 $v = 1 if ( $n eq $next); | |
386 } | |
387 if ($v || defined $code{$interface}->{$next}) { | |
278 | 388 # write continuation's arguments into the interface arguments |
389 # we may need a commit for a shared DataGear | |
390 for my $arg ( @{$outputArgs{$codeGearName}->{$next}} ) { | |
391 my $v = shift(@args); | |
392 print $fd "\t*O_$arg = $v;\n"; | |
393 } | |
394 print $fd "${prev}goto meta(context, $next);\n"; | |
395 next; | |
260
6b5444bbea8a
generated stub no comiple errors
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
259
diff
changeset
|
396 } |
259
195518ab62fc
fix type gathering pattern match in generate_stub.pl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
255
diff
changeset
|
397 } else { |
195518ab62fc
fix type gathering pattern match in generate_stub.pl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
255
diff
changeset
|
398 s/new\s+(\w+)\(\)/\&ALLOCATE(context, \1)->\1/g; # replacing new |
249 | 399 } |
400 # gather type name and type | |
259
195518ab62fc
fix type gathering pattern match in generate_stub.pl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
255
diff
changeset
|
401 } elsif (/^}/) { |
278 | 402 $inStub = 0; |
249 | 403 $inTypedef = 0; |
404 } | |
250 | 405 print $fd $_; |
194 | 406 } |
250 | 407 if (defined $prevCodeGearName) { |
408 if (!defined $stub{$prevCodeGearName."_stub"}) { | |
251 | 409 $stub{$prevCodeGearName."_stub"} = &generateStub($fd,$prevCodeGearName,$dataGearName{$codeGearName}); |
250 | 410 } |
228 | 411 } |
194 | 412 } |
413 | |
414 # end |