annotate src/parallel_execution/generate_stub.pl @ 401:408b4aab7610

Supported par goto iterate statement for perl script
author Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
date Tue, 29 Aug 2017 21:50:57 +0900
parents 2d375c583064
children e958a409943c
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
194
081607dcf893 create generate_stub.pl
mir3636
parents:
diff changeset
1 #!/usr/bin/perl
081607dcf893 create generate_stub.pl
mir3636
parents:
diff changeset
2
250
8a8963ce9858 fix generate_stub
mir3636
parents: 249
diff changeset
3 use strict;
254
edb3aff688d0 fix generator CLI
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 253
diff changeset
4 use Getopt::Std;
393
99c50356d917 fix generate_stub.pl
mir3636
parents: 391
diff changeset
5 use File::Path qw(make_path);
250
8a8963ce9858 fix generate_stub
mir3636
parents: 249
diff changeset
6
194
081607dcf893 create generate_stub.pl
mir3636
parents:
diff changeset
7 # interface.cbc
081607dcf893 create generate_stub.pl
mir3636
parents:
diff changeset
8 # typedef struct Worker {
081607dcf893 create generate_stub.pl
mir3636
parents:
diff changeset
9 # int id;
081607dcf893 create generate_stub.pl
mir3636
parents:
diff changeset
10 # struct Context* contexts;
081607dcf893 create generate_stub.pl
mir3636
parents:
diff changeset
11 # enum Code execute;
081607dcf893 create generate_stub.pl
mir3636
parents:
diff changeset
12 # enum Code taskSend;
081607dcf893 create generate_stub.pl
mir3636
parents:
diff changeset
13 # enum Code taskRecive;
081607dcf893 create generate_stub.pl
mir3636
parents:
diff changeset
14 # enum Code shutdown;
081607dcf893 create generate_stub.pl
mir3636
parents:
diff changeset
15 # struct Queue* tasks;
081607dcf893 create generate_stub.pl
mir3636
parents:
diff changeset
16 # } Worker;
081607dcf893 create generate_stub.pl
mir3636
parents:
diff changeset
17
255
79bbe2c63fb0 cmake generate c from cbc
mir3636
parents: 254
diff changeset
18 our($opt_o,$opt_d,$opt_h);
79bbe2c63fb0 cmake generate c from cbc
mir3636
parents: 254
diff changeset
19 getopts('o:d:h');
79bbe2c63fb0 cmake generate c from cbc
mir3636
parents: 254
diff changeset
20
79bbe2c63fb0 cmake generate c from cbc
mir3636
parents: 254
diff changeset
21 my $dir = ".";
79bbe2c63fb0 cmake generate c from cbc
mir3636
parents: 254
diff changeset
22 if ($opt_d) {
79bbe2c63fb0 cmake generate c from cbc
mir3636
parents: 254
diff changeset
23 $dir = $opt_d;
79bbe2c63fb0 cmake generate c from cbc
mir3636
parents: 254
diff changeset
24 if (! -d $dir) {
393
99c50356d917 fix generate_stub.pl
mir3636
parents: 391
diff changeset
25 make_path $dir;
255
79bbe2c63fb0 cmake generate c from cbc
mir3636
parents: 254
diff changeset
26 }
79bbe2c63fb0 cmake generate c from cbc
mir3636
parents: 254
diff changeset
27 }
254
edb3aff688d0 fix generator CLI
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 253
diff changeset
28
edb3aff688d0 fix generator CLI
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 253
diff changeset
29 for my $fn (@ARGV) {
255
79bbe2c63fb0 cmake generate c from cbc
mir3636
parents: 254
diff changeset
30 next if ($fn !~ /\.cbc$/);
249
afa1e02e4386 fix generate stub
mir3636
parents: 243
diff changeset
31 &getDataGear($fn);
afa1e02e4386 fix generate stub
mir3636
parents: 243
diff changeset
32 &generateDataGear($fn);
194
081607dcf893 create generate_stub.pl
mir3636
parents:
diff changeset
33 }
081607dcf893 create generate_stub.pl
mir3636
parents:
diff changeset
34
250
8a8963ce9858 fix generate_stub
mir3636
parents: 249
diff changeset
35 my %var;
8a8963ce9858 fix generate_stub
mir3636
parents: 249
diff changeset
36 my %code;
8a8963ce9858 fix generate_stub
mir3636
parents: 249
diff changeset
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
8a8963ce9858 fix generate_stub
mir3636
parents: 249
diff changeset
40 my %dataGear;
8a8963ce9858 fix generate_stub
mir3636
parents: 249
diff changeset
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
ebc13549394c generate stubArgs
mir3636
parents: 252
diff changeset
45 my $implementation;
ebc13549394c generate stubArgs
mir3636
parents: 252
diff changeset
46 my $interface;
250
8a8963ce9858 fix generate_stub
mir3636
parents: 249
diff changeset
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
081607dcf893 create generate_stub.pl
mir3636
parents:
diff changeset
76 sub getDataGear {
081607dcf893 create generate_stub.pl
mir3636
parents:
diff changeset
77 my ($filename) = @_;
253
ebc13549394c generate stubArgs
mir3636
parents: 252
diff changeset
78 my ($codeGearName, $name, $inTypedef);
194
081607dcf893 create generate_stub.pl
mir3636
parents:
diff changeset
79 open my $fd,"<",$filename or die("can't open $filename $!");
081607dcf893 create generate_stub.pl
mir3636
parents:
diff changeset
80 while (<$fd>) {
081607dcf893 create generate_stub.pl
mir3636
parents:
diff changeset
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
081607dcf893 create generate_stub.pl
mir3636
parents:
diff changeset
83 $inTypedef = 1;
081607dcf893 create generate_stub.pl
mir3636
parents:
diff changeset
84 $name = $1;
081607dcf893 create generate_stub.pl
mir3636
parents:
diff changeset
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
5170539348ec rename TaskManagerImpl.cbc
mir3636
parents: 268
diff changeset
96 } elsif (/^(\w+)(\*)+ create(\w+)\(/) {
249
afa1e02e4386 fix generate stub
mir3636
parents: 243
diff changeset
97 if (defined $interface) {
afa1e02e4386 fix generate stub
mir3636
parents: 243
diff changeset
98 die "duplicate interface $interface\n";
afa1e02e4386 fix generate stub
mir3636
parents: 243
diff changeset
99 }
afa1e02e4386 fix generate stub
mir3636
parents: 243
diff changeset
100 $interface = $1;
269
5170539348ec rename TaskManagerImpl.cbc
mir3636
parents: 268
diff changeset
101 $implementation = $3;
250
8a8963ce9858 fix generate_stub
mir3636
parents: 249
diff changeset
102 if ( -f "$interface.cbc") {
8a8963ce9858 fix generate_stub
mir3636
parents: 249
diff changeset
103 &getDataGear("$interface.cbc");
8a8963ce9858 fix generate_stub
mir3636
parents: 249
diff changeset
104 }
393
99c50356d917 fix generate_stub.pl
mir3636
parents: 391
diff changeset
105 } elsif (/^(\s)*(\w+)\-\>(\w+)\s\=\s\((.*)\)create(\w+)\((.*)\);$/) {
385
c1512f358c37 add getCodeGear to generate_stub.pl
mir3636
parents: 384
diff changeset
106 #my $intfn = ucfirst($2);
c1512f358c37 add getCodeGear to generate_stub.pl
mir3636
parents: 384
diff changeset
107 my $impln = $5;
c1512f358c37 add getCodeGear to generate_stub.pl
mir3636
parents: 384
diff changeset
108 if ( -f "$impln.cbc") {
c1512f358c37 add getCodeGear to generate_stub.pl
mir3636
parents: 384
diff changeset
109 &getCodeGear("$impln.cbc");
c1512f358c37 add getCodeGear to generate_stub.pl
mir3636
parents: 384
diff changeset
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
68c03e7057d9 get arg
mir3636
parents: 201
diff changeset
119 }
194
081607dcf893 create generate_stub.pl
mir3636
parents:
diff changeset
120 next;
081607dcf893 create generate_stub.pl
mir3636
parents:
diff changeset
121 }
249
afa1e02e4386 fix generate stub
mir3636
parents: 243
diff changeset
122 # gather type name and type
194
081607dcf893 create generate_stub.pl
mir3636
parents:
diff changeset
123 $dataGear{$name} .= $_;
385
c1512f358c37 add getCodeGear to generate_stub.pl
mir3636
parents: 384
diff changeset
124 if (/^\s*(.*)\s+(\w+);$/ ) {
280
2c2e4e597eb0 generate no compile errors
mir3636
parents: 278
diff changeset
125 my $ttype = $1;
2c2e4e597eb0 generate no compile errors
mir3636
parents: 278
diff changeset
126 my $tname = $2;
2c2e4e597eb0 generate no compile errors
mir3636
parents: 278
diff changeset
127 if ($ttype =~ /^(union|struct) (\w+)/) {
2c2e4e597eb0 generate no compile errors
mir3636
parents: 278
diff changeset
128 $ttype = $2;
2c2e4e597eb0 generate no compile errors
mir3636
parents: 278
diff changeset
129 }
2c2e4e597eb0 generate no compile errors
mir3636
parents: 278
diff changeset
130 $var{$name}->{$tname} = $ttype;
250
8a8963ce9858 fix generate_stub
mir3636
parents: 249
diff changeset
131 }
194
081607dcf893 create generate_stub.pl
mir3636
parents:
diff changeset
132 if (/^}/) {
081607dcf893 create generate_stub.pl
mir3636
parents:
diff changeset
133 $inTypedef = 0;
081607dcf893 create generate_stub.pl
mir3636
parents:
diff changeset
134 }
081607dcf893 create generate_stub.pl
mir3636
parents:
diff changeset
135 }
081607dcf893 create generate_stub.pl
mir3636
parents:
diff changeset
136 }
081607dcf893 create generate_stub.pl
mir3636
parents:
diff changeset
137
385
c1512f358c37 add getCodeGear to generate_stub.pl
mir3636
parents: 384
diff changeset
138 sub getCodeGear {
c1512f358c37 add getCodeGear to generate_stub.pl
mir3636
parents: 384
diff changeset
139 my ($filename) = @_;
c1512f358c37 add getCodeGear to generate_stub.pl
mir3636
parents: 384
diff changeset
140 open my $fd,"<",$filename or die("can't open $filename $!");
c1512f358c37 add getCodeGear to generate_stub.pl
mir3636
parents: 384
diff changeset
141 my ($name,$impln);
c1512f358c37 add getCodeGear to generate_stub.pl
mir3636
parents: 384
diff changeset
142 while (<$fd>) {
c1512f358c37 add getCodeGear to generate_stub.pl
mir3636
parents: 384
diff changeset
143 if (/^(\w+)(\*)+ create(\w+)\(/) {
c1512f358c37 add getCodeGear to generate_stub.pl
mir3636
parents: 384
diff changeset
144 $name = $1;
c1512f358c37 add getCodeGear to generate_stub.pl
mir3636
parents: 384
diff changeset
145 $impln = $3;
c1512f358c37 add getCodeGear to generate_stub.pl
mir3636
parents: 384
diff changeset
146 }
c1512f358c37 add getCodeGear to generate_stub.pl
mir3636
parents: 384
diff changeset
147 if (defined $name) {
c1512f358c37 add getCodeGear to generate_stub.pl
mir3636
parents: 384
diff changeset
148 if (/^\_\_code (\w+)$impln\((.*)\)(.*)/) {
c1512f358c37 add getCodeGear to generate_stub.pl
mir3636
parents: 384
diff changeset
149 my $args = $2;
c1512f358c37 add getCodeGear to generate_stub.pl
mir3636
parents: 384
diff changeset
150 my $method = $1;
c1512f358c37 add getCodeGear to generate_stub.pl
mir3636
parents: 384
diff changeset
151 $code{$name}->{$method} = [];
c1512f358c37 add getCodeGear to generate_stub.pl
mir3636
parents: 384
diff changeset
152 while($args) {
c1512f358c37 add getCodeGear to generate_stub.pl
mir3636
parents: 384
diff changeset
153 if ($args =~ s/(^\s*,\s*)//) {
c1512f358c37 add getCodeGear to generate_stub.pl
mir3636
parents: 384
diff changeset
154 }
c1512f358c37 add getCodeGear to generate_stub.pl
mir3636
parents: 384
diff changeset
155 # continuation case
c1512f358c37 add getCodeGear to generate_stub.pl
mir3636
parents: 384
diff changeset
156 if ($args =~ s/^(\s)*\_\_code\s+(\w+)\(([^)]*)\)//) {
c1512f358c37 add getCodeGear to generate_stub.pl
mir3636
parents: 384
diff changeset
157 my $next = $2;
c1512f358c37 add getCodeGear to generate_stub.pl
mir3636
parents: 384
diff changeset
158 my @args = split(/,/,$3);
387
590f03af1a2c fix getCodeGear
mir3636
parents: 385
diff changeset
159 push(@{$code{$name}->{$method}},"\_\_code $next");
385
c1512f358c37 add getCodeGear to generate_stub.pl
mir3636
parents: 384
diff changeset
160 } elsif ($args =~ s/^(struct|union) (\w+)(\*)+\s(\w+)//) {
c1512f358c37 add getCodeGear to generate_stub.pl
mir3636
parents: 384
diff changeset
161 my $structType = $1;
c1512f358c37 add getCodeGear to generate_stub.pl
mir3636
parents: 384
diff changeset
162 my $typeName = $2;
c1512f358c37 add getCodeGear to generate_stub.pl
mir3636
parents: 384
diff changeset
163 my $varName = $4;
c1512f358c37 add getCodeGear to generate_stub.pl
mir3636
parents: 384
diff changeset
164 my $typeField = lcfirst($typeName);
387
590f03af1a2c fix getCodeGear
mir3636
parents: 385
diff changeset
165 push(@{$code{$name}->{$method}},"$typeName $varName");
385
c1512f358c37 add getCodeGear to generate_stub.pl
mir3636
parents: 384
diff changeset
166 } elsif ($args =~ s/(.*,)//) {
c1512f358c37 add getCodeGear to generate_stub.pl
mir3636
parents: 384
diff changeset
167 } else {
c1512f358c37 add getCodeGear to generate_stub.pl
mir3636
parents: 384
diff changeset
168 last;
c1512f358c37 add getCodeGear to generate_stub.pl
mir3636
parents: 384
diff changeset
169 }
c1512f358c37 add getCodeGear to generate_stub.pl
mir3636
parents: 384
diff changeset
170 }
c1512f358c37 add getCodeGear to generate_stub.pl
mir3636
parents: 384
diff changeset
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 }
bba401f93dcd Add handle par goto statement
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents: 393
diff changeset
181 if ($args =~ s/^(\s)*\_\_code\s+(\w+)\(//) {
bba401f93dcd Add handle par goto statement
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents: 393
diff changeset
182 $inputIncFlag = 0;
bba401f93dcd Add handle par goto statement
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents: 393
diff changeset
183 } 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
184 if($inputIncFlag) {
bba401f93dcd Add handle par goto statement
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents: 393
diff changeset
185 $inputCount++;
bba401f93dcd Add handle par goto statement
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents: 393
diff changeset
186 }
bba401f93dcd Add handle par goto statement
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents: 393
diff changeset
187 else {
bba401f93dcd Add handle par goto statement
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents: 393
diff changeset
188 $outputCount++;
bba401f93dcd Add handle par goto statement
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents: 393
diff changeset
189 }
bba401f93dcd Add handle par goto statement
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents: 393
diff changeset
190 } elsif ($args =~ s/(.*,)//) {
bba401f93dcd Add handle par goto statement
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents: 393
diff changeset
191 } else {
bba401f93dcd Add handle par goto statement
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents: 393
diff changeset
192 last;
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 }
bba401f93dcd Add handle par goto statement
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents: 393
diff changeset
195 $codeGear{$codeGearName}->{"input"} = $inputCount;
bba401f93dcd Add handle par goto statement
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents: 393
diff changeset
196 $codeGear{$codeGearName}->{"output"} = $outputCount;
385
c1512f358c37 add getCodeGear to generate_stub.pl
mir3636
parents: 384
diff changeset
197 }
c1512f358c37 add getCodeGear to generate_stub.pl
mir3636
parents: 384
diff changeset
198 }
c1512f358c37 add getCodeGear to generate_stub.pl
mir3636
parents: 384
diff changeset
199 }
c1512f358c37 add getCodeGear to generate_stub.pl
mir3636
parents: 384
diff changeset
200
250
8a8963ce9858 fix generate_stub
mir3636
parents: 249
diff changeset
201 sub generateStub {
251
0ab52d6e2fd9 fix sub generateStub
mir3636
parents: 250
diff changeset
202 my($fd,$prevCodeGearName,$dataGearName) = @_;
274
d14eb393023d fix generate_stub
mir3636
parents: 269
diff changeset
203 print $fd "__code ", $prevCodeGearName ,"_stub(struct Context* context) {\n";
251
0ab52d6e2fd9 fix sub generateStub
mir3636
parents: 250
diff changeset
204 print $fd $dataGearName;
250
8a8963ce9858 fix generate_stub
mir3636
parents: 249
diff changeset
205 print $fd "\n} \n\n";
251
0ab52d6e2fd9 fix sub generateStub
mir3636
parents: 250
diff changeset
206 return 1;
250
8a8963ce9858 fix generate_stub
mir3636
parents: 249
diff changeset
207 }
8a8963ce9858 fix generate_stub
mir3636
parents: 249
diff changeset
208
253
ebc13549394c generate stubArgs
mir3636
parents: 252
diff changeset
209 sub generateStubArgs {
260
6b5444bbea8a generated stub no comiple errors
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 259
diff changeset
210 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
211 my $varname1 = $output?"O_$varName":$varName;
6b5444bbea8a generated stub no comiple errors
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 259
diff changeset
212 for my $n ( @{$dataGearVar{$codeGearName}} ) {
6b5444bbea8a generated stub no comiple errors
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 259
diff changeset
213 # we already have it
6b5444bbea8a generated stub no comiple errors
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 259
diff changeset
214 return 0 if ( $n eq $varname1);
6b5444bbea8a generated stub no comiple errors
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 259
diff changeset
215 }
6b5444bbea8a generated stub no comiple errors
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 259
diff changeset
216 push @{$dataGearVar{$codeGearName}}, $varname1;
384
ee5d2b1685d7 Fix perlscript
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents: 383
diff changeset
217 push @{$dataGearVarType{$codeGearName}}, $typeName;
260
6b5444bbea8a generated stub no comiple errors
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 259
diff changeset
218 if ($typeName eq $implementation) {
6b5444bbea8a generated stub no comiple errors
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 259
diff changeset
219 # get implementation
258
4fe19a06d666 generate next args
mir3636
parents: 255
diff changeset
220 $dataGearName{$codeGearName} .= "\t$typeName* $varName = ($typeName*)GearImpl(context, $interface, $varName);\n";
253
ebc13549394c generate stubArgs
mir3636
parents: 252
diff changeset
221 } else {
259
195518ab62fc fix type gathering pattern match in generate_stub.pl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 255
diff changeset
222 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
223 # input data gear field
253
ebc13549394c generate stubArgs
mir3636
parents: 252
diff changeset
224 if ($varName eq $ivar) {
280
2c2e4e597eb0 generate no compile errors
mir3636
parents: 278
diff changeset
225 if ($typeName eq $var{$interface}->{$ivar}) {
2c2e4e597eb0 generate no compile errors
mir3636
parents: 278
diff changeset
226 if ($output) {
2c2e4e597eb0 generate no compile errors
mir3636
parents: 278
diff changeset
227 $dataGearName{$codeGearName} .= "\t$typeName** O_$varName = &Gearef(context, $interface)->$varName;\n";
2c2e4e597eb0 generate no compile errors
mir3636
parents: 278
diff changeset
228 $outputVar{$codeGearName} .= "\t$typeName* $varName;\n";
2c2e4e597eb0 generate no compile errors
mir3636
parents: 278
diff changeset
229 return 1;
2c2e4e597eb0 generate no compile errors
mir3636
parents: 278
diff changeset
230 }
396
bba401f93dcd Add handle par goto statement
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents: 393
diff changeset
231
280
2c2e4e597eb0 generate no compile errors
mir3636
parents: 278
diff changeset
232 $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
233 return 1;
6b5444bbea8a generated stub no comiple errors
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 259
diff changeset
234 }
253
ebc13549394c generate stubArgs
mir3636
parents: 252
diff changeset
235 }
ebc13549394c generate stubArgs
mir3636
parents: 252
diff changeset
236 }
259
195518ab62fc fix type gathering pattern match in generate_stub.pl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 255
diff changeset
237 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
238 if ($varName eq $cName) {
260
6b5444bbea8a generated stub no comiple errors
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 259
diff changeset
239 # 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
240 $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
241 return 1;
253
ebc13549394c generate stubArgs
mir3636
parents: 252
diff changeset
242 }
ebc13549394c generate stubArgs
mir3636
parents: 252
diff changeset
243 }
389
d9a7620a1106 handle continuation in stub
masataka
parents: 388
diff changeset
244 # global or local variable case
d9a7620a1106 handle continuation in stub
masataka
parents: 388
diff changeset
245 if ($typeName eq "Code") {
396
bba401f93dcd Add handle par goto statement
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents: 393
diff changeset
246 $dataGearName{$codeGearName} .= "\tenum $typeName $varName = Gearef(context, $interface)->$varName;\n";
389
d9a7620a1106 handle continuation in stub
masataka
parents: 388
diff changeset
247 return 1;
d9a7620a1106 handle continuation in stub
masataka
parents: 388
diff changeset
248 }
268
378ce6f74f4b fix generate_stub
mir3636
parents: 262
diff changeset
249 $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
250 return 1;
253
ebc13549394c generate stubArgs
mir3636
parents: 252
diff changeset
251 }
ebc13549394c generate stubArgs
mir3636
parents: 252
diff changeset
252 }
ebc13549394c generate stubArgs
mir3636
parents: 252
diff changeset
253
194
081607dcf893 create generate_stub.pl
mir3636
parents:
diff changeset
254 sub generateDataGear {
249
afa1e02e4386 fix generate stub
mir3636
parents: 243
diff changeset
255 my ($filename) = @_;
afa1e02e4386 fix generate stub
mir3636
parents: 243
diff changeset
256 open my $in,"<",$filename or die("can't open $filename $!");
254
edb3aff688d0 fix generator CLI
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 253
diff changeset
257
edb3aff688d0 fix generator CLI
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 253
diff changeset
258 my $fn;
edb3aff688d0 fix generator CLI
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 253
diff changeset
259 if ($opt_o) {
396
bba401f93dcd Add handle par goto statement
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents: 393
diff changeset
260 $fn = $opt_o;
254
edb3aff688d0 fix generator CLI
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 253
diff changeset
261 } else {
edb3aff688d0 fix generator CLI
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 253
diff changeset
262 my $fn1 = $filename;
edb3aff688d0 fix generator CLI
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 253
diff changeset
263 $fn1 =~ s/\.cbc/.c/;
edb3aff688d0 fix generator CLI
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 253
diff changeset
264 my $i = 1;
255
79bbe2c63fb0 cmake generate c from cbc
mir3636
parents: 254
diff changeset
265 $fn = "$dir/$fn1";
254
edb3aff688d0 fix generator CLI
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 253
diff changeset
266 while ( -f $fn) {
255
79bbe2c63fb0 cmake generate c from cbc
mir3636
parents: 254
diff changeset
267 $fn = "$dir/$fn1.$i";
254
edb3aff688d0 fix generator CLI
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 253
diff changeset
268 $i++;
edb3aff688d0 fix generator CLI
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 253
diff changeset
269 }
250
8a8963ce9858 fix generate_stub
mir3636
parents: 249
diff changeset
270 }
259
195518ab62fc fix type gathering pattern match in generate_stub.pl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 255
diff changeset
271 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
272 if (! -d $1) {
393
99c50356d917 fix generate_stub.pl
mir3636
parents: 391
diff changeset
273 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
274 }
195518ab62fc fix type gathering pattern match in generate_stub.pl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 255
diff changeset
275 }
249
afa1e02e4386 fix generate stub
mir3636
parents: 243
diff changeset
276 open my $fd,">",$fn or die("can't write $fn $!");
254
edb3aff688d0 fix generator CLI
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 253
diff changeset
277
249
afa1e02e4386 fix generate stub
mir3636
parents: 243
diff changeset
278 my $prevCodeGearName;
250
8a8963ce9858 fix generate_stub
mir3636
parents: 249
diff changeset
279 my $inTypedef = 0;
278
23767f714f4a fix generate_stub
mir3636
parents: 274
diff changeset
280 my $inStub = 0;
396
bba401f93dcd Add handle par goto statement
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents: 393
diff changeset
281 my $inParGoto = 0;
250
8a8963ce9858 fix generate_stub
mir3636
parents: 249
diff changeset
282 my %stub;
251
0ab52d6e2fd9 fix sub generateStub
mir3636
parents: 250
diff changeset
283 my $codeGearName;
254
edb3aff688d0 fix generator CLI
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 253
diff changeset
284
249
afa1e02e4386 fix generate stub
mir3636
parents: 243
diff changeset
285 while (<$in>) {
278
23767f714f4a fix generate_stub
mir3636
parents: 274
diff changeset
286 if (! $inTypedef && ! $inStub) {
249
afa1e02e4386 fix generate stub
mir3636
parents: 243
diff changeset
287 if (/^typedef struct (\w+) {/) {
afa1e02e4386 fix generate stub
mir3636
parents: 243
diff changeset
288 $inTypedef = 1;
253
ebc13549394c generate stubArgs
mir3636
parents: 252
diff changeset
289 } elsif (/^\_\_code (\w+)\((.*)\)(.*)/) {
251
0ab52d6e2fd9 fix sub generateStub
mir3636
parents: 250
diff changeset
290 $codeGearName = $1;
253
ebc13549394c generate stubArgs
mir3636
parents: 252
diff changeset
291 my $args = $2;
ebc13549394c generate stubArgs
mir3636
parents: 252
diff changeset
292 my $tail = $3;
250
8a8963ce9858 fix generate_stub
mir3636
parents: 249
diff changeset
293 if ($codeGearName =~ /_stub$/) {
262
2c56a9536c0d add comments
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 261
diff changeset
294 # don't touch already existing stub
278
23767f714f4a fix generate_stub
mir3636
parents: 274
diff changeset
295 $inStub = 1;
250
8a8963ce9858 fix generate_stub
mir3636
parents: 249
diff changeset
296 $stub{$codeGearName} = 1;
8a8963ce9858 fix generate_stub
mir3636
parents: 249
diff changeset
297 print $fd $_;
8a8963ce9858 fix generate_stub
mir3636
parents: 249
diff changeset
298 next;
8a8963ce9858 fix generate_stub
mir3636
parents: 249
diff changeset
299 }
249
afa1e02e4386 fix generate stub
mir3636
parents: 243
diff changeset
300 if (defined $prevCodeGearName) {
262
2c56a9536c0d add comments
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 261
diff changeset
301 # stub is generated just before next CodeGear
250
8a8963ce9858 fix generate_stub
mir3636
parents: 249
diff changeset
302 if (defined $stub{$prevCodeGearName."_stub"}) {
8a8963ce9858 fix generate_stub
mir3636
parents: 249
diff changeset
303 undef $prevCodeGearName;
278
23767f714f4a fix generate_stub
mir3636
parents: 274
diff changeset
304 } else {
23767f714f4a fix generate_stub
mir3636
parents: 274
diff changeset
305 &generateStub($fd,$prevCodeGearName,$dataGearName{$prevCodeGearName});
23767f714f4a fix generate_stub
mir3636
parents: 274
diff changeset
306 $stub{$prevCodeGearName."_stub"} = 1;
250
8a8963ce9858 fix generate_stub
mir3636
parents: 249
diff changeset
307 }
249
afa1e02e4386 fix generate stub
mir3636
parents: 243
diff changeset
308 }
262
2c56a9536c0d add comments
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 261
diff changeset
309 # analyzing CodeGear argument
2c56a9536c0d add comments
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 261
diff changeset
310 # these arguments are extract from current context's arugment DataGear Interface
2c56a9536c0d add comments
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 261
diff changeset
311 # and passed to the CodeGear
2c56a9536c0d add comments
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 261
diff changeset
312 # struct Implementaion needs special handling
2c56a9536c0d add comments
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 261
diff changeset
313 # __code next(...) ---> enum Code next
253
ebc13549394c generate stubArgs
mir3636
parents: 252
diff changeset
314 $prevCodeGearName = $codeGearName;
ebc13549394c generate stubArgs
mir3636
parents: 252
diff changeset
315 $dataGearVar{$codeGearName} = [];
260
6b5444bbea8a generated stub no comiple errors
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 259
diff changeset
316 $outputVar{$codeGearName} = "";
6b5444bbea8a generated stub no comiple errors
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 259
diff changeset
317 $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
318 my $newArgs = "struct Context *context,";
305
ec0a5b4fba05 CUDAWorker
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 280
diff changeset
319 if ($args=~/^struct Context\s*\*\s*context/) {
ec0a5b4fba05 CUDAWorker
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 280
diff changeset
320 $newArgs = "";
ec0a5b4fba05 CUDAWorker
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 280
diff changeset
321 }
253
ebc13549394c generate stubArgs
mir3636
parents: 252
diff changeset
322 while($args) {
ebc13549394c generate stubArgs
mir3636
parents: 252
diff changeset
323 if ($args =~ s/(^\s*,\s*)//) {
ebc13549394c generate stubArgs
mir3636
parents: 252
diff changeset
324 $newArgs .= $1;
ebc13549394c generate stubArgs
mir3636
parents: 252
diff changeset
325 }
262
2c56a9536c0d add comments
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 261
diff changeset
326 # continuation case
280
2c2e4e597eb0 generate no compile errors
mir3636
parents: 278
diff changeset
327 if ($args =~ s/^(\s)*\_\_code\s+(\w+)\(([^)]*)\)//) {
2c2e4e597eb0 generate no compile errors
mir3636
parents: 278
diff changeset
328 my $next = $2;
2c2e4e597eb0 generate no compile errors
mir3636
parents: 278
diff changeset
329 my @args = split(/,/,$3);
398
fc4fcd441700 Fix spanwTasks
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents: 397
diff changeset
330 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
331 $newArgs .= "enum Code $next";
258
4fe19a06d666 generate next args
mir3636
parents: 255
diff changeset
332 }
262
2c56a9536c0d add comments
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 261
diff changeset
333 # analyze continuation arguments
2c56a9536c0d add comments
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 261
diff changeset
334 # output arguments are defined in the Interface take the pointer of these
2c56a9536c0d add comments
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 261
diff changeset
335 # output arguments are put into the Interface DataGear just before the goto
253
ebc13549394c generate stubArgs
mir3636
parents: 252
diff changeset
336 for my $arg (@args) {
ebc13549394c generate stubArgs
mir3636
parents: 252
diff changeset
337 $arg =~ s/^\s*//;
260
6b5444bbea8a generated stub no comiple errors
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 259
diff changeset
338 last if ($arg =~ /\.\.\./);
253
ebc13549394c generate stubArgs
mir3636
parents: 252
diff changeset
339 $arg =~ s/^(struct|union) (\w+)(\*)+\s(\w+)//;
ebc13549394c generate stubArgs
mir3636
parents: 252
diff changeset
340 my $structType = $1;
ebc13549394c generate stubArgs
mir3636
parents: 252
diff changeset
341 my $typeName = $2;
ebc13549394c generate stubArgs
mir3636
parents: 252
diff changeset
342 my $varName = $4;
ebc13549394c generate stubArgs
mir3636
parents: 252
diff changeset
343 my $typeField = lcfirst($typeName);
260
6b5444bbea8a generated stub no comiple errors
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 259
diff changeset
344 push(@{$outputArgs{$codeGearName}->{$next}}, $varName);
6b5444bbea8a generated stub no comiple errors
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 259
diff changeset
345 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
346 $newArgs .= ",$structType $typeName **O_$varName";
6b5444bbea8a generated stub no comiple errors
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 259
diff changeset
347 }
253
ebc13549394c generate stubArgs
mir3636
parents: 252
diff changeset
348 }
ebc13549394c generate stubArgs
mir3636
parents: 252
diff changeset
349 } elsif ($args =~ s/^(struct|union) (\w+)(\*)+\s(\w+)//) {
ebc13549394c generate stubArgs
mir3636
parents: 252
diff changeset
350 my $structType = $1;
ebc13549394c generate stubArgs
mir3636
parents: 252
diff changeset
351 my $typeName = $2;
ebc13549394c generate stubArgs
mir3636
parents: 252
diff changeset
352 my $varName = $4;
ebc13549394c generate stubArgs
mir3636
parents: 252
diff changeset
353 my $typeField = lcfirst($typeName);
260
6b5444bbea8a generated stub no comiple errors
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 259
diff changeset
354 $newArgs .= $&; # assuming no duplicate
6b5444bbea8a generated stub no comiple errors
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 259
diff changeset
355 &generateStubArgs($codeGearName, $varName, $typeName, $typeField, $interface,0);
255
79bbe2c63fb0 cmake generate c from cbc
mir3636
parents: 254
diff changeset
356 } elsif ($args =~ s/(.*,)//) {
79bbe2c63fb0 cmake generate c from cbc
mir3636
parents: 254
diff changeset
357 $newArgs .= $1;
79bbe2c63fb0 cmake generate c from cbc
mir3636
parents: 254
diff changeset
358 } else {
79bbe2c63fb0 cmake generate c from cbc
mir3636
parents: 254
diff changeset
359 $newArgs .= $args;
79bbe2c63fb0 cmake generate c from cbc
mir3636
parents: 254
diff changeset
360 last;
253
ebc13549394c generate stubArgs
mir3636
parents: 252
diff changeset
361 }
ebc13549394c generate stubArgs
mir3636
parents: 252
diff changeset
362 }
262
2c56a9536c0d add comments
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 261
diff changeset
363 # generate goto statement from stub to the CodeGear in the buffer
253
ebc13549394c generate stubArgs
mir3636
parents: 252
diff changeset
364 $dataGearName{$codeGearName} .= "\tgoto $codeGearName(context";
ebc13549394c generate stubArgs
mir3636
parents: 252
diff changeset
365 for my $arg ( @{$dataGearVar{$codeGearName}}) {
ebc13549394c generate stubArgs
mir3636
parents: 252
diff changeset
366 $dataGearName{$codeGearName} .= ", $arg";
ebc13549394c generate stubArgs
mir3636
parents: 252
diff changeset
367 }
ebc13549394c generate stubArgs
mir3636
parents: 252
diff changeset
368 $dataGearName{$codeGearName} .= ");";
262
2c56a9536c0d add comments
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 261
diff changeset
369 # generate CodeGear header with new arguments
253
ebc13549394c generate stubArgs
mir3636
parents: 252
diff changeset
370 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
371 if ($outputVar{$codeGearName} ne "") {
324
d9887056ae5b Update Todo and Add comment to perl script
one
parents: 305
diff changeset
372 # output data var can be use before write
d9887056ae5b Update Todo and Add comment to perl script
one
parents: 305
diff changeset
373 # 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
374 print $fd $outputVar{$codeGearName};
6b5444bbea8a generated stub no comiple errors
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 259
diff changeset
375 }
250
8a8963ce9858 fix generate_stub
mir3636
parents: 249
diff changeset
376 next;
384
ee5d2b1685d7 Fix perlscript
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents: 383
diff changeset
377 } elsif (/^(.*)goto (\w+)\-\>(\w+)\((.*)\);/) {
ee5d2b1685d7 Fix perlscript
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents: 383
diff changeset
378 # handling goto statement
ee5d2b1685d7 Fix perlscript
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents: 383
diff changeset
379 # 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
380 my $prev = $1;
ee5d2b1685d7 Fix perlscript
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents: 383
diff changeset
381 my $next = $2;
ee5d2b1685d7 Fix perlscript
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents: 383
diff changeset
382 my $method = $3;
ee5d2b1685d7 Fix perlscript
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents: 383
diff changeset
383 my @args = split(/,/,$4);
ee5d2b1685d7 Fix perlscript
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents: 383
diff changeset
384 my @types = @{$dataGearVarType{$codeGearName}};
ee5d2b1685d7 Fix perlscript
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents: 383
diff changeset
385 my $ntype;
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;
ee5d2b1685d7 Fix perlscript
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents: 383
diff changeset
390 }
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 print $fd "\tGearef(context, $ntype)->$next = $next->$next;\n";
ee5d2b1685d7 Fix perlscript
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents: 383
diff changeset
393 # Put interface argument
ee5d2b1685d7 Fix perlscript
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents: 383
diff changeset
394 my $prot = $code{$ntype}->{$method};
385
c1512f358c37 add getCodeGear to generate_stub.pl
mir3636
parents: 384
diff changeset
395 my $i = 1;
384
ee5d2b1685d7 Fix perlscript
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents: 383
diff changeset
396 for my $arg (@args) {
385
c1512f358c37 add getCodeGear to generate_stub.pl
mir3636
parents: 384
diff changeset
397 my $p = @$prot[$i];
c1512f358c37 add getCodeGear to generate_stub.pl
mir3636
parents: 384
diff changeset
398 next if ( $p eq $arg);
387
590f03af1a2c fix getCodeGear
mir3636
parents: 385
diff changeset
399 $p =~ s/^(.*)\s(\w+)//;
590f03af1a2c fix getCodeGear
mir3636
parents: 385
diff changeset
400 my $pType = $1;
590f03af1a2c fix getCodeGear
mir3636
parents: 385
diff changeset
401 my $pName = $2;
590f03af1a2c fix getCodeGear
mir3636
parents: 385
diff changeset
402 $arg =~ s/^(\s)*(\w+)/$2/;
590f03af1a2c fix getCodeGear
mir3636
parents: 385
diff changeset
403 if ($pType =~ s/\_\_code$//) {
590f03af1a2c fix getCodeGear
mir3636
parents: 385
diff changeset
404 print $fd "\tGearef(context, $ntype)->$pName = C_$arg;\n";
391
2d9c500f263e fix generate_stub
mir3636
parents: 389
diff changeset
405 } elsif ($pType =~ s/Data$//){
2d9c500f263e fix generate_stub
mir3636
parents: 389
diff changeset
406 print $fd "\tGearef(context, $ntype)->$pName = (union Data*) $arg;\n";
387
590f03af1a2c fix getCodeGear
mir3636
parents: 385
diff changeset
407 } else {
590f03af1a2c fix getCodeGear
mir3636
parents: 385
diff changeset
408 print $fd "\tGearef(context, $ntype)->$pName = $arg;\n";
590f03af1a2c fix getCodeGear
mir3636
parents: 385
diff changeset
409 }
385
c1512f358c37 add getCodeGear to generate_stub.pl
mir3636
parents: 384
diff changeset
410 $i++;
384
ee5d2b1685d7 Fix perlscript
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents: 383
diff changeset
411 }
ee5d2b1685d7 Fix perlscript
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents: 383
diff changeset
412 print $fd "${prev}goto meta(context, $next->$next->$ntype.$method);\n";
ee5d2b1685d7 Fix perlscript
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents: 383
diff changeset
413 next;
396
bba401f93dcd Add handle par goto statement
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents: 393
diff changeset
414 } elsif(/^(.*)par goto (\w+)\((.*)\);/) {
bba401f93dcd Add handle par goto statement
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents: 393
diff changeset
415 # handling par goto statement
bba401f93dcd Add handle par goto statement
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents: 393
diff changeset
416 # convert it to the parallel
bba401f93dcd Add handle par goto statement
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents: 393
diff changeset
417 my $prev = $1;
bba401f93dcd Add handle par goto statement
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents: 393
diff changeset
418 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
419 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
420 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
421 my @dataGears = split(/,\s*/, $3);
bba401f93dcd Add handle par goto statement
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents: 393
diff changeset
422 my $nextCodeGear = pop(@dataGears);
401
408b4aab7610 Supported par goto iterate statement for perl script
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents: 400
diff changeset
423 my $iterateCount;
408b4aab7610 Supported par goto iterate statement for perl script
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents: 400
diff changeset
424 # parse examples 'par goto(.., iterate(10), exit);'
408b4aab7610 Supported par goto iterate statement for perl script
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents: 400
diff changeset
425 if ($3 =~ /iterate\((\d*)\)/) {
408b4aab7610 Supported par goto iterate statement for perl script
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents: 400
diff changeset
426 $iterateCount = $1;
408b4aab7610 Supported par goto iterate statement for perl script
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents: 400
diff changeset
427 $inputCount--;
408b4aab7610 Supported par goto iterate statement for perl script
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents: 400
diff changeset
428 # 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
429 pop(@dataGears);
408b4aab7610 Supported par goto iterate statement for perl script
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents: 400
diff changeset
430 }
396
bba401f93dcd Add handle par goto statement
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents: 393
diff changeset
431 if (! $inParGoto) {
bba401f93dcd Add handle par goto statement
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents: 393
diff changeset
432 $inParGoto = 1;
398
fc4fcd441700 Fix spanwTasks
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents: 397
diff changeset
433 print $fd "${prev}struct SingleLinkedQueue* queue = &context->tasks->queue->SingleLinkedQueue;\n";
fc4fcd441700 Fix spanwTasks
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents: 397
diff changeset
434 print $fd "${prev}struct Element* element;\n";
fc4fcd441700 Fix spanwTasks
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents: 397
diff changeset
435 print $fd "${prev}struct Context* task;\n";
396
bba401f93dcd Add handle par goto statement
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents: 393
diff changeset
436 }
bba401f93dcd Add handle par goto statement
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents: 393
diff changeset
437 my $initTask = << "EOFEOF";
398
fc4fcd441700 Fix spanwTasks
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents: 397
diff changeset
438 ${prev}task = NEW(struct Context);
fc4fcd441700 Fix spanwTasks
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents: 397
diff changeset
439 ${prev}initContext(task);
fc4fcd441700 Fix spanwTasks
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents: 397
diff changeset
440 ${prev}task->next = C_$codeGearName;
fc4fcd441700 Fix spanwTasks
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents: 397
diff changeset
441 ${prev}task->idgCount = $inputCount;
fc4fcd441700 Fix spanwTasks
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents: 397
diff changeset
442 ${prev}task->idg = task->dataNum;
fc4fcd441700 Fix spanwTasks
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents: 397
diff changeset
443 ${prev}task->maxIdg = task->idg + $inputCount;
fc4fcd441700 Fix spanwTasks
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents: 397
diff changeset
444 ${prev}task->odg = task->maxIdg;
fc4fcd441700 Fix spanwTasks
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents: 397
diff changeset
445 ${prev}task->maxOdg = task->odg + $outputCount;
396
bba401f93dcd Add handle par goto statement
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents: 393
diff changeset
446 EOFEOF
bba401f93dcd Add handle par goto statement
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents: 393
diff changeset
447 print $fd $initTask;
401
408b4aab7610 Supported par goto iterate statement for perl script
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents: 400
diff changeset
448 if (defined $iterateCount) {
408b4aab7610 Supported par goto iterate statement for perl script
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents: 400
diff changeset
449 print $fd "${prev}task->iterate = 0;\n";
408b4aab7610 Supported par goto iterate statement for perl script
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents: 400
diff changeset
450 print $fd "${prev}task->iterator = createOneDimIterator(context, $iterateCount);\n";
408b4aab7610 Supported par goto iterate statement for perl script
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents: 400
diff changeset
451 }
396
bba401f93dcd Add handle par goto statement
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents: 393
diff changeset
452 for my $i (0..$inputCount-1) {
bba401f93dcd Add handle par goto statement
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents: 393
diff changeset
453 print $fd "${prev}task->data[task->idg+$i] = (union Data*)@dataGears[$i];\n";
bba401f93dcd Add handle par goto statement
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents: 393
diff changeset
454 }
bba401f93dcd Add handle par goto statement
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents: 393
diff changeset
455
bba401f93dcd Add handle par goto statement
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents: 393
diff changeset
456 for my $i (0..$outputCount-1) {
bba401f93dcd Add handle par goto statement
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents: 393
diff changeset
457 print $fd "${prev}task->data[task->odg+$i] = (union Data*)@dataGears[$inputCount+$i];\n";
bba401f93dcd Add handle par goto statement
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents: 393
diff changeset
458 }
398
fc4fcd441700 Fix spanwTasks
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents: 397
diff changeset
459 my $putTask = << "EOFEOF";
fc4fcd441700 Fix spanwTasks
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents: 397
diff changeset
460 ${prev}element = &ALLOCATE(context, Element)->Element;
fc4fcd441700 Fix spanwTasks
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents: 397
diff changeset
461 ${prev}element->next = NULL;
fc4fcd441700 Fix spanwTasks
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents: 397
diff changeset
462 ${prev}element->data = (union Data*)task;
399
394e38952c80 Add dummy data to SingleLinkedQueue
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents: 398
diff changeset
463 ${prev}queue->last->next = element;
394e38952c80 Add dummy data to SingleLinkedQueue
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents: 398
diff changeset
464 ${prev}queue->last = element;
398
fc4fcd441700 Fix spanwTasks
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents: 397
diff changeset
465 EOFEOF
fc4fcd441700 Fix spanwTasks
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents: 397
diff changeset
466 print $fd $putTask;
396
bba401f93dcd Add handle par goto statement
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents: 393
diff changeset
467 next;
260
6b5444bbea8a generated stub no comiple errors
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 259
diff changeset
468 } elsif (/^(.*)goto (\w+)\((.*)\);/) {
278
23767f714f4a fix generate_stub
mir3636
parents: 274
diff changeset
469 # handling goto statement
262
2c56a9536c0d add comments
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 261
diff changeset
470 # convert it to the meta call form with two arugments, that is context and enum Code
250
8a8963ce9858 fix generate_stub
mir3636
parents: 249
diff changeset
471 my $prev = $1;
260
6b5444bbea8a generated stub no comiple errors
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 259
diff changeset
472 my $next = $2;
6b5444bbea8a generated stub no comiple errors
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 259
diff changeset
473 my @args = split(/,/,$3);
388
8940d1451a0d handle local continuation
masataka
parents: 387
diff changeset
474 my $v = 0;
8940d1451a0d handle local continuation
masataka
parents: 387
diff changeset
475 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
476 # continuation arguments
388
8940d1451a0d handle local continuation
masataka
parents: 387
diff changeset
477 $v = 1 if ( $n eq $next);
8940d1451a0d handle local continuation
masataka
parents: 387
diff changeset
478 }
396
bba401f93dcd Add handle par goto statement
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents: 393
diff changeset
479 if ($v || defined $code{$interface}->{$next}) {
278
23767f714f4a fix generate_stub
mir3636
parents: 274
diff changeset
480 # write continuation's arguments into the interface arguments
23767f714f4a fix generate_stub
mir3636
parents: 274
diff changeset
481 # we may need a commit for a shared DataGear
23767f714f4a fix generate_stub
mir3636
parents: 274
diff changeset
482 for my $arg ( @{$outputArgs{$codeGearName}->{$next}} ) {
23767f714f4a fix generate_stub
mir3636
parents: 274
diff changeset
483 my $v = shift(@args);
23767f714f4a fix generate_stub
mir3636
parents: 274
diff changeset
484 print $fd "\t*O_$arg = $v;\n";
23767f714f4a fix generate_stub
mir3636
parents: 274
diff changeset
485 }
397
c43ec0e3fa84 Add par_meta
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents: 396
diff changeset
486 if ($inParGoto) {
398
fc4fcd441700 Fix spanwTasks
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents: 397
diff changeset
487 print $fd "${prev}taskManager->tasks = context->tasks;\n";
fc4fcd441700 Fix spanwTasks
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents: 397
diff changeset
488 print $fd "${prev}taskManager->next1 = C_$next;\n";
fc4fcd441700 Fix spanwTasks
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents: 397
diff changeset
489 print $fd "${prev}goto par_meta(context, Gearef(context, TaskManager)->taskManager->TaskManager.spawnTasks, C_$next);\n";
397
c43ec0e3fa84 Add par_meta
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents: 396
diff changeset
490 } else {
c43ec0e3fa84 Add par_meta
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents: 396
diff changeset
491 print $fd "${prev}goto meta(context, $next);\n";
c43ec0e3fa84 Add par_meta
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents: 396
diff changeset
492 }
c43ec0e3fa84 Add par_meta
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents: 396
diff changeset
493 next;
c43ec0e3fa84 Add par_meta
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents: 396
diff changeset
494 }
c43ec0e3fa84 Add par_meta
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents: 396
diff changeset
495 if ($inParGoto) {
398
fc4fcd441700 Fix spanwTasks
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents: 397
diff changeset
496 print $fd "${prev}taskManager->tasks = context->tasks;\n";
fc4fcd441700 Fix spanwTasks
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents: 397
diff changeset
497 print $fd "${prev}taskManager->next1 = C_$next;\n";
fc4fcd441700 Fix spanwTasks
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents: 397
diff changeset
498 print $fd "${prev}goto par_meta(context, Gearef(context, TaskManager)->taskManager->TaskManager.spawnTasks, C_$next);\n";
278
23767f714f4a fix generate_stub
mir3636
parents: 274
diff changeset
499 next;
260
6b5444bbea8a generated stub no comiple errors
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 259
diff changeset
500 }
398
fc4fcd441700 Fix spanwTasks
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents: 397
diff changeset
501 } elsif(/^}/) {
fc4fcd441700 Fix spanwTasks
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents: 397
diff changeset
502 $inParGoto = 0;
396
bba401f93dcd Add handle par goto statement
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents: 393
diff changeset
503 }
bba401f93dcd Add handle par goto statement
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents: 393
diff changeset
504 else {
259
195518ab62fc fix type gathering pattern match in generate_stub.pl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 255
diff changeset
505 s/new\s+(\w+)\(\)/\&ALLOCATE(context, \1)->\1/g; # replacing new
249
afa1e02e4386 fix generate stub
mir3636
parents: 243
diff changeset
506 }
396
bba401f93dcd Add handle par goto statement
Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
parents: 393
diff changeset
507 # 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
508 } elsif (/^}/) {
278
23767f714f4a fix generate_stub
mir3636
parents: 274
diff changeset
509 $inStub = 0;
249
afa1e02e4386 fix generate stub
mir3636
parents: 243
diff changeset
510 $inTypedef = 0;
afa1e02e4386 fix generate stub
mir3636
parents: 243
diff changeset
511 }
250
8a8963ce9858 fix generate_stub
mir3636
parents: 249
diff changeset
512 print $fd $_;
194
081607dcf893 create generate_stub.pl
mir3636
parents:
diff changeset
513 }
250
8a8963ce9858 fix generate_stub
mir3636
parents: 249
diff changeset
514 if (defined $prevCodeGearName) {
8a8963ce9858 fix generate_stub
mir3636
parents: 249
diff changeset
515 if (!defined $stub{$prevCodeGearName."_stub"}) {
251
0ab52d6e2fd9 fix sub generateStub
mir3636
parents: 250
diff changeset
516 $stub{$prevCodeGearName."_stub"} = &generateStub($fd,$prevCodeGearName,$dataGearName{$codeGearName});
250
8a8963ce9858 fix generate_stub
mir3636
parents: 249
diff changeset
517 }
228
55260ff44c8c generate stub
mir3636
parents: 226
diff changeset
518 }
194
081607dcf893 create generate_stub.pl
mir3636
parents:
diff changeset
519 }
081607dcf893 create generate_stub.pl
mir3636
parents:
diff changeset
520
081607dcf893 create generate_stub.pl
mir3636
parents:
diff changeset
521 # end