Mercurial > hg > Members > Moririn
annotate src/parallel_execution/generate_stub.pl @ 415:eec6553a2aa6
fix redblacktree
author | mir3636 |
---|---|
date | Thu, 05 Oct 2017 17:00:48 +0900 |
parents | 00d9b0664bdb |
children | a74bec89c198 |
rev | line source |
---|---|
194 | 1 #!/usr/bin/perl |
2 | |
250 | 3 use strict; |
254 | 4 use Getopt::Std; |
393 | 5 use File::Path qw(make_path); |
250 | 6 |
194 | 7 # interface.cbc |
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 | |
255 | 18 our($opt_o,$opt_d,$opt_h); |
19 getopts('o:d:h'); | |
20 | |
21 my $dir = "."; | |
22 if ($opt_d) { | |
23 $dir = $opt_d; | |
24 if (! -d $dir) { | |
393 | 25 make_path $dir; |
255 | 26 } |
27 } | |
254 | 28 |
29 for my $fn (@ARGV) { | |
255 | 30 next if ($fn !~ /\.cbc$/); |
249 | 31 &getDataGear($fn); |
32 &generateDataGear($fn); | |
194 | 33 } |
34 | |
250 | 35 my %var; |
36 my %code; | |
37 my %dataGearVar; | |
260
6b5444bbea8a
generated stub no comiple errors
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
259
diff
changeset
|
38 my %outputVar; # output var initializer |
6b5444bbea8a
generated stub no comiple errors
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
259
diff
changeset
|
39 my %outputArgs; # continuation's output variables |
250 | 40 my %dataGear; |
41 my %dataGearName; | |
384
ee5d2b1685d7
Fix perlscript
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
383
diff
changeset
|
42 my %generic; |
ee5d2b1685d7
Fix perlscript
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
383
diff
changeset
|
43 my %dataGearVarType; |
396
bba401f93dcd
Add handle par goto statement
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
393
diff
changeset
|
44 my %codeGear; |
253 | 45 my $implementation; |
46 my $interface; | |
250 | 47 |
384
ee5d2b1685d7
Fix perlscript
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
383
diff
changeset
|
48 # interface definision |
ee5d2b1685d7
Fix perlscript
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
383
diff
changeset
|
49 # |
ee5d2b1685d7
Fix perlscript
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
383
diff
changeset
|
50 # typedef struct Stack<Type, Impl>{ |
ee5d2b1685d7
Fix perlscript
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
383
diff
changeset
|
51 # Type* stack; |
ee5d2b1685d7
Fix perlscript
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
383
diff
changeset
|
52 # Type* data; |
ee5d2b1685d7
Fix perlscript
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
383
diff
changeset
|
53 # Type* data1; |
ee5d2b1685d7
Fix perlscript
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
383
diff
changeset
|
54 # __code whenEmpty(...); |
ee5d2b1685d7
Fix perlscript
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
383
diff
changeset
|
55 # __code clear(Impl* stack,__code next(...)); |
ee5d2b1685d7
Fix perlscript
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
383
diff
changeset
|
56 # __code push(Impl* stack,Type* data, __code next(...)); |
ee5d2b1685d7
Fix perlscript
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
383
diff
changeset
|
57 # __code pop(Impl* stack, __code next(Type*, ...)); |
ee5d2b1685d7
Fix perlscript
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
383
diff
changeset
|
58 # __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
|
59 # __code isEmpty(Impl* stack, __code next(...), __code whenEmpty(...)); |
ee5d2b1685d7
Fix perlscript
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
383
diff
changeset
|
60 # __code get(Impl* stack, Type** data, __code next(...)); |
ee5d2b1685d7
Fix perlscript
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
383
diff
changeset
|
61 # __code get2(Impl* stack,..., __code next(...)); |
ee5d2b1685d7
Fix perlscript
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
383
diff
changeset
|
62 # __code next(...); |
ee5d2b1685d7
Fix perlscript
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
383
diff
changeset
|
63 # } Stack; |
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 # calling example |
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 # goto nodeStack->push((union Data*)node, stackTest3); |
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 # generated meta level code |
ee5d2b1685d7
Fix perlscript
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
383
diff
changeset
|
70 # |
ee5d2b1685d7
Fix perlscript
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
383
diff
changeset
|
71 # Gearef(context, Stack)->stack = nodeStack->stack; |
ee5d2b1685d7
Fix perlscript
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
383
diff
changeset
|
72 # Gearef(context, Stack)->data = (union Data*)node; |
ee5d2b1685d7
Fix perlscript
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
383
diff
changeset
|
73 # Gearef(context, Stack)->next = C_stackTest3; |
ee5d2b1685d7
Fix perlscript
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
383
diff
changeset
|
74 # goto meta(context, nodeStack->push); |
ee5d2b1685d7
Fix perlscript
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
383
diff
changeset
|
75 |
194 | 76 sub getDataGear { |
77 my ($filename) = @_; | |
253 | 78 my ($codeGearName, $name, $inTypedef); |
194 | 79 open my $fd,"<",$filename or die("can't open $filename $!"); |
80 while (<$fd>) { | |
81 if (! $inTypedef) { | |
384
ee5d2b1685d7
Fix perlscript
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
383
diff
changeset
|
82 if (/^typedef struct (\w+)\s*<(.*)>/) { |
194 | 83 $inTypedef = 1; |
84 $name = $1; | |
85 $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
|
86 $var{$name} = {}; |
195518ab62fc
fix type gathering pattern match in generate_stub.pl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
255
diff
changeset
|
87 $code{$name} = {}; |
384
ee5d2b1685d7
Fix perlscript
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
383
diff
changeset
|
88 $generic{$name} = \split(/,/,$2); |
ee5d2b1685d7
Fix perlscript
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
383
diff
changeset
|
89 } elsif (/^typedef struct (\w+)/) { |
ee5d2b1685d7
Fix perlscript
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
383
diff
changeset
|
90 $inTypedef = 1; |
ee5d2b1685d7
Fix perlscript
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
383
diff
changeset
|
91 $name = $1; |
ee5d2b1685d7
Fix perlscript
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
383
diff
changeset
|
92 $dataGear{$name} = $_; |
ee5d2b1685d7
Fix perlscript
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
383
diff
changeset
|
93 $var{$name} = {}; |
ee5d2b1685d7
Fix perlscript
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
383
diff
changeset
|
94 $code{$name} = {}; |
ee5d2b1685d7
Fix perlscript
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
383
diff
changeset
|
95 $generic{$name} = []; |
269 | 96 } elsif (/^(\w+)(\*)+ create(\w+)\(/) { |
249 | 97 if (defined $interface) { |
98 die "duplicate interface $interface\n"; | |
99 } | |
100 $interface = $1; | |
269 | 101 $implementation = $3; |
250 | 102 if ( -f "$interface.cbc") { |
103 &getDataGear("$interface.cbc"); | |
104 } | |
393 | 105 } elsif (/^(\s)*(\w+)\-\>(\w+)\s\=\s\((.*)\)create(\w+)\((.*)\);$/) { |
385 | 106 #my $intfn = ucfirst($2); |
107 my $impln = $5; | |
108 if ( -f "$impln.cbc") { | |
109 &getCodeGear("$impln.cbc"); | |
110 } | |
396
bba401f93dcd
Add handle par goto statement
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
393
diff
changeset
|
111 } elsif(/^(.*)par goto (\w+)\((.*)\)/) { |
bba401f93dcd
Add handle par goto statement
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
393
diff
changeset
|
112 my $codeGearName = $2; |
bba401f93dcd
Add handle par goto statement
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
393
diff
changeset
|
113 if ($filename =~ /^(.*)\/(.*)/) { |
bba401f93dcd
Add handle par goto statement
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
393
diff
changeset
|
114 $codeGearName = "$1/$codeGearName"; |
bba401f93dcd
Add handle par goto statement
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
393
diff
changeset
|
115 } |
bba401f93dcd
Add handle par goto statement
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
393
diff
changeset
|
116 if ( -f "$codeGearName.cbc") { |
bba401f93dcd
Add handle par goto statement
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
393
diff
changeset
|
117 &getCodeGear("$codeGearName.cbc"); |
bba401f93dcd
Add handle par goto statement
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
393
diff
changeset
|
118 } |
226 | 119 } |
194 | 120 next; |
121 } | |
249 | 122 # gather type name and type |
194 | 123 $dataGear{$name} .= $_; |
385 | 124 if (/^\s*(.*)\s+(\w+);$/ ) { |
280 | 125 my $ttype = $1; |
126 my $tname = $2; | |
127 if ($ttype =~ /^(union|struct) (\w+)/) { | |
128 $ttype = $2; | |
129 } | |
130 $var{$name}->{$tname} = $ttype; | |
250 | 131 } |
194 | 132 if (/^}/) { |
133 $inTypedef = 0; | |
134 } | |
135 } | |
136 } | |
137 | |
385 | 138 sub getCodeGear { |
139 my ($filename) = @_; | |
140 open my $fd,"<",$filename or die("can't open $filename $!"); | |
141 my ($name,$impln); | |
142 while (<$fd>) { | |
143 if (/^(\w+)(\*)+ create(\w+)\(/) { | |
144 $name = $1; | |
145 $impln = $3; | |
146 } | |
147 if (defined $name) { | |
148 if (/^\_\_code (\w+)$impln\((.*)\)(.*)/) { | |
149 my $args = $2; | |
150 my $method = $1; | |
151 $code{$name}->{$method} = []; | |
152 while($args) { | |
153 if ($args =~ s/(^\s*,\s*)//) { | |
154 } | |
155 # continuation case | |
156 if ($args =~ s/^(\s)*\_\_code\s+(\w+)\(([^)]*)\)//) { | |
157 my $next = $2; | |
158 my @args = split(/,/,$3); | |
387 | 159 push(@{$code{$name}->{$method}},"\_\_code $next"); |
385 | 160 } elsif ($args =~ s/^(struct|union) (\w+)(\*)+\s(\w+)//) { |
161 my $structType = $1; | |
162 my $typeName = $2; | |
163 my $varName = $4; | |
164 my $typeField = lcfirst($typeName); | |
387 | 165 push(@{$code{$name}->{$method}},"$typeName $varName"); |
385 | 166 } elsif ($args =~ s/(.*,)//) { |
167 } else { | |
168 last; | |
169 } | |
170 } | |
171 } | |
396
bba401f93dcd
Add handle par goto statement
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
393
diff
changeset
|
172 } elsif (/^\_\_code (\w+)\((.*)\)(.*)/) { |
bba401f93dcd
Add handle par goto statement
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
393
diff
changeset
|
173 my $codeGearName = $1; |
bba401f93dcd
Add handle par goto statement
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
393
diff
changeset
|
174 my $args = $2; |
bba401f93dcd
Add handle par goto statement
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
393
diff
changeset
|
175 my $inputCount = 0; |
bba401f93dcd
Add handle par goto statement
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
393
diff
changeset
|
176 my $outputCount = 0; |
bba401f93dcd
Add handle par goto statement
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
393
diff
changeset
|
177 my $inputIncFlag = 1; |
bba401f93dcd
Add handle par goto statement
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
393
diff
changeset
|
178 while($args) { |
bba401f93dcd
Add handle par goto statement
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
393
diff
changeset
|
179 if ($args =~ s/(^\s*,\s*)//) { |
bba401f93dcd
Add handle par goto statement
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
393
diff
changeset
|
180 } |
404
c5cd9888bf2a
Fix bitonicSort
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
403
diff
changeset
|
181 if ($args =~ s/^(\s)*\_\_code\s+(\w+)\((.*?)\)//) { |
396
bba401f93dcd
Add handle par goto statement
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
393
diff
changeset
|
182 $inputIncFlag = 0; |
404
c5cd9888bf2a
Fix bitonicSort
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
403
diff
changeset
|
183 $outputCount = split(/,/,$3); |
c5cd9888bf2a
Fix bitonicSort
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
403
diff
changeset
|
184 $outputCount--; |
396
bba401f93dcd
Add handle par goto statement
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
393
diff
changeset
|
185 } elsif ($args =~ s/^(struct|union) (\w+)(\*)+\s(\w+)//) { |
bba401f93dcd
Add handle par goto statement
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
393
diff
changeset
|
186 if($inputIncFlag) { |
bba401f93dcd
Add handle par goto statement
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
393
diff
changeset
|
187 $inputCount++; |
bba401f93dcd
Add handle par goto statement
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
393
diff
changeset
|
188 } |
bba401f93dcd
Add handle par goto statement
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
393
diff
changeset
|
189 } elsif ($args =~ s/(.*,)//) { |
bba401f93dcd
Add handle par goto statement
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
393
diff
changeset
|
190 } else { |
bba401f93dcd
Add handle par goto statement
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
393
diff
changeset
|
191 last; |
bba401f93dcd
Add handle par goto statement
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
393
diff
changeset
|
192 } |
bba401f93dcd
Add handle par goto statement
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
393
diff
changeset
|
193 } |
bba401f93dcd
Add handle par goto statement
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
393
diff
changeset
|
194 $codeGear{$codeGearName}->{"input"} = $inputCount; |
bba401f93dcd
Add handle par goto statement
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
393
diff
changeset
|
195 $codeGear{$codeGearName}->{"output"} = $outputCount; |
385 | 196 } |
197 } | |
198 } | |
199 | |
250 | 200 sub generateStub { |
251 | 201 my($fd,$prevCodeGearName,$dataGearName) = @_; |
274 | 202 print $fd "__code ", $prevCodeGearName ,"_stub(struct Context* context) {\n"; |
251 | 203 print $fd $dataGearName; |
250 | 204 print $fd "\n} \n\n"; |
251 | 205 return 1; |
250 | 206 } |
207 | |
253 | 208 sub generateStubArgs { |
260
6b5444bbea8a
generated stub no comiple errors
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
259
diff
changeset
|
209 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
|
210 my $varname1 = $output?"O_$varName":$varName; |
6b5444bbea8a
generated stub no comiple errors
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
259
diff
changeset
|
211 for my $n ( @{$dataGearVar{$codeGearName}} ) { |
6b5444bbea8a
generated stub no comiple errors
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
259
diff
changeset
|
212 # we already have it |
6b5444bbea8a
generated stub no comiple errors
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
259
diff
changeset
|
213 return 0 if ( $n eq $varname1); |
6b5444bbea8a
generated stub no comiple errors
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
259
diff
changeset
|
214 } |
6b5444bbea8a
generated stub no comiple errors
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
259
diff
changeset
|
215 push @{$dataGearVar{$codeGearName}}, $varname1; |
384
ee5d2b1685d7
Fix perlscript
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
383
diff
changeset
|
216 push @{$dataGearVarType{$codeGearName}}, $typeName; |
260
6b5444bbea8a
generated stub no comiple errors
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
259
diff
changeset
|
217 if ($typeName eq $implementation) { |
6b5444bbea8a
generated stub no comiple errors
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
259
diff
changeset
|
218 # get implementation |
258 | 219 $dataGearName{$codeGearName} .= "\t$typeName* $varName = ($typeName*)GearImpl(context, $interface, $varName);\n"; |
253 | 220 } else { |
259
195518ab62fc
fix type gathering pattern match in generate_stub.pl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
255
diff
changeset
|
221 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
|
222 # input data gear field |
253 | 223 if ($varName eq $ivar) { |
280 | 224 if ($typeName eq $var{$interface}->{$ivar}) { |
225 if ($output) { | |
226 $dataGearName{$codeGearName} .= "\t$typeName** O_$varName = &Gearef(context, $interface)->$varName;\n"; | |
227 $outputVar{$codeGearName} .= "\t$typeName* $varName;\n"; | |
228 return 1; | |
229 } | |
396
bba401f93dcd
Add handle par goto statement
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
393
diff
changeset
|
230 |
280 | 231 $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
|
232 return 1; |
6b5444bbea8a
generated stub no comiple errors
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
259
diff
changeset
|
233 } |
253 | 234 } |
235 } | |
259
195518ab62fc
fix type gathering pattern match in generate_stub.pl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
255
diff
changeset
|
236 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
|
237 if ($varName eq $cName) { |
260
6b5444bbea8a
generated stub no comiple errors
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
259
diff
changeset
|
238 # 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
|
239 $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
|
240 return 1; |
253 | 241 } |
242 } | |
389 | 243 # global or local variable case |
244 if ($typeName eq "Code") { | |
396
bba401f93dcd
Add handle par goto statement
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
393
diff
changeset
|
245 $dataGearName{$codeGearName} .= "\tenum $typeName $varName = Gearef(context, $interface)->$varName;\n"; |
389 | 246 return 1; |
247 } | |
268 | 248 $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
|
249 return 1; |
253 | 250 } |
251 } | |
252 | |
194 | 253 sub generateDataGear { |
249 | 254 my ($filename) = @_; |
255 open my $in,"<",$filename or die("can't open $filename $!"); | |
254 | 256 |
257 my $fn; | |
258 if ($opt_o) { | |
396
bba401f93dcd
Add handle par goto statement
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
393
diff
changeset
|
259 $fn = $opt_o; |
254 | 260 } else { |
261 my $fn1 = $filename; | |
262 $fn1 =~ s/\.cbc/.c/; | |
263 my $i = 1; | |
255 | 264 $fn = "$dir/$fn1"; |
254 | 265 while ( -f $fn) { |
255 | 266 $fn = "$dir/$fn1.$i"; |
254 | 267 $i++; |
268 } | |
250 | 269 } |
259
195518ab62fc
fix type gathering pattern match in generate_stub.pl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
255
diff
changeset
|
270 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
|
271 if (! -d $1) { |
393 | 272 make_path $1; |
259
195518ab62fc
fix type gathering pattern match in generate_stub.pl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
255
diff
changeset
|
273 } |
195518ab62fc
fix type gathering pattern match in generate_stub.pl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
255
diff
changeset
|
274 } |
249 | 275 open my $fd,">",$fn or die("can't write $fn $!"); |
254 | 276 |
249 | 277 my $prevCodeGearName; |
250 | 278 my $inTypedef = 0; |
278 | 279 my $inStub = 0; |
396
bba401f93dcd
Add handle par goto statement
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
393
diff
changeset
|
280 my $inParGoto = 0; |
250 | 281 my %stub; |
251 | 282 my $codeGearName; |
254 | 283 |
249 | 284 while (<$in>) { |
278 | 285 if (! $inTypedef && ! $inStub) { |
249 | 286 if (/^typedef struct (\w+) {/) { |
287 $inTypedef = 1; | |
253 | 288 } elsif (/^\_\_code (\w+)\((.*)\)(.*)/) { |
251 | 289 $codeGearName = $1; |
253 | 290 my $args = $2; |
291 my $tail = $3; | |
250 | 292 if ($codeGearName =~ /_stub$/) { |
262 | 293 # don't touch already existing stub |
278 | 294 $inStub = 1; |
250 | 295 $stub{$codeGearName} = 1; |
296 print $fd $_; | |
297 next; | |
298 } | |
249 | 299 if (defined $prevCodeGearName) { |
262 | 300 # stub is generated just before next CodeGear |
250 | 301 if (defined $stub{$prevCodeGearName."_stub"}) { |
302 undef $prevCodeGearName; | |
278 | 303 } else { |
304 &generateStub($fd,$prevCodeGearName,$dataGearName{$prevCodeGearName}); | |
305 $stub{$prevCodeGearName."_stub"} = 1; | |
250 | 306 } |
249 | 307 } |
262 | 308 # analyzing CodeGear argument |
309 # these arguments are extract from current context's arugment DataGear Interface | |
310 # and passed to the CodeGear | |
311 # struct Implementaion needs special handling | |
312 # __code next(...) ---> enum Code next | |
253 | 313 $prevCodeGearName = $codeGearName; |
314 $dataGearVar{$codeGearName} = []; | |
260
6b5444bbea8a
generated stub no comiple errors
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
259
diff
changeset
|
315 $outputVar{$codeGearName} = ""; |
6b5444bbea8a
generated stub no comiple errors
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
259
diff
changeset
|
316 $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
|
317 my $newArgs = "struct Context *context,"; |
305 | 318 if ($args=~/^struct Context\s*\*\s*context/) { |
319 $newArgs = ""; | |
320 } | |
253 | 321 while($args) { |
322 if ($args =~ s/(^\s*,\s*)//) { | |
323 $newArgs .= $1; | |
324 } | |
262 | 325 # continuation case |
280 | 326 if ($args =~ s/^(\s)*\_\_code\s+(\w+)\(([^)]*)\)//) { |
327 my $next = $2; | |
328 my @args = split(/,/,$3); | |
398
fc4fcd441700
Fix spanwTasks
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
397
diff
changeset
|
329 if (&generateStubArgs($codeGearName, $next, "Code", $next, $interface,0) ) { |
260
6b5444bbea8a
generated stub no comiple errors
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
259
diff
changeset
|
330 $newArgs .= "enum Code $next"; |
258 | 331 } |
262 | 332 # analyze continuation arguments |
333 # output arguments are defined in the Interface take the pointer of these | |
334 # output arguments are put into the Interface DataGear just before the goto | |
253 | 335 for my $arg (@args) { |
336 $arg =~ s/^\s*//; | |
260
6b5444bbea8a
generated stub no comiple errors
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
259
diff
changeset
|
337 last if ($arg =~ /\.\.\./); |
253 | 338 $arg =~ s/^(struct|union) (\w+)(\*)+\s(\w+)//; |
339 my $structType = $1; | |
340 my $typeName = $2; | |
341 my $varName = $4; | |
342 my $typeField = lcfirst($typeName); | |
260
6b5444bbea8a
generated stub no comiple errors
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
259
diff
changeset
|
343 push(@{$outputArgs{$codeGearName}->{$next}}, $varName); |
6b5444bbea8a
generated stub no comiple errors
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
259
diff
changeset
|
344 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
|
345 $newArgs .= ",$structType $typeName **O_$varName"; |
6b5444bbea8a
generated stub no comiple errors
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
259
diff
changeset
|
346 } |
253 | 347 } |
348 } elsif ($args =~ s/^(struct|union) (\w+)(\*)+\s(\w+)//) { | |
349 my $structType = $1; | |
350 my $typeName = $2; | |
351 my $varName = $4; | |
352 my $typeField = lcfirst($typeName); | |
260
6b5444bbea8a
generated stub no comiple errors
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
259
diff
changeset
|
353 $newArgs .= $&; # assuming no duplicate |
6b5444bbea8a
generated stub no comiple errors
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
259
diff
changeset
|
354 &generateStubArgs($codeGearName, $varName, $typeName, $typeField, $interface,0); |
255 | 355 } elsif ($args =~ s/(.*,)//) { |
356 $newArgs .= $1; | |
357 } else { | |
358 $newArgs .= $args; | |
359 last; | |
253 | 360 } |
361 } | |
262 | 362 # generate goto statement from stub to the CodeGear in the buffer |
253 | 363 $dataGearName{$codeGearName} .= "\tgoto $codeGearName(context"; |
364 for my $arg ( @{$dataGearVar{$codeGearName}}) { | |
365 $dataGearName{$codeGearName} .= ", $arg"; | |
366 } | |
367 $dataGearName{$codeGearName} .= ");"; | |
262 | 368 # generate CodeGear header with new arguments |
253 | 369 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
|
370 if ($outputVar{$codeGearName} ne "") { |
324 | 371 # output data var can be use before write |
372 # 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
|
373 print $fd $outputVar{$codeGearName}; |
6b5444bbea8a
generated stub no comiple errors
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
259
diff
changeset
|
374 } |
250 | 375 next; |
384
ee5d2b1685d7
Fix perlscript
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
383
diff
changeset
|
376 } elsif (/^(.*)goto (\w+)\-\>(\w+)\((.*)\);/) { |
ee5d2b1685d7
Fix perlscript
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
383
diff
changeset
|
377 # handling goto statement |
ee5d2b1685d7
Fix perlscript
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
383
diff
changeset
|
378 # 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
|
379 my $prev = $1; |
ee5d2b1685d7
Fix perlscript
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
383
diff
changeset
|
380 my $next = $2; |
ee5d2b1685d7
Fix perlscript
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
383
diff
changeset
|
381 my $method = $3; |
ee5d2b1685d7
Fix perlscript
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
383
diff
changeset
|
382 my @args = split(/,/,$4); |
ee5d2b1685d7
Fix perlscript
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
383
diff
changeset
|
383 my @types = @{$dataGearVarType{$codeGearName}}; |
ee5d2b1685d7
Fix perlscript
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
383
diff
changeset
|
384 my $ntype; |
415 | 385 my $ftype; |
384
ee5d2b1685d7
Fix perlscript
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
383
diff
changeset
|
386 for my $v (@{$dataGearVar{$codeGearName}}) { |
ee5d2b1685d7
Fix perlscript
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
383
diff
changeset
|
387 my $t = shift @types; |
ee5d2b1685d7
Fix perlscript
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
383
diff
changeset
|
388 if ($v eq $next) { |
ee5d2b1685d7
Fix perlscript
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
383
diff
changeset
|
389 $ntype = $t; |
415 | 390 $ftype = lcfirst($ntype); |
384
ee5d2b1685d7
Fix perlscript
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
383
diff
changeset
|
391 } |
ee5d2b1685d7
Fix perlscript
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
383
diff
changeset
|
392 } |
415 | 393 print $fd "\tGearef(context, $ntype)->$ftype = $next->$ftype;\n"; |
394 # Put interface argument | |
384
ee5d2b1685d7
Fix perlscript
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
383
diff
changeset
|
395 my $prot = $code{$ntype}->{$method}; |
385 | 396 my $i = 1; |
384
ee5d2b1685d7
Fix perlscript
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
383
diff
changeset
|
397 for my $arg (@args) { |
415 | 398 my $pType; |
399 my $pName; | |
385 | 400 my $p = @$prot[$i]; |
401 next if ( $p eq $arg); | |
387 | 402 $p =~ s/^(.*)\s(\w+)//; |
415 | 403 $pType = $1; |
404 $pName = $2; | |
387 | 405 $arg =~ s/^(\s)*(\w+)/$2/; |
406 if ($pType =~ s/\_\_code$//) { | |
407 print $fd "\tGearef(context, $ntype)->$pName = C_$arg;\n"; | |
391 | 408 } elsif ($pType =~ s/Data$//){ |
409 print $fd "\tGearef(context, $ntype)->$pName = (union Data*) $arg;\n"; | |
387 | 410 } else { |
411 print $fd "\tGearef(context, $ntype)->$pName = $arg;\n"; | |
412 } | |
385 | 413 $i++; |
384
ee5d2b1685d7
Fix perlscript
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
383
diff
changeset
|
414 } |
415 | 415 print $fd "${prev}goto meta(context, $next->$ftype->$ntype.$method);\n"; |
384
ee5d2b1685d7
Fix perlscript
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
383
diff
changeset
|
416 next; |
396
bba401f93dcd
Add handle par goto statement
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
393
diff
changeset
|
417 } elsif(/^(.*)par goto (\w+)\((.*)\);/) { |
bba401f93dcd
Add handle par goto statement
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
393
diff
changeset
|
418 # handling par goto statement |
bba401f93dcd
Add handle par goto statement
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
393
diff
changeset
|
419 # convert it to the parallel |
bba401f93dcd
Add handle par goto statement
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
393
diff
changeset
|
420 my $prev = $1; |
bba401f93dcd
Add handle par goto statement
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
393
diff
changeset
|
421 my $codeGearName = $2; |
401
408b4aab7610
Supported par goto iterate statement for perl script
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
400
diff
changeset
|
422 my $inputCount = $codeGear{$codeGearName}->{'input'}; |
408b4aab7610
Supported par goto iterate statement for perl script
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
400
diff
changeset
|
423 my $outputCount = $codeGear{$codeGearName}->{'output'}; |
396
bba401f93dcd
Add handle par goto statement
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
393
diff
changeset
|
424 my @dataGears = split(/,\s*/, $3); |
bba401f93dcd
Add handle par goto statement
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
393
diff
changeset
|
425 my $nextCodeGear = pop(@dataGears); |
403
83c9aeb1fe3e
Generate MultiDimIterator by perl script
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
402
diff
changeset
|
426 my @iterateCounts; |
401
408b4aab7610
Supported par goto iterate statement for perl script
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
400
diff
changeset
|
427 # parse examples 'par goto(.., iterate(10), exit);' |
402
e958a409943c
Change iterator implement from oneDim to multiDim
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
401
diff
changeset
|
428 if ($3 =~ /iterate\((.*)?\)/) { |
403
83c9aeb1fe3e
Generate MultiDimIterator by perl script
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
402
diff
changeset
|
429 @iterateCounts = split(/,/,$1);; |
401
408b4aab7610
Supported par goto iterate statement for perl script
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
400
diff
changeset
|
430 $inputCount--; |
408b4aab7610
Supported par goto iterate statement for perl script
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
400
diff
changeset
|
431 # pop iterate statement |
408b4aab7610
Supported par goto iterate statement for perl script
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
400
diff
changeset
|
432 pop(@dataGears); |
408b4aab7610
Supported par goto iterate statement for perl script
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
400
diff
changeset
|
433 } |
396
bba401f93dcd
Add handle par goto statement
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
393
diff
changeset
|
434 if (! $inParGoto) { |
bba401f93dcd
Add handle par goto statement
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
393
diff
changeset
|
435 $inParGoto = 1; |
398
fc4fcd441700
Fix spanwTasks
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
397
diff
changeset
|
436 print $fd "${prev}struct Element* element;\n"; |
396
bba401f93dcd
Add handle par goto statement
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
393
diff
changeset
|
437 } |
bba401f93dcd
Add handle par goto statement
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
393
diff
changeset
|
438 my $initTask = << "EOFEOF"; |
406
9b35e6581b5c
Use task member of context by par goto meta
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
404
diff
changeset
|
439 ${prev}context->task = NEW(struct Context); |
9b35e6581b5c
Use task member of context by par goto meta
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
404
diff
changeset
|
440 ${prev}initContext(context->task); |
9b35e6581b5c
Use task member of context by par goto meta
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
404
diff
changeset
|
441 ${prev}context->task->next = C_$codeGearName; |
9b35e6581b5c
Use task member of context by par goto meta
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
404
diff
changeset
|
442 ${prev}context->task->idgCount = $inputCount; |
9b35e6581b5c
Use task member of context by par goto meta
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
404
diff
changeset
|
443 ${prev}context->task->idg = context->task->dataNum; |
9b35e6581b5c
Use task member of context by par goto meta
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
404
diff
changeset
|
444 ${prev}context->task->maxIdg = context->task->idg + $inputCount; |
9b35e6581b5c
Use task member of context by par goto meta
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
404
diff
changeset
|
445 ${prev}context->task->odg = context->task->maxIdg; |
9b35e6581b5c
Use task member of context by par goto meta
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
404
diff
changeset
|
446 ${prev}context->task->maxOdg = context->task->odg + $outputCount; |
396
bba401f93dcd
Add handle par goto statement
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
393
diff
changeset
|
447 EOFEOF |
bba401f93dcd
Add handle par goto statement
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
393
diff
changeset
|
448 print $fd $initTask; |
403
83c9aeb1fe3e
Generate MultiDimIterator by perl script
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
402
diff
changeset
|
449 if (@iterateCounts) { |
406
9b35e6581b5c
Use task member of context by par goto meta
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
404
diff
changeset
|
450 print $fd "${prev}context->task->iterate = 0;\n"; |
403
83c9aeb1fe3e
Generate MultiDimIterator by perl script
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
402
diff
changeset
|
451 my $len = @iterateCounts; |
83c9aeb1fe3e
Generate MultiDimIterator by perl script
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
402
diff
changeset
|
452 if ($len == 1) { |
406
9b35e6581b5c
Use task member of context by par goto meta
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
404
diff
changeset
|
453 print $fd "${prev}context->task->iterator = createMultiDimIterator(context, $iterateCounts[0], 1, 1);\n"; |
403
83c9aeb1fe3e
Generate MultiDimIterator by perl script
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
402
diff
changeset
|
454 } elsif ($len == 2) { |
406
9b35e6581b5c
Use task member of context by par goto meta
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
404
diff
changeset
|
455 print $fd "${prev}context->task->iterator = createMultiDimIterator(context, $iterateCounts[0], $iterateCounts[1], 1);\n"; |
403
83c9aeb1fe3e
Generate MultiDimIterator by perl script
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
402
diff
changeset
|
456 } elsif ($len == 3) { |
406
9b35e6581b5c
Use task member of context by par goto meta
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
404
diff
changeset
|
457 print $fd "${prev}context->task->iterator = createMultiDimIterator(context, $iterateCounts[0], $iterateCounts[1], $iterateCounts[2]);\n"; |
403
83c9aeb1fe3e
Generate MultiDimIterator by perl script
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
402
diff
changeset
|
458 } |
401
408b4aab7610
Supported par goto iterate statement for perl script
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
400
diff
changeset
|
459 } |
396
bba401f93dcd
Add handle par goto statement
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
393
diff
changeset
|
460 for my $i (0..$inputCount-1) { |
406
9b35e6581b5c
Use task member of context by par goto meta
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
404
diff
changeset
|
461 print $fd "${prev}context->task->data[context->task->idg+$i] = (union Data*)@dataGears[$i];\n"; |
396
bba401f93dcd
Add handle par goto statement
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
393
diff
changeset
|
462 } |
bba401f93dcd
Add handle par goto statement
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
393
diff
changeset
|
463 |
bba401f93dcd
Add handle par goto statement
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
393
diff
changeset
|
464 for my $i (0..$outputCount-1) { |
406
9b35e6581b5c
Use task member of context by par goto meta
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
404
diff
changeset
|
465 print $fd "${prev}context->task->data[context->task->odg+$i] = (union Data*)@dataGears[$inputCount+$i];\n"; |
396
bba401f93dcd
Add handle par goto statement
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
393
diff
changeset
|
466 } |
398
fc4fcd441700
Fix spanwTasks
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
397
diff
changeset
|
467 my $putTask = << "EOFEOF"; |
404
c5cd9888bf2a
Fix bitonicSort
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
403
diff
changeset
|
468 ${prev}element = &ALLOCATE(context, Element)->Element; |
c5cd9888bf2a
Fix bitonicSort
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
403
diff
changeset
|
469 ${prev}element->next = NULL; |
406
9b35e6581b5c
Use task member of context by par goto meta
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
404
diff
changeset
|
470 ${prev}element->data = (union Data*)context->task; |
407 | 471 ${prev}context->tasks->queue->SingleLinkedQueue.last->next = element; |
472 ${prev}context->tasks->queue->SingleLinkedQueue.last = element; | |
398
fc4fcd441700
Fix spanwTasks
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
397
diff
changeset
|
473 EOFEOF |
fc4fcd441700
Fix spanwTasks
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
397
diff
changeset
|
474 print $fd $putTask; |
396
bba401f93dcd
Add handle par goto statement
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
393
diff
changeset
|
475 next; |
260
6b5444bbea8a
generated stub no comiple errors
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
259
diff
changeset
|
476 } elsif (/^(.*)goto (\w+)\((.*)\);/) { |
278 | 477 # handling goto statement |
262 | 478 # convert it to the meta call form with two arugments, that is context and enum Code |
250 | 479 my $prev = $1; |
260
6b5444bbea8a
generated stub no comiple errors
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
259
diff
changeset
|
480 my $next = $2; |
6b5444bbea8a
generated stub no comiple errors
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
259
diff
changeset
|
481 my @args = split(/,/,$3); |
388 | 482 my $v = 0; |
483 for my $n ( @{$dataGearVar{$codeGearName}} ) { | |
396
bba401f93dcd
Add handle par goto statement
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
393
diff
changeset
|
484 # continuation arguments |
388 | 485 $v = 1 if ( $n eq $next); |
486 } | |
396
bba401f93dcd
Add handle par goto statement
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
393
diff
changeset
|
487 if ($v || defined $code{$interface}->{$next}) { |
278 | 488 # write continuation's arguments into the interface arguments |
489 # we may need a commit for a shared DataGear | |
490 for my $arg ( @{$outputArgs{$codeGearName}->{$next}} ) { | |
491 my $v = shift(@args); | |
492 print $fd "\t*O_$arg = $v;\n"; | |
493 } | |
397 | 494 if ($inParGoto) { |
398
fc4fcd441700
Fix spanwTasks
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
397
diff
changeset
|
495 print $fd "${prev}taskManager->tasks = context->tasks;\n"; |
fc4fcd441700
Fix spanwTasks
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
397
diff
changeset
|
496 print $fd "${prev}taskManager->next1 = C_$next;\n"; |
406
9b35e6581b5c
Use task member of context by par goto meta
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
404
diff
changeset
|
497 print $fd "${prev}goto meta(context, C_$next);\n"; |
397 | 498 } else { |
499 print $fd "${prev}goto meta(context, $next);\n"; | |
500 } | |
501 next; | |
502 } | |
503 if ($inParGoto) { | |
398
fc4fcd441700
Fix spanwTasks
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
397
diff
changeset
|
504 print $fd "${prev}taskManager->tasks = context->tasks;\n"; |
fc4fcd441700
Fix spanwTasks
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
397
diff
changeset
|
505 print $fd "${prev}taskManager->next1 = C_$next;\n"; |
406
9b35e6581b5c
Use task member of context by par goto meta
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
404
diff
changeset
|
506 print $fd "${prev}goto meta(context, C_$next);\n"; |
278 | 507 next; |
260
6b5444bbea8a
generated stub no comiple errors
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
259
diff
changeset
|
508 } |
398
fc4fcd441700
Fix spanwTasks
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
397
diff
changeset
|
509 } elsif(/^}/) { |
fc4fcd441700
Fix spanwTasks
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
397
diff
changeset
|
510 $inParGoto = 0; |
396
bba401f93dcd
Add handle par goto statement
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
393
diff
changeset
|
511 } |
bba401f93dcd
Add handle par goto statement
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
393
diff
changeset
|
512 else { |
259
195518ab62fc
fix type gathering pattern match in generate_stub.pl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
255
diff
changeset
|
513 s/new\s+(\w+)\(\)/\&ALLOCATE(context, \1)->\1/g; # replacing new |
249 | 514 } |
396
bba401f93dcd
Add handle par goto statement
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents:
393
diff
changeset
|
515 # 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
|
516 } elsif (/^}/) { |
278 | 517 $inStub = 0; |
249 | 518 $inTypedef = 0; |
519 } | |
250 | 520 print $fd $_; |
194 | 521 } |
250 | 522 if (defined $prevCodeGearName) { |
523 if (!defined $stub{$prevCodeGearName."_stub"}) { | |
251 | 524 $stub{$prevCodeGearName."_stub"} = &generateStub($fd,$prevCodeGearName,$dataGearName{$codeGearName}); |
250 | 525 } |
228 | 526 } |
194 | 527 } |
528 | |
529 # end |