annotate src/gearsTools/generate_stub.pl @ 245:9471a8635489

fix regex at collection for data gears at generate_stub
author anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
date Tue, 04 Feb 2020 09:22:07 +0900
parents f0821818e3ed
children 63a65e3a5340
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) = @_;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
78 my ($codeGearName, $name, $inTypedef);
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;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
137 if ($ttype =~ /^(union|struct)?\s*(\w+)/) {
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
138 $ttype = $2;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
139 }
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
140 $var{$name}->{$tname} = $ttype;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
141 }
242
26be78edaf83 impl auto collection for data gears from interface
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 82
diff changeset
142 if (/__code (\w+)/) {
26be78edaf83 impl auto collection for data gears from interface
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 82
diff changeset
143 my $args = $';
245
9471a8635489 fix regex at collection for data gears at generate_stub
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 244
diff changeset
144 while ($args =~ /(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
145 #$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
146 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
147 my $ttype = $2;
26be78edaf83 impl auto collection for data gears from interface
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 82
diff changeset
148 my $tname = $3;
26be78edaf83 impl auto collection for data gears from interface
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 82
diff changeset
149
26be78edaf83 impl auto collection for data gears from interface
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 82
diff changeset
150 $ttype =~ s/Impl/struct $name/;
26be78edaf83 impl auto collection for data gears from interface
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 82
diff changeset
151 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
152 $ttype = "const $ttype";
26be78edaf83 impl auto collection for data gears from interface
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 82
diff changeset
153 }
26be78edaf83 impl auto collection for data gears from interface
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 82
diff changeset
154 $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
155 }
26be78edaf83 impl auto collection for data gears from interface
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 82
diff changeset
156 }
44
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
157 if (/^}/) {
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
158 $inTypedef = 0;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
159 }
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
160 }
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
161
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
162 }
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
163
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
164 sub getCodeGear {
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
165 my ($filename) = @_;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
166 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
167 my ($name,$impln);
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
168 while (<$fd>) {
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
169 if (/^(\w+)(\*)+ create(\w+)\(/) {
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
170 $name = $1;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
171 $impln = $3;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
172 } elsif(/^typedef struct (.*)<.*>\s*{/) {
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
173 $name = $1;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
174 }
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
175 if (defined $name) {
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
176 if (/^\s*\_\_code (\w+)\((.*)\);/) {
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
177 my $args = $2;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
178 my $method = $1;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
179 $code{$name}->{$method} = [];
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
180 while($args) {
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
181 # replace comma
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
182 $args =~ s/(^\s*,\s*)//;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
183 # continuation case
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
184 if ($args =~ s/^(\s)*\_\_code\s+(\w+)\(([^)]*)\)//) {
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
185 my $next = $2;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
186 my @args = split(/,/,$3);
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
187 push(@{$code{$name}->{$method}},"\_\_code $next");
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
188 } elsif ($args =~ s/^(struct|union)?\s*(\w+)(\**)\s+(\w+)//) {
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
189 my $structType = $1;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
190 my $typeName = $2;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
191 my $ptrType = $3;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
192 my $varName = $4;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
193 my $typeField = lcfirst($typeName);
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
194 push(@{$code{$name}->{$method}},"$typeName$ptrType $varName");
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
195 } elsif ($args =~ s/(.*,)//) {
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
196 } else {
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
197 last;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
198 }
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
199 }
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
200 }
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
201 } elsif (/^\_\_code (\w+)\((.*)\)(.*)/) {
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
202 my $codeGearName = $1;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
203 my $args = $2;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
204 my $inputCount = 0;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
205 my $outputCount = 0;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
206 my $inputIncFlag = 1;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
207 while($args) {
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
208 if ($args =~ s/(^\s*,\s*)//) {
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 if ($args =~ s/^(\s)*\_\_code\s+(\w+)\((.*?)\)//) {
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
211 $codeGear{$codeGearName}->{"code"}->{$2} = "\_\_code";
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
212 $inputIncFlag = 0;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
213 my @outputs = split(/,/,$3);
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
214 for my $output (@outputs) {
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
215 if ($output =~ /\s*(struct|union)?\s*(\w+)(\*)?+\s(\w+)/) {
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
216 my $type = $2;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
217 my $varName = $4;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
218 $codeGear{$codeGearName}->{"var"}->{$varName} = "$type $outputCount";
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
219 $outputCount++;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
220 }
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
221 }
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
222 } elsif ($args =~ s/^(struct|union)?\s*(\w+)(\*)?+\s(\w+)// && $inputIncFlag) {
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
223 my $type = $2;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
224 my $varName = $4;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
225 $codeGear{$codeGearName}->{"var"}->{$varName} = "$type $inputCount";
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
226 $inputCount++;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
227 } elsif ($args =~ s/(.*,)//) {
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
228 } else {
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
229 last;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
230 }
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
231 }
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
232 $codeGear{$codeGearName}->{"input"} = $inputCount;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
233 $codeGear{$codeGearName}->{"output"} = $outputCount;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
234 }
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
235 }
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
236 }
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
237
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
238 sub generateStub {
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
239 my($fd,$prevCodeGearName,$dataGearName) = @_;
52
214d21c891c7 rename to cbc
kono
parents: 46
diff changeset
240 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
241 print $fd $dataGearName;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
242 print $fd "\n} \n\n";
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
243 return 1;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
244 }
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
245
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
246 sub generateStubArgs {
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
247 my($codeGearName, $varName, $typeName, $ptrType, $typeField, $interface,$output) = @_;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
248 my $varname1 = $output?"O_$varName":$varName;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
249 for my $n ( @{$dataGearVar{$codeGearName}} ) {
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
250 # we already have it
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
251 return 0 if ( $n eq $varname1);
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 push @{$dataGearVar{$codeGearName}}, $varname1;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
254 push @{$dataGearVarType{$codeGearName}}, $typeName;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
255 if ($typeName eq $implementation) {
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
256 # get implementation
52
214d21c891c7 rename to cbc
kono
parents: 46
diff changeset
257 $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
258 } else {
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
259 # interface var
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
260 for my $ivar (keys %{$var{$interface}}) {
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
261 # input data gear field
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
262 if ($varName eq $ivar) {
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
263 if ($typeName eq $var{$interface}->{$ivar}) {
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
264 if ($output) {
52
214d21c891c7 rename to cbc
kono
parents: 46
diff changeset
265 $dataGearName{$codeGearName} .= "\t$typeName$ptrType* O_$varName = &Gearef(cbc_context, $interface)->$varName;\n";
82
d419660ad71d tweak generate_stub.pl
anatofuz
parents: 52
diff changeset
266 $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
267 return 1;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
268 }
52
214d21c891c7 rename to cbc
kono
parents: 46
diff changeset
269 $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
270 return 1;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
271 }
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
272 }
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
273 }
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
274
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
275 # interface continuation
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
276 for my $cName (keys %{$code{$interface}}) {
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
277 if ($varName eq $cName) {
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
278 # continuation field
52
214d21c891c7 rename to cbc
kono
parents: 46
diff changeset
279 $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
280 return 1;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
281 }
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
282 }
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
283
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
284 # par goto var
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
285 for my $var (keys %{$codeGear{$codeGearName}->{"var"}}) {
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
286 # input data gear field
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
287 if ($varName eq $var) {
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
288 my ($type, $count) = split(/\s/, $codeGear{$codeGearName}->{"var"}->{$var});
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
289 if ($typeName eq $type) {
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
290 if ($output) {
52
214d21c891c7 rename to cbc
kono
parents: 46
diff changeset
291 $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
292 $outputVar{$codeGearName} .= "\t$typeName$ptrType $varName = *O_$varName;\n";
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
293 return 1;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
294 }
52
214d21c891c7 rename to cbc
kono
parents: 46
diff changeset
295 $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
296 return 1;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
297 }
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
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
301 # par goto continuation
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
302 for my $cName (keys %{$codeGear{$codeGearName}->{"code"}}) {
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
303 if ($varName eq $cName) {
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
304 # continuation field
52
214d21c891c7 rename to cbc
kono
parents: 46
diff changeset
305 $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
306 return 1;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
307 }
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
308 }
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
309
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
310 # par goto continuation
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
311 # global or local variable case
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
312 if ($typeName eq "Code") {
52
214d21c891c7 rename to cbc
kono
parents: 46
diff changeset
313 $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
314 return 1;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
315 }
52
214d21c891c7 rename to cbc
kono
parents: 46
diff changeset
316 $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
317 return 1;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
318 }
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
319 }
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
320
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
321 sub generateDataGear {
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
322 my ($filename) = @_;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
323 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
324
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
325 my $fn;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
326 if ($opt_o) {
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
327 $fn = $opt_o;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
328 } else {
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
329 my $fn1 = $filename;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
330 $fn1 =~ s/\.cbc/.c/;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
331 my $i = 1;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
332 $fn = "$dir/$fn1";
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
333 while ( -f $fn) {
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
334 $fn = "$dir/$fn1.$i";
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
335 $i++;
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 }
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
338 if ( $fn =~ m=(.*)/[^/]+$= ) {
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
339 if (! -d $1) {
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
340 make_path $1;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
341 }
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
342 }
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
343 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
344
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
345 my $prevCodeGearName;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
346 my $inTypedef = 0;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
347 my $inStub = 0;
45
5f19e9554c30 supless warning
k.fukuda
parents:
diff changeset
348 my $hasParGoto = 0;
44
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
349 my $inMain = 0 ;
52
214d21c891c7 rename to cbc
kono
parents: 46
diff changeset
350 my $inCode = 0 ;
44
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
351 my %stub;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
352 my $codeGearName;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
353 my %localVarType;
52
214d21c891c7 rename to cbc
kono
parents: 46
diff changeset
354 my %localCode;
44
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
355
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
356 while (<$in>) {
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
357 if (! $inTypedef && ! $inStub && ! $inMain) {
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
358 if (/^typedef struct (\w+) \{/) {
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
359 $inTypedef = 1;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
360 } elsif (/^int main\((.*)\) \{/) {
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
361 $inMain = 1;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
362 } elsif(/^#interface "(.*)"/) {
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
363 my $interfaceHeader = $1;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
364 # #interface not write
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
365 next unless ($interfaceHeader =~ /context.h/);
52
214d21c891c7 rename to cbc
kono
parents: 46
diff changeset
366 } elsif (/^\s\s*_\_code (\w+)\((.*)\)(.*)/) {
214d21c891c7 rename to cbc
kono
parents: 46
diff changeset
367 $localCode{$1} = 1;
214d21c891c7 rename to cbc
kono
parents: 46
diff changeset
368 } elsif (/^\s\s*_\_code *\(\s*\*\s*(\w+)\)\((.*)\)(.*)/) {
214d21c891c7 rename to cbc
kono
parents: 46
diff changeset
369 $localCode{$1} = 1;
44
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
370 } elsif (/^\_\_code (\w+)\((.*)\)(.*)/) {
52
214d21c891c7 rename to cbc
kono
parents: 46
diff changeset
371 $inCode = 1;
214d21c891c7 rename to cbc
kono
parents: 46
diff changeset
372 %localCode = {};
44
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
373 %localVarType = {};
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
374 $codeGearName = $1;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
375 my $args = $2;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
376 my $tail = $3;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
377 if ($codeGearName =~ /_stub$/) {
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
378 # don't touch already existing stub
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
379 $inStub = 1;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
380 $stub{$codeGearName} = 1;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
381 print $fd $_;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
382 next;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
383 }
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
384 if (defined $prevCodeGearName) {
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
385 # stub is generated just before next CodeGear
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
386 if (defined $stub{$prevCodeGearName."_stub"}) {
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
387 undef $prevCodeGearName;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
388 } else {
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
389 &generateStub($fd,$prevCodeGearName,$dataGearName{$prevCodeGearName});
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
390 $stub{$prevCodeGearName."_stub"} = 1;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
391 }
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
392 }
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
393 # analyzing CodeGear argument
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
394 # 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
395 # and passed to the CodeGear
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
396 # struct Implementaion needs special handling
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
397 # __code next(...) ---> enum Code next
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
398 $prevCodeGearName = $codeGearName;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
399 $dataGearVar{$codeGearName} = [];
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
400 $outputVar{$codeGearName} = "";
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
401 $outputArgs{$codeGearName} = {};
52
214d21c891c7 rename to cbc
kono
parents: 46
diff changeset
402 my $newArgs = "struct Context *cbc_context,";
214d21c891c7 rename to cbc
kono
parents: 46
diff changeset
403 if ($args=~/^struct Context\s*\*\s*cbc_context/) {
44
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
404 $newArgs = "";
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
405 }
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
406 if (!$args){
52
214d21c891c7 rename to cbc
kono
parents: 46
diff changeset
407 $newArgs = "struct Context *cbc_context";
44
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 while($args) {
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
410 if ($args =~ s/(^\s*,\s*)//) {
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
411 $newArgs .= $1;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
412 }
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
413 # continuation case
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
414 if ($args =~ s/^(\s)*\_\_code\s+(\w+)\(([^)]*)\)//) {
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
415 my $next = $2;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
416 my @args = split(/,/,$3);
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
417 if (&generateStubArgs($codeGearName, $next, "Code", "", $next, $interface,0) ) {
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
418 $newArgs .= "enum Code $next";
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
419 }
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
420 # analyze continuation arguments
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
421 # 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
422 # 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
423 for my $arg (@args) {
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
424 $arg =~ s/^\s*//;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
425 last if ($arg =~ /\.\.\./);
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
426 $arg =~ s/^(struct|union)?\s*(\w+)(\**)\s(\w+)//;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
427 my $structType = $1;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
428 my $typeName = $2;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
429 my $ptrType = $3;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
430 my $varName = $4;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
431 my $typeField = lcfirst($typeName);
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
432 push(@{$outputArgs{$codeGearName}->{$next}}, $varName);
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
433 if (&generateStubArgs($codeGearName, $varName, $typeName, $ptrType, $typeField, $interface,1)) {
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
434 $newArgs .= ",$structType $typeName **O_$varName";
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 }
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
437 } elsif ($args =~ s/^(struct|union)?\s*(\w+)(\**)\s(\w+)//) {
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
438 my $structType = $1;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
439 my $typeName = $2;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
440 my $ptrType = $3;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
441 my $varName = $4;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
442 my $typeField = lcfirst($typeName);
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
443 $newArgs .= $&; # assuming no duplicate
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
444 &generateStubArgs($codeGearName, $varName, $typeName, $ptrType, $typeField, $interface,0);
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
445 } elsif ($args =~ s/(.*,)//) {
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
446 $newArgs .= $1;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
447 } else {
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
448 $newArgs .= $args;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
449 last;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
450 }
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
451 }
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
452 # generate goto statement from stub to the CodeGear in the buffer
52
214d21c891c7 rename to cbc
kono
parents: 46
diff changeset
453 $dataGearName{$codeGearName} .= "\tgoto $codeGearName(cbc_context";
44
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
454 for my $arg ( @{$dataGearVar{$codeGearName}}) {
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
455 $dataGearName{$codeGearName} .= ", $arg";
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
456 }
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
457 $dataGearName{$codeGearName} .= ");";
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
458 # generate CodeGear header with new arguments
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
459 print $fd "__code $codeGearName($newArgs)$tail\n";
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
460 if ($outputVar{$codeGearName} ne "") {
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
461 # output data var can be use before write
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
462 # it should be initialze by gearef
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
463 print $fd $outputVar{$codeGearName};
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
464 }
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
465 next;
52
214d21c891c7 rename to cbc
kono
parents: 46
diff changeset
466 } elsif (! $inCode) {
82
d419660ad71d tweak generate_stub.pl
anatofuz
parents: 52
diff changeset
467 s/new\s+(\w+)\(\)/\&ALLOCATE(cbc_context, \1)->\1/g; # replacing new
52
214d21c891c7 rename to cbc
kono
parents: 46
diff changeset
468 print $fd $_;
214d21c891c7 rename to cbc
kono
parents: 46
diff changeset
469 next;
44
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
470 } elsif (/^(.*)goto (\w+)\-\>(\w+)\((.*)\);/) {
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
471 # handling goto statement
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
472 # 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
473 my $prev = $1;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
474 my $next = $2;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
475 my $method = $3;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
476 my $tmpArgs = $4;
82
d419660ad71d tweak generate_stub.pl
anatofuz
parents: 52
diff changeset
477 #$tmpArgs =~ s/\(.*\)/\(\)/;
44
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
478 my @args = split(/,/,$tmpArgs);
52
214d21c891c7 rename to cbc
kono
parents: 46
diff changeset
479 if (! defined $dataGearVarType{$codeGearName}) {
214d21c891c7 rename to cbc
kono
parents: 46
diff changeset
480 print $fd $_ ;
214d21c891c7 rename to cbc
kono
parents: 46
diff changeset
481 next ;
214d21c891c7 rename to cbc
kono
parents: 46
diff changeset
482 }
44
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
483 my @types = @{$dataGearVarType{$codeGearName}};
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
484 my $ntype;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
485 my $ftype;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
486 for my $v (@{$dataGearVar{$codeGearName}}) {
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
487 my $t = shift @types;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
488 if ($v eq $next || $v eq "O_$next") {
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
489 $ntype = $t;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
490 $ftype = lcfirst($ntype);
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
491 }
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
492 }
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
493 if (!defined $ntype) {
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
494 $ntype = $localVarType{$next};
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
495 $ftype = lcfirst($ntype);
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
496 }
52
214d21c891c7 rename to cbc
kono
parents: 46
diff changeset
497 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
498 # Put interface argument
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
499 my $prot = $code{$ntype}->{$method};
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
500 my $i = 1;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
501 for my $arg (@args) {
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
502 my $pType;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
503 my $pName;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
504 my $p = @$prot[$i];
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
505 next if ($p eq $arg);
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
506 $p =~ s/^(.*)\s(\w+)//;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
507 $pType = $1;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
508 $pName = $2;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
509 $arg =~ s/^(\s)*(\w+)/$2/;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
510 if ($pType =~ s/\_\_code$//) {
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
511 if ($arg =~ /(\w+)\(.*\)/) {
52
214d21c891c7 rename to cbc
kono
parents: 46
diff changeset
512 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
513 } else {
52
214d21c891c7 rename to cbc
kono
parents: 46
diff changeset
514 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
515 }
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
516 } elsif ($pType =~ /Data\**$/){
52
214d21c891c7 rename to cbc
kono
parents: 46
diff changeset
517 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
518 } else {
52
214d21c891c7 rename to cbc
kono
parents: 46
diff changeset
519 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
520 }
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
521 $i++;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
522 }
52
214d21c891c7 rename to cbc
kono
parents: 46
diff changeset
523 # print $fd "${prev}cbc_context->before = C_$codeGearName;\n";
214d21c891c7 rename to cbc
kono
parents: 46
diff changeset
524 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
525 next;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
526 } elsif(/^(.*)par goto (\w+)\((.*)\);/) {
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
527 # handling par goto statement
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
528 # convert it to the parallel
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
529 my $prev = $1;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
530 my $codeGearName = $2;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
531 my $args = $3;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
532 my $inputCount = $codeGear{$codeGearName}->{'input'};
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
533 my $outputCount = $codeGear{$codeGearName}->{'output'};
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
534 my @iterateCounts;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
535 # parse examples 'par goto(.., iterate(10), exit);'
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
536 if ($args =~ /iterate\((.*)?\),/) {
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
537 @iterateCounts = split(/,/,$1);;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
538 $inputCount--;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
539 }
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
540 # replace iterate keyword
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
541 $args =~ s/iterate\((.*)?\),//;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
542 my @dataGears = split(/,\s*/, $args);
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
543 my $nextCodeGear = pop(@dataGears);
45
5f19e9554c30 supless warning
k.fukuda
parents:
diff changeset
544 if (! $hasParGoto) {
5f19e9554c30 supless warning
k.fukuda
parents:
diff changeset
545 $hasParGoto = 1;
44
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
546 print $fd "${prev}struct Element* element;\n";
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
547 }
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
548 my $initTask = << "EOFEOF";
52
214d21c891c7 rename to cbc
kono
parents: 46
diff changeset
549 ${prev}cbc_context->task = NEW(struct Context);
214d21c891c7 rename to cbc
kono
parents: 46
diff changeset
550 ${prev}initContext(cbc_context->task);
214d21c891c7 rename to cbc
kono
parents: 46
diff changeset
551 ${prev}cbc_context->task->next = C_$codeGearName;
214d21c891c7 rename to cbc
kono
parents: 46
diff changeset
552 ${prev}cbc_context->task->idgCount = $inputCount;
214d21c891c7 rename to cbc
kono
parents: 46
diff changeset
553 ${prev}cbc_context->task->idg = cbc_context->task->dataNum;
214d21c891c7 rename to cbc
kono
parents: 46
diff changeset
554 ${prev}cbc_context->task->maxIdg = cbc_context->task->idg + $inputCount;
214d21c891c7 rename to cbc
kono
parents: 46
diff changeset
555 ${prev}cbc_context->task->odg = cbc_context->task->maxIdg;
214d21c891c7 rename to cbc
kono
parents: 46
diff changeset
556 ${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
557 EOFEOF
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
558 print $fd $initTask;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
559 if (@iterateCounts) {
52
214d21c891c7 rename to cbc
kono
parents: 46
diff changeset
560 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
561 my $len = @iterateCounts;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
562 if ($len == 1) {
52
214d21c891c7 rename to cbc
kono
parents: 46
diff changeset
563 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
564 } elsif ($len == 2) {
52
214d21c891c7 rename to cbc
kono
parents: 46
diff changeset
565 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
566 } elsif ($len == 3) {
52
214d21c891c7 rename to cbc
kono
parents: 46
diff changeset
567 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
568 }
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 for my $dataGear (@dataGears) {
52
214d21c891c7 rename to cbc
kono
parents: 46
diff changeset
571 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
572 }
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
573 for my $i (0..$inputCount-1) {
52
214d21c891c7 rename to cbc
kono
parents: 46
diff changeset
574 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
575 }
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
576 for my $i (0..$outputCount-1) {
52
214d21c891c7 rename to cbc
kono
parents: 46
diff changeset
577 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
578 }
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
579 my $putTask = << "EOFEOF";
52
214d21c891c7 rename to cbc
kono
parents: 46
diff changeset
580 ${prev}element = &ALLOCATE(cbc_context, Element)->Element;
214d21c891c7 rename to cbc
kono
parents: 46
diff changeset
581 ${prev}element->data = (union Data*)cbc_context->task;
214d21c891c7 rename to cbc
kono
parents: 46
diff changeset
582 ${prev}element->next = cbc_context->taskList;
214d21c891c7 rename to cbc
kono
parents: 46
diff changeset
583 ${prev}cbc_context->taskList = element;
44
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
584 EOFEOF
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
585 print $fd $putTask;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
586 next;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
587 } elsif (/^(.*)goto (\w+)\((.*)\);/) {
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
588 # handling goto statement
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
589 # 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
590 my $prev = $1;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
591 my $next = $2;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
592 my @args = split(/,/, $3);
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
593 my $v = 0;
52
214d21c891c7 rename to cbc
kono
parents: 46
diff changeset
594 if (defined $localCode{$next}) {
214d21c891c7 rename to cbc
kono
parents: 46
diff changeset
595 print $fd $_; next;
214d21c891c7 rename to cbc
kono
parents: 46
diff changeset
596 }
44
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
597 for my $n ( @{$dataGearVar{$codeGearName}} ) {
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
598 # continuation arguments
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
599 $v = 1 if ( $n eq $next);
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 if ($v || defined $code{$interface}->{$next}) {
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
602 # write continuation's arguments into the interface arguments
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
603 # we may need a commit for a shared DataGear
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
604 for my $arg ( @{$outputArgs{$codeGearName}->{$next}} ) {
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
605 my $v = shift(@args);
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
606 print $fd "\t*O_$arg = $v;\n";
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
607 }
45
5f19e9554c30 supless warning
k.fukuda
parents:
diff changeset
608 if ($hasParGoto) {
52
214d21c891c7 rename to cbc
kono
parents: 46
diff changeset
609 print $fd "${prev}Gearef(cbc_context, TaskManager)->taskList = cbc_context->taskList;\n";
214d21c891c7 rename to cbc
kono
parents: 46
diff changeset
610 print $fd "${prev}Gearef(cbc_context, TaskManager)->next1 = C_$next;\n";
214d21c891c7 rename to cbc
kono
parents: 46
diff changeset
611 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
612 } else {
52
214d21c891c7 rename to cbc
kono
parents: 46
diff changeset
613 # print $fd "${prev}cbc_context->before = C_$codeGearName;\n";
214d21c891c7 rename to cbc
kono
parents: 46
diff changeset
614 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
615 }
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
616 next;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
617 }
45
5f19e9554c30 supless warning
k.fukuda
parents:
diff changeset
618 if ($hasParGoto) {
52
214d21c891c7 rename to cbc
kono
parents: 46
diff changeset
619 print $fd "${prev}Gearef(cbc_context, TaskManager)->taskList = cbc_context->taskList;\n";
214d21c891c7 rename to cbc
kono
parents: 46
diff changeset
620 print $fd "${prev}Gearef(cbc_context, TaskManager)->next1 = C_$next;\n";
214d21c891c7 rename to cbc
kono
parents: 46
diff changeset
621 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
622 next;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
623 } elsif ($next eq "meta") {
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
624 print $fd $_;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
625 next;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
626 } else {
52
214d21c891c7 rename to cbc
kono
parents: 46
diff changeset
627 # print $fd "${prev}cbc_context->before = C_$codeGearName;\n";
214d21c891c7 rename to cbc
kono
parents: 46
diff changeset
628 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
629 next;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
630 }
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
631 } elsif(/^.*(struct|union)?\s(\w+)\*\s(\w+)\s?[=;]/) {
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
632 my $type = $2;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
633 my $varName = $3;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
634 $localVarType{$varName} = $type;
52
214d21c891c7 rename to cbc
kono
parents: 46
diff changeset
635 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
636 } elsif(/^}/) {
45
5f19e9554c30 supless warning
k.fukuda
parents:
diff changeset
637 $hasParGoto = 0;
44
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
638 } else {
52
214d21c891c7 rename to cbc
kono
parents: 46
diff changeset
639 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
640 }
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
641 # gather type name and type
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
642 } elsif ($inMain) {
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
643 if (/^(.*)goto start_code\(main_context\);/) {
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
644 print $fd $_;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
645 next;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
646 } elsif (/^(.*)goto (\w+)\((.*)\);/) {
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
647 my $prev = $1;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
648 my $next = $2;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
649 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
650 print $fd "${prev}initContext(main_context);\n";
52
214d21c891c7 rename to cbc
kono
parents: 46
diff changeset
651 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
652 print $fd "${prev}goto start_code(main_context);\n";
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
653 next;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
654 }
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
655 }
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
656 if (/^}/) {
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
657 $inStub = 0;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
658 $inTypedef = 0;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
659 $inMain = 0;
52
214d21c891c7 rename to cbc
kono
parents: 46
diff changeset
660 $inCode = 0;
44
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
661 }
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
662 print $fd $_;
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
663 }
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
664 if (defined $prevCodeGearName) {
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
665 if (!defined $stub{$prevCodeGearName."_stub"}) {
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
666 $stub{$prevCodeGearName."_stub"} = &generateStub($fd,$prevCodeGearName,$dataGearName{$codeGearName});
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
667 }
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
668 }
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
669 }
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
670
94ca6db2ee9c add perl script
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
671 # end