annotate src/gearsTools/generate_stub.pl @ 323:6d96bba13d5d

merged
author anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
date Fri, 07 Feb 2020 14:58:30 +0900
parents edc8e6c71dc6 42a37a8a02c9
children fde5f96c6ff1
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
44
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1 #!/usr/bin/perl
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
2
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
3 use strict;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
4 use Getopt::Std;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
5 use File::Path qw(make_path);
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
6
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
7 # interface.h
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
8 # typedef struct Worker {
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
9 # int id;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
10 # struct Context* contexts;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
11 # enum Code execute;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
12 # enum Code taskSend;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
13 # enum Code taskRecive;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
14 # enum Code shutdown;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
15 # struct Queue* tasks;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
16 # } Worker;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
17
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
18 our($opt_o,$opt_d,$opt_h);
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
19 getopts('o:d:h');
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
20
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
21 my $dir = ".";
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
22 if ($opt_d) {
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
23 $dir = $opt_d;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
24 if (! -d $dir) {
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
25 make_path $dir;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
26 }
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
27 }
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
28
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
29 for my $fn (@ARGV) {
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
30 next if ($fn !~ /\.cbc$/);
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
31 &getDataGear($fn);
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
32 &generateDataGear($fn);
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
33 }
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
34
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
35 my %var;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
36 my %code;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
37 my %dataGearVar;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
38 my %outputVar; # output var initializer
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
39 my %outputArgs; # continuation's output variables
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
40 my %dataGear;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
41 my %dataGearName;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
42 my %generic;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
43 my %dataGearVarType;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
44 my %codeGear;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
45 my $implementation;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
46 my $interface;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
47
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
48 # interface definision
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
49 #
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
50 # typedef struct Stack<Type, Impl>{
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
51 # Type* stack;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
52 # Type* data;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
53 # Type* data1;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
54 # __code whenEmpty(...);
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
55 # __code clear(Impl* stack,__code next(...));
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
56 # __code push(Impl* stack,Type* data, __code next(...));
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
57 # __code pop(Impl* stack, __code next(Type*, ...));
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
58 # __code pop2(Impl* stack, Type** data, Type** data1, __code next(Type**, Type**, ...));
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
59 # __code isEmpty(Impl* stack, __code next(...), __code whenEmpty(...));
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
60 # __code get(Impl* stack, Type** data, __code next(...));
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
61 # __code get2(Impl* stack,..., __code next(...));
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
62 # __code next(...);
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
63 # } Stack;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
64 #
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
65 # calling example
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
66 #
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
67 # goto nodeStack->push((union Data*)node, stackTest3);
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
68 #
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
69 # generated meta level code
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
70 #
52
214d21c891c7 rename to cbc
kono
parents: 46
diff changeset
71 # Gearef(cbc_context, Stack)->stack = (union Data*)nodeStack;
214d21c891c7 rename to cbc
kono
parents: 46
diff changeset
72 # Gearef(cbc_context, Stack)->data = (union Data*)node;
214d21c891c7 rename to cbc
kono
parents: 46
diff changeset
73 # Gearef(cbc_context, Stack)->next = C_stackTest3;
214d21c891c7 rename to cbc
kono
parents: 46
diff changeset
74 # goto meta(cbc_context, nodeStack->push);
44
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
75
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
76 sub getDataGear {
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
77 my ($filename) = @_;
249
42a37a8a02c9 impl described_data_gear mode
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 248
diff changeset
78 my ($codeGearName, $name, $inTypedef,$described_data_gear);
44
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
79 open my $fd,"<",$filename or die("can't open $filename $!");
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
80 while (<$fd>) {
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
81 if (! $inTypedef) {
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
82 if (/^typedef struct (\w+)\s*<(.*)>/) {
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
83 $inTypedef = 1;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
84 $name = $1;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
85 $dataGear{$name} = $_;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
86 $var{$name} = {};
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
87 $code{$name} = {};
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
88 $generic{$name} = \split(/,/,$2);
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
89 } elsif (/^typedef struct (\w+)/) {
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
90 $inTypedef = 1;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
91 $name = $1;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
92 $dataGear{$name} = $_;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
93 $var{$name} = {};
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
94 $code{$name} = {};
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
95 $generic{$name} = [];
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
96 } elsif (/^(\w+)(\*)+ create(\w+)\(/) {
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
97 if (defined $interface) {
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
98 die "duplicate interface $interface\n";
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
99 }
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
100 $interface = $1;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
101 $implementation = $3;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
102 if ( -f "$interface.cbc") {
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
103 &getDataGear("$interface.cbc");
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
104 }
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
105 } elsif(/^(.*)par goto (\w+)\((.*)\)/) {
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
106 my $codeGearName = $2;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
107 if ($filename =~ /^(.*)\/(.*)/) {
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
108 $codeGearName = "$1/$codeGearName";
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
109 }
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
110 if ( -f "$codeGearName.cbc") {
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
111 &getCodeGear("$codeGearName.cbc");
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
112 }
242
26be78edaf83 impl auto collection for data gears from interface
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 82
diff changeset
113 } elsif(/^#interface "(.*)"/) {
44
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
114 # use interface
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
115 my $interfaceHeader = $1;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
116 next if ($interfaceHeader =~ /context.h/);
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
117 if (-f $interfaceHeader) {
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
118 &getDataGear("$interfaceHeader");
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
119 &getCodeGear("$interfaceHeader");
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
120 }
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
121 } elsif (/^\_\_code (\w+)\((.*)\)(.*)/) {
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
122 my $codeGearName = $1;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
123 if ($filename =~ /^(.*)\/(.*)/) {
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
124 $codeGearName = "$1/$codeGearName";
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
125 }
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
126 if ( -f "$codeGearName.cbc") {
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
127 &getCodeGear("$codeGearName.cbc");
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
128 }
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
129 }
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
130 next;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
131 }
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
132 # gather type name and type
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
133 $dataGear{$name} .= $_;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
134 if (/^\s*(.*)\s+(\w+);$/ ) {
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
135 my $ttype = $1;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
136 my $tname = $2;
298
2e71e7776062 fix generate_stub
anatofuz
parents: 82
diff changeset
137 if ($ttype =~ /^(union|struct|const)?\s*(\w+)/) {
2e71e7776062 fix generate_stub
anatofuz
parents: 82
diff changeset
138 if ($1 ne 'const') {
2e71e7776062 fix generate_stub
anatofuz
parents: 82
diff changeset
139 $ttype = $2;
2e71e7776062 fix generate_stub
anatofuz
parents: 82
diff changeset
140 } else {
2e71e7776062 fix generate_stub
anatofuz
parents: 82
diff changeset
141 $ttype = "const $2";
2e71e7776062 fix generate_stub
anatofuz
parents: 82
diff changeset
142 }
44
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
143 }
249
42a37a8a02c9 impl described_data_gear mode
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 248
diff changeset
144 $described_data_gear = 1;
44
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
145 $var{$name}->{$tname} = $ttype;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
146 }
242
26be78edaf83 impl auto collection for data gears from interface
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 82
diff changeset
147 if (/__code (\w+)/) {
249
42a37a8a02c9 impl described_data_gear mode
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 248
diff changeset
148 next if $described_data_gear;
242
26be78edaf83 impl auto collection for data gears from interface
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 82
diff changeset
149 my $args = $';
247
63a65e3a5340 tweak_regex...
anatofuz
parents: 245
diff changeset
150 while ($args =~ /\s*(struct|union|const)?\s*([\w\[\]_]+)\*?\s*(\w+),?/g) {
242
26be78edaf83 impl auto collection for data gears from interface
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 82
diff changeset
151 #$args eq (Impl* vm, pde_t* pgdir, char* init, uint sz, __code next(...));
26be78edaf83 impl auto collection for data gears from interface
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 82
diff changeset
152 my $const_type = $1;
26be78edaf83 impl auto collection for data gears from interface
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 82
diff changeset
153 my $ttype = $2;
26be78edaf83 impl auto collection for data gears from interface
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 82
diff changeset
154 my $tname = $3;
26be78edaf83 impl auto collection for data gears from interface
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 82
diff changeset
155
248
96fd8e1db32f fix_gen_stub.pl
anatofuz
parents: 247
diff changeset
156 $ttype =~ s/(Impl|Isa|Type)/Data/;
242
26be78edaf83 impl auto collection for data gears from interface
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 82
diff changeset
157 if ($const_type eq 'const') {
26be78edaf83 impl auto collection for data gears from interface
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 82
diff changeset
158 $ttype = "const $ttype";
26be78edaf83 impl auto collection for data gears from interface
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 82
diff changeset
159 }
26be78edaf83 impl auto collection for data gears from interface
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 82
diff changeset
160 $var{$name}->{$tname} = $ttype;
26be78edaf83 impl auto collection for data gears from interface
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 82
diff changeset
161 }
26be78edaf83 impl auto collection for data gears from interface
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 82
diff changeset
162 }
44
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
163 if (/^}/) {
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
164 $inTypedef = 0;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
165 }
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
166 }
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
167
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
168 }
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
169
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
170 sub getCodeGear {
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
171 my ($filename) = @_;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
172 open my $fd,"<",$filename or die("can't open $filename $!");
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
173 my ($name,$impln);
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
174 while (<$fd>) {
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
175 if (/^(\w+)(\*)+ create(\w+)\(/) {
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
176 $name = $1;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
177 $impln = $3;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
178 } elsif(/^typedef struct (.*)<.*>\s*{/) {
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
179 $name = $1;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
180 }
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
181 if (defined $name) {
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
182 if (/^\s*\_\_code (\w+)\((.*)\);/) {
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
183 my $args = $2;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
184 my $method = $1;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
185 $code{$name}->{$method} = [];
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
186 while($args) {
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
187 # replace comma
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
188 $args =~ s/(^\s*,\s*)//;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
189 # continuation case
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
190 if ($args =~ s/^(\s)*\_\_code\s+(\w+)\(([^)]*)\)//) {
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
191 my $next = $2;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
192 my @args = split(/,/,$3);
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
193 push(@{$code{$name}->{$method}},"\_\_code $next");
298
2e71e7776062 fix generate_stub
anatofuz
parents: 82
diff changeset
194 } elsif ($args =~ s/^(struct|union|const)?\s*(\w+)(\**)\s+(\w+)//) {
44
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
195 my $structType = $1;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
196 my $typeName = $2;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
197 my $ptrType = $3;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
198 my $varName = $4;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
199 my $typeField = lcfirst($typeName);
298
2e71e7776062 fix generate_stub
anatofuz
parents: 82
diff changeset
200 if ($structType =~ /const/) {
2e71e7776062 fix generate_stub
anatofuz
parents: 82
diff changeset
201 $typeName = "$structType $typeName";
2e71e7776062 fix generate_stub
anatofuz
parents: 82
diff changeset
202 }
44
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
203 push(@{$code{$name}->{$method}},"$typeName$ptrType $varName");
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
204 } elsif ($args =~ s/(.*,)//) {
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
205 } else {
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
206 last;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
207 }
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
208 }
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
209 }
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
210 } elsif (/^\_\_code (\w+)\((.*)\)(.*)/) {
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
211 my $codeGearName = $1;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
212 my $args = $2;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
213 my $inputCount = 0;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
214 my $outputCount = 0;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
215 my $inputIncFlag = 1;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
216 while($args) {
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
217 if ($args =~ s/(^\s*,\s*)//) {
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
218 }
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
219 if ($args =~ s/^(\s)*\_\_code\s+(\w+)\((.*?)\)//) {
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
220 $codeGear{$codeGearName}->{"code"}->{$2} = "\_\_code";
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
221 $inputIncFlag = 0;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
222 my @outputs = split(/,/,$3);
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
223 for my $output (@outputs) {
298
2e71e7776062 fix generate_stub
anatofuz
parents: 82
diff changeset
224 if ($output =~ /\s*(struct|union|const)?\s*(\w+)(\*)?+\s(\w+)/) {
2e71e7776062 fix generate_stub
anatofuz
parents: 82
diff changeset
225 my $structType = $1;
44
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
226 my $type = $2;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
227 my $varName = $4;
298
2e71e7776062 fix generate_stub
anatofuz
parents: 82
diff changeset
228 if ($structType =~ /const/) {
2e71e7776062 fix generate_stub
anatofuz
parents: 82
diff changeset
229 $type = "$structType $type";
2e71e7776062 fix generate_stub
anatofuz
parents: 82
diff changeset
230 }
44
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
231 $codeGear{$codeGearName}->{"var"}->{$varName} = "$type $outputCount";
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
232 $outputCount++;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
233 }
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
234 }
298
2e71e7776062 fix generate_stub
anatofuz
parents: 82
diff changeset
235 } elsif ($args =~ s/^(struct|union|const)?\s*(\w+)(\*)?+\s(\w+)// && $inputIncFlag) {
2e71e7776062 fix generate_stub
anatofuz
parents: 82
diff changeset
236 my $structType = $1;
44
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
237 my $type = $2;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
238 my $varName = $4;
298
2e71e7776062 fix generate_stub
anatofuz
parents: 82
diff changeset
239 if ($structType =~ /const/) {
2e71e7776062 fix generate_stub
anatofuz
parents: 82
diff changeset
240 $type = "$structType $type";
2e71e7776062 fix generate_stub
anatofuz
parents: 82
diff changeset
241 }
44
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
242 $codeGear{$codeGearName}->{"var"}->{$varName} = "$type $inputCount";
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
243 $inputCount++;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
244 } elsif ($args =~ s/(.*,)//) {
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
245 } else {
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
246 last;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
247 }
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
248 }
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
249 $codeGear{$codeGearName}->{"input"} = $inputCount;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
250 $codeGear{$codeGearName}->{"output"} = $outputCount;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
251 }
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
252 }
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
253 }
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
254
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
255 sub generateStub {
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
256 my($fd,$prevCodeGearName,$dataGearName) = @_;
52
214d21c891c7 rename to cbc
kono
parents: 46
diff changeset
257 print $fd "__code ", $prevCodeGearName ,"_stub(struct Context* cbc_context) {\n";
44
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
258 print $fd $dataGearName;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
259 print $fd "\n} \n\n";
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
260 return 1;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
261 }
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
262
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
263 sub generateStubArgs {
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
264 my($codeGearName, $varName, $typeName, $ptrType, $typeField, $interface,$output) = @_;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
265 my $varname1 = $output?"O_$varName":$varName;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
266 for my $n ( @{$dataGearVar{$codeGearName}} ) {
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
267 # we already have it
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
268 return 0 if ( $n eq $varname1);
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
269 }
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
270 push @{$dataGearVar{$codeGearName}}, $varname1;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
271 push @{$dataGearVarType{$codeGearName}}, $typeName;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
272 if ($typeName eq $implementation) {
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
273 # get implementation
52
214d21c891c7 rename to cbc
kono
parents: 46
diff changeset
274 $dataGearName{$codeGearName} .= "\t$typeName* $varName = ($typeName*)GearImpl(cbc_context, $interface, $varName);\n";
44
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
275 } else {
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
276 # interface var
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
277 for my $ivar (keys %{$var{$interface}}) {
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
278 # input data gear field
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
279 if ($varName eq $ivar) {
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
280 if ($typeName eq $var{$interface}->{$ivar}) {
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
281 if ($output) {
52
214d21c891c7 rename to cbc
kono
parents: 46
diff changeset
282 $dataGearName{$codeGearName} .= "\t$typeName$ptrType* O_$varName = &Gearef(cbc_context, $interface)->$varName;\n";
82
d419660ad71d tweak generate_stub.pl
anatofuz
parents: 52
diff changeset
283 $outputVar{$codeGearName} .= "\t$typeName$ptrType $varName __attribute__((unused)) = *O_$varName;\n";
44
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
284 return 1;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
285 }
52
214d21c891c7 rename to cbc
kono
parents: 46
diff changeset
286 $dataGearName{$codeGearName} .= "\t$typeName$ptrType $varName = Gearef(cbc_context, $interface)->$varName;\n";
44
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
287 return 1;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
288 }
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
289 }
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
290 }
298
2e71e7776062 fix generate_stub
anatofuz
parents: 82
diff changeset
291
44
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
292 # interface continuation
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
293 for my $cName (keys %{$code{$interface}}) {
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
294 if ($varName eq $cName) {
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
295 # continuation field
52
214d21c891c7 rename to cbc
kono
parents: 46
diff changeset
296 $dataGearName{$codeGearName} .= "\tenum Code $varName = Gearef(cbc_context, $interface)->$varName;\n";
44
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
297 return 1;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
298 }
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
299 }
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
300 # par goto var
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
301 for my $var (keys %{$codeGear{$codeGearName}->{"var"}}) {
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
302 # input data gear field
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
303 if ($varName eq $var) {
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
304 my ($type, $count) = split(/\s/, $codeGear{$codeGearName}->{"var"}->{$var});
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
305 if ($typeName eq $type) {
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
306 if ($output) {
52
214d21c891c7 rename to cbc
kono
parents: 46
diff changeset
307 $dataGearName{$codeGearName} .= "\t$typeName$ptrType* O_$varName = ($typeName $ptrType*)&cbc_context->data[cbc_context->odg + $count];\n";
44
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
308 $outputVar{$codeGearName} .= "\t$typeName$ptrType $varName = *O_$varName;\n";
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
309 return 1;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
310 }
52
214d21c891c7 rename to cbc
kono
parents: 46
diff changeset
311 $dataGearName{$codeGearName} .= "\t$typeName$ptrType $varName = &cbc_context->data[cbc_context->idg + $count]->$typeName;\n";
44
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
312 return 1;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
313 }
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
314 }
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
315 }
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
316
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
317 # par goto continuation
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
318 for my $cName (keys %{$codeGear{$codeGearName}->{"code"}}) {
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
319 if ($varName eq $cName) {
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
320 # continuation field
52
214d21c891c7 rename to cbc
kono
parents: 46
diff changeset
321 $dataGearName{$codeGearName} .= "\tenum Code $varName = cbc_context->next;\n";
44
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
322 return 1;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
323 }
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
324 }
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
325
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
326 # par goto continuation
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
327 # global or local variable case
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
328 if ($typeName eq "Code") {
52
214d21c891c7 rename to cbc
kono
parents: 46
diff changeset
329 $dataGearName{$codeGearName} .= "\tenum $typeName$ptrType $varName = Gearef(cbc_context, $interface)->$varName;\n";
44
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
330 return 1;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
331 }
52
214d21c891c7 rename to cbc
kono
parents: 46
diff changeset
332 $dataGearName{$codeGearName} .= "\t$typeName$ptrType $varName = Gearef(cbc_context, $typeName);\n";
44
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
333 return 1;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
334 }
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
335 }
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
336
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
337 sub generateDataGear {
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
338 my ($filename) = @_;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
339 open my $in,"<",$filename or die("can't open $filename $!");
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
340
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
341 my $fn;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
342 if ($opt_o) {
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
343 $fn = $opt_o;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
344 } else {
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
345 my $fn1 = $filename;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
346 $fn1 =~ s/\.cbc/.c/;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
347 my $i = 1;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
348 $fn = "$dir/$fn1";
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
349 while ( -f $fn) {
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
350 $fn = "$dir/$fn1.$i";
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
351 $i++;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
352 }
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
353 }
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
354 if ( $fn =~ m=(.*)/[^/]+$= ) {
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
355 if (! -d $1) {
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
356 make_path $1;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
357 }
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
358 }
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
359 open my $fd,">",$fn or die("can't write $fn $!");
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
360
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
361 my $prevCodeGearName;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
362 my $inTypedef = 0;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
363 my $inStub = 0;
45
5f19e9554c30 supless warning
k.fukuda
parents:
diff changeset
364 my $hasParGoto = 0;
44
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
365 my $inMain = 0 ;
52
214d21c891c7 rename to cbc
kono
parents: 46
diff changeset
366 my $inCode = 0 ;
44
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
367 my %stub;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
368 my $codeGearName;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
369 my %localVarType;
52
214d21c891c7 rename to cbc
kono
parents: 46
diff changeset
370 my %localCode;
44
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
371
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
372 while (<$in>) {
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
373 if (! $inTypedef && ! $inStub && ! $inMain) {
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
374 if (/^typedef struct (\w+) \{/) {
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
375 $inTypedef = 1;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
376 } elsif (/^int main\((.*)\) \{/) {
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
377 $inMain = 1;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
378 } elsif(/^#interface "(.*)"/) {
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
379 my $interfaceHeader = $1;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
380 # #interface not write
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
381 next unless ($interfaceHeader =~ /context.h/);
52
214d21c891c7 rename to cbc
kono
parents: 46
diff changeset
382 } elsif (/^\s\s*_\_code (\w+)\((.*)\)(.*)/) {
214d21c891c7 rename to cbc
kono
parents: 46
diff changeset
383 $localCode{$1} = 1;
214d21c891c7 rename to cbc
kono
parents: 46
diff changeset
384 } elsif (/^\s\s*_\_code *\(\s*\*\s*(\w+)\)\((.*)\)(.*)/) {
214d21c891c7 rename to cbc
kono
parents: 46
diff changeset
385 $localCode{$1} = 1;
44
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
386 } elsif (/^\_\_code (\w+)\((.*)\)(.*)/) {
52
214d21c891c7 rename to cbc
kono
parents: 46
diff changeset
387 $inCode = 1;
214d21c891c7 rename to cbc
kono
parents: 46
diff changeset
388 %localCode = {};
44
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
389 %localVarType = {};
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
390 $codeGearName = $1;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
391 my $args = $2;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
392 my $tail = $3;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
393 if ($codeGearName =~ /_stub$/) {
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
394 # don't touch already existing stub
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
395 $inStub = 1;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
396 $stub{$codeGearName} = 1;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
397 print $fd $_;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
398 next;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
399 }
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
400 if (defined $prevCodeGearName) {
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
401 # stub is generated just before next CodeGear
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
402 if (defined $stub{$prevCodeGearName."_stub"}) {
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
403 undef $prevCodeGearName;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
404 } else {
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
405 &generateStub($fd,$prevCodeGearName,$dataGearName{$prevCodeGearName});
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
406 $stub{$prevCodeGearName."_stub"} = 1;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
407 }
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
408 }
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
409 # analyzing CodeGear argument
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
410 # these arguments are extract from current context's arugment DataGear Interface
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
411 # and passed to the CodeGear
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
412 # struct Implementaion needs special handling
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
413 # __code next(...) ---> enum Code next
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
414 $prevCodeGearName = $codeGearName;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
415 $dataGearVar{$codeGearName} = [];
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
416 $outputVar{$codeGearName} = "";
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
417 $outputArgs{$codeGearName} = {};
52
214d21c891c7 rename to cbc
kono
parents: 46
diff changeset
418 my $newArgs = "struct Context *cbc_context,";
214d21c891c7 rename to cbc
kono
parents: 46
diff changeset
419 if ($args=~/^struct Context\s*\*\s*cbc_context/) {
44
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
420 $newArgs = "";
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
421 }
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
422 if (!$args){
52
214d21c891c7 rename to cbc
kono
parents: 46
diff changeset
423 $newArgs = "struct Context *cbc_context";
44
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
424 }
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
425 while($args) {
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
426 if ($args =~ s/(^\s*,\s*)//) {
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
427 $newArgs .= $1;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
428 }
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
429 # continuation case
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
430 if ($args =~ s/^(\s)*\_\_code\s+(\w+)\(([^)]*)\)//) {
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
431 my $next = $2;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
432 my @args = split(/,/,$3);
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
433 if (&generateStubArgs($codeGearName, $next, "Code", "", $next, $interface,0) ) {
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
434 $newArgs .= "enum Code $next";
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
435 }
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
436 # analyze continuation arguments
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
437 # output arguments are defined in the Interface take the pointer of these
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
438 # output arguments are put into the Interface DataGear just before the goto
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
439 for my $arg (@args) {
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
440 $arg =~ s/^\s*//;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
441 last if ($arg =~ /\.\.\./);
298
2e71e7776062 fix generate_stub
anatofuz
parents: 82
diff changeset
442 $arg =~ s/^(struct|union|const)?\s*(\w+)(\**)\s(\w+)//;
44
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
443 my $structType = $1;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
444 my $typeName = $2;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
445 my $ptrType = $3;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
446 my $varName = $4;
298
2e71e7776062 fix generate_stub
anatofuz
parents: 82
diff changeset
447 if ($structType =~ /const/) {
2e71e7776062 fix generate_stub
anatofuz
parents: 82
diff changeset
448 $typeName = "$structType $typeName";
2e71e7776062 fix generate_stub
anatofuz
parents: 82
diff changeset
449 }
44
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
450 my $typeField = lcfirst($typeName);
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
451 push(@{$outputArgs{$codeGearName}->{$next}}, $varName);
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
452 if (&generateStubArgs($codeGearName, $varName, $typeName, $ptrType, $typeField, $interface,1)) {
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
453 $newArgs .= ",$structType $typeName **O_$varName";
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
454 }
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
455 }
298
2e71e7776062 fix generate_stub
anatofuz
parents: 82
diff changeset
456 } elsif ($args =~ s/^(struct|union|const)?\s*(\w+)(\**)\s(\w+)//) {
44
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
457 my $structType = $1;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
458 my $typeName = $2;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
459 my $ptrType = $3;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
460 my $varName = $4;
298
2e71e7776062 fix generate_stub
anatofuz
parents: 82
diff changeset
461 $newArgs .= $&; # assuming no duplicate
2e71e7776062 fix generate_stub
anatofuz
parents: 82
diff changeset
462 if ($structType =~ /const/) {
2e71e7776062 fix generate_stub
anatofuz
parents: 82
diff changeset
463 $typeName = "$structType $typeName";
2e71e7776062 fix generate_stub
anatofuz
parents: 82
diff changeset
464 }
44
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
465 my $typeField = lcfirst($typeName);
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
466 &generateStubArgs($codeGearName, $varName, $typeName, $ptrType, $typeField, $interface,0);
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
467 } elsif ($args =~ s/(.*,)//) {
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
468 $newArgs .= $1;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
469 } else {
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
470 $newArgs .= $args;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
471 last;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
472 }
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
473 }
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
474 # generate goto statement from stub to the CodeGear in the buffer
52
214d21c891c7 rename to cbc
kono
parents: 46
diff changeset
475 $dataGearName{$codeGearName} .= "\tgoto $codeGearName(cbc_context";
44
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
476 for my $arg ( @{$dataGearVar{$codeGearName}}) {
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
477 $dataGearName{$codeGearName} .= ", $arg";
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
478 }
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
479 $dataGearName{$codeGearName} .= ");";
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
480 # generate CodeGear header with new arguments
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
481 print $fd "__code $codeGearName($newArgs)$tail\n";
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
482 if ($outputVar{$codeGearName} ne "") {
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
483 # output data var can be use before write
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
484 # it should be initialze by gearef
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
485 print $fd $outputVar{$codeGearName};
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
486 }
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
487 next;
52
214d21c891c7 rename to cbc
kono
parents: 46
diff changeset
488 } elsif (! $inCode) {
82
d419660ad71d tweak generate_stub.pl
anatofuz
parents: 52
diff changeset
489 s/new\s+(\w+)\(\)/\&ALLOCATE(cbc_context, \1)->\1/g; # replacing new
52
214d21c891c7 rename to cbc
kono
parents: 46
diff changeset
490 print $fd $_;
214d21c891c7 rename to cbc
kono
parents: 46
diff changeset
491 next;
44
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
492 } elsif (/^(.*)goto (\w+)\-\>(\w+)\((.*)\);/) {
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
493 # handling goto statement
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
494 # convert it to the meta call form with two arugments, that is context and enum Code
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
495 my $prev = $1;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
496 my $next = $2;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
497 my $method = $3;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
498 my $tmpArgs = $4;
82
d419660ad71d tweak generate_stub.pl
anatofuz
parents: 52
diff changeset
499 #$tmpArgs =~ s/\(.*\)/\(\)/;
44
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
500 my @args = split(/,/,$tmpArgs);
52
214d21c891c7 rename to cbc
kono
parents: 46
diff changeset
501 if (! defined $dataGearVarType{$codeGearName}) {
214d21c891c7 rename to cbc
kono
parents: 46
diff changeset
502 print $fd $_ ;
214d21c891c7 rename to cbc
kono
parents: 46
diff changeset
503 next ;
214d21c891c7 rename to cbc
kono
parents: 46
diff changeset
504 }
44
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
505 my @types = @{$dataGearVarType{$codeGearName}};
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
506 my $ntype;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
507 my $ftype;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
508 for my $v (@{$dataGearVar{$codeGearName}}) {
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
509 my $t = shift @types;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
510 if ($v eq $next || $v eq "O_$next") {
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
511 $ntype = $t;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
512 $ftype = lcfirst($ntype);
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
513 }
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
514 }
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
515 if (!defined $ntype) {
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
516 $ntype = $localVarType{$next};
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
517 $ftype = lcfirst($ntype);
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
518 }
52
214d21c891c7 rename to cbc
kono
parents: 46
diff changeset
519 print $fd "\tGearef(cbc_context, $ntype)->$ftype = (union Data*) $next;\n";
44
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
520 # Put interface argument
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
521 my $prot = $code{$ntype}->{$method};
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
522 my $i = 1;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
523 for my $arg (@args) {
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
524 my $pType;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
525 my $pName;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
526 my $p = @$prot[$i];
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
527 next if ($p eq $arg);
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
528 $p =~ s/^(.*)\s(\w+)//;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
529 $pType = $1;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
530 $pName = $2;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
531 $arg =~ s/^(\s)*(\w+)/$2/;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
532 if ($pType =~ s/\_\_code$//) {
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
533 if ($arg =~ /(\w+)\(.*\)/) {
52
214d21c891c7 rename to cbc
kono
parents: 46
diff changeset
534 print $fd "\tGearef(cbc_context, $ntype)->$pName = $1;\n";
44
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
535 } else {
52
214d21c891c7 rename to cbc
kono
parents: 46
diff changeset
536 print $fd "\tGearef(cbc_context, $ntype)->$pName = C_$arg;\n";
44
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
537 }
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
538 } elsif ($pType =~ /Data\**$/){
52
214d21c891c7 rename to cbc
kono
parents: 46
diff changeset
539 print $fd "\tGearef(cbc_context, $ntype)->$pName = (union $pType) $arg;\n";
44
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
540 } else {
52
214d21c891c7 rename to cbc
kono
parents: 46
diff changeset
541 print $fd "\tGearef(cbc_context, $ntype)->$pName = $arg;\n";
44
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
542 }
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
543 $i++;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
544 }
52
214d21c891c7 rename to cbc
kono
parents: 46
diff changeset
545 # print $fd "${prev}cbc_context->before = C_$codeGearName;\n";
214d21c891c7 rename to cbc
kono
parents: 46
diff changeset
546 print $fd "${prev}goto meta(cbc_context, $next->$method);\n";
44
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
547 next;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
548 } elsif(/^(.*)par goto (\w+)\((.*)\);/) {
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
549 # handling par goto statement
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
550 # convert it to the parallel
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
551 my $prev = $1;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
552 my $codeGearName = $2;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
553 my $args = $3;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
554 my $inputCount = $codeGear{$codeGearName}->{'input'};
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
555 my $outputCount = $codeGear{$codeGearName}->{'output'};
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
556 my @iterateCounts;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
557 # parse examples 'par goto(.., iterate(10), exit);'
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
558 if ($args =~ /iterate\((.*)?\),/) {
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
559 @iterateCounts = split(/,/,$1);;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
560 $inputCount--;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
561 }
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
562 # replace iterate keyword
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
563 $args =~ s/iterate\((.*)?\),//;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
564 my @dataGears = split(/,\s*/, $args);
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
565 my $nextCodeGear = pop(@dataGears);
45
5f19e9554c30 supless warning
k.fukuda
parents:
diff changeset
566 if (! $hasParGoto) {
5f19e9554c30 supless warning
k.fukuda
parents:
diff changeset
567 $hasParGoto = 1;
44
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
568 print $fd "${prev}struct Element* element;\n";
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
569 }
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
570 my $initTask = << "EOFEOF";
52
214d21c891c7 rename to cbc
kono
parents: 46
diff changeset
571 ${prev}cbc_context->task = NEW(struct Context);
214d21c891c7 rename to cbc
kono
parents: 46
diff changeset
572 ${prev}initContext(cbc_context->task);
214d21c891c7 rename to cbc
kono
parents: 46
diff changeset
573 ${prev}cbc_context->task->next = C_$codeGearName;
214d21c891c7 rename to cbc
kono
parents: 46
diff changeset
574 ${prev}cbc_context->task->idgCount = $inputCount;
214d21c891c7 rename to cbc
kono
parents: 46
diff changeset
575 ${prev}cbc_context->task->idg = cbc_context->task->dataNum;
214d21c891c7 rename to cbc
kono
parents: 46
diff changeset
576 ${prev}cbc_context->task->maxIdg = cbc_context->task->idg + $inputCount;
214d21c891c7 rename to cbc
kono
parents: 46
diff changeset
577 ${prev}cbc_context->task->odg = cbc_context->task->maxIdg;
214d21c891c7 rename to cbc
kono
parents: 46
diff changeset
578 ${prev}cbc_context->task->maxOdg = cbc_context->task->odg + $outputCount;
44
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
579 EOFEOF
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
580 print $fd $initTask;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
581 if (@iterateCounts) {
52
214d21c891c7 rename to cbc
kono
parents: 46
diff changeset
582 print $fd "${prev}cbc_context->task->iterate = 0;\n";
44
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
583 my $len = @iterateCounts;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
584 if ($len == 1) {
52
214d21c891c7 rename to cbc
kono
parents: 46
diff changeset
585 print $fd "${prev}cbc_context->task->iterator = createMultiDimIterator(cbc_context, $iterateCounts[0], 1, 1);\n";
44
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
586 } elsif ($len == 2) {
52
214d21c891c7 rename to cbc
kono
parents: 46
diff changeset
587 print $fd "${prev}cbc_context->task->iterator = createMultiDimIterator(cbc_context, $iterateCounts[0], $iterateCounts[1], 1);\n";
44
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
588 } elsif ($len == 3) {
52
214d21c891c7 rename to cbc
kono
parents: 46
diff changeset
589 print $fd "${prev}cbc_context->task->iterator = createMultiDimIterator(cbc_context, $iterateCounts[0], $iterateCounts[1], $iterateCounts[2]);\n";
44
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
590 }
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
591 }
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
592 for my $dataGear (@dataGears) {
52
214d21c891c7 rename to cbc
kono
parents: 46
diff changeset
593 print $fd "${prev}GET_META($dataGear)->wait = createSynchronizedQueue(cbc_context);\n";
44
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
594 }
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
595 for my $i (0..$inputCount-1) {
52
214d21c891c7 rename to cbc
kono
parents: 46
diff changeset
596 print $fd "${prev}cbc_context->task->data[cbc_context->task->idg+$i] = (union Data*)@dataGears[$i];\n";
44
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
597 }
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
598 for my $i (0..$outputCount-1) {
52
214d21c891c7 rename to cbc
kono
parents: 46
diff changeset
599 print $fd "${prev}cbc_context->task->data[cbc_context->task->odg+$i] = (union Data*)@dataGears[$inputCount+$i];\n";
44
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
600 }
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
601 my $putTask = << "EOFEOF";
52
214d21c891c7 rename to cbc
kono
parents: 46
diff changeset
602 ${prev}element = &ALLOCATE(cbc_context, Element)->Element;
214d21c891c7 rename to cbc
kono
parents: 46
diff changeset
603 ${prev}element->data = (union Data*)cbc_context->task;
214d21c891c7 rename to cbc
kono
parents: 46
diff changeset
604 ${prev}element->next = cbc_context->taskList;
214d21c891c7 rename to cbc
kono
parents: 46
diff changeset
605 ${prev}cbc_context->taskList = element;
44
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
606 EOFEOF
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
607 print $fd $putTask;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
608 next;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
609 } elsif (/^(.*)goto (\w+)\((.*)\);/) {
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
610 # handling goto statement
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
611 # convert it to the meta call form with two arugments, that is context and enum Code
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
612 my $prev = $1;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
613 my $next = $2;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
614 my @args = split(/,/, $3);
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
615 my $v = 0;
52
214d21c891c7 rename to cbc
kono
parents: 46
diff changeset
616 if (defined $localCode{$next}) {
214d21c891c7 rename to cbc
kono
parents: 46
diff changeset
617 print $fd $_; next;
214d21c891c7 rename to cbc
kono
parents: 46
diff changeset
618 }
44
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
619 for my $n ( @{$dataGearVar{$codeGearName}} ) {
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
620 # continuation arguments
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
621 $v = 1 if ( $n eq $next);
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
622 }
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
623 if ($v || defined $code{$interface}->{$next}) {
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
624 # write continuation's arguments into the interface arguments
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
625 # we may need a commit for a shared DataGear
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
626 for my $arg ( @{$outputArgs{$codeGearName}->{$next}} ) {
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
627 my $v = shift(@args);
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
628 print $fd "\t*O_$arg = $v;\n";
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
629 }
45
5f19e9554c30 supless warning
k.fukuda
parents:
diff changeset
630 if ($hasParGoto) {
52
214d21c891c7 rename to cbc
kono
parents: 46
diff changeset
631 print $fd "${prev}Gearef(cbc_context, TaskManager)->taskList = cbc_context->taskList;\n";
214d21c891c7 rename to cbc
kono
parents: 46
diff changeset
632 print $fd "${prev}Gearef(cbc_context, TaskManager)->next1 = C_$next;\n";
214d21c891c7 rename to cbc
kono
parents: 46
diff changeset
633 print $fd "${prev}goto meta(cbc_context, C_$next);\n";
44
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
634 } else {
52
214d21c891c7 rename to cbc
kono
parents: 46
diff changeset
635 # print $fd "${prev}cbc_context->before = C_$codeGearName;\n";
214d21c891c7 rename to cbc
kono
parents: 46
diff changeset
636 print $fd "${prev}goto meta(cbc_context, $next);\n";
44
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
637 }
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
638 next;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
639 }
45
5f19e9554c30 supless warning
k.fukuda
parents:
diff changeset
640 if ($hasParGoto) {
52
214d21c891c7 rename to cbc
kono
parents: 46
diff changeset
641 print $fd "${prev}Gearef(cbc_context, TaskManager)->taskList = cbc_context->taskList;\n";
214d21c891c7 rename to cbc
kono
parents: 46
diff changeset
642 print $fd "${prev}Gearef(cbc_context, TaskManager)->next1 = C_$next;\n";
214d21c891c7 rename to cbc
kono
parents: 46
diff changeset
643 print $fd "${prev}goto parGotoMeta(cbc_context, C_$next);\n";
44
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
644 next;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
645 } elsif ($next eq "meta") {
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
646 print $fd $_;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
647 next;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
648 } else {
52
214d21c891c7 rename to cbc
kono
parents: 46
diff changeset
649 # print $fd "${prev}cbc_context->before = C_$codeGearName;\n";
214d21c891c7 rename to cbc
kono
parents: 46
diff changeset
650 print $fd "${prev}goto meta(cbc_context, C_$next);\n";
44
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
651 next;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
652 }
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
653 } elsif(/^.*(struct|union)?\s(\w+)\*\s(\w+)\s?[=;]/) {
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
654 my $type = $2;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
655 my $varName = $3;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
656 $localVarType{$varName} = $type;
52
214d21c891c7 rename to cbc
kono
parents: 46
diff changeset
657 s/new\s+(\w+)\(\)/\&ALLOCATE(cbc_context, \1)->\1/g; # replacing new
44
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
658 } elsif(/^}/) {
45
5f19e9554c30 supless warning
k.fukuda
parents:
diff changeset
659 $hasParGoto = 0;
44
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
660 } else {
52
214d21c891c7 rename to cbc
kono
parents: 46
diff changeset
661 s/new\s+(\w+)\(\)/\&ALLOCATE(cbc_context, \1)->\1/g; # replacing new
44
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
662 }
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
663 # gather type name and type
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
664 } elsif ($inMain) {
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
665 if (/^(.*)goto start_code\(main_context\);/) {
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
666 print $fd $_;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
667 next;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
668 } elsif (/^(.*)goto (\w+)\((.*)\);/) {
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
669 my $prev = $1;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
670 my $next = $2;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
671 print $fd "${prev}struct Context* main_context = NEW(struct Context);\n";
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
672 print $fd "${prev}initContext(main_context);\n";
52
214d21c891c7 rename to cbc
kono
parents: 46
diff changeset
673 print $fd "${prev}main_cbc_context->next = C_$next;\n";
44
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
674 print $fd "${prev}goto start_code(main_context);\n";
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
675 next;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
676 }
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
677 }
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
678 if (/^}/) {
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
679 $inStub = 0;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
680 $inTypedef = 0;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
681 $inMain = 0;
52
214d21c891c7 rename to cbc
kono
parents: 46
diff changeset
682 $inCode = 0;
44
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
683 }
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
684 print $fd $_;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
685 }
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
686 if (defined $prevCodeGearName) {
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
687 if (!defined $stub{$prevCodeGearName."_stub"}) {
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
688 $stub{$prevCodeGearName."_stub"} = &generateStub($fd,$prevCodeGearName,$dataGearName{$codeGearName});
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
689 }
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
690 }
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
691 }
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
692
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
693 # end