comparison src/parallel_execution/generate_stub.pl @ 258:4fe19a06d666

generate next args
author mir3636
date Sat, 28 Jan 2017 12:25:35 +0900
parents 79bbe2c63fb0
children 0cd43e22aee1
comparison
equal deleted inserted replaced
257:cd3486e4ba70 258:4fe19a06d666
94 94
95 sub generateStubArgs { 95 sub generateStubArgs {
96 my($codeGearName, $varName, $typeName, $typeField, $interface) = @_; 96 my($codeGearName, $varName, $typeName, $typeField, $interface) = @_;
97 push @{$dataGearVar{$codeGearName}},$varName; 97 push @{$dataGearVar{$codeGearName}},$varName;
98 if ($typeField ne $varName) { 98 if ($typeField ne $varName) {
99 $dataGearName{$codeGearName} .= "\t$typeName* $varName = ($typeName*)GearImpl(context, $typeName, $varName);\n"; 99 $dataGearName{$codeGearName} .= "\t$typeName* $varName = ($typeName*)GearImpl(context, $interface, $varName);\n";
100 # print STDOUT "$codeGearName \t$typeName* $varName = ($typeName*)GearImpl(context, $typeName, $varName);\n"; 100 # print STDOUT "$codeGearName \t$typeName* $varName = ($typeName*)GearImpl(context, $typeName, $varName);\n";
101 } else { 101 } else {
102 for my $ivar ($var{$interface}) { 102 for my $ivar ($var{$interface}) {
103 if ($varName eq $ivar) { 103 if ($varName eq $ivar) {
104 $dataGearName{$codeGearName} .= "\t$typeName* $varName = Gearef(context, $interface)->$varName;\n"; 104 $dataGearName{$codeGearName} .= "\t$typeName* $varName = Gearef(context, $interface)->$varName;\n";
105 # print STDOUT "$codeGearName \t$typeName* $varName = Gearef(context, $interface)->$varName;\n"; 105 # print STDOUT "$codeGearName \t$typeName* $varName = Gearef(context, $interface)->$varName;\n";
106 return; 106 return;
107 } 107 }
108 } 108 }
109 $dataGearName{$codeGearName} .= "\t$typeName* $varName = Gearef(context, $typeName)->$typeField;\n"; 109 $dataGearName{$codeGearName} .= "\t$typeName* $varName = Gearef(context, $typeName);\n";
110 # print STDOUT "$codeGearName \t$typeName* $varName = Gearef(context, $typeName)->$typeField;\n"; 110 # print STDOUT "$codeGearName \t$typeName* $varName = Gearef(context, $typeName)->$typeField;\n";
111 } 111 }
112 } 112 }
113 113
114 sub generateDataGear { 114 sub generateDataGear {
137 137
138 while (<$in>) { 138 while (<$in>) {
139 if (! $inTypedef) { 139 if (! $inTypedef) {
140 if (/^typedef struct (\w+) {/) { 140 if (/^typedef struct (\w+) {/) {
141 $inTypedef = 1; 141 $inTypedef = 1;
142 # get __code name
142 } elsif (/^\_\_code (\w+)\((.*)\)(.*)/) { 143 } elsif (/^\_\_code (\w+)\((.*)\)(.*)/) {
143 $codeGearName = $1; 144 $codeGearName = $1;
144 my $args = $2; 145 my $args = $2;
145 my $tail = $3; 146 my $tail = $3;
146 if ($codeGearName =~ /_stub$/) { 147 if ($codeGearName =~ /_stub$/) {
162 while($args) { 163 while($args) {
163 if ($args =~ s/(^\s*,\s*)//) { 164 if ($args =~ s/(^\s*,\s*)//) {
164 $newArgs .= $1; 165 $newArgs .= $1;
165 } 166 }
166 # replace __code next 167 # replace __code next
167 if ($args =~ s/^\_\_code\s(\w+)\([^)]*\)//) { 168 if ($args =~ s/^\_\_code\s(\w+)\(([^)]*)\)//) {
168 my $next = $1; 169 my $next = $1;
169 my @args = split(/,/,$2); 170 my @args = split(/,/,$3);
171 my $nextArg = $2;
172 # generate stub args of next args
173 while ($nextArg =~ s/union (\w+)(\*)+\s([^,]*)//) {
174 my $typeName = $1.$2;
175 my $varName = $3;
176 my $typeField = lcfirst($1);
177 $newArgs .= "union $typeName\* $3, ";
178 &generateStubArgs($codeGearName, $varName, $1, $typeField, $interface);
179 }
170 $newArgs .= "enum Code $next"; 180 $newArgs .= "enum Code $next";
171 for my $arg (@args) { 181 for my $arg (@args) {
172 $arg =~ s/^\s*//; 182 $arg =~ s/^\s*//;
173 $arg =~ s/^(struct|union) (\w+)(\*)+\s(\w+)//; 183 $arg =~ s/^(struct|union) (\w+)(\*)+\s(\w+)//;
174 my $structType = $1; 184 my $structType = $1;
196 $dataGearName{$codeGearName} .= ", $arg"; 206 $dataGearName{$codeGearName} .= ", $arg";
197 } 207 }
198 $dataGearName{$codeGearName} .= ");"; 208 $dataGearName{$codeGearName} .= ");";
199 print $fd "__code $codeGearName($newArgs)$tail\n"; 209 print $fd "__code $codeGearName($newArgs)$tail\n";
200 next; 210 next;
201 } elsif (/^(.*)goto next\(\.\.\.(.*)\);/) { 211 } elsif (/^(.*)goto\s(\w+)\((.*)\.\.\.\);/) {
212 #print STDOUT "$3\n";
202 my $prev = $1; 213 my $prev = $1;
203 my $args = $2; 214 my $args = $3;
204 print $fd "${prev}goto meta(context, next);\n"; 215 print $fd "${prev}goto meta(context, $2);\n";
205 next; 216 next;
206 } 217 }
207 print $fd $_; 218 print $fd $_;
208 next; 219 next;
209 } 220 }