Mercurial > hg > Gears > Gears
comparison src/parallel_execution/generate_stub.pl @ 714:d5bd1c640db0
impl name space at gears
author | anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Fri, 28 Aug 2020 12:24:42 +0900 |
parents | ed7183a46dca |
children | fd9b9fa4ec98 |
comparison
equal
deleted
inserted
replaced
713:843a94916d8a | 714:d5bd1c640db0 |
---|---|
69 my $headerNameToInfo = createHeaderNameToInfo($FindBin::Bin); | 69 my $headerNameToInfo = createHeaderNameToInfo($FindBin::Bin); |
70 my $searchCbCFromCodeGearNameWCurrentFrileName = createSearchCbCFromCodeGearNameWCurrentFrileName($FindBin::Bin); | 70 my $searchCbCFromCodeGearNameWCurrentFrileName = createSearchCbCFromCodeGearNameWCurrentFrileName($FindBin::Bin); |
71 my %filename2EachCodeGearArgs; | 71 my %filename2EachCodeGearArgs; |
72 my %stub; | 72 my %stub; |
73 | 73 |
74 my $implInterfaceInfo = {isImpl => undef, implementation => undef, interface => undef}; | 74 my $implInterfaceInfo = {isImpl => undef, implementation => undef, interface => undef, parsedInterfaceInfo => undef, genConstructor => undef}; |
75 my $generateHaveOutputStub = { counter => {}, list => {} }; | 75 my $generateHaveOutputStub = { counter => undef, list => undef }; |
76 my $replaceCodeGearNames = {}; | |
76 | 77 |
77 | 78 |
78 # this for statement is main routine | 79 # this for statement is main routine |
79 for my $fn (@ARGV) { | 80 for my $fn (@ARGV) { |
80 next if ($fn !~ /\.cbc$/); | 81 next if ($fn !~ /\.cbc$/); |
141 $implInterfaceInfo->{isImpl} = 1; | 142 $implInterfaceInfo->{isImpl} = 1; |
142 $implInterfaceInfo->{interface} = $interfaceName; | 143 $implInterfaceInfo->{interface} = $interfaceName; |
143 $implInterfaceInfo->{implementation} = $3; | 144 $implInterfaceInfo->{implementation} = $3; |
144 my $cbc_source_path = $searchCbCFromCodeGearNameWCurrentFrileName->($interfaceName, $filename); | 145 my $cbc_source_path = $searchCbCFromCodeGearNameWCurrentFrileName->($interfaceName, $filename); |
145 if ($cbc_source_path) { | 146 if ($cbc_source_path) { |
147 # Probably not executed | |
146 &getDataGear($cbc_source_path); | 148 &getDataGear($cbc_source_path); |
147 } | 149 } |
150 $implInterfaceInfo->{genConstructor} = 0; | |
148 } elsif(/^(.*)par goto (\w+)\((.*)\)/) { | 151 } elsif(/^(.*)par goto (\w+)\((.*)\)/) { |
149 my $codeGearName = $2; | 152 my $codeGearName = $2; |
150 my $cbc_source_path = $searchCbCFromCodeGearNameWCurrentFrileName->($codeGearName, $filename); | 153 my $cbc_source_path = $searchCbCFromCodeGearNameWCurrentFrileName->($codeGearName, $filename); |
151 if ($cbc_source_path) { | 154 if ($cbc_source_path) { |
152 &getCodeGear($cbc_source_path); | 155 &getCodeGear($cbc_source_path); |
156 my $interfaceHeader = $1; | 159 my $interfaceHeader = $1; |
157 next if ($interfaceHeader =~ /context.h/); | 160 next if ($interfaceHeader =~ /context.h/); |
158 $interfaceHeader =~ m|(\w+)\.\w+$|; #remove filename extention | 161 $interfaceHeader =~ m|(\w+)\.\w+$|; #remove filename extention |
159 my $interfaceName = $1; | 162 my $interfaceName = $1; |
160 includeInterface(\%call_interfaces, $filename, $interfaceName, $headerNameToInfo); | 163 includeInterface(\%call_interfaces, $filename, $interfaceName, $headerNameToInfo); |
164 } elsif(/^#impl "(.*)"/) { | |
165 # use interface | |
166 my $interfaceHeader = $1; | |
167 $interfaceHeader =~ m|(\w+)\.\w+$|; #remove filename extention | |
168 my $interfaceName = $1; | |
169 includeInterface(\%call_interfaces, $filename, $interfaceName, $headerNameToInfo); | |
170 my $interfacePATH = $headerNameToInfo->{$interfaceName}->{path}; | |
171 | |
172 my $implName = basename $filename; | |
173 $implName =~ s/\.cbc$//; | |
174 | |
175 $implInterfaceInfo->{isImpl} = 1; | |
176 $implInterfaceInfo->{interface} = $interfaceName; | |
177 $implInterfaceInfo->{implementation} = $implName; | |
178 $implInterfaceInfo->{genConstructor} = 1; | |
179 $implInterfaceInfo->{parsedInterfaceInfo} = Gears::Interface->separate_code_and_data_gear_after_parse($interfacePATH); | |
180 | |
161 } elsif (/^\_\_code (\w+)\((.*)\)(.*)/) { | 181 } elsif (/^\_\_code (\w+)\((.*)\)(.*)/) { |
162 my $codeGearName = $1; | 182 my $codeGearName = $1; |
183 my $args = $2; | |
184 | |
163 if ($codeGearName =~ /_stub$/) { | 185 if ($codeGearName =~ /_stub$/) { |
164 $stub{$codeGearName}->{static} = 1; | 186 $stub{$codeGearName}->{static} = 1; |
165 $stub{$codeGearName}->{wrote} = 1; | 187 $stub{$codeGearName}->{wrote} = 1; |
166 $currentCodeGear = undef; | 188 $currentCodeGear = undef; |
167 next; | 189 next; |
168 } | 190 } |
169 my $args = $2; | 191 |
192 if ($implInterfaceInfo->{parsedInterfaceInfo}) { | |
193 if (exists_codegear_in_interface({codeGearName => $codeGearName, parsedInfo => $implInterfaceInfo->{parsedInterfaceInfo}})) { | |
194 my $replaceCodeGear = "${codeGearName}$implInterfaceInfo->{implementation}"; #${pop}SingleLinkedStack | |
195 $replaceCodeGearNames->{$codeGearName} = $replaceCodeGear; | |
196 $codeGearName = $replaceCodeGear; | |
197 } | |
198 } | |
199 | |
170 my $cbc_source_path = $searchCbCFromCodeGearNameWCurrentFrileName->($codeGearName, $filename); | 200 my $cbc_source_path = $searchCbCFromCodeGearNameWCurrentFrileName->($codeGearName, $filename); |
171 if ($cbc_source_path) { | 201 if ($cbc_source_path) { |
172 &getCodeGear($cbc_source_path); | 202 &getCodeGear($cbc_source_path); |
173 } | 203 } |
174 my $vname2type = Gears::Util->parseCodeGearDeclarationArg($args); | 204 my $vname2type = Gears::Util->parseCodeGearDeclarationArg($args); |
175 for my $vname (keys %$vname2type) { | 205 for my $vname (keys %$vname2type) { |
176 $codeGearInfo->{$codeGearName}->{arg}->{$vname} = $vname2type->{$vname}; | 206 $codeGearInfo->{$codeGearName}->{arg}->{$vname} = $vname2type->{$vname}; |
177 } | 207 } |
178 $currentCodeGear = $codeGearName; | 208 $currentCodeGear = $codeGearName; |
179 } elsif ((/^\s*(union|struct|const|enum)?\s*(\w+)(\*)\s+(\w+)\s+=/) && $currentCodeGear) { # collect local variables | 209 } elsif ((/^\s*(union|struct|const|enum)?\s*(\w+)(\*)\s+(\w+)\s+=/) && $currentCodeGear) { # collect local variables |
180 my $structType = $1; | 210 my $structType = $1; |
181 my $interfaceName = $2; | 211 my $interfaceName = $2; |
182 my $instance = $4; | 212 my $instance = $4; |
183 $codeGearInfo->{$currentCodeGear}->{localVar}->{$instance} = $interfaceName; | 213 $codeGearInfo->{$currentCodeGear}->{localVar}->{$instance} = $interfaceName; |
184 } elsif (/^(.*)goto (\w+)\-\>(\w+)\((.*)\);/) { | 214 } elsif (/^(.*)goto (\w+)\-\>(\w+)\((.*)\);/) { |
185 # handling goto statement | 215 # handling goto statement |
186 # convert it to the meta call form with two arugments, that is context and enum Code | 216 # determine the interface you are using, and in the case of a goto CodeGear with output, create a special stub flag |
187 my $prev = $1; | 217 my $prev = $1; |
188 my $instance = $2; | 218 my $instance = $2; |
189 my $method = $3; | 219 my $method = $3; |
190 my $tmpArgs = $4; | 220 my $tmpArgs = $4; |
191 my $typeName = $codeGearInfo->{$currentCodeGear}->{arg}->{$instance}; | 221 my $typeName = $codeGearInfo->{$currentCodeGear}->{arg}->{$instance}; |
202 } | 232 } |
203 } | 233 } |
204 unless (exists $call_interfaces{$filename}->{$typeName}) { | 234 unless (exists $call_interfaces{$filename}->{$typeName}) { |
205 warn "[AUTOINCLUDE] Forget #interface '$typeName' declaration in $filename"; | 235 warn "[AUTOINCLUDE] Forget #interface '$typeName' declaration in $filename"; |
206 includeInterface(\%call_interfaces, $filename, $typeName, $headerNameToInfo); | 236 includeInterface(\%call_interfaces, $filename, $typeName, $headerNameToInfo); |
237 } | |
238 | |
239 | |
240 if ($implInterfaceInfo->{parsedInterfaceInfo}) { | |
241 if (exists_codegear_in_interface({codeGearName => $tmpArgs, parsedInfo => $implInterfaceInfo->{parsedInterfaceInfo}})) { | |
242 my $replaceCodeGear = "${tmpArgs}$implInterfaceInfo->{implementation}"; #${pop}SingleLinkedStack | |
243 $tmpArgs = $replaceCodeGear; | |
244 } | |
207 } | 245 } |
208 | 246 |
209 my $nextOutPutArgs = findExistsOutputDataGear($typeName, $method); | 247 my $nextOutPutArgs = findExistsOutputDataGear($typeName, $method); |
210 my $outputStubElem = { modifyEnumCode => $currentCodeGear, createStubName => $tmpArgs }; | 248 my $outputStubElem = { modifyEnumCode => $currentCodeGear, createStubName => $tmpArgs }; |
211 | 249 |
555 $inCode = 1; | 593 $inCode = 1; |
556 %localVarType = (); | 594 %localVarType = (); |
557 $codeGearName = $1; | 595 $codeGearName = $1; |
558 my $args = $2; | 596 my $args = $2; |
559 my $tail = $3; | 597 my $tail = $3; |
598 | |
599 #replace Code Gear Name to Implemenatation | |
600 if (exists $replaceCodeGearNames->{$codeGearName}) { | |
601 $codeGearName = $replaceCodeGearNames->{$codeGearName}; | |
602 } | |
603 | |
560 if ($codeGearName =~ /_stub$/) { | 604 if ($codeGearName =~ /_stub$/) { |
561 # don't touch already existing stub | 605 # don't touch already existing stub |
562 $inStub = 1; | 606 $inStub = 1; |
563 $stub{$codeGearName}->{static} = 1; | 607 $stub{$codeGearName}->{static} = 1; |
564 $stub{$codeGearName}->{wrote} = 1; | 608 $stub{$codeGearName}->{wrote} = 1; |
704 print $fd "${indent}Gearef(${context_name}, $ntype)->$pName = $1;\n"; | 748 print $fd "${indent}Gearef(${context_name}, $ntype)->$pName = $1;\n"; |
705 } else { | 749 } else { |
706 my $hasGotoArgOrLocalVar = undef; | 750 my $hasGotoArgOrLocalVar = undef; |
707 my $outputStubElem = $generateHaveOutputStub->{list}->{$codeGearName}; | 751 my $outputStubElem = $generateHaveOutputStub->{list}->{$codeGearName}; |
708 | 752 |
753 if ($implInterfaceInfo->{parsedInterfaceInfo}) { | |
754 if (exists_codegear_in_interface({codeGearName => $arg, parsedInfo => $implInterfaceInfo->{parsedInterfaceInfo}})) { | |
755 my $replaceCodeGear = "${arg}$implInterfaceInfo->{implementation}"; #${pop}SingleLinkedStack | |
756 $arg = $replaceCodeGear; | |
757 } | |
758 } | |
759 | |
709 if ($outputStubElem && !$stub{$outputStubElem->{createStubName}."_stub"}->{static}) { | 760 if ($outputStubElem && !$stub{$outputStubElem->{createStubName}."_stub"}->{static}) { |
710 my $pick_next = "$outputStubElem->{createStubName}_$outputStubElem->{counter}"; | 761 my $pick_next = "$outputStubElem->{createStubName}_$outputStubElem->{counter}"; |
711 print $fd "${indent}Gearef(${context_name}, $ntype)->$pName = C_$pick_next;\n"; | 762 print $fd "${indent}Gearef(${context_name}, $ntype)->$pName = C_$pick_next;\n"; |
712 $i++; | 763 $i++; |
713 next; | 764 next; |
722 } | 773 } |
723 | 774 |
724 # inteface case | 775 # inteface case |
725 | 776 |
726 if ($arg =~ /->/) { | 777 if ($arg =~ /->/) { |
727 print $fd "${indent}Gearef(${context_name}, $ntype)->$pName = $arg;\n"; #Gearef->()->next = next; | 778 print $fd "${indent}Gearef(${context_name}, $ntype)->$pName = $arg;\n"; #Gearef->()->next = bar->baz; |
728 $i++; | 779 $i++; |
729 next; | 780 next; |
730 } | 781 } |
731 | 782 |
732 if ($hasGotoArgOrLocalVar) { | 783 if ($hasGotoArgOrLocalVar) { |
733 print $fd "${indent}Gearef(${context_name}, $ntype)->$pName = $arg;\n"; #Gearef->()->next = next; | 784 print $fd "${indent}Gearef(${context_name}, $ntype)->$pName = $arg;\n"; #Gearef->()->next = next; |
734 $i++; | 785 $i++; |
735 next; | 786 next; |
736 } | 787 } |
737 | 788 |
738 #TODO: goto to special stub | |
739 print $fd "${indent}Gearef(${context_name}, $ntype)->$pName = C_$arg;\n"; | 789 print $fd "${indent}Gearef(${context_name}, $ntype)->$pName = C_$arg;\n"; |
740 $i++; | 790 $i++; |
741 next; | 791 next; |
742 } | 792 } |
743 } elsif ($pType =~ /Data\**$/){ | 793 } elsif ($pType =~ /Data\**$/){ |
893 $stub{$prevCodeGearName."_stub"} = &generateStub($fd,$prevCodeGearName,$dataGearName{$codeGearName}); | 943 $stub{$prevCodeGearName."_stub"} = &generateStub($fd,$prevCodeGearName,$dataGearName{$codeGearName}); |
894 } | 944 } |
895 } | 945 } |
896 | 946 |
897 | 947 |
948 | |
898 #Create a stub when the output is a different interface | 949 #Create a stub when the output is a different interface |
899 for my $modifyEnumCodeCodeGear (keys %{$generateHaveOutputStub->{list}}) { | 950 for my $modifyEnumCodeCodeGear (keys %{$generateHaveOutputStub->{list}}) { |
900 my $outputStubElem = $generateHaveOutputStub->{list}->{$modifyEnumCodeCodeGear}; | 951 my $outputStubElem = $generateHaveOutputStub->{list}->{$modifyEnumCodeCodeGear}; |
901 my $targetStubName = $outputStubElem->{createStubName}; | 952 my $targetStubName = $outputStubElem->{createStubName}; |
902 my $createStubName = "$outputStubElem->{createStubName}_$outputStubElem->{counter}"; | 953 my $createStubName = "$outputStubElem->{createStubName}_$outputStubElem->{counter}"; |
903 my $replaceArgs = $outputStubElem->{args}; | 954 my $replaceArgs = $outputStubElem->{args}; |
904 | |
905 my $replaceStubContents = $dataGearName{$targetStubName}; | 955 my $replaceStubContents = $dataGearName{$targetStubName}; |
906 | 956 |
907 #If the stub was handwritten, skip | 957 #If the stub was handwritten, skip |
908 if ($stub{"${targetStubName}_stub"}->{static}) { | 958 if ($stub{"${targetStubName}_stub"}->{static}) { |
909 next; | 959 next; |
910 } | 960 } |
911 | 961 |
912 for my $arg (keys %$replaceArgs) { | 962 for my $arg (keys %$replaceArgs) { |
913 my $interface = $replaceArgs->{$arg}; | 963 my $interface = $replaceArgs->{$arg}; |
914 print "replace $arg $interface\n"; | 964 $replaceStubContents =~ s/,(.*)\)->$arg/, $interface)->$arg/; |
915 $replaceStubContents =~ s/,(.*)\)->$arg/,$interface)->$arg/; | |
916 } | 965 } |
917 | 966 |
918 generateStub($fd,$createStubName,$replaceStubContents); | 967 generateStub($fd,$createStubName,$replaceStubContents); |
919 | |
920 } | 968 } |
921 | 969 |
922 } | 970 } |
923 | 971 |
924 sub createHeaderNameToInfo { | 972 sub createHeaderNameToInfo { |
1000 return $1; | 1048 return $1; |
1001 } | 1049 } |
1002 return ""; | 1050 return ""; |
1003 } | 1051 } |
1004 | 1052 |
1053 sub exists_codegear_in_interface { | |
1054 my $arg = shift; | |
1055 | |
1056 my $codeGearName = $arg->{codeGearName}; | |
1057 my $parsedInterfaceInfo = $arg->{parsedInfo}; | |
1058 my @res = grep { $_->{name} eq $codeGearName } @{$parsedInterfaceInfo->{codes}}; | |
1059 return @res; | |
1060 } | |
1061 |