comparison src/parallel_execution/generate_stub.pl @ 278:23767f714f4a

fix generate_stub
author mir3636
date Thu, 02 Feb 2017 20:27:56 +0900
parents d14eb393023d
children 2c2e4e597eb0
comparison
equal deleted inserted replaced
277:9d671e63df74 278:23767f714f4a
147 } 147 }
148 open my $fd,">",$fn or die("can't write $fn $!"); 148 open my $fd,">",$fn or die("can't write $fn $!");
149 149
150 my $prevCodeGearName; 150 my $prevCodeGearName;
151 my $inTypedef = 0; 151 my $inTypedef = 0;
152 my $inStub = 0;
152 my %stub; 153 my %stub;
153 my $codeGearName; 154 my $codeGearName;
154 155
155 while (<$in>) { 156 while (<$in>) {
156 if (! $inTypedef) { 157 if (! $inTypedef && ! $inStub) {
157 if (/^typedef struct (\w+) {/) { 158 if (/^typedef struct (\w+) {/) {
158 $inTypedef = 1; 159 $inTypedef = 1;
159 } elsif (/^\_\_code (\w+)\((.*)\)(.*)/) { 160 } elsif (/^\_\_code (\w+)\((.*)\)(.*)/) {
160 $codeGearName = $1; 161 $codeGearName = $1;
161 my $args = $2; 162 my $args = $2;
162 my $tail = $3; 163 my $tail = $3;
163 if ($codeGearName =~ /_stub$/) { 164 if ($codeGearName =~ /_stub$/) {
164 # don't touch already existing stub 165 # don't touch already existing stub
166 $inStub = 1;
165 $stub{$codeGearName} = 1; 167 $stub{$codeGearName} = 1;
166 print $fd $_; 168 print $fd $_;
167 next; 169 next;
168 } 170 }
169 if (defined $prevCodeGearName) { 171 if (defined $prevCodeGearName) {
170 # stub is generated just before next CodeGear 172 # stub is generated just before next CodeGear
171 if (defined $stub{$prevCodeGearName."_stub"}) { 173 if (defined $stub{$prevCodeGearName."_stub"}) {
172 undef $prevCodeGearName; 174 undef $prevCodeGearName;
173 print $fd $_; 175 } else {
174 next; 176 &generateStub($fd,$prevCodeGearName,$dataGearName{$prevCodeGearName});
175 } 177 $stub{$prevCodeGearName."_stub"} = 1;
176 $stub{$prevCodeGearName."_stub"} = &generateStub($fd,$prevCodeGearName,$dataGearName{$prevCodeGearName}); 178 }
177 } 179 }
178 # analyzing CodeGear argument 180 # analyzing CodeGear argument
179 # these arguments are extract from current context's arugment DataGear Interface 181 # these arguments are extract from current context's arugment DataGear Interface
180 # and passed to the CodeGear 182 # and passed to the CodeGear
181 # struct Implementaion needs special handling 183 # struct Implementaion needs special handling
237 if ($outputVar{$codeGearName} ne "") { 239 if ($outputVar{$codeGearName} ne "") {
238 print $fd $outputVar{$codeGearName}; 240 print $fd $outputVar{$codeGearName};
239 } 241 }
240 next; 242 next;
241 } elsif (/^(.*)goto (\w+)\((.*)\);/) { 243 } elsif (/^(.*)goto (\w+)\((.*)\);/) {
242 # handling got statement 244 # handling goto statement
243 # convert it to the meta call form with two arugments, that is context and enum Code 245 # convert it to the meta call form with two arugments, that is context and enum Code
244 my $prev = $1; 246 my $prev = $1;
245 my $next = $2; 247 my $next = $2;
246 my @args = split(/,/,$3); 248 my @args = split(/,/,$3);
247 # write continuation's arguments into the interface arguments 249 if (defined $code{$interface}->{$next}) {
248 # we may need a commit for a shared DataGear 250 # write continuation's arguments into the interface arguments
249 for my $arg ( @{$outputArgs{$codeGearName}->{$next}} ) { 251 # we may need a commit for a shared DataGear
250 my $v = shift(@args); 252 for my $arg ( @{$outputArgs{$codeGearName}->{$next}} ) {
251 print $fd "\t*O_$arg = $v;\n"; 253 my $v = shift(@args);
252 } 254 print $fd "\t*O_$arg = $v;\n";
253 print $fd "${prev}goto meta(context, $next);\n"; 255 }
254 next; 256 print $fd "${prev}goto meta(context, $next);\n";
257 next;
258 }
255 } else { 259 } else {
256 s/new\s+(\w+)\(\)/\&ALLOCATE(context, \1)->\1/g; # replacing new 260 s/new\s+(\w+)\(\)/\&ALLOCATE(context, \1)->\1/g; # replacing new
257 } 261 }
258 # gather type name and type 262 # gather type name and type
259 } elsif (/^}/) { 263 } elsif (/^}/) {
264 $inStub = 0;
260 $inTypedef = 0; 265 $inTypedef = 0;
261 } 266 }
262 print $fd $_; 267 print $fd $_;
263 } 268 }
264 if (defined $prevCodeGearName) { 269 if (defined $prevCodeGearName) {