annotate src/parallel_execution/generate_stub.pl @ 280:2c2e4e597eb0

generate no compile errors
author mir3636
date Fri, 03 Feb 2017 17:47:27 +0900
parents 23767f714f4a
children ec0a5b4fba05
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;
250
8a8963ce9858 fix generate_stub
mir3636
parents: 249
diff changeset
5
194
081607dcf893 create generate_stub.pl
mir3636
parents:
diff changeset
6 # interface.cbc
081607dcf893 create generate_stub.pl
mir3636
parents:
diff changeset
7 # typedef struct Worker {
081607dcf893 create generate_stub.pl
mir3636
parents:
diff changeset
8 # int id;
081607dcf893 create generate_stub.pl
mir3636
parents:
diff changeset
9 # struct Context* contexts;
081607dcf893 create generate_stub.pl
mir3636
parents:
diff changeset
10 # enum Code execute;
081607dcf893 create generate_stub.pl
mir3636
parents:
diff changeset
11 # enum Code taskSend;
081607dcf893 create generate_stub.pl
mir3636
parents:
diff changeset
12 # enum Code taskRecive;
081607dcf893 create generate_stub.pl
mir3636
parents:
diff changeset
13 # enum Code shutdown;
081607dcf893 create generate_stub.pl
mir3636
parents:
diff changeset
14 # struct Queue* tasks;
081607dcf893 create generate_stub.pl
mir3636
parents:
diff changeset
15 # } Worker;
081607dcf893 create generate_stub.pl
mir3636
parents:
diff changeset
16
255
79bbe2c63fb0 cmake generate c from cbc
mir3636
parents: 254
diff changeset
17 our($opt_o,$opt_d,$opt_h);
79bbe2c63fb0 cmake generate c from cbc
mir3636
parents: 254
diff changeset
18 getopts('o:d:h');
79bbe2c63fb0 cmake generate c from cbc
mir3636
parents: 254
diff changeset
19
79bbe2c63fb0 cmake generate c from cbc
mir3636
parents: 254
diff changeset
20 my $dir = ".";
79bbe2c63fb0 cmake generate c from cbc
mir3636
parents: 254
diff changeset
21 if ($opt_d) {
79bbe2c63fb0 cmake generate c from cbc
mir3636
parents: 254
diff changeset
22 $dir = $opt_d;
79bbe2c63fb0 cmake generate c from cbc
mir3636
parents: 254
diff changeset
23 if (! -d $dir) {
79bbe2c63fb0 cmake generate c from cbc
mir3636
parents: 254
diff changeset
24 mkdir $dir;
79bbe2c63fb0 cmake generate c from cbc
mir3636
parents: 254
diff changeset
25 }
79bbe2c63fb0 cmake generate c from cbc
mir3636
parents: 254
diff changeset
26 }
254
edb3aff688d0 fix generator CLI
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 253
diff changeset
27
edb3aff688d0 fix generator CLI
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 253
diff changeset
28 for my $fn (@ARGV) {
255
79bbe2c63fb0 cmake generate c from cbc
mir3636
parents: 254
diff changeset
29 next if ($fn !~ /\.cbc$/);
249
afa1e02e4386 fix generate stub
mir3636
parents: 243
diff changeset
30 &getDataGear($fn);
afa1e02e4386 fix generate stub
mir3636
parents: 243
diff changeset
31 &generateDataGear($fn);
194
081607dcf893 create generate_stub.pl
mir3636
parents:
diff changeset
32 }
081607dcf893 create generate_stub.pl
mir3636
parents:
diff changeset
33
250
8a8963ce9858 fix generate_stub
mir3636
parents: 249
diff changeset
34 my %var;
8a8963ce9858 fix generate_stub
mir3636
parents: 249
diff changeset
35 my %code;
8a8963ce9858 fix generate_stub
mir3636
parents: 249
diff changeset
36 my %dataGearVar;
260
6b5444bbea8a generated stub no comiple errors
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 259
diff changeset
37 my %outputVar; # output var initializer
6b5444bbea8a generated stub no comiple errors
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 259
diff changeset
38 my %outputArgs; # continuation's output variables
250
8a8963ce9858 fix generate_stub
mir3636
parents: 249
diff changeset
39 my %dataGear;
8a8963ce9858 fix generate_stub
mir3636
parents: 249
diff changeset
40 my %dataGearName;
253
ebc13549394c generate stubArgs
mir3636
parents: 252
diff changeset
41 my $implementation;
ebc13549394c generate stubArgs
mir3636
parents: 252
diff changeset
42 my $interface;
250
8a8963ce9858 fix generate_stub
mir3636
parents: 249
diff changeset
43
194
081607dcf893 create generate_stub.pl
mir3636
parents:
diff changeset
44 sub getDataGear {
081607dcf893 create generate_stub.pl
mir3636
parents:
diff changeset
45 my ($filename) = @_;
253
ebc13549394c generate stubArgs
mir3636
parents: 252
diff changeset
46 my ($codeGearName, $name, $inTypedef);
194
081607dcf893 create generate_stub.pl
mir3636
parents:
diff changeset
47 open my $fd,"<",$filename or die("can't open $filename $!");
081607dcf893 create generate_stub.pl
mir3636
parents:
diff changeset
48 while (<$fd>) {
081607dcf893 create generate_stub.pl
mir3636
parents:
diff changeset
49 if (! $inTypedef) {
259
195518ab62fc fix type gathering pattern match in generate_stub.pl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 255
diff changeset
50 if (/^typedef struct (\w+)/) {
194
081607dcf893 create generate_stub.pl
mir3636
parents:
diff changeset
51 $inTypedef = 1;
081607dcf893 create generate_stub.pl
mir3636
parents:
diff changeset
52 $name = $1;
081607dcf893 create generate_stub.pl
mir3636
parents:
diff changeset
53 $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
54 $var{$name} = {};
195518ab62fc fix type gathering pattern match in generate_stub.pl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 255
diff changeset
55 $code{$name} = {};
269
5170539348ec rename TaskManagerImpl.cbc
mir3636
parents: 268
diff changeset
56 } elsif (/^(\w+)(\*)+ create(\w+)\(/) {
249
afa1e02e4386 fix generate stub
mir3636
parents: 243
diff changeset
57 if (defined $interface) {
afa1e02e4386 fix generate stub
mir3636
parents: 243
diff changeset
58 die "duplicate interface $interface\n";
afa1e02e4386 fix generate stub
mir3636
parents: 243
diff changeset
59 }
afa1e02e4386 fix generate stub
mir3636
parents: 243
diff changeset
60 $interface = $1;
269
5170539348ec rename TaskManagerImpl.cbc
mir3636
parents: 268
diff changeset
61 $implementation = $3;
250
8a8963ce9858 fix generate_stub
mir3636
parents: 249
diff changeset
62 if ( -f "$interface.cbc") {
8a8963ce9858 fix generate_stub
mir3636
parents: 249
diff changeset
63 &getDataGear("$interface.cbc");
8a8963ce9858 fix generate_stub
mir3636
parents: 249
diff changeset
64 }
226
68c03e7057d9 get arg
mir3636
parents: 201
diff changeset
65 }
194
081607dcf893 create generate_stub.pl
mir3636
parents:
diff changeset
66 next;
081607dcf893 create generate_stub.pl
mir3636
parents:
diff changeset
67 }
249
afa1e02e4386 fix generate stub
mir3636
parents: 243
diff changeset
68 # gather type name and type
194
081607dcf893 create generate_stub.pl
mir3636
parents:
diff changeset
69 $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
70 if (/^\s*(.*)\s+(\w+);$/ ) {
280
2c2e4e597eb0 generate no compile errors
mir3636
parents: 278
diff changeset
71 my $ttype = $1;
2c2e4e597eb0 generate no compile errors
mir3636
parents: 278
diff changeset
72 my $tname = $2;
2c2e4e597eb0 generate no compile errors
mir3636
parents: 278
diff changeset
73 if ($ttype =~ /^(union|struct) (\w+)/) {
2c2e4e597eb0 generate no compile errors
mir3636
parents: 278
diff changeset
74 $ttype = $2;
2c2e4e597eb0 generate no compile errors
mir3636
parents: 278
diff changeset
75 }
2c2e4e597eb0 generate no compile errors
mir3636
parents: 278
diff changeset
76 $var{$name}->{$tname} = $ttype;
250
8a8963ce9858 fix generate_stub
mir3636
parents: 249
diff changeset
77 } elsif (/\_\_code (\w+)\(/) {
259
195518ab62fc fix type gathering pattern match in generate_stub.pl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 255
diff changeset
78 $code{$name}->{$1} = 1;
250
8a8963ce9858 fix generate_stub
mir3636
parents: 249
diff changeset
79 }
194
081607dcf893 create generate_stub.pl
mir3636
parents:
diff changeset
80 if (/^}/) {
081607dcf893 create generate_stub.pl
mir3636
parents:
diff changeset
81 $inTypedef = 0;
081607dcf893 create generate_stub.pl
mir3636
parents:
diff changeset
82 }
081607dcf893 create generate_stub.pl
mir3636
parents:
diff changeset
83 }
081607dcf893 create generate_stub.pl
mir3636
parents:
diff changeset
84 }
081607dcf893 create generate_stub.pl
mir3636
parents:
diff changeset
85
250
8a8963ce9858 fix generate_stub
mir3636
parents: 249
diff changeset
86 sub generateStub {
251
0ab52d6e2fd9 fix sub generateStub
mir3636
parents: 250
diff changeset
87 my($fd,$prevCodeGearName,$dataGearName) = @_;
274
d14eb393023d fix generate_stub
mir3636
parents: 269
diff changeset
88 print $fd "__code ", $prevCodeGearName ,"_stub(struct Context* context) {\n";
251
0ab52d6e2fd9 fix sub generateStub
mir3636
parents: 250
diff changeset
89 print $fd $dataGearName;
250
8a8963ce9858 fix generate_stub
mir3636
parents: 249
diff changeset
90 print $fd "\n} \n\n";
251
0ab52d6e2fd9 fix sub generateStub
mir3636
parents: 250
diff changeset
91 return 1;
250
8a8963ce9858 fix generate_stub
mir3636
parents: 249
diff changeset
92 }
8a8963ce9858 fix generate_stub
mir3636
parents: 249
diff changeset
93
253
ebc13549394c generate stubArgs
mir3636
parents: 252
diff changeset
94 sub generateStubArgs {
260
6b5444bbea8a generated stub no comiple errors
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 259
diff changeset
95 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
96 my $varname1 = $output?"O_$varName":$varName;
6b5444bbea8a generated stub no comiple errors
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 259
diff changeset
97 for my $n ( @{$dataGearVar{$codeGearName}} ) {
6b5444bbea8a generated stub no comiple errors
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 259
diff changeset
98 # we already have it
6b5444bbea8a generated stub no comiple errors
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 259
diff changeset
99 return 0 if ( $n eq $varname1);
6b5444bbea8a generated stub no comiple errors
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 259
diff changeset
100 }
6b5444bbea8a generated stub no comiple errors
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 259
diff changeset
101 push @{$dataGearVar{$codeGearName}}, $varname1;
6b5444bbea8a generated stub no comiple errors
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 259
diff changeset
102 if ($typeName eq $implementation) {
6b5444bbea8a generated stub no comiple errors
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 259
diff changeset
103 # get implementation
258
4fe19a06d666 generate next args
mir3636
parents: 255
diff changeset
104 $dataGearName{$codeGearName} .= "\t$typeName* $varName = ($typeName*)GearImpl(context, $interface, $varName);\n";
253
ebc13549394c generate stubArgs
mir3636
parents: 252
diff changeset
105 } else {
259
195518ab62fc fix type gathering pattern match in generate_stub.pl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 255
diff changeset
106 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
107 # input data gear field
253
ebc13549394c generate stubArgs
mir3636
parents: 252
diff changeset
108 if ($varName eq $ivar) {
280
2c2e4e597eb0 generate no compile errors
mir3636
parents: 278
diff changeset
109 if ($typeName eq $var{$interface}->{$ivar}) {
2c2e4e597eb0 generate no compile errors
mir3636
parents: 278
diff changeset
110 if ($output) {
2c2e4e597eb0 generate no compile errors
mir3636
parents: 278
diff changeset
111 $dataGearName{$codeGearName} .= "\t$typeName** O_$varName = &Gearef(context, $interface)->$varName;\n";
2c2e4e597eb0 generate no compile errors
mir3636
parents: 278
diff changeset
112 $outputVar{$codeGearName} .= "\t$typeName* $varName;\n";
2c2e4e597eb0 generate no compile errors
mir3636
parents: 278
diff changeset
113 return 1;
2c2e4e597eb0 generate no compile errors
mir3636
parents: 278
diff changeset
114 }
2c2e4e597eb0 generate no compile errors
mir3636
parents: 278
diff changeset
115
2c2e4e597eb0 generate no compile errors
mir3636
parents: 278
diff changeset
116 $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
117 return 1;
6b5444bbea8a generated stub no comiple errors
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 259
diff changeset
118 }
253
ebc13549394c generate stubArgs
mir3636
parents: 252
diff changeset
119 }
ebc13549394c generate stubArgs
mir3636
parents: 252
diff changeset
120 }
259
195518ab62fc fix type gathering pattern match in generate_stub.pl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 255
diff changeset
121 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
122 if ($varName eq $cName) {
260
6b5444bbea8a generated stub no comiple errors
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 259
diff changeset
123 # 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
124 $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
125 return 1;
253
ebc13549394c generate stubArgs
mir3636
parents: 252
diff changeset
126 }
ebc13549394c generate stubArgs
mir3636
parents: 252
diff changeset
127 }
260
6b5444bbea8a generated stub no comiple errors
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 259
diff changeset
128 # global variable case
268
378ce6f74f4b fix generate_stub
mir3636
parents: 262
diff changeset
129 $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
130 return 1;
253
ebc13549394c generate stubArgs
mir3636
parents: 252
diff changeset
131 }
ebc13549394c generate stubArgs
mir3636
parents: 252
diff changeset
132 }
ebc13549394c generate stubArgs
mir3636
parents: 252
diff changeset
133
194
081607dcf893 create generate_stub.pl
mir3636
parents:
diff changeset
134 sub generateDataGear {
249
afa1e02e4386 fix generate stub
mir3636
parents: 243
diff changeset
135 my ($filename) = @_;
afa1e02e4386 fix generate stub
mir3636
parents: 243
diff changeset
136 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
137
edb3aff688d0 fix generator CLI
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 253
diff changeset
138 my $fn;
edb3aff688d0 fix generator CLI
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 253
diff changeset
139 if ($opt_o) {
edb3aff688d0 fix generator CLI
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 253
diff changeset
140 $fn = $opt_o;
edb3aff688d0 fix generator CLI
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 253
diff changeset
141 } else {
edb3aff688d0 fix generator CLI
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 253
diff changeset
142 my $fn1 = $filename;
edb3aff688d0 fix generator CLI
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 253
diff changeset
143 $fn1 =~ s/\.cbc/.c/;
edb3aff688d0 fix generator CLI
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 253
diff changeset
144 my $i = 1;
255
79bbe2c63fb0 cmake generate c from cbc
mir3636
parents: 254
diff changeset
145 $fn = "$dir/$fn1";
254
edb3aff688d0 fix generator CLI
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 253
diff changeset
146 while ( -f $fn) {
255
79bbe2c63fb0 cmake generate c from cbc
mir3636
parents: 254
diff changeset
147 $fn = "$dir/$fn1.$i";
254
edb3aff688d0 fix generator CLI
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 253
diff changeset
148 $i++;
edb3aff688d0 fix generator CLI
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 253
diff changeset
149 }
250
8a8963ce9858 fix generate_stub
mir3636
parents: 249
diff changeset
150 }
259
195518ab62fc fix type gathering pattern match in generate_stub.pl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 255
diff changeset
151 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
152 if (! -d $1) {
195518ab62fc fix type gathering pattern match in generate_stub.pl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 255
diff changeset
153 mkdir $1;
195518ab62fc fix type gathering pattern match in generate_stub.pl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 255
diff changeset
154 }
195518ab62fc fix type gathering pattern match in generate_stub.pl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 255
diff changeset
155 }
249
afa1e02e4386 fix generate stub
mir3636
parents: 243
diff changeset
156 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
157
249
afa1e02e4386 fix generate stub
mir3636
parents: 243
diff changeset
158 my $prevCodeGearName;
250
8a8963ce9858 fix generate_stub
mir3636
parents: 249
diff changeset
159 my $inTypedef = 0;
278
23767f714f4a fix generate_stub
mir3636
parents: 274
diff changeset
160 my $inStub = 0;
250
8a8963ce9858 fix generate_stub
mir3636
parents: 249
diff changeset
161 my %stub;
251
0ab52d6e2fd9 fix sub generateStub
mir3636
parents: 250
diff changeset
162 my $codeGearName;
254
edb3aff688d0 fix generator CLI
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 253
diff changeset
163
249
afa1e02e4386 fix generate stub
mir3636
parents: 243
diff changeset
164 while (<$in>) {
278
23767f714f4a fix generate_stub
mir3636
parents: 274
diff changeset
165 if (! $inTypedef && ! $inStub) {
249
afa1e02e4386 fix generate stub
mir3636
parents: 243
diff changeset
166 if (/^typedef struct (\w+) {/) {
afa1e02e4386 fix generate stub
mir3636
parents: 243
diff changeset
167 $inTypedef = 1;
253
ebc13549394c generate stubArgs
mir3636
parents: 252
diff changeset
168 } elsif (/^\_\_code (\w+)\((.*)\)(.*)/) {
251
0ab52d6e2fd9 fix sub generateStub
mir3636
parents: 250
diff changeset
169 $codeGearName = $1;
253
ebc13549394c generate stubArgs
mir3636
parents: 252
diff changeset
170 my $args = $2;
ebc13549394c generate stubArgs
mir3636
parents: 252
diff changeset
171 my $tail = $3;
250
8a8963ce9858 fix generate_stub
mir3636
parents: 249
diff changeset
172 if ($codeGearName =~ /_stub$/) {
262
2c56a9536c0d add comments
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 261
diff changeset
173 # don't touch already existing stub
278
23767f714f4a fix generate_stub
mir3636
parents: 274
diff changeset
174 $inStub = 1;
250
8a8963ce9858 fix generate_stub
mir3636
parents: 249
diff changeset
175 $stub{$codeGearName} = 1;
8a8963ce9858 fix generate_stub
mir3636
parents: 249
diff changeset
176 print $fd $_;
8a8963ce9858 fix generate_stub
mir3636
parents: 249
diff changeset
177 next;
8a8963ce9858 fix generate_stub
mir3636
parents: 249
diff changeset
178 }
249
afa1e02e4386 fix generate stub
mir3636
parents: 243
diff changeset
179 if (defined $prevCodeGearName) {
262
2c56a9536c0d add comments
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 261
diff changeset
180 # stub is generated just before next CodeGear
250
8a8963ce9858 fix generate_stub
mir3636
parents: 249
diff changeset
181 if (defined $stub{$prevCodeGearName."_stub"}) {
8a8963ce9858 fix generate_stub
mir3636
parents: 249
diff changeset
182 undef $prevCodeGearName;
278
23767f714f4a fix generate_stub
mir3636
parents: 274
diff changeset
183 } else {
23767f714f4a fix generate_stub
mir3636
parents: 274
diff changeset
184 &generateStub($fd,$prevCodeGearName,$dataGearName{$prevCodeGearName});
23767f714f4a fix generate_stub
mir3636
parents: 274
diff changeset
185 $stub{$prevCodeGearName."_stub"} = 1;
250
8a8963ce9858 fix generate_stub
mir3636
parents: 249
diff changeset
186 }
249
afa1e02e4386 fix generate stub
mir3636
parents: 243
diff changeset
187 }
262
2c56a9536c0d add comments
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 261
diff changeset
188 # analyzing CodeGear argument
2c56a9536c0d add comments
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 261
diff changeset
189 # 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
190 # and passed to the CodeGear
2c56a9536c0d add comments
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 261
diff changeset
191 # struct Implementaion needs special handling
2c56a9536c0d add comments
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 261
diff changeset
192 # __code next(...) ---> enum Code next
253
ebc13549394c generate stubArgs
mir3636
parents: 252
diff changeset
193 $prevCodeGearName = $codeGearName;
ebc13549394c generate stubArgs
mir3636
parents: 252
diff changeset
194 $dataGearVar{$codeGearName} = [];
260
6b5444bbea8a generated stub no comiple errors
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 259
diff changeset
195 $outputVar{$codeGearName} = "";
6b5444bbea8a generated stub no comiple errors
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 259
diff changeset
196 $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
197 my $newArgs = "struct Context *context,";
253
ebc13549394c generate stubArgs
mir3636
parents: 252
diff changeset
198 while($args) {
ebc13549394c generate stubArgs
mir3636
parents: 252
diff changeset
199 if ($args =~ s/(^\s*,\s*)//) {
ebc13549394c generate stubArgs
mir3636
parents: 252
diff changeset
200 $newArgs .= $1;
ebc13549394c generate stubArgs
mir3636
parents: 252
diff changeset
201 }
262
2c56a9536c0d add comments
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 261
diff changeset
202 # continuation case
280
2c2e4e597eb0 generate no compile errors
mir3636
parents: 278
diff changeset
203 if ($args =~ s/^(\s)*\_\_code\s+(\w+)\(([^)]*)\)//) {
2c2e4e597eb0 generate no compile errors
mir3636
parents: 278
diff changeset
204 my $next = $2;
2c2e4e597eb0 generate no compile errors
mir3636
parents: 278
diff changeset
205 my @args = split(/,/,$3);
260
6b5444bbea8a generated stub no comiple errors
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 259
diff changeset
206 if ( &generateStubArgs($codeGearName, $next, "Code", $next, $interface,0) ) {
6b5444bbea8a generated stub no comiple errors
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 259
diff changeset
207 $newArgs .= "enum Code $next";
258
4fe19a06d666 generate next args
mir3636
parents: 255
diff changeset
208 }
262
2c56a9536c0d add comments
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 261
diff changeset
209 # analyze continuation arguments
2c56a9536c0d add comments
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 261
diff changeset
210 # 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
211 # output arguments are put into the Interface DataGear just before the goto
253
ebc13549394c generate stubArgs
mir3636
parents: 252
diff changeset
212 for my $arg (@args) {
ebc13549394c generate stubArgs
mir3636
parents: 252
diff changeset
213 $arg =~ s/^\s*//;
260
6b5444bbea8a generated stub no comiple errors
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 259
diff changeset
214 last if ($arg =~ /\.\.\./);
253
ebc13549394c generate stubArgs
mir3636
parents: 252
diff changeset
215 $arg =~ s/^(struct|union) (\w+)(\*)+\s(\w+)//;
ebc13549394c generate stubArgs
mir3636
parents: 252
diff changeset
216 my $structType = $1;
ebc13549394c generate stubArgs
mir3636
parents: 252
diff changeset
217 my $typeName = $2;
ebc13549394c generate stubArgs
mir3636
parents: 252
diff changeset
218 my $varName = $4;
ebc13549394c generate stubArgs
mir3636
parents: 252
diff changeset
219 my $typeField = lcfirst($typeName);
260
6b5444bbea8a generated stub no comiple errors
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 259
diff changeset
220 push(@{$outputArgs{$codeGearName}->{$next}}, $varName);
6b5444bbea8a generated stub no comiple errors
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 259
diff changeset
221 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
222 $newArgs .= ",$structType $typeName **O_$varName";
6b5444bbea8a generated stub no comiple errors
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 259
diff changeset
223 }
253
ebc13549394c generate stubArgs
mir3636
parents: 252
diff changeset
224 }
ebc13549394c generate stubArgs
mir3636
parents: 252
diff changeset
225 } elsif ($args =~ s/^(struct|union) (\w+)(\*)+\s(\w+)//) {
ebc13549394c generate stubArgs
mir3636
parents: 252
diff changeset
226 my $structType = $1;
ebc13549394c generate stubArgs
mir3636
parents: 252
diff changeset
227 my $typeName = $2;
ebc13549394c generate stubArgs
mir3636
parents: 252
diff changeset
228 my $varName = $4;
ebc13549394c generate stubArgs
mir3636
parents: 252
diff changeset
229 my $typeField = lcfirst($typeName);
260
6b5444bbea8a generated stub no comiple errors
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 259
diff changeset
230 $newArgs .= $&; # assuming no duplicate
6b5444bbea8a generated stub no comiple errors
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 259
diff changeset
231 &generateStubArgs($codeGearName, $varName, $typeName, $typeField, $interface,0);
255
79bbe2c63fb0 cmake generate c from cbc
mir3636
parents: 254
diff changeset
232 } elsif ($args =~ s/(.*,)//) {
79bbe2c63fb0 cmake generate c from cbc
mir3636
parents: 254
diff changeset
233 $newArgs .= $1;
79bbe2c63fb0 cmake generate c from cbc
mir3636
parents: 254
diff changeset
234 } else {
79bbe2c63fb0 cmake generate c from cbc
mir3636
parents: 254
diff changeset
235 $newArgs .= $args;
79bbe2c63fb0 cmake generate c from cbc
mir3636
parents: 254
diff changeset
236 last;
253
ebc13549394c generate stubArgs
mir3636
parents: 252
diff changeset
237 }
ebc13549394c generate stubArgs
mir3636
parents: 252
diff changeset
238 }
262
2c56a9536c0d add comments
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 261
diff changeset
239 # generate goto statement from stub to the CodeGear in the buffer
253
ebc13549394c generate stubArgs
mir3636
parents: 252
diff changeset
240 $dataGearName{$codeGearName} .= "\tgoto $codeGearName(context";
ebc13549394c generate stubArgs
mir3636
parents: 252
diff changeset
241 for my $arg ( @{$dataGearVar{$codeGearName}}) {
ebc13549394c generate stubArgs
mir3636
parents: 252
diff changeset
242 $dataGearName{$codeGearName} .= ", $arg";
ebc13549394c generate stubArgs
mir3636
parents: 252
diff changeset
243 }
ebc13549394c generate stubArgs
mir3636
parents: 252
diff changeset
244 $dataGearName{$codeGearName} .= ");";
262
2c56a9536c0d add comments
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 261
diff changeset
245 # generate CodeGear header with new arguments
253
ebc13549394c generate stubArgs
mir3636
parents: 252
diff changeset
246 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
247 if ($outputVar{$codeGearName} ne "") {
6b5444bbea8a generated stub no comiple errors
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 259
diff changeset
248 print $fd $outputVar{$codeGearName};
6b5444bbea8a generated stub no comiple errors
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 259
diff changeset
249 }
250
8a8963ce9858 fix generate_stub
mir3636
parents: 249
diff changeset
250 next;
260
6b5444bbea8a generated stub no comiple errors
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 259
diff changeset
251 } elsif (/^(.*)goto (\w+)\((.*)\);/) {
278
23767f714f4a fix generate_stub
mir3636
parents: 274
diff changeset
252 # handling goto statement
262
2c56a9536c0d add comments
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 261
diff changeset
253 # 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
254 my $prev = $1;
260
6b5444bbea8a generated stub no comiple errors
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 259
diff changeset
255 my $next = $2;
6b5444bbea8a generated stub no comiple errors
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 259
diff changeset
256 my @args = split(/,/,$3);
278
23767f714f4a fix generate_stub
mir3636
parents: 274
diff changeset
257 if (defined $code{$interface}->{$next}) {
23767f714f4a fix generate_stub
mir3636
parents: 274
diff changeset
258 # write continuation's arguments into the interface arguments
23767f714f4a fix generate_stub
mir3636
parents: 274
diff changeset
259 # we may need a commit for a shared DataGear
23767f714f4a fix generate_stub
mir3636
parents: 274
diff changeset
260 for my $arg ( @{$outputArgs{$codeGearName}->{$next}} ) {
23767f714f4a fix generate_stub
mir3636
parents: 274
diff changeset
261 my $v = shift(@args);
23767f714f4a fix generate_stub
mir3636
parents: 274
diff changeset
262 print $fd "\t*O_$arg = $v;\n";
23767f714f4a fix generate_stub
mir3636
parents: 274
diff changeset
263 }
23767f714f4a fix generate_stub
mir3636
parents: 274
diff changeset
264 print $fd "${prev}goto meta(context, $next);\n";
23767f714f4a fix generate_stub
mir3636
parents: 274
diff changeset
265 next;
260
6b5444bbea8a generated stub no comiple errors
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 259
diff changeset
266 }
259
195518ab62fc fix type gathering pattern match in generate_stub.pl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 255
diff changeset
267 } else {
195518ab62fc fix type gathering pattern match in generate_stub.pl
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 255
diff changeset
268 s/new\s+(\w+)\(\)/\&ALLOCATE(context, \1)->\1/g; # replacing new
249
afa1e02e4386 fix generate stub
mir3636
parents: 243
diff changeset
269 }
afa1e02e4386 fix generate stub
mir3636
parents: 243
diff changeset
270 # 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
271 } elsif (/^}/) {
278
23767f714f4a fix generate_stub
mir3636
parents: 274
diff changeset
272 $inStub = 0;
249
afa1e02e4386 fix generate stub
mir3636
parents: 243
diff changeset
273 $inTypedef = 0;
afa1e02e4386 fix generate stub
mir3636
parents: 243
diff changeset
274 }
250
8a8963ce9858 fix generate_stub
mir3636
parents: 249
diff changeset
275 print $fd $_;
194
081607dcf893 create generate_stub.pl
mir3636
parents:
diff changeset
276 }
250
8a8963ce9858 fix generate_stub
mir3636
parents: 249
diff changeset
277 if (defined $prevCodeGearName) {
8a8963ce9858 fix generate_stub
mir3636
parents: 249
diff changeset
278 if (!defined $stub{$prevCodeGearName."_stub"}) {
251
0ab52d6e2fd9 fix sub generateStub
mir3636
parents: 250
diff changeset
279 $stub{$prevCodeGearName."_stub"} = &generateStub($fd,$prevCodeGearName,$dataGearName{$codeGearName});
250
8a8963ce9858 fix generate_stub
mir3636
parents: 249
diff changeset
280 }
228
55260ff44c8c generate stub
mir3636
parents: 226
diff changeset
281 }
194
081607dcf893 create generate_stub.pl
mir3636
parents:
diff changeset
282 }
081607dcf893 create generate_stub.pl
mir3636
parents:
diff changeset
283
081607dcf893 create generate_stub.pl
mir3636
parents:
diff changeset
284 # end