annotate src/parallel_execution/trans_impl.pl @ 559:2dc06f944a85

tweak
author anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
date Tue, 19 Nov 2019 00:06:07 +0900
parents 8a825fc15817
children 2276952ed717
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
555
bcc137ca91da add trans_impl.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1 #!/usr/bin/env perl
bcc137ca91da add trans_impl.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2 use strict;
bcc137ca91da add trans_impl.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
3 use warnings;
bcc137ca91da add trans_impl.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
4
557
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 556
diff changeset
5 use FindBin;
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 556
diff changeset
6 use lib "$FindBin::Bin/lib";
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 556
diff changeset
7 use Gears::Util;
555
bcc137ca91da add trans_impl.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
8
557
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 556
diff changeset
9 use DDP { deparse => 1};
555
bcc137ca91da add trans_impl.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
10
557
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 556
diff changeset
11 my $impl_file = shift or die 'require impl file';
559
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 558
diff changeset
12 my $impl_ir = Gears::Util->parse_impl($impl_file);
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 558
diff changeset
13 my $interface_file = Gears::Util->find_header($impl_ir->{isa},"$FindBin::Bin");
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 558
diff changeset
14
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 558
diff changeset
15
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 558
diff changeset
16 my $inter_ir = Gears::Util->parse_code_verbose($interface_file);
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 558
diff changeset
17 my $stdout = *STDOUT;
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 558
diff changeset
18 emit_constracutor($stdout,$impl_ir,$inter_ir);
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 558
diff changeset
19 #emit_include_part($stdout, "Stack");
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 558
diff changeset
20 #emit_impl_header_in_comment($stdout, $impl_file);
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 558
diff changeset
21
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 558
diff changeset
22 sub emit_include_part {
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 558
diff changeset
23 my ($out, $interface) = @_;
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 558
diff changeset
24 print $out <<"EOF"
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 558
diff changeset
25 #include "../context.h";
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 558
diff changeset
26 #interface "$interface.h";
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 558
diff changeset
27
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 558
diff changeset
28 EOF
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 558
diff changeset
29 }
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 558
diff changeset
30
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 558
diff changeset
31 sub emit_impl_header_in_comment {
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 558
diff changeset
32 my ($out, $impl_file) = @_;
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 558
diff changeset
33 my $line = Gears::Util->slup($impl_file);
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 558
diff changeset
34 print $out "// ----\n";
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 558
diff changeset
35 map { print $out "// $_\n" } split /\n/, $line;
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 558
diff changeset
36 print $out "// ----\n";
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 558
diff changeset
37 }
558
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 557
diff changeset
38
559
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 558
diff changeset
39 sub emit_constracutor {
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 558
diff changeset
40 my ($out, $impl_ir, $inter_ir) = @_;
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 558
diff changeset
41
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 558
diff changeset
42 my $instance_inter = shift @{$inter_ir->{data}};
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 558
diff changeset
43 if ($instance_inter =~ /union\s*Data\*\s*(\w+)/) {
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 558
diff changeset
44 $instance_inter = $1;
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 558
diff changeset
45 }
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 558
diff changeset
46 my $instance_impl = lcfirst $impl_ir->{name};
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 558
diff changeset
47
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 558
diff changeset
48 print $out <<"EOF";
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 558
diff changeset
49 $impl_ir->{name}* create$impl_ir->{name}(struct Context* context) {
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 558
diff changeset
50 struct $impl_ir->{isa}* $instance_inter = new $impl_ir->{isa}();
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 558
diff changeset
51 struct $impl_ir->{name}* $instance_impl = new $impl_ir->{name}();
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 558
diff changeset
52 $instance_inter->$instance_inter = (union Data*)$instance_impl;
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 558
diff changeset
53 EOF
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 558
diff changeset
54
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 558
diff changeset
55 for my $datum (@{$impl_ir->{data}}) {
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 558
diff changeset
56 if ($datum =~ /\w+ \w+\* (\w+)/) {
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 558
diff changeset
57 print $out " ${instance_impl}->$1 = NULL;\n"
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 558
diff changeset
58 }
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 558
diff changeset
59 }
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 558
diff changeset
60
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 558
diff changeset
61 for my $code (@{$inter_ir->{codes}}) {
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 558
diff changeset
62 my $code_gear = $code->[0];
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 558
diff changeset
63 print $out " ${instance_inter}->$code_gear = C_$code_gear$impl_ir->{name};\n"
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 558
diff changeset
64 }
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 558
diff changeset
65
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 558
diff changeset
66 print $out " return $instance_inter;\n";
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 558
diff changeset
67 print $out "}\n";
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 558
diff changeset
68 }
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 558
diff changeset
69