Mercurial > hg > GearsTemplate
annotate src/parallel_execution/generate_stub.pl @ 388:8940d1451a0d
handle local continuation
author | masataka |
---|---|
date | Sat, 29 Jul 2017 19:08:25 +0900 |
parents | 590f03af1a2c |
children | d9a7620a1106 |
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 } | |
260
6b5444bbea8a
generated stub no comiple errors
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
259
diff
changeset
|
209 # global variable case |
268 | 210 $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
|
211 return 1; |
253 | 212 } |
213 } | |
214 | |
194 | 215 sub generateDataGear { |
249 | 216 my ($filename) = @_; |
217 open my $in,"<",$filename or die("can't open $filename $!"); | |
254 | 218 |
219 my $fn; | |
220 if ($opt_o) { | |
221 $fn = $opt_o; | |
222 } else { | |
223 my $fn1 = $filename; | |
224 $fn1 =~ s/\.cbc/.c/; | |
225 my $i = 1; | |
255 | 226 $fn = "$dir/$fn1"; |
254 | 227 while ( -f $fn) { |
255 | 228 $fn = "$dir/$fn1.$i"; |
254 | 229 $i++; |
230 } | |
250 | 231 } |
259
195518ab62fc
fix type gathering pattern match in generate_stub.pl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
255
diff
changeset
|
232 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
|
233 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
|
234 mkdir $1; |
195518ab62fc
fix type gathering pattern match in generate_stub.pl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
255
diff
changeset
|
235 } |
195518ab62fc
fix type gathering pattern match in generate_stub.pl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
255
diff
changeset
|
236 } |
249 | 237 open my $fd,">",$fn or die("can't write $fn $!"); |
254 | 238 |
249 | 239 my $prevCodeGearName; |
250 | 240 my $inTypedef = 0; |
278 | 241 my $inStub = 0; |
250 | 242 my %stub; |
251 | 243 my $codeGearName; |
254 | 244 |
249 | 245 while (<$in>) { |
278 | 246 if (! $inTypedef && ! $inStub) { |
249 | 247 if (/^typedef struct (\w+) {/) { |
248 $inTypedef = 1; | |
253 | 249 } elsif (/^\_\_code (\w+)\((.*)\)(.*)/) { |
251 | 250 $codeGearName = $1; |
253 | 251 my $args = $2; |
252 my $tail = $3; | |
250 | 253 if ($codeGearName =~ /_stub$/) { |
262 | 254 # don't touch already existing stub |
278 | 255 $inStub = 1; |
250 | 256 $stub{$codeGearName} = 1; |
257 print $fd $_; | |
258 next; | |
259 } | |
249 | 260 if (defined $prevCodeGearName) { |
262 | 261 # stub is generated just before next CodeGear |
250 | 262 if (defined $stub{$prevCodeGearName."_stub"}) { |
263 undef $prevCodeGearName; | |
278 | 264 } else { |
265 &generateStub($fd,$prevCodeGearName,$dataGearName{$prevCodeGearName}); | |
266 $stub{$prevCodeGearName."_stub"} = 1; | |
250 | 267 } |
249 | 268 } |
262 | 269 # analyzing CodeGear argument |
270 # these arguments are extract from current context's arugment DataGear Interface | |
271 # and passed to the CodeGear | |
272 # struct Implementaion needs special handling | |
273 # __code next(...) ---> enum Code next | |
253 | 274 $prevCodeGearName = $codeGearName; |
275 $dataGearVar{$codeGearName} = []; | |
260
6b5444bbea8a
generated stub no comiple errors
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
259
diff
changeset
|
276 $outputVar{$codeGearName} = ""; |
6b5444bbea8a
generated stub no comiple errors
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
259
diff
changeset
|
277 $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
|
278 my $newArgs = "struct Context *context,"; |
305 | 279 if ($args=~/^struct Context\s*\*\s*context/) { |
280 $newArgs = ""; | |
281 } | |
253 | 282 while($args) { |
283 if ($args =~ s/(^\s*,\s*)//) { | |
284 $newArgs .= $1; | |
285 } | |
262 | 286 # continuation case |
280 | 287 if ($args =~ s/^(\s)*\_\_code\s+(\w+)\(([^)]*)\)//) { |
288 my $next = $2; | |
289 my @args = split(/,/,$3); | |
260
6b5444bbea8a
generated stub no comiple errors
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
259
diff
changeset
|
290 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
|
291 $newArgs .= "enum Code $next"; |
258 | 292 } |
262 | 293 # analyze continuation arguments |
294 # output arguments are defined in the Interface take the pointer of these | |
295 # output arguments are put into the Interface DataGear just before the goto | |
253 | 296 for my $arg (@args) { |
297 $arg =~ s/^\s*//; | |
260
6b5444bbea8a
generated stub no comiple errors
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
259
diff
changeset
|
298 last if ($arg =~ /\.\.\./); |
253 | 299 $arg =~ s/^(struct|union) (\w+)(\*)+\s(\w+)//; |
300 my $structType = $1; | |
301 my $typeName = $2; | |
302 my $varName = $4; | |
303 my $typeField = lcfirst($typeName); | |
260
6b5444bbea8a
generated stub no comiple errors
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
259
diff
changeset
|
304 push(@{$outputArgs{$codeGearName}->{$next}}, $varName); |
6b5444bbea8a
generated stub no comiple errors
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
259
diff
changeset
|
305 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
|
306 $newArgs .= ",$structType $typeName **O_$varName"; |
6b5444bbea8a
generated stub no comiple errors
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
259
diff
changeset
|
307 } |
253 | 308 } |
309 } elsif ($args =~ s/^(struct|union) (\w+)(\*)+\s(\w+)//) { | |
310 my $structType = $1; | |
311 my $typeName = $2; | |
312 my $varName = $4; | |
313 my $typeField = lcfirst($typeName); | |
260
6b5444bbea8a
generated stub no comiple errors
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
259
diff
changeset
|
314 $newArgs .= $&; # assuming no duplicate |
6b5444bbea8a
generated stub no comiple errors
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
259
diff
changeset
|
315 &generateStubArgs($codeGearName, $varName, $typeName, $typeField, $interface,0); |
255 | 316 } elsif ($args =~ s/(.*,)//) { |
317 $newArgs .= $1; | |
318 } else { | |
319 $newArgs .= $args; | |
320 last; | |
253 | 321 } |
322 } | |
262 | 323 # generate goto statement from stub to the CodeGear in the buffer |
253 | 324 $dataGearName{$codeGearName} .= "\tgoto $codeGearName(context"; |
325 for my $arg ( @{$dataGearVar{$codeGearName}}) { | |
326 $dataGearName{$codeGearName} .= ", $arg"; | |
327 } | |
328 $dataGearName{$codeGearName} .= ");"; | |
262 | 329 # generate CodeGear header with new arguments |
253 | 330 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
|
331 if ($outputVar{$codeGearName} ne "") { |
324 | 332 # output data var can be use before write |
333 # 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
|
334 print $fd $outputVar{$codeGearName}; |
6b5444bbea8a
generated stub no comiple errors
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
259
diff
changeset
|
335 } |
250 | 336 next; |
384
ee5d2b1685d7
Fix perlscript
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
383
diff
changeset
|
337 } elsif (/^(.*)goto (\w+)\-\>(\w+)\((.*)\);/) { |
ee5d2b1685d7
Fix perlscript
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
383
diff
changeset
|
338 # handling goto statement |
ee5d2b1685d7
Fix perlscript
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
383
diff
changeset
|
339 # 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
|
340 my $prev = $1; |
ee5d2b1685d7
Fix perlscript
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
383
diff
changeset
|
341 my $next = $2; |
ee5d2b1685d7
Fix perlscript
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
383
diff
changeset
|
342 my $method = $3; |
ee5d2b1685d7
Fix perlscript
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
383
diff
changeset
|
343 my @args = split(/,/,$4); |
ee5d2b1685d7
Fix perlscript
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
383
diff
changeset
|
344 my @types = @{$dataGearVarType{$codeGearName}}; |
ee5d2b1685d7
Fix perlscript
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
383
diff
changeset
|
345 my $ntype; |
ee5d2b1685d7
Fix perlscript
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
383
diff
changeset
|
346 for my $v (@{$dataGearVar{$codeGearName}}) { |
ee5d2b1685d7
Fix perlscript
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
383
diff
changeset
|
347 my $t = shift @types; |
ee5d2b1685d7
Fix perlscript
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
383
diff
changeset
|
348 if ($v eq $next) { |
ee5d2b1685d7
Fix perlscript
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
383
diff
changeset
|
349 $ntype = $t; |
ee5d2b1685d7
Fix perlscript
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
383
diff
changeset
|
350 } |
ee5d2b1685d7
Fix perlscript
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
383
diff
changeset
|
351 } |
ee5d2b1685d7
Fix perlscript
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
383
diff
changeset
|
352 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
|
353 # Put interface argument |
ee5d2b1685d7
Fix perlscript
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
383
diff
changeset
|
354 my $prot = $code{$ntype}->{$method}; |
385 | 355 my $i = 1; |
384
ee5d2b1685d7
Fix perlscript
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
383
diff
changeset
|
356 for my $arg (@args) { |
385 | 357 my $p = @$prot[$i]; |
358 next if ( $p eq $arg); | |
387 | 359 $p =~ s/^(.*)\s(\w+)//; |
360 my $pType = $1; | |
361 my $pName = $2; | |
362 $arg =~ s/^(\s)*(\w+)/$2/; | |
363 if ($pType =~ s/\_\_code$//) { | |
364 print $fd "\tGearef(context, $ntype)->$pName = C_$arg;\n"; | |
365 } else { | |
366 print $fd "\tGearef(context, $ntype)->$pName = $arg;\n"; | |
367 } | |
385 | 368 $i++; |
384
ee5d2b1685d7
Fix perlscript
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
383
diff
changeset
|
369 } |
ee5d2b1685d7
Fix perlscript
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
383
diff
changeset
|
370 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
|
371 next; |
260
6b5444bbea8a
generated stub no comiple errors
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
259
diff
changeset
|
372 } elsif (/^(.*)goto (\w+)\((.*)\);/) { |
278 | 373 # handling goto statement |
262 | 374 # convert it to the meta call form with two arugments, that is context and enum Code |
250 | 375 my $prev = $1; |
260
6b5444bbea8a
generated stub no comiple errors
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
259
diff
changeset
|
376 my $next = $2; |
6b5444bbea8a
generated stub no comiple errors
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
259
diff
changeset
|
377 my @args = split(/,/,$3); |
388 | 378 my $v = 0; |
379 for my $n ( @{$dataGearVar{$codeGearName}} ) { | |
380 # continuation arguments | |
381 $v = 1 if ( $n eq $next); | |
382 } | |
383 if ($v || defined $code{$interface}->{$next}) { | |
278 | 384 # write continuation's arguments into the interface arguments |
385 # we may need a commit for a shared DataGear | |
386 for my $arg ( @{$outputArgs{$codeGearName}->{$next}} ) { | |
387 my $v = shift(@args); | |
388 print $fd "\t*O_$arg = $v;\n"; | |
389 } | |
390 print $fd "${prev}goto meta(context, $next);\n"; | |
391 next; | |
260
6b5444bbea8a
generated stub no comiple errors
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
259
diff
changeset
|
392 } |
259
195518ab62fc
fix type gathering pattern match in generate_stub.pl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
255
diff
changeset
|
393 } else { |
195518ab62fc
fix type gathering pattern match in generate_stub.pl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
255
diff
changeset
|
394 s/new\s+(\w+)\(\)/\&ALLOCATE(context, \1)->\1/g; # replacing new |
249 | 395 } |
396 # 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
|
397 } elsif (/^}/) { |
278 | 398 $inStub = 0; |
249 | 399 $inTypedef = 0; |
400 } | |
250 | 401 print $fd $_; |
194 | 402 } |
250 | 403 if (defined $prevCodeGearName) { |
404 if (!defined $stub{$prevCodeGearName."_stub"}) { | |
251 | 405 $stub{$prevCodeGearName."_stub"} = &generateStub($fd,$prevCodeGearName,$dataGearName{$codeGearName}); |
250 | 406 } |
228 | 407 } |
194 | 408 } |
409 | |
410 # end |