Mercurial > hg > CbC > CbC_xv6
annotate src/gearsTools/generate_stub.pl @ 357:e194c940c664
fix Getopt
author | anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Mon, 15 Jun 2020 18:41:01 +0900 |
parents | fde5f96c6ff1 |
children | 87a28b02c88f |
rev | line source |
---|---|
44 | 1 #!/usr/bin/perl |
2 | |
3 use strict; | |
354
fde5f96c6ff1
use common perl script
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
323
diff
changeset
|
4 use Getopt::Long; |
44 | 5 use File::Path qw(make_path); |
6 | |
7 # interface.h | |
8 # typedef struct Worker { | |
9 # int id; | |
10 # struct Context* contexts; | |
11 # enum Code execute; | |
12 # enum Code taskSend; | |
13 # enum Code taskRecive; | |
14 # enum Code shutdown; | |
15 # struct Queue* tasks; | |
16 # } Worker; | |
17 | |
354
fde5f96c6ff1
use common perl script
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
323
diff
changeset
|
18 our($opt_o,$opt_d,$opt_h, $opt_project); |
fde5f96c6ff1
use common perl script
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
323
diff
changeset
|
19 |
fde5f96c6ff1
use common perl script
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
323
diff
changeset
|
20 GetOptions( |
357 | 21 "o=s" => \$opt_o, |
22 "d=s" => \$opt_d, | |
23 "h" => \$opt_h, | |
24 "project=s" => \$opt_project, | |
354
fde5f96c6ff1
use common perl script
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
323
diff
changeset
|
25 ); |
44 | 26 |
27 my $dir = "."; | |
28 if ($opt_d) { | |
29 $dir = $opt_d; | |
30 if (! -d $dir) { | |
31 make_path $dir; | |
32 } | |
33 } | |
34 | |
354
fde5f96c6ff1
use common perl script
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
323
diff
changeset
|
35 |
fde5f96c6ff1
use common perl script
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
323
diff
changeset
|
36 |
fde5f96c6ff1
use common perl script
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
323
diff
changeset
|
37 my %projects = ( |
fde5f96c6ff1
use common perl script
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
323
diff
changeset
|
38 gears => { cotnext => "context" }, |
fde5f96c6ff1
use common perl script
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
323
diff
changeset
|
39 xv6 => { context => "cbc_context" }, |
fde5f96c6ff1
use common perl script
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
323
diff
changeset
|
40 ); |
fde5f96c6ff1
use common perl script
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
323
diff
changeset
|
41 |
fde5f96c6ff1
use common perl script
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
323
diff
changeset
|
42 |
fde5f96c6ff1
use common perl script
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
323
diff
changeset
|
43 my $context_name = "context"; |
fde5f96c6ff1
use common perl script
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
323
diff
changeset
|
44 if ($opt_project && exists $projects{$opt_project}) { |
fde5f96c6ff1
use common perl script
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
323
diff
changeset
|
45 $context_name = $projects{$opt_project}->{context}; |
fde5f96c6ff1
use common perl script
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
323
diff
changeset
|
46 } |
fde5f96c6ff1
use common perl script
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
323
diff
changeset
|
47 |
44 | 48 for my $fn (@ARGV) { |
49 next if ($fn !~ /\.cbc$/); | |
50 &getDataGear($fn); | |
51 &generateDataGear($fn); | |
52 } | |
53 | |
54 my %var; | |
55 my %code; | |
56 my %dataGearVar; | |
57 my %outputVar; # output var initializer | |
58 my %outputArgs; # continuation's output variables | |
59 my %dataGear; | |
60 my %dataGearName; | |
61 my %generic; | |
62 my %dataGearVarType; | |
63 my %codeGear; | |
64 my $implementation; | |
65 my $interface; | |
66 | |
67 # interface definision | |
68 # | |
69 # typedef struct Stack<Type, Impl>{ | |
70 # Type* stack; | |
71 # Type* data; | |
72 # Type* data1; | |
73 # __code whenEmpty(...); | |
74 # __code clear(Impl* stack,__code next(...)); | |
75 # __code push(Impl* stack,Type* data, __code next(...)); | |
76 # __code pop(Impl* stack, __code next(Type*, ...)); | |
77 # __code pop2(Impl* stack, Type** data, Type** data1, __code next(Type**, Type**, ...)); | |
78 # __code isEmpty(Impl* stack, __code next(...), __code whenEmpty(...)); | |
79 # __code get(Impl* stack, Type** data, __code next(...)); | |
80 # __code get2(Impl* stack,..., __code next(...)); | |
81 # __code next(...); | |
82 # } Stack; | |
83 # | |
84 # calling example | |
85 # | |
86 # goto nodeStack->push((union Data*)node, stackTest3); | |
87 # | |
88 # generated meta level code | |
89 # | |
354
fde5f96c6ff1
use common perl script
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
323
diff
changeset
|
90 # Gearef(context, Stack)->stack = (union Data*)nodeStack; |
fde5f96c6ff1
use common perl script
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
323
diff
changeset
|
91 # Gearef(context, Stack)->data = (union Data*)node; |
fde5f96c6ff1
use common perl script
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
323
diff
changeset
|
92 # Gearef(context, Stack)->next = C_stackTest3; |
fde5f96c6ff1
use common perl script
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
323
diff
changeset
|
93 # goto meta(context, nodeStack->push); |
44 | 94 |
95 sub getDataGear { | |
96 my ($filename) = @_; | |
249
42a37a8a02c9
impl described_data_gear mode
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
248
diff
changeset
|
97 my ($codeGearName, $name, $inTypedef,$described_data_gear); |
44 | 98 open my $fd,"<",$filename or die("can't open $filename $!"); |
99 while (<$fd>) { | |
100 if (! $inTypedef) { | |
101 if (/^typedef struct (\w+)\s*<(.*)>/) { | |
102 $inTypedef = 1; | |
103 $name = $1; | |
104 $dataGear{$name} = $_; | |
105 $var{$name} = {}; | |
106 $code{$name} = {}; | |
107 $generic{$name} = \split(/,/,$2); | |
108 } elsif (/^typedef struct (\w+)/) { | |
109 $inTypedef = 1; | |
110 $name = $1; | |
111 $dataGear{$name} = $_; | |
112 $var{$name} = {}; | |
113 $code{$name} = {}; | |
114 $generic{$name} = []; | |
115 } elsif (/^(\w+)(\*)+ create(\w+)\(/) { | |
116 if (defined $interface) { | |
117 die "duplicate interface $interface\n"; | |
118 } | |
119 $interface = $1; | |
120 $implementation = $3; | |
121 if ( -f "$interface.cbc") { | |
122 &getDataGear("$interface.cbc"); | |
123 } | |
124 } elsif(/^(.*)par goto (\w+)\((.*)\)/) { | |
125 my $codeGearName = $2; | |
126 if ($filename =~ /^(.*)\/(.*)/) { | |
127 $codeGearName = "$1/$codeGearName"; | |
128 } | |
129 if ( -f "$codeGearName.cbc") { | |
130 &getCodeGear("$codeGearName.cbc"); | |
131 } | |
242
26be78edaf83
impl auto collection for data gears from interface
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
82
diff
changeset
|
132 } elsif(/^#interface "(.*)"/) { |
44 | 133 # use interface |
134 my $interfaceHeader = $1; | |
135 next if ($interfaceHeader =~ /context.h/); | |
136 if (-f $interfaceHeader) { | |
137 &getDataGear("$interfaceHeader"); | |
138 &getCodeGear("$interfaceHeader"); | |
354
fde5f96c6ff1
use common perl script
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
323
diff
changeset
|
139 } else { |
fde5f96c6ff1
use common perl script
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
323
diff
changeset
|
140 if ($filename =~ /([\w\/]+)\/(.+)$/) { |
fde5f96c6ff1
use common perl script
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
323
diff
changeset
|
141 $interfaceHeader = "$1/$interfaceHeader"; |
fde5f96c6ff1
use common perl script
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
323
diff
changeset
|
142 if (-f $interfaceHeader) { |
fde5f96c6ff1
use common perl script
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
323
diff
changeset
|
143 &getDataGear("$interfaceHeader"); |
fde5f96c6ff1
use common perl script
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
323
diff
changeset
|
144 &getCodeGear("$interfaceHeader"); |
fde5f96c6ff1
use common perl script
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
323
diff
changeset
|
145 } |
fde5f96c6ff1
use common perl script
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
323
diff
changeset
|
146 } |
44 | 147 } |
148 } elsif (/^\_\_code (\w+)\((.*)\)(.*)/) { | |
149 my $codeGearName = $1; | |
150 if ($filename =~ /^(.*)\/(.*)/) { | |
151 $codeGearName = "$1/$codeGearName"; | |
152 } | |
153 if ( -f "$codeGearName.cbc") { | |
154 &getCodeGear("$codeGearName.cbc"); | |
155 } | |
156 } | |
157 next; | |
158 } | |
159 # gather type name and type | |
160 $dataGear{$name} .= $_; | |
161 if (/^\s*(.*)\s+(\w+);$/ ) { | |
162 my $ttype = $1; | |
163 my $tname = $2; | |
354
fde5f96c6ff1
use common perl script
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
323
diff
changeset
|
164 if ($ttype =~ /^(union|struct|const|enu,)?\s*(\w+)/) { |
298 | 165 if ($1 ne 'const') { |
166 $ttype = $2; | |
167 } else { | |
354
fde5f96c6ff1
use common perl script
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
323
diff
changeset
|
168 my $vname = $2; |
fde5f96c6ff1
use common perl script
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
323
diff
changeset
|
169 my $ttype = $1; |
fde5f96c6ff1
use common perl script
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
323
diff
changeset
|
170 if ($ttype =~ /(const|enum)/) { |
fde5f96c6ff1
use common perl script
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
323
diff
changeset
|
171 $ttype = "$1 $vname"; |
fde5f96c6ff1
use common perl script
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
323
diff
changeset
|
172 } |
298 | 173 } |
44 | 174 } |
249
42a37a8a02c9
impl described_data_gear mode
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
248
diff
changeset
|
175 $described_data_gear = 1; |
44 | 176 $var{$name}->{$tname} = $ttype; |
177 } | |
242
26be78edaf83
impl auto collection for data gears from interface
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
82
diff
changeset
|
178 if (/__code (\w+)/) { |
249
42a37a8a02c9
impl described_data_gear mode
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
248
diff
changeset
|
179 next if $described_data_gear; |
242
26be78edaf83
impl auto collection for data gears from interface
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
82
diff
changeset
|
180 my $args = $'; |
354
fde5f96c6ff1
use common perl script
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
323
diff
changeset
|
181 while ($args =~ /\s*(struct|union|const|enum)?\s*([\w\[\]_]+)\*?\s*(\w+),?/g) { |
242
26be78edaf83
impl auto collection for data gears from interface
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
82
diff
changeset
|
182 #$args eq (Impl* vm, pde_t* pgdir, char* init, uint sz, __code next(...)); |
26be78edaf83
impl auto collection for data gears from interface
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
82
diff
changeset
|
183 my $const_type = $1; |
26be78edaf83
impl auto collection for data gears from interface
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
82
diff
changeset
|
184 my $ttype = $2; |
26be78edaf83
impl auto collection for data gears from interface
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
82
diff
changeset
|
185 my $tname = $3; |
26be78edaf83
impl auto collection for data gears from interface
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
82
diff
changeset
|
186 |
248 | 187 $ttype =~ s/(Impl|Isa|Type)/Data/; |
354
fde5f96c6ff1
use common perl script
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
323
diff
changeset
|
188 if ($const_type =~ /(const|enum)/) { |
fde5f96c6ff1
use common perl script
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
323
diff
changeset
|
189 $ttype = "$1 $ttype"; |
242
26be78edaf83
impl auto collection for data gears from interface
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
82
diff
changeset
|
190 } |
26be78edaf83
impl auto collection for data gears from interface
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
82
diff
changeset
|
191 $var{$name}->{$tname} = $ttype; |
26be78edaf83
impl auto collection for data gears from interface
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
82
diff
changeset
|
192 } |
26be78edaf83
impl auto collection for data gears from interface
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
82
diff
changeset
|
193 } |
44 | 194 if (/^}/) { |
195 $inTypedef = 0; | |
196 } | |
197 } | |
198 | |
199 } | |
200 | |
201 sub getCodeGear { | |
202 my ($filename) = @_; | |
203 open my $fd,"<",$filename or die("can't open $filename $!"); | |
204 my ($name,$impln); | |
205 while (<$fd>) { | |
206 if (/^(\w+)(\*)+ create(\w+)\(/) { | |
207 $name = $1; | |
208 $impln = $3; | |
209 } elsif(/^typedef struct (.*)<.*>\s*{/) { | |
210 $name = $1; | |
211 } | |
212 if (defined $name) { | |
213 if (/^\s*\_\_code (\w+)\((.*)\);/) { | |
214 my $args = $2; | |
215 my $method = $1; | |
216 $code{$name}->{$method} = []; | |
217 while($args) { | |
218 # replace comma | |
219 $args =~ s/(^\s*,\s*)//; | |
220 # continuation case | |
221 if ($args =~ s/^(\s)*\_\_code\s+(\w+)\(([^)]*)\)//) { | |
222 my $next = $2; | |
223 my @args = split(/,/,$3); | |
224 push(@{$code{$name}->{$method}},"\_\_code $next"); | |
298 | 225 } elsif ($args =~ s/^(struct|union|const)?\s*(\w+)(\**)\s+(\w+)//) { |
44 | 226 my $structType = $1; |
227 my $typeName = $2; | |
228 my $ptrType = $3; | |
229 my $varName = $4; | |
230 my $typeField = lcfirst($typeName); | |
298 | 231 if ($structType =~ /const/) { |
232 $typeName = "$structType $typeName"; | |
233 } | |
44 | 234 push(@{$code{$name}->{$method}},"$typeName$ptrType $varName"); |
235 } elsif ($args =~ s/(.*,)//) { | |
236 } else { | |
237 last; | |
238 } | |
239 } | |
240 } | |
241 } elsif (/^\_\_code (\w+)\((.*)\)(.*)/) { | |
242 my $codeGearName = $1; | |
243 my $args = $2; | |
244 my $inputCount = 0; | |
245 my $outputCount = 0; | |
246 my $inputIncFlag = 1; | |
247 while($args) { | |
248 if ($args =~ s/(^\s*,\s*)//) { | |
249 } | |
250 if ($args =~ s/^(\s)*\_\_code\s+(\w+)\((.*?)\)//) { | |
251 $codeGear{$codeGearName}->{"code"}->{$2} = "\_\_code"; | |
252 $inputIncFlag = 0; | |
253 my @outputs = split(/,/,$3); | |
254 for my $output (@outputs) { | |
298 | 255 if ($output =~ /\s*(struct|union|const)?\s*(\w+)(\*)?+\s(\w+)/) { |
256 my $structType = $1; | |
44 | 257 my $type = $2; |
258 my $varName = $4; | |
298 | 259 if ($structType =~ /const/) { |
260 $type = "$structType $type"; | |
261 } | |
44 | 262 $codeGear{$codeGearName}->{"var"}->{$varName} = "$type $outputCount"; |
263 $outputCount++; | |
264 } | |
265 } | |
298 | 266 } elsif ($args =~ s/^(struct|union|const)?\s*(\w+)(\*)?+\s(\w+)// && $inputIncFlag) { |
267 my $structType = $1; | |
44 | 268 my $type = $2; |
269 my $varName = $4; | |
298 | 270 if ($structType =~ /const/) { |
271 $type = "$structType $type"; | |
272 } | |
44 | 273 $codeGear{$codeGearName}->{"var"}->{$varName} = "$type $inputCount"; |
274 $inputCount++; | |
275 } elsif ($args =~ s/(.*,)//) { | |
276 } else { | |
277 last; | |
278 } | |
279 } | |
280 $codeGear{$codeGearName}->{"input"} = $inputCount; | |
281 $codeGear{$codeGearName}->{"output"} = $outputCount; | |
282 } | |
283 } | |
284 } | |
285 | |
286 sub generateStub { | |
287 my($fd,$prevCodeGearName,$dataGearName) = @_; | |
354
fde5f96c6ff1
use common perl script
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
323
diff
changeset
|
288 print $fd "__code ", $prevCodeGearName ,"_stub(struct Context* $context_name) {\n"; |
44 | 289 print $fd $dataGearName; |
290 print $fd "\n} \n\n"; | |
291 return 1; | |
292 } | |
293 | |
294 sub generateStubArgs { | |
295 my($codeGearName, $varName, $typeName, $ptrType, $typeField, $interface,$output) = @_; | |
296 my $varname1 = $output?"O_$varName":$varName; | |
297 for my $n ( @{$dataGearVar{$codeGearName}} ) { | |
298 # we already have it | |
299 return 0 if ( $n eq $varname1); | |
300 } | |
301 push @{$dataGearVar{$codeGearName}}, $varname1; | |
302 push @{$dataGearVarType{$codeGearName}}, $typeName; | |
303 if ($typeName eq $implementation) { | |
304 # get implementation | |
354
fde5f96c6ff1
use common perl script
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
323
diff
changeset
|
305 $dataGearName{$codeGearName} .= "\t$typeName* $varName = ($typeName*)GearImpl($context_name, $interface, $varName);\n"; |
44 | 306 } else { |
307 # interface var | |
308 for my $ivar (keys %{$var{$interface}}) { | |
309 # input data gear field | |
310 if ($varName eq $ivar) { | |
311 if ($typeName eq $var{$interface}->{$ivar}) { | |
312 if ($output) { | |
354
fde5f96c6ff1
use common perl script
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
323
diff
changeset
|
313 $dataGearName{$codeGearName} .= "\t$typeName$ptrType* O_$varName = &Gearef($context_name, $interface)->$varName;\n"; |
82 | 314 $outputVar{$codeGearName} .= "\t$typeName$ptrType $varName __attribute__((unused)) = *O_$varName;\n"; |
44 | 315 return 1; |
316 } | |
354
fde5f96c6ff1
use common perl script
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
323
diff
changeset
|
317 $dataGearName{$codeGearName} .= "\t$typeName$ptrType $varName = Gearef($context_name, $interface)->$varName;\n"; |
44 | 318 return 1; |
319 } | |
320 } | |
321 } | |
298 | 322 |
44 | 323 # interface continuation |
324 for my $cName (keys %{$code{$interface}}) { | |
325 if ($varName eq $cName) { | |
326 # continuation field | |
354
fde5f96c6ff1
use common perl script
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
323
diff
changeset
|
327 $dataGearName{$codeGearName} .= "\tenum Code $varName = Gearef($context_name, $interface)->$varName;\n"; |
44 | 328 return 1; |
329 } | |
330 } | |
331 # par goto var | |
332 for my $var (keys %{$codeGear{$codeGearName}->{"var"}}) { | |
333 # input data gear field | |
334 if ($varName eq $var) { | |
335 my ($type, $count) = split(/\s/, $codeGear{$codeGearName}->{"var"}->{$var}); | |
336 if ($typeName eq $type) { | |
337 if ($output) { | |
354
fde5f96c6ff1
use common perl script
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
323
diff
changeset
|
338 $dataGearName{$codeGearName} .= "\t$typeName$ptrType* O_$varName = ($typeName $ptrType*)&${context_name}->data[${context_name}\->odg + $count];\n"; |
44 | 339 $outputVar{$codeGearName} .= "\t$typeName$ptrType $varName = *O_$varName;\n"; |
340 return 1; | |
341 } | |
354
fde5f96c6ff1
use common perl script
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
323
diff
changeset
|
342 $dataGearName{$codeGearName} .= "\t$typeName$ptrType $varName = &${context_name}->data[${context_name}\->idg + $count]->$typeName;\n"; |
44 | 343 return 1; |
344 } | |
345 } | |
346 } | |
347 | |
348 # par goto continuation | |
349 for my $cName (keys %{$codeGear{$codeGearName}->{"code"}}) { | |
350 if ($varName eq $cName) { | |
351 # continuation field | |
354
fde5f96c6ff1
use common perl script
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
323
diff
changeset
|
352 $dataGearName{$codeGearName} .= "\tenum Code $varName = ${context_name}\->next;\n"; |
44 | 353 return 1; |
354 } | |
355 } | |
356 | |
357 # par goto continuation | |
358 # global or local variable case | |
359 if ($typeName eq "Code") { | |
354
fde5f96c6ff1
use common perl script
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
323
diff
changeset
|
360 $dataGearName{$codeGearName} .= "\tenum $typeName$ptrType $varName = Gearef(${context_name}, $interface)->$varName;\n"; |
44 | 361 return 1; |
362 } | |
354
fde5f96c6ff1
use common perl script
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
323
diff
changeset
|
363 $dataGearName{$codeGearName} .= "\t$typeName$ptrType $varName = Gearef($context_name, $typeName);\n"; |
44 | 364 return 1; |
365 } | |
366 } | |
367 | |
368 sub generateDataGear { | |
369 my ($filename) = @_; | |
370 open my $in,"<",$filename or die("can't open $filename $!"); | |
371 | |
372 my $fn; | |
373 if ($opt_o) { | |
374 $fn = $opt_o; | |
375 } else { | |
376 my $fn1 = $filename; | |
377 $fn1 =~ s/\.cbc/.c/; | |
378 my $i = 1; | |
379 $fn = "$dir/$fn1"; | |
380 while ( -f $fn) { | |
381 $fn = "$dir/$fn1.$i"; | |
382 $i++; | |
383 } | |
384 } | |
385 if ( $fn =~ m=(.*)/[^/]+$= ) { | |
386 if (! -d $1) { | |
387 make_path $1; | |
388 } | |
389 } | |
390 open my $fd,">",$fn or die("can't write $fn $!"); | |
391 | |
392 my $prevCodeGearName; | |
393 my $inTypedef = 0; | |
394 my $inStub = 0; | |
45 | 395 my $hasParGoto = 0; |
44 | 396 my $inMain = 0 ; |
52 | 397 my $inCode = 0 ; |
44 | 398 my %stub; |
399 my $codeGearName; | |
400 my %localVarType; | |
52 | 401 my %localCode; |
44 | 402 |
403 while (<$in>) { | |
404 if (! $inTypedef && ! $inStub && ! $inMain) { | |
405 if (/^typedef struct (\w+) \{/) { | |
406 $inTypedef = 1; | |
407 } elsif (/^int main\((.*)\) \{/) { | |
408 $inMain = 1; | |
409 } elsif(/^#interface "(.*)"/) { | |
410 my $interfaceHeader = $1; | |
411 # #interface not write | |
412 next unless ($interfaceHeader =~ /context.h/); | |
52 | 413 } elsif (/^\s\s*_\_code (\w+)\((.*)\)(.*)/) { |
414 $localCode{$1} = 1; | |
415 } elsif (/^\s\s*_\_code *\(\s*\*\s*(\w+)\)\((.*)\)(.*)/) { | |
416 $localCode{$1} = 1; | |
44 | 417 } elsif (/^\_\_code (\w+)\((.*)\)(.*)/) { |
52 | 418 $inCode = 1; |
419 %localCode = {}; | |
44 | 420 %localVarType = {}; |
421 $codeGearName = $1; | |
422 my $args = $2; | |
423 my $tail = $3; | |
424 if ($codeGearName =~ /_stub$/) { | |
425 # don't touch already existing stub | |
426 $inStub = 1; | |
427 $stub{$codeGearName} = 1; | |
428 print $fd $_; | |
429 next; | |
430 } | |
431 if (defined $prevCodeGearName) { | |
432 # stub is generated just before next CodeGear | |
433 if (defined $stub{$prevCodeGearName."_stub"}) { | |
434 undef $prevCodeGearName; | |
435 } else { | |
436 &generateStub($fd,$prevCodeGearName,$dataGearName{$prevCodeGearName}); | |
437 $stub{$prevCodeGearName."_stub"} = 1; | |
438 } | |
439 } | |
440 # analyzing CodeGear argument | |
441 # these arguments are extract from current context's arugment DataGear Interface | |
442 # and passed to the CodeGear | |
443 # struct Implementaion needs special handling | |
444 # __code next(...) ---> enum Code next | |
445 $prevCodeGearName = $codeGearName; | |
446 $dataGearVar{$codeGearName} = []; | |
447 $outputVar{$codeGearName} = ""; | |
448 $outputArgs{$codeGearName} = {}; | |
354
fde5f96c6ff1
use common perl script
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
323
diff
changeset
|
449 my $newArgs = "struct Context *${context_name},"; |
fde5f96c6ff1
use common perl script
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
323
diff
changeset
|
450 if ($args=~/^struct Context\s*\*\s*${context_name}/) { |
44 | 451 $newArgs = ""; |
452 } | |
453 if (!$args){ | |
354
fde5f96c6ff1
use common perl script
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
323
diff
changeset
|
454 $newArgs = "struct Context *${context_name}"; |
44 | 455 } |
456 while($args) { | |
457 if ($args =~ s/(^\s*,\s*)//) { | |
458 $newArgs .= $1; | |
459 } | |
460 # continuation case | |
461 if ($args =~ s/^(\s)*\_\_code\s+(\w+)\(([^)]*)\)//) { | |
462 my $next = $2; | |
463 my @args = split(/,/,$3); | |
464 if (&generateStubArgs($codeGearName, $next, "Code", "", $next, $interface,0) ) { | |
465 $newArgs .= "enum Code $next"; | |
466 } | |
467 # analyze continuation arguments | |
468 # output arguments are defined in the Interface take the pointer of these | |
469 # output arguments are put into the Interface DataGear just before the goto | |
470 for my $arg (@args) { | |
471 $arg =~ s/^\s*//; | |
472 last if ($arg =~ /\.\.\./); | |
354
fde5f96c6ff1
use common perl script
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
323
diff
changeset
|
473 $arg =~ s/^(struct|union|const|enum)?\s*(\w+)(\**)\s(\w+)//; |
44 | 474 my $structType = $1; |
475 my $typeName = $2; | |
476 my $ptrType = $3; | |
477 my $varName = $4; | |
354
fde5f96c6ff1
use common perl script
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
323
diff
changeset
|
478 if ($structType =~ /(const|enum)/) { |
298 | 479 $typeName = "$structType $typeName"; |
480 } | |
44 | 481 my $typeField = lcfirst($typeName); |
482 push(@{$outputArgs{$codeGearName}->{$next}}, $varName); | |
483 if (&generateStubArgs($codeGearName, $varName, $typeName, $ptrType, $typeField, $interface,1)) { | |
484 $newArgs .= ",$structType $typeName **O_$varName"; | |
485 } | |
486 } | |
354
fde5f96c6ff1
use common perl script
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
323
diff
changeset
|
487 } elsif ($args =~ s/^(struct|union|const|enum)?\s*(\w+)(\**)\s(\w+)//) { |
44 | 488 my $structType = $1; |
489 my $typeName = $2; | |
490 my $ptrType = $3; | |
491 my $varName = $4; | |
298 | 492 $newArgs .= $&; # assuming no duplicate |
354
fde5f96c6ff1
use common perl script
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
323
diff
changeset
|
493 if ($structType =~ /(const|enum)/) { |
298 | 494 $typeName = "$structType $typeName"; |
495 } | |
44 | 496 my $typeField = lcfirst($typeName); |
497 &generateStubArgs($codeGearName, $varName, $typeName, $ptrType, $typeField, $interface,0); | |
498 } elsif ($args =~ s/(.*,)//) { | |
499 $newArgs .= $1; | |
500 } else { | |
501 $newArgs .= $args; | |
502 last; | |
503 } | |
504 } | |
505 # generate goto statement from stub to the CodeGear in the buffer | |
354
fde5f96c6ff1
use common perl script
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
323
diff
changeset
|
506 $dataGearName{$codeGearName} .= "\tgoto $codeGearName(${context_name}"; |
44 | 507 for my $arg ( @{$dataGearVar{$codeGearName}}) { |
508 $dataGearName{$codeGearName} .= ", $arg"; | |
509 } | |
510 $dataGearName{$codeGearName} .= ");"; | |
511 # generate CodeGear header with new arguments | |
512 print $fd "__code $codeGearName($newArgs)$tail\n"; | |
513 if ($outputVar{$codeGearName} ne "") { | |
514 # output data var can be use before write | |
515 # it should be initialze by gearef | |
516 print $fd $outputVar{$codeGearName}; | |
517 } | |
518 next; | |
52 | 519 } elsif (! $inCode) { |
354
fde5f96c6ff1
use common perl script
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
323
diff
changeset
|
520 s/new\s+(\w+)\(\)/\&ALLOCATE(${context_name}, \1)->\1/g; # replacing new |
52 | 521 print $fd $_; |
522 next; | |
44 | 523 } elsif (/^(.*)goto (\w+)\-\>(\w+)\((.*)\);/) { |
524 # handling goto statement | |
525 # convert it to the meta call form with two arugments, that is context and enum Code | |
526 my $prev = $1; | |
527 my $next = $2; | |
528 my $method = $3; | |
529 my $tmpArgs = $4; | |
82 | 530 #$tmpArgs =~ s/\(.*\)/\(\)/; |
44 | 531 my @args = split(/,/,$tmpArgs); |
52 | 532 if (! defined $dataGearVarType{$codeGearName}) { |
533 print $fd $_ ; | |
534 next ; | |
535 } | |
44 | 536 my @types = @{$dataGearVarType{$codeGearName}}; |
537 my $ntype; | |
538 my $ftype; | |
539 for my $v (@{$dataGearVar{$codeGearName}}) { | |
540 my $t = shift @types; | |
541 if ($v eq $next || $v eq "O_$next") { | |
542 $ntype = $t; | |
543 $ftype = lcfirst($ntype); | |
544 } | |
545 } | |
546 if (!defined $ntype) { | |
547 $ntype = $localVarType{$next}; | |
548 $ftype = lcfirst($ntype); | |
549 } | |
354
fde5f96c6ff1
use common perl script
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
323
diff
changeset
|
550 print $fd "\tGearef(${context_name}, $ntype)->$ftype = (union Data*) $next;\n"; |
44 | 551 # Put interface argument |
552 my $prot = $code{$ntype}->{$method}; | |
553 my $i = 1; | |
554 for my $arg (@args) { | |
555 my $pType; | |
556 my $pName; | |
557 my $p = @$prot[$i]; | |
558 next if ($p eq $arg); | |
559 $p =~ s/^(.*)\s(\w+)//; | |
560 $pType = $1; | |
561 $pName = $2; | |
562 $arg =~ s/^(\s)*(\w+)/$2/; | |
563 if ($pType =~ s/\_\_code$//) { | |
564 if ($arg =~ /(\w+)\(.*\)/) { | |
354
fde5f96c6ff1
use common perl script
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
323
diff
changeset
|
565 print $fd "\tGearef(${context_name}, $ntype)->$pName = $1;\n"; |
44 | 566 } else { |
354
fde5f96c6ff1
use common perl script
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
323
diff
changeset
|
567 print $fd "\tGearef(${context_name}, $ntype)->$pName = C_$arg;\n"; |
44 | 568 } |
569 } elsif ($pType =~ /Data\**$/){ | |
354
fde5f96c6ff1
use common perl script
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
323
diff
changeset
|
570 print $fd "\tGearef(${context_name}, $ntype)->$pName = (union $pType) $arg;\n"; |
44 | 571 } else { |
354
fde5f96c6ff1
use common perl script
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
323
diff
changeset
|
572 print $fd "\tGearef(${context_name}, $ntype)->$pName = $arg;\n"; |
44 | 573 } |
574 $i++; | |
575 } | |
354
fde5f96c6ff1
use common perl script
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
323
diff
changeset
|
576 print $fd "${prev}context->before = C_$codeGearName;\n"; |
fde5f96c6ff1
use common perl script
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
323
diff
changeset
|
577 print $fd "${prev}goto meta(context, $next->$method);\n"; |
44 | 578 next; |
579 } elsif(/^(.*)par goto (\w+)\((.*)\);/) { | |
580 # handling par goto statement | |
581 # convert it to the parallel | |
582 my $prev = $1; | |
583 my $codeGearName = $2; | |
584 my $args = $3; | |
585 my $inputCount = $codeGear{$codeGearName}->{'input'}; | |
586 my $outputCount = $codeGear{$codeGearName}->{'output'}; | |
587 my @iterateCounts; | |
588 # parse examples 'par goto(.., iterate(10), exit);' | |
589 if ($args =~ /iterate\((.*)?\),/) { | |
590 @iterateCounts = split(/,/,$1);; | |
591 $inputCount--; | |
592 } | |
593 # replace iterate keyword | |
594 $args =~ s/iterate\((.*)?\),//; | |
595 my @dataGears = split(/,\s*/, $args); | |
596 my $nextCodeGear = pop(@dataGears); | |
45 | 597 if (! $hasParGoto) { |
598 $hasParGoto = 1; | |
44 | 599 print $fd "${prev}struct Element* element;\n"; |
600 } | |
601 my $initTask = << "EOFEOF"; | |
354
fde5f96c6ff1
use common perl script
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
323
diff
changeset
|
602 ${prev}${context_name}\->task = NEW(struct Context); |
fde5f96c6ff1
use common perl script
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
323
diff
changeset
|
603 ${prev}initContext(${context_name}\->task); |
fde5f96c6ff1
use common perl script
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
323
diff
changeset
|
604 ${prev}${context_name}\->task->next = C_$codeGearName; |
fde5f96c6ff1
use common perl script
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
323
diff
changeset
|
605 ${prev}${context_name}\->task->idgCount = $inputCount; |
fde5f96c6ff1
use common perl script
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
323
diff
changeset
|
606 ${prev}${context_name}\->task->idg = ${context_name}\->task->dataNum; |
fde5f96c6ff1
use common perl script
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
323
diff
changeset
|
607 ${prev}${context_name}\->task->maxIdg = ${context_name}\->task->idg + $inputCount; |
fde5f96c6ff1
use common perl script
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
323
diff
changeset
|
608 ${prev}${context_name}\->task->odg = ${context_name}\->task->maxIdg; |
fde5f96c6ff1
use common perl script
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
323
diff
changeset
|
609 ${prev}${context_name}\->task->maxOdg = ${context_name}\->task->odg + $outputCount; |
44 | 610 EOFEOF |
611 print $fd $initTask; | |
612 if (@iterateCounts) { | |
354
fde5f96c6ff1
use common perl script
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
323
diff
changeset
|
613 print $fd "${prev}${context_name}\->task->iterate = 0;\n"; |
44 | 614 my $len = @iterateCounts; |
615 if ($len == 1) { | |
354
fde5f96c6ff1
use common perl script
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
323
diff
changeset
|
616 print $fd "${prev}${context_name}\->task->iterator = createMultiDimIterator(${context_name}, $iterateCounts[0], 1, 1);\n"; |
44 | 617 } elsif ($len == 2) { |
354
fde5f96c6ff1
use common perl script
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
323
diff
changeset
|
618 print $fd "${prev}${context_name}\->task->iterator = createMultiDimIterator(${context_name}, $iterateCounts[0], $iterateCounts[1], 1);\n"; |
44 | 619 } elsif ($len == 3) { |
354
fde5f96c6ff1
use common perl script
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
323
diff
changeset
|
620 print $fd "${prev}${context_name}\->task->iterator = createMultiDimIterator(${context_name}, $iterateCounts[0], $iterateCounts[1], $iterateCounts[2]);\n"; |
44 | 621 } |
622 } | |
623 for my $dataGear (@dataGears) { | |
354
fde5f96c6ff1
use common perl script
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
323
diff
changeset
|
624 print $fd "${prev}GET_META($dataGear)->wait = createSynchronizedQueue(${context_name});\n"; |
44 | 625 } |
626 for my $i (0..$inputCount-1) { | |
354
fde5f96c6ff1
use common perl script
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
323
diff
changeset
|
627 print $fd "${prev}${context_name}\->task->data[${context_name}\->task->idg+$i] = (union Data*)@dataGears[$i];\n"; |
44 | 628 } |
629 for my $i (0..$outputCount-1) { | |
354
fde5f96c6ff1
use common perl script
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
323
diff
changeset
|
630 print $fd "${prev}${context_name}\->task->data[${context_name}\->task->odg+$i] = (union Data*)@dataGears[$inputCount+$i];\n"; |
44 | 631 } |
632 my $putTask = << "EOFEOF"; | |
354
fde5f96c6ff1
use common perl script
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
323
diff
changeset
|
633 ${prev}element = &ALLOCATE(${context_name}, Element)->Element; |
fde5f96c6ff1
use common perl script
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
323
diff
changeset
|
634 ${prev}element->data = (union Data*)${context_name}\->task; |
fde5f96c6ff1
use common perl script
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
323
diff
changeset
|
635 ${prev}element->next = ${context_name}\->taskList; |
fde5f96c6ff1
use common perl script
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
323
diff
changeset
|
636 ${prev}${context_name}\->taskList = element; |
44 | 637 EOFEOF |
638 print $fd $putTask; | |
639 next; | |
640 } elsif (/^(.*)goto (\w+)\((.*)\);/) { | |
641 # handling goto statement | |
642 # convert it to the meta call form with two arugments, that is context and enum Code | |
643 my $prev = $1; | |
644 my $next = $2; | |
645 my @args = split(/,/, $3); | |
646 my $v = 0; | |
52 | 647 if (defined $localCode{$next}) { |
648 print $fd $_; next; | |
649 } | |
44 | 650 for my $n ( @{$dataGearVar{$codeGearName}} ) { |
651 # continuation arguments | |
652 $v = 1 if ( $n eq $next); | |
653 } | |
654 if ($v || defined $code{$interface}->{$next}) { | |
655 # write continuation's arguments into the interface arguments | |
656 # we may need a commit for a shared DataGear | |
657 for my $arg ( @{$outputArgs{$codeGearName}->{$next}} ) { | |
658 my $v = shift(@args); | |
659 print $fd "\t*O_$arg = $v;\n"; | |
660 } | |
45 | 661 if ($hasParGoto) { |
354
fde5f96c6ff1
use common perl script
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
323
diff
changeset
|
662 print $fd "${prev}Gearef(${context_name}, TaskManager)->taskList = ${context_name}->taskList;\n"; |
fde5f96c6ff1
use common perl script
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
323
diff
changeset
|
663 print $fd "${prev}Gearef(${context_name}, TaskManager)->next1 = C_$next;\n"; |
fde5f96c6ff1
use common perl script
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
323
diff
changeset
|
664 print $fd "${prev}goto meta(${context_name}, C_$next);\n"; |
44 | 665 } else { |
354
fde5f96c6ff1
use common perl script
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
323
diff
changeset
|
666 print $fd "${prev}${context_name}->before = C_$codeGearName;\n"; |
fde5f96c6ff1
use common perl script
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
323
diff
changeset
|
667 print $fd "${prev}goto meta(${context_name}, $next);\n"; |
44 | 668 } |
669 next; | |
670 } | |
45 | 671 if ($hasParGoto) { |
354
fde5f96c6ff1
use common perl script
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
323
diff
changeset
|
672 print $fd "${prev}Gearef(${context_name}, TaskManager)->taskList = ${context_name}\->taskList;\n"; |
fde5f96c6ff1
use common perl script
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
323
diff
changeset
|
673 print $fd "${prev}Gearef(${context_name}, TaskManager)->next1 = C_$next;\n"; |
fde5f96c6ff1
use common perl script
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
323
diff
changeset
|
674 print $fd "${prev}goto parGotoMeta(${context_name}, C_$next);\n"; |
44 | 675 next; |
676 } elsif ($next eq "meta") { | |
677 print $fd $_; | |
678 next; | |
679 } else { | |
354
fde5f96c6ff1
use common perl script
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
323
diff
changeset
|
680 print $fd "${prev}${context_name}\->before = C_$codeGearName;\n"; |
fde5f96c6ff1
use common perl script
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
323
diff
changeset
|
681 print $fd "${prev}goto meta(${context_name}, C_$next);\n"; |
44 | 682 next; |
683 } | |
684 } elsif(/^.*(struct|union)?\s(\w+)\*\s(\w+)\s?[=;]/) { | |
685 my $type = $2; | |
686 my $varName = $3; | |
687 $localVarType{$varName} = $type; | |
354
fde5f96c6ff1
use common perl script
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
323
diff
changeset
|
688 s/new\s+(\w+)\(\)/\&ALLOCATE(${context_name}, \1)->\1/g; # replacing new |
44 | 689 } elsif(/^}/) { |
45 | 690 $hasParGoto = 0; |
44 | 691 } else { |
354
fde5f96c6ff1
use common perl script
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
323
diff
changeset
|
692 s/new\s+(\w+)\(\)/\&ALLOCATE(${context_name}, \1)->\1/g; # replacing new |
44 | 693 } |
694 # gather type name and type | |
695 } elsif ($inMain) { | |
354
fde5f96c6ff1
use common perl script
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
323
diff
changeset
|
696 if (/^(.*)goto start_code\(main_${context_name}\);/) { |
44 | 697 print $fd $_; |
698 next; | |
699 } elsif (/^(.*)goto (\w+)\((.*)\);/) { | |
700 my $prev = $1; | |
701 my $next = $2; | |
354
fde5f96c6ff1
use common perl script
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
323
diff
changeset
|
702 print $fd "${prev}struct Context* main_${context_name} = NEW(struct Context);\n"; |
fde5f96c6ff1
use common perl script
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
323
diff
changeset
|
703 print $fd "${prev}initContext(main_${context_name});\n"; |
fde5f96c6ff1
use common perl script
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
323
diff
changeset
|
704 print $fd "${prev}main_${context_name}->next = C_$next;\n"; |
fde5f96c6ff1
use common perl script
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
323
diff
changeset
|
705 print $fd "${prev}goto start_code(main_${context_name});\n"; |
44 | 706 next; |
707 } | |
708 } | |
709 if (/^}/) { | |
710 $inStub = 0; | |
711 $inTypedef = 0; | |
712 $inMain = 0; | |
52 | 713 $inCode = 0; |
44 | 714 } |
715 print $fd $_; | |
716 } | |
717 if (defined $prevCodeGearName) { | |
718 if (!defined $stub{$prevCodeGearName."_stub"}) { | |
719 $stub{$prevCodeGearName."_stub"} = &generateStub($fd,$prevCodeGearName,$dataGearName{$codeGearName}); | |
720 } | |
721 } | |
722 } | |
723 | |
724 # end |