annotate src/gearsTools/generate_stub.pl @ 249:42a37a8a02c9

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