annotate src/gearsTools/trans_impl.pl @ 123:004e825f37c7

tweak trans_impl.pl
author anatofuz
date Mon, 02 Dec 2019 19:57:06 +0900
parents f6558602f31e
children f103beea19f4
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
122
anatofuz
parents: 112
diff changeset
9 use File::Spec;
102
b84aac4ab529 import trans_impl.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
10 use Getopt::Std;
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;
b84aac4ab529 import trans_impl.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
13 getopts("w" => \%opt);
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
anatofuz
parents: 112
diff changeset
17 use Data::Dumper;
anatofuz
parents: 112
diff changeset
18 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
19 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
20
112
b9df8ea87b42 fix trans_impl.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 109
diff changeset
21 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
22
b84aac4ab529 import trans_impl.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
23
b84aac4ab529 import trans_impl.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
24 my $output_file = $impl_file;
b84aac4ab529 import trans_impl.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
25 $output_file =~ s/\.h/.cbc/;
123
004e825f37c7 tweak trans_impl.pl
anatofuz
parents: 122
diff changeset
26 my $stdout = *STDOUT;
102
b84aac4ab529 import trans_impl.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
27
123
004e825f37c7 tweak trans_impl.pl
anatofuz
parents: 122
diff changeset
28 if ($opt{w}) {
004e825f37c7 tweak trans_impl.pl
anatofuz
parents: 122
diff changeset
29 open $stdout, '>', $output_file;
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
b84aac4ab529 import trans_impl.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
32 emit_include_part($stdout, $inter_ir->{name});
b84aac4ab529 import trans_impl.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
33 emit_impl_header_in_comment($stdout, $impl_file);
b84aac4ab529 import trans_impl.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
34 emit_constracutor($stdout,$impl_ir,$inter_ir);
b84aac4ab529 import trans_impl.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
35 emit_code_gears($stdout,$impl_ir,$inter_ir);
123
004e825f37c7 tweak trans_impl.pl
anatofuz
parents: 122
diff changeset
36 close $stdout;
102
b84aac4ab529 import trans_impl.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
37
b84aac4ab529 import trans_impl.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
38 sub emit_include_part {
b84aac4ab529 import trans_impl.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
39 my ($out, $interface) = @_;
b84aac4ab529 import trans_impl.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
40 print $out <<"EOF"
b84aac4ab529 import trans_impl.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
41 #include "../context.h";
b84aac4ab529 import trans_impl.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
42 #interface "$interface.h";
b84aac4ab529 import trans_impl.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
43
b84aac4ab529 import trans_impl.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
44 EOF
b84aac4ab529 import trans_impl.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
45 }
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 sub emit_impl_header_in_comment {
b84aac4ab529 import trans_impl.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
48 my ($out, $impl_file) = @_;
b84aac4ab529 import trans_impl.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
49 my $line = Gears::Util->slup($impl_file);
b84aac4ab529 import trans_impl.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
50 print $out "// ----\n";
b84aac4ab529 import trans_impl.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
51 map { print $out "// $_\n" } split /\n/, $line;
b84aac4ab529 import trans_impl.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
52 print $out "// ----\n\n";
b84aac4ab529 import trans_impl.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
53 }
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 sub emit_constracutor {
b84aac4ab529 import trans_impl.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
56 my ($out, $impl_ir, $inter_ir) = @_;
b84aac4ab529 import trans_impl.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
57
112
b9df8ea87b42 fix trans_impl.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 109
diff changeset
58 my @inter_data = @{$inter_ir->{data}};
b9df8ea87b42 fix trans_impl.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 109
diff changeset
59 my @impl_data = @{$impl_ir->{data}};
102
b84aac4ab529 import trans_impl.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
60 my $instance_inter = shift @inter_data;
112
b9df8ea87b42 fix trans_impl.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 109
diff changeset
61
102
b84aac4ab529 import trans_impl.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
62 if ($instance_inter =~ /union\s*Data\*\s*(\w+)/) {
b84aac4ab529 import trans_impl.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
63 $instance_inter = $1;
b84aac4ab529 import trans_impl.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
64 }
112
b9df8ea87b42 fix trans_impl.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 109
diff changeset
65
b9df8ea87b42 fix trans_impl.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 109
diff changeset
66 my $instance_impl = lcfirst $impl_ir->{name};
b9df8ea87b42 fix trans_impl.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 109
diff changeset
67 $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
68
b84aac4ab529 import trans_impl.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
69 print $out <<"EOF";
b84aac4ab529 import trans_impl.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
70 $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
71 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
72 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
73 $instance_inter->$instance_inter = (union Data*)$instance_impl;
b84aac4ab529 import trans_impl.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
74 EOF
b84aac4ab529 import trans_impl.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
75
109
4f9d95dc4efd fix createInstance
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 105
diff changeset
76 for my $datum (@impl_data) {
102
b84aac4ab529 import trans_impl.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
77 if ($datum =~ /\w+ \w+\* (\w+)/) {
b84aac4ab529 import trans_impl.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
78 print $out " ${instance_impl}->$1 = NULL;\n";
b84aac4ab529 import trans_impl.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
79 next;
b84aac4ab529 import trans_impl.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
80 }
b84aac4ab529 import trans_impl.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
81 if ($datum =~ /\w+ \w+ (\w+)/) {
b84aac4ab529 import trans_impl.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
82 print $out " ${instance_impl}->$1 = 0;\n";
b84aac4ab529 import trans_impl.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
83 }
b84aac4ab529 import trans_impl.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
84 }
b84aac4ab529 import trans_impl.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
85
109
4f9d95dc4efd fix createInstance
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 105
diff changeset
86 for my $datum (@inter_data) {
4f9d95dc4efd fix createInstance
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 105
diff changeset
87 if ($datum =~ /\w+ \w+\* (\w+)/) {
4f9d95dc4efd fix createInstance
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 105
diff changeset
88 print $out " ${instance_inter}->$1 = NULL;\n";
4f9d95dc4efd fix createInstance
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 105
diff changeset
89 next;
4f9d95dc4efd fix createInstance
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 105
diff changeset
90 }
4f9d95dc4efd fix createInstance
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 105
diff changeset
91 if ($datum =~ /\w+ \w+ (\w+)/) {
4f9d95dc4efd fix createInstance
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 105
diff changeset
92 print $out " ${instance_inter}->$1 = 0;\n";
4f9d95dc4efd fix createInstance
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 105
diff changeset
93 }
4f9d95dc4efd fix createInstance
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 105
diff changeset
94 }
4f9d95dc4efd fix createInstance
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 105
diff changeset
95
102
b84aac4ab529 import trans_impl.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
96 for my $code (@{$inter_ir->{codes}}) {
112
b9df8ea87b42 fix trans_impl.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 109
diff changeset
97 my $code_gear = $code->{name};
102
b84aac4ab529 import trans_impl.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
98 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
99 }
b84aac4ab529 import trans_impl.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
100
b84aac4ab529 import trans_impl.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
101 print $out " return $instance_inter;\n";
b84aac4ab529 import trans_impl.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
102 print $out "}\n";
b84aac4ab529 import trans_impl.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
103 }
b84aac4ab529 import trans_impl.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
104
b84aac4ab529 import trans_impl.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
105
b84aac4ab529 import trans_impl.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
106 sub emit_code_gears {
b84aac4ab529 import trans_impl.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
107 my ($out, $impl_ir, $inter_ir) = @_;
b84aac4ab529 import trans_impl.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
108 my $impl = $impl_ir->{name};
b84aac4ab529 import trans_impl.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
109
b84aac4ab529 import trans_impl.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
110 my @inter_data = @{$inter_ir->{data}};
b84aac4ab529 import trans_impl.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
111 my $instance_inter = shift @inter_data;
b84aac4ab529 import trans_impl.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
112 if ($instance_inter =~ /union\s*Data\*\s*(\w+)/) {
b84aac4ab529 import trans_impl.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
113 $instance_inter = $1;
b84aac4ab529 import trans_impl.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
114 }
b84aac4ab529 import trans_impl.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
115 my $instance_impl = lcfirst $impl_ir->{name};
105
f1be2d5abc8a fix camel2snake
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 104
diff changeset
116 $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
117 my $data_gear_types = {};
b84aac4ab529 import trans_impl.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
118
b84aac4ab529 import trans_impl.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
119 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
120 my $data_gears = $code_ir->{args};
b9df8ea87b42 fix trans_impl.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 109
diff changeset
121 $data_gears =~ s/Impl/struct $impl/g;
103
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 102
diff changeset
122 while ($data_gears =~ /Type\*\s*(\w+),/g) {
102
b84aac4ab529 import trans_impl.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
123 my $target = $1;
b84aac4ab529 import trans_impl.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
124 if (exists $data_gear_types->{$target}){
b84aac4ab529 import trans_impl.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
125 $data_gears =~ s/Type\*/$data_gear_types->{$target}/;
b84aac4ab529 import trans_impl.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
126 } else {
b84aac4ab529 import trans_impl.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
127 my $td = "";
b84aac4ab529 import trans_impl.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
128 map { $td = $_ if ($_ =~ /$target/) } @inter_data;
b84aac4ab529 import trans_impl.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
129 if ($td =~ /(\w+)\s*([\w\*]+)\s*(\w+)/) {
b84aac4ab529 import trans_impl.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
130 my $tmp = "$1 $2";
b84aac4ab529 import trans_impl.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
131 $data_gears =~ s/Type\*/$tmp/;
b84aac4ab529 import trans_impl.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
132 $data_gear_types->{$target} = $tmp;
b84aac4ab529 import trans_impl.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
133 }
b84aac4ab529 import trans_impl.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
134 }
b84aac4ab529 import trans_impl.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
135 }
b84aac4ab529 import trans_impl.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
136
112
b9df8ea87b42 fix trans_impl.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 109
diff changeset
137 print $out "__code $code_ir->{name}$impl(";
102
b84aac4ab529 import trans_impl.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
138 print $out "$data_gears) {\n\n";
b84aac4ab529 import trans_impl.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
139
b84aac4ab529 import trans_impl.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
140 #__code next(...), __code whenEmpty(...)
b84aac4ab529 import trans_impl.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
141 my @cg = ();
b84aac4ab529 import trans_impl.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
142 while ($data_gears =~ /__code ([\w(\.)\*\s,]+?\)),?/g) {
b84aac4ab529 import trans_impl.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
143 push(@cg, $1);
b84aac4ab529 import trans_impl.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
144 }
b84aac4ab529 import trans_impl.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
145
b84aac4ab529 import trans_impl.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
146 if (@cg) {
b84aac4ab529 import trans_impl.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
147 if (@cg == 2) {
b84aac4ab529 import trans_impl.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
148 print $out " if (:TODO:) {\n";
b84aac4ab529 import trans_impl.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
149 print $out " goto ",shift(@cg),";\n";
b84aac4ab529 import trans_impl.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
150 print $out " }\n";
b84aac4ab529 import trans_impl.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
151 print $out " goto ",shift(@cg),";\n";
b84aac4ab529 import trans_impl.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
152 } else {
b84aac4ab529 import trans_impl.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
153 print $out " goto ",shift(@cg),";\n";
b84aac4ab529 import trans_impl.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
154 }
b84aac4ab529 import trans_impl.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
155 }
b84aac4ab529 import trans_impl.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
156 print $out "}\n\n";
b84aac4ab529 import trans_impl.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
157 }
b84aac4ab529 import trans_impl.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
158 }