annotate src/gearsTools/trans_impl.pl @ 128:7ce72e373d9b

fix initialize data gears
author anatofuz
date Tue, 03 Dec 2019 11:12:52 +0900
parents 46d792f92156
children 3312d7ce91e6
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
102
b84aac4ab529 import trans_impl.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1 #!/usr/bin/env perl
b84aac4ab529 import trans_impl.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2 use strict;
b84aac4ab529 import trans_impl.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
3 use warnings;
b84aac4ab529 import trans_impl.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
4
b84aac4ab529 import trans_impl.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
5 use FindBin;
b84aac4ab529 import trans_impl.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
6 use lib "$FindBin::Bin/lib";
b84aac4ab529 import trans_impl.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
7 use Gears::Util;
b84aac4ab529 import trans_impl.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
8
124
53be0626c3fa tweak trans_impl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 122
diff changeset
9 use Getopt::Std;
122
anatofuz
parents: 112
diff changeset
10 use File::Spec;
102
b84aac4ab529 import trans_impl.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
11
b84aac4ab529 import trans_impl.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
12 my %opt;
127
46d792f92156 impl output option at trans_impl.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 125
diff changeset
13 getopts("wo:" => \%opt);
102
b84aac4ab529 import trans_impl.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
14
b84aac4ab529 import trans_impl.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
15 my $impl_file = shift or die 'require impl file';
122
anatofuz
parents: 112
diff changeset
16 my $impl_ir = Gears::Util->parse_with_rewrite(File::Spec->rel2abs($impl_file));
112
b9df8ea87b42 fix trans_impl.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 109
diff changeset
17 my $interface_file = Gears::Util->find_header($impl_ir->{isa},"$FindBin::Bin/..");
102
b84aac4ab529 import trans_impl.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
18
112
b9df8ea87b42 fix trans_impl.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 109
diff changeset
19 my $inter_ir = Gears::Util->parse_with_rewrite($interface_file);
102
b84aac4ab529 import trans_impl.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
20
b84aac4ab529 import trans_impl.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
21
b84aac4ab529 import trans_impl.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
22 my $output_file = $impl_file;
b84aac4ab529 import trans_impl.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
23 $output_file =~ s/\.h/.cbc/;
123
004e825f37c7 tweak trans_impl.pl
anatofuz
parents: 122
diff changeset
24 my $stdout = *STDOUT;
102
b84aac4ab529 import trans_impl.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
25
123
004e825f37c7 tweak trans_impl.pl
anatofuz
parents: 122
diff changeset
26 if ($opt{w}) {
004e825f37c7 tweak trans_impl.pl
anatofuz
parents: 122
diff changeset
27 open $stdout, '>', $output_file;
127
46d792f92156 impl output option at trans_impl.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 125
diff changeset
28 } elsif ($opt{o}) {
46d792f92156 impl output option at trans_impl.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 125
diff changeset
29 open $stdout, '>', $opt{o};
102
b84aac4ab529 import trans_impl.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
30 }
b84aac4ab529 import trans_impl.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
31
127
46d792f92156 impl output option at trans_impl.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 125
diff changeset
32
102
b84aac4ab529 import trans_impl.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
33 emit_include_part($stdout, $inter_ir->{name});
b84aac4ab529 import trans_impl.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
34 emit_impl_header_in_comment($stdout, $impl_file);
b84aac4ab529 import trans_impl.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
35 emit_constracutor($stdout,$impl_ir,$inter_ir);
b84aac4ab529 import trans_impl.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
36 emit_code_gears($stdout,$impl_ir,$inter_ir);
123
004e825f37c7 tweak trans_impl.pl
anatofuz
parents: 122
diff changeset
37 close $stdout;
102
b84aac4ab529 import trans_impl.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
38
b84aac4ab529 import trans_impl.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
39 sub emit_include_part {
b84aac4ab529 import trans_impl.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
40 my ($out, $interface) = @_;
b84aac4ab529 import trans_impl.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
41 print $out <<"EOF"
b84aac4ab529 import trans_impl.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
42 #include "../context.h";
b84aac4ab529 import trans_impl.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
43 #interface "$interface.h";
b84aac4ab529 import trans_impl.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
44
b84aac4ab529 import trans_impl.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
45 EOF
b84aac4ab529 import trans_impl.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
46 }
b84aac4ab529 import trans_impl.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
47
b84aac4ab529 import trans_impl.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
48 sub emit_impl_header_in_comment {
b84aac4ab529 import trans_impl.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
49 my ($out, $impl_file) = @_;
b84aac4ab529 import trans_impl.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
50 my $line = Gears::Util->slup($impl_file);
b84aac4ab529 import trans_impl.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
51 print $out "// ----\n";
b84aac4ab529 import trans_impl.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
52 map { print $out "// $_\n" } split /\n/, $line;
b84aac4ab529 import trans_impl.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
53 print $out "// ----\n\n";
b84aac4ab529 import trans_impl.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
54 }
b84aac4ab529 import trans_impl.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
55
b84aac4ab529 import trans_impl.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
56 sub emit_constracutor {
b84aac4ab529 import trans_impl.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
57 my ($out, $impl_ir, $inter_ir) = @_;
b84aac4ab529 import trans_impl.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
58
112
b9df8ea87b42 fix trans_impl.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 109
diff changeset
59 my @inter_data = @{$inter_ir->{data}};
b9df8ea87b42 fix trans_impl.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 109
diff changeset
60 my @impl_data = @{$impl_ir->{data}};
102
b84aac4ab529 import trans_impl.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
61 my $instance_inter = shift @inter_data;
112
b9df8ea87b42 fix trans_impl.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 109
diff changeset
62
102
b84aac4ab529 import trans_impl.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
63 if ($instance_inter =~ /union\s*Data\*\s*(\w+)/) {
b84aac4ab529 import trans_impl.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
64 $instance_inter = $1;
b84aac4ab529 import trans_impl.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
65 }
112
b9df8ea87b42 fix trans_impl.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 109
diff changeset
66
b9df8ea87b42 fix trans_impl.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 109
diff changeset
67 my $instance_impl = lcfirst $impl_ir->{name};
b9df8ea87b42 fix trans_impl.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 109
diff changeset
68 $instance_impl =~ s/([A-Z])/_\l$1/g;
102
b84aac4ab529 import trans_impl.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
69
b84aac4ab529 import trans_impl.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
70 print $out <<"EOF";
b84aac4ab529 import trans_impl.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
71 $impl_ir->{isa}* create$impl_ir->{name}(struct Context* cbc_context) {
b84aac4ab529 import trans_impl.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
72 struct $impl_ir->{isa}* $instance_inter = new $impl_ir->{isa}();
b84aac4ab529 import trans_impl.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
73 struct $impl_ir->{name}* $instance_impl = new $impl_ir->{name}();
b84aac4ab529 import trans_impl.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
74 $instance_inter->$instance_inter = (union Data*)$instance_impl;
b84aac4ab529 import trans_impl.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
75 EOF
b84aac4ab529 import trans_impl.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
76
109
4f9d95dc4efd fix createInstance
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 105
diff changeset
77 for my $datum (@impl_data) {
102
b84aac4ab529 import trans_impl.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
78 if ($datum =~ /\w+ \w+\* (\w+)/) {
b84aac4ab529 import trans_impl.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
79 print $out " ${instance_impl}->$1 = NULL;\n";
b84aac4ab529 import trans_impl.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
80 next;
b84aac4ab529 import trans_impl.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
81 }
b84aac4ab529 import trans_impl.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
82 if ($datum =~ /\w+ \w+ (\w+)/) {
b84aac4ab529 import trans_impl.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
83 print $out " ${instance_impl}->$1 = 0;\n";
b84aac4ab529 import trans_impl.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
84 }
128
7ce72e373d9b fix initialize data gears
anatofuz
parents: 127
diff changeset
85
7ce72e373d9b fix initialize data gears
anatofuz
parents: 127
diff changeset
86 if ($datum =~ /\w+(\*)? (\w+)/) {
7ce72e373d9b fix initialize data gears
anatofuz
parents: 127
diff changeset
87 my $is_pointer = $1;
7ce72e373d9b fix initialize data gears
anatofuz
parents: 127
diff changeset
88 my $var_name = $2;
7ce72e373d9b fix initialize data gears
anatofuz
parents: 127
diff changeset
89 if ($1) {
7ce72e373d9b fix initialize data gears
anatofuz
parents: 127
diff changeset
90 print $out " ${instance_impl}->$var_name = NULL;\n";
7ce72e373d9b fix initialize data gears
anatofuz
parents: 127
diff changeset
91 } else {
7ce72e373d9b fix initialize data gears
anatofuz
parents: 127
diff changeset
92 print $out " ${instance_impl}->$var_name = 0;\n";
7ce72e373d9b fix initialize data gears
anatofuz
parents: 127
diff changeset
93 }
7ce72e373d9b fix initialize data gears
anatofuz
parents: 127
diff changeset
94 }
102
b84aac4ab529 import trans_impl.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
95 }
b84aac4ab529 import trans_impl.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
96
109
4f9d95dc4efd fix createInstance
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 105
diff changeset
97 for my $datum (@inter_data) {
4f9d95dc4efd fix createInstance
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 105
diff changeset
98 if ($datum =~ /\w+ \w+\* (\w+)/) {
4f9d95dc4efd fix createInstance
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 105
diff changeset
99 print $out " ${instance_inter}->$1 = NULL;\n";
4f9d95dc4efd fix createInstance
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 105
diff changeset
100 next;
4f9d95dc4efd fix createInstance
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 105
diff changeset
101 }
4f9d95dc4efd fix createInstance
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 105
diff changeset
102 if ($datum =~ /\w+ \w+ (\w+)/) {
4f9d95dc4efd fix createInstance
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 105
diff changeset
103 print $out " ${instance_inter}->$1 = 0;\n";
128
7ce72e373d9b fix initialize data gears
anatofuz
parents: 127
diff changeset
104 next;
7ce72e373d9b fix initialize data gears
anatofuz
parents: 127
diff changeset
105 }
7ce72e373d9b fix initialize data gears
anatofuz
parents: 127
diff changeset
106 if ($datum =~ /\w+(\*)? (\w+)/) {
7ce72e373d9b fix initialize data gears
anatofuz
parents: 127
diff changeset
107 my $is_pointer = $1;
7ce72e373d9b fix initialize data gears
anatofuz
parents: 127
diff changeset
108 my $var_name = $2;
7ce72e373d9b fix initialize data gears
anatofuz
parents: 127
diff changeset
109 if ($1) {
7ce72e373d9b fix initialize data gears
anatofuz
parents: 127
diff changeset
110 print $out " ${instance_impl}->$var_name = NULL;\n";
7ce72e373d9b fix initialize data gears
anatofuz
parents: 127
diff changeset
111 } else {
7ce72e373d9b fix initialize data gears
anatofuz
parents: 127
diff changeset
112 print $out " ${instance_impl}->$var_name = 0;\n";
7ce72e373d9b fix initialize data gears
anatofuz
parents: 127
diff changeset
113 }
109
4f9d95dc4efd fix createInstance
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 105
diff changeset
114 }
4f9d95dc4efd fix createInstance
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 105
diff changeset
115 }
4f9d95dc4efd fix createInstance
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 105
diff changeset
116
102
b84aac4ab529 import trans_impl.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
117 for my $code (@{$inter_ir->{codes}}) {
112
b9df8ea87b42 fix trans_impl.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 109
diff changeset
118 my $code_gear = $code->{name};
102
b84aac4ab529 import trans_impl.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
119 print $out " ${instance_inter}->$code_gear = C_$code_gear$impl_ir->{name};\n"
b84aac4ab529 import trans_impl.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
120 }
b84aac4ab529 import trans_impl.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
121
b84aac4ab529 import trans_impl.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
122 print $out " return $instance_inter;\n";
b84aac4ab529 import trans_impl.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
123 print $out "}\n";
b84aac4ab529 import trans_impl.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
124 }
b84aac4ab529 import trans_impl.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
125
b84aac4ab529 import trans_impl.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
126
b84aac4ab529 import trans_impl.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
127 sub emit_code_gears {
b84aac4ab529 import trans_impl.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
128 my ($out, $impl_ir, $inter_ir) = @_;
b84aac4ab529 import trans_impl.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
129 my $impl = $impl_ir->{name};
124
53be0626c3fa tweak trans_impl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 122
diff changeset
130 my $interface_name = $inter_ir->{name};
102
b84aac4ab529 import trans_impl.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
131
b84aac4ab529 import trans_impl.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
132 my @inter_data = @{$inter_ir->{data}};
b84aac4ab529 import trans_impl.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
133 my $instance_inter = shift @inter_data;
b84aac4ab529 import trans_impl.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
134 if ($instance_inter =~ /union\s*Data\*\s*(\w+)/) {
b84aac4ab529 import trans_impl.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
135 $instance_inter = $1;
b84aac4ab529 import trans_impl.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
136 }
b84aac4ab529 import trans_impl.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
137 my $instance_impl = lcfirst $impl_ir->{name};
105
f1be2d5abc8a fix camel2snake
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 104
diff changeset
138 $instance_impl =~ s/([A-Z])/_\l$1/g;
102
b84aac4ab529 import trans_impl.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
139 my $data_gear_types = {};
b84aac4ab529 import trans_impl.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
140
124
53be0626c3fa tweak trans_impl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 122
diff changeset
141 if (defined $impl_ir->{codes}) {
53be0626c3fa tweak trans_impl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 122
diff changeset
142 for my $cg (@{$impl_ir->{codes}}) {
53be0626c3fa tweak trans_impl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 122
diff changeset
143 my $data_gears = $cg->{args};
53be0626c3fa tweak trans_impl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 122
diff changeset
144 while ($data_gears =~ /Type\*\s*(\w+),/g) {
53be0626c3fa tweak trans_impl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 122
diff changeset
145 $data_gears =~ s/Type\*/struct $impl*/;
53be0626c3fa tweak trans_impl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 122
diff changeset
146 }
53be0626c3fa tweak trans_impl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 122
diff changeset
147
53be0626c3fa tweak trans_impl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 122
diff changeset
148 while ($data_gears =~ /Isa\*\s*(\w+),/g) {
53be0626c3fa tweak trans_impl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 122
diff changeset
149 $data_gears =~ s/Isa\*/struct $interface_name*/;
53be0626c3fa tweak trans_impl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 122
diff changeset
150 }
53be0626c3fa tweak trans_impl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 122
diff changeset
151 print $out "__code $cg->{name}$impl(";
53be0626c3fa tweak trans_impl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 122
diff changeset
152 print $out "$data_gears) {\n\n";
53be0626c3fa tweak trans_impl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 122
diff changeset
153
53be0626c3fa tweak trans_impl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 122
diff changeset
154 #__code next(...), __code whenEmpty(...)
53be0626c3fa tweak trans_impl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 122
diff changeset
155 my @cg = ();
53be0626c3fa tweak trans_impl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 122
diff changeset
156 while ($data_gears =~ /__code ([\w(\.)\*\s,]+?\)),?/g) {
53be0626c3fa tweak trans_impl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 122
diff changeset
157 push(@cg, $1);
53be0626c3fa tweak trans_impl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 122
diff changeset
158 }
53be0626c3fa tweak trans_impl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 122
diff changeset
159
53be0626c3fa tweak trans_impl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 122
diff changeset
160 if (@cg) {
53be0626c3fa tweak trans_impl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 122
diff changeset
161 if (@cg == 2) {
53be0626c3fa tweak trans_impl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 122
diff changeset
162 print $out " if (:TODO:) {\n";
53be0626c3fa tweak trans_impl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 122
diff changeset
163 print $out " goto ",shift(@cg),";\n";
53be0626c3fa tweak trans_impl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 122
diff changeset
164 print $out " }\n";
53be0626c3fa tweak trans_impl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 122
diff changeset
165 print $out " goto ",shift(@cg),";\n";
53be0626c3fa tweak trans_impl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 122
diff changeset
166 } else {
53be0626c3fa tweak trans_impl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 122
diff changeset
167 print $out " goto ",shift(@cg),";\n";
53be0626c3fa tweak trans_impl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 122
diff changeset
168 }
53be0626c3fa tweak trans_impl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 122
diff changeset
169 }
53be0626c3fa tweak trans_impl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 122
diff changeset
170 print $out "}\n\n";
53be0626c3fa tweak trans_impl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 122
diff changeset
171 }
53be0626c3fa tweak trans_impl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 122
diff changeset
172 }
53be0626c3fa tweak trans_impl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 122
diff changeset
173
102
b84aac4ab529 import trans_impl.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
174 for my $code_ir (@{$inter_ir->{codes}}) {
112
b9df8ea87b42 fix trans_impl.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 109
diff changeset
175 my $data_gears = $code_ir->{args};
b9df8ea87b42 fix trans_impl.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 109
diff changeset
176 $data_gears =~ s/Impl/struct $impl/g;
124
53be0626c3fa tweak trans_impl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 122
diff changeset
177
103
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 102
diff changeset
178 while ($data_gears =~ /Type\*\s*(\w+),/g) {
124
53be0626c3fa tweak trans_impl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 122
diff changeset
179 $data_gears =~ s/Type\*/struct $interface_name*/;
102
b84aac4ab529 import trans_impl.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
180 }
b84aac4ab529 import trans_impl.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
181
112
b9df8ea87b42 fix trans_impl.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 109
diff changeset
182 print $out "__code $code_ir->{name}$impl(";
102
b84aac4ab529 import trans_impl.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
183 print $out "$data_gears) {\n\n";
b84aac4ab529 import trans_impl.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
184
b84aac4ab529 import trans_impl.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
185 #__code next(...), __code whenEmpty(...)
b84aac4ab529 import trans_impl.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
186 my @cg = ();
b84aac4ab529 import trans_impl.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
187 while ($data_gears =~ /__code ([\w(\.)\*\s,]+?\)),?/g) {
b84aac4ab529 import trans_impl.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
188 push(@cg, $1);
b84aac4ab529 import trans_impl.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
189 }
b84aac4ab529 import trans_impl.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
190
b84aac4ab529 import trans_impl.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
191 if (@cg) {
b84aac4ab529 import trans_impl.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
192 if (@cg == 2) {
b84aac4ab529 import trans_impl.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
193 print $out " if (:TODO:) {\n";
b84aac4ab529 import trans_impl.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
194 print $out " goto ",shift(@cg),";\n";
b84aac4ab529 import trans_impl.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
195 print $out " }\n";
b84aac4ab529 import trans_impl.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
196 print $out " goto ",shift(@cg),";\n";
b84aac4ab529 import trans_impl.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
197 } else {
b84aac4ab529 import trans_impl.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
198 print $out " goto ",shift(@cg),";\n";
b84aac4ab529 import trans_impl.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
199 }
b84aac4ab529 import trans_impl.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
200 }
b84aac4ab529 import trans_impl.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
201 print $out "}\n\n";
b84aac4ab529 import trans_impl.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
202 }
b84aac4ab529 import trans_impl.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
203 }