Mercurial > hg > GearsTemplate
annotate src/parallel_execution/lib/Gears/Context.pm @ 575:3e3158198cb5
bug fix...
author | anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Mon, 25 Nov 2019 17:03:33 +0900 |
parents | 7d66643d837d |
children | d6718b5ad312 |
rev | line source |
---|---|
572
3c35bcb82f08
mv Gears.pm to Gears/Context.pm
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
568
diff
changeset
|
1 package Gears::Context; |
565 | 2 |
3 use strict; | |
4 use warnings; | |
5 | |
6 use Gears::Util; | |
574
7d66643d837d
impl auto_gen_context toolset
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
573
diff
changeset
|
7 use Gears::Context::Template; |
7d66643d837d
impl auto_gen_context toolset
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
573
diff
changeset
|
8 use Carp qw/croak/; |
565 | 9 |
10 sub new { | |
11 my ($class, %args) = @_; | |
12 my $self = { | |
13 data_gears_with_count => {}, | |
574
7d66643d837d
impl auto_gen_context toolset
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
573
diff
changeset
|
14 find_root => $args{find_root} // ".", |
575 | 15 output => $args{output}, |
565 | 16 }; |
17 | |
18 if ($args{compile_sources}) { | |
19 $self->{compile_sources} = $args{compile_sources}; | |
20 map { Gears::Util->file_checking($_); } @{$self->{compile_sources}}; | |
21 } | |
575 | 22 |
565 | 23 return bless $self, $class; |
24 } | |
25 | |
574
7d66643d837d
impl auto_gen_context toolset
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
573
diff
changeset
|
26 |
566
dada17cba91d
interface to struct...
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
565
diff
changeset
|
27 sub extraction_dg_compile_sources { |
565 | 28 my $self = shift; |
574
7d66643d837d
impl auto_gen_context toolset
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
573
diff
changeset
|
29 my %counter; |
7d66643d837d
impl auto_gen_context toolset
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
573
diff
changeset
|
30 for my $cbc_file (@{$self->{compile_sources}}) { |
7d66643d837d
impl auto_gen_context toolset
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
573
diff
changeset
|
31 open my $fh , '<', $cbc_file; |
7d66643d837d
impl auto_gen_context toolset
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
573
diff
changeset
|
32 while (my $line = <$fh>) { |
575 | 33 if ($line =~ /#interface\s*"(.*)\.h"/ || $line =~ /^\/\/\s*use\s*"(.*)\.h"/) { |
574
7d66643d837d
impl auto_gen_context toolset
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
573
diff
changeset
|
34 $self->{data_gears_with_count}->{$1}->{caller}->{$cbc_file}++; |
7d66643d837d
impl auto_gen_context toolset
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
573
diff
changeset
|
35 $counter{interfaces}->{$1}++; |
7d66643d837d
impl auto_gen_context toolset
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
573
diff
changeset
|
36 next; |
7d66643d837d
impl auto_gen_context toolset
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
573
diff
changeset
|
37 } |
7d66643d837d
impl auto_gen_context toolset
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
573
diff
changeset
|
38 |
7d66643d837d
impl auto_gen_context toolset
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
573
diff
changeset
|
39 if ($line =~ /__code/) { |
7d66643d837d
impl auto_gen_context toolset
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
573
diff
changeset
|
40 while ($line =~ /struct (\w+)*/g) { |
7d66643d837d
impl auto_gen_context toolset
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
573
diff
changeset
|
41 next if $1 eq "Context"; |
7d66643d837d
impl auto_gen_context toolset
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
573
diff
changeset
|
42 $self->{data_gears_with_count}->{$1}->{caller}->{$cbc_file}++; |
7d66643d837d
impl auto_gen_context toolset
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
573
diff
changeset
|
43 next if (exists $counter{interfaces}->{$1}); |
7d66643d837d
impl auto_gen_context toolset
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
573
diff
changeset
|
44 $counter{impl}->{$1}++; |
7d66643d837d
impl auto_gen_context toolset
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
573
diff
changeset
|
45 } |
7d66643d837d
impl auto_gen_context toolset
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
573
diff
changeset
|
46 } |
7d66643d837d
impl auto_gen_context toolset
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
573
diff
changeset
|
47 } |
7d66643d837d
impl auto_gen_context toolset
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
573
diff
changeset
|
48 close $fh; |
7d66643d837d
impl auto_gen_context toolset
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
573
diff
changeset
|
49 } |
575 | 50 $counter{interfaces}->{Meta}++; |
51 $self->{data_gears_with_count}->{Meta}++; | |
574
7d66643d837d
impl auto_gen_context toolset
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
573
diff
changeset
|
52 return \%counter; |
565 | 53 } |
54 | |
574
7d66643d837d
impl auto_gen_context toolset
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
573
diff
changeset
|
55 sub set_data_gear_header_path { |
568
840597c5d242
add_parse_create_each_context.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
567
diff
changeset
|
56 my $self = shift; |
840597c5d242
add_parse_create_each_context.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
567
diff
changeset
|
57 my @data_gears_name; |
840597c5d242
add_parse_create_each_context.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
567
diff
changeset
|
58 if (@_) { |
840597c5d242
add_parse_create_each_context.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
567
diff
changeset
|
59 @data_gears_name = @_; |
840597c5d242
add_parse_create_each_context.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
567
diff
changeset
|
60 } else { |
573
5f4b7ff18a34
set header path each include struct
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
572
diff
changeset
|
61 map { push (@data_gears_name,$_) if $_ ne "Context" } keys %{$self->{data_gears_with_count}}; |
568
840597c5d242
add_parse_create_each_context.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
567
diff
changeset
|
62 } |
574
7d66643d837d
impl auto_gen_context toolset
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
573
diff
changeset
|
63 return _find_headers($self->{find_root},\@data_gears_name); |
7d66643d837d
impl auto_gen_context toolset
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
573
diff
changeset
|
64 } |
7d66643d837d
impl auto_gen_context toolset
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
573
diff
changeset
|
65 |
7d66643d837d
impl auto_gen_context toolset
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
573
diff
changeset
|
66 sub update_dg_each_header_path { |
7d66643d837d
impl auto_gen_context toolset
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
573
diff
changeset
|
67 my ($self, $dgs, $dg2path) = @_; |
7d66643d837d
impl auto_gen_context toolset
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
573
diff
changeset
|
68 my $new_dgs; |
7d66643d837d
impl auto_gen_context toolset
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
573
diff
changeset
|
69 for my $kind (keys %$dgs) { |
7d66643d837d
impl auto_gen_context toolset
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
573
diff
changeset
|
70 for my $dg_name (keys %{$dgs->{$kind}}) { |
7d66643d837d
impl auto_gen_context toolset
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
573
diff
changeset
|
71 if ($dg2path->{$dg_name}) { |
7d66643d837d
impl auto_gen_context toolset
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
573
diff
changeset
|
72 $new_dgs->{$kind}->{$dg_name} = $dg2path->{$dg_name}; |
7d66643d837d
impl auto_gen_context toolset
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
573
diff
changeset
|
73 } else { |
7d66643d837d
impl auto_gen_context toolset
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
573
diff
changeset
|
74 croak "failed trans header $dg_name\n"; |
7d66643d837d
impl auto_gen_context toolset
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
573
diff
changeset
|
75 } |
7d66643d837d
impl auto_gen_context toolset
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
573
diff
changeset
|
76 } |
7d66643d837d
impl auto_gen_context toolset
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
573
diff
changeset
|
77 } |
7d66643d837d
impl auto_gen_context toolset
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
573
diff
changeset
|
78 return $new_dgs; |
7d66643d837d
impl auto_gen_context toolset
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
573
diff
changeset
|
79 } |
7d66643d837d
impl auto_gen_context toolset
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
573
diff
changeset
|
80 |
575 | 81 sub tree2create_context_h { |
574
7d66643d837d
impl auto_gen_context toolset
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
573
diff
changeset
|
82 my ($self, $dg2path) = @_; |
575 | 83 my $data_struct_str = $self->tree2data_struct_str($dg2path); |
84 | |
85 my $output = $self->_select_output(); | |
86 Gears::Context::Template->emit_top_header($output); | |
87 Gears::Context::Template->emit_data_gears($output,$data_struct_str); | |
88 Gears::Context::Template->emit_last_header($output); | |
89 close $output; | |
568
840597c5d242
add_parse_create_each_context.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
567
diff
changeset
|
90 } |
840597c5d242
add_parse_create_each_context.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
567
diff
changeset
|
91 |
575 | 92 sub _select_output { |
93 my $self = shift; | |
94 print "$self->{output}\n"; | |
95 if ($self->{output} eq 'stdout') { | |
96 return *STDOUT; | |
97 } | |
98 open my $fh, '>', $self->{output}; | |
99 return $fh; | |
100 } | |
101 | |
102 sub tree2data_struct_str { | |
103 my ($self, $dg_str) = @_; | |
574
7d66643d837d
impl auto_gen_context toolset
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
573
diff
changeset
|
104 my $data_struct_str = ""; |
7d66643d837d
impl auto_gen_context toolset
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
573
diff
changeset
|
105 for my $interface (sort keys %$dg_str) { |
7d66643d837d
impl auto_gen_context toolset
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
573
diff
changeset
|
106 $data_struct_str .= Gears::Util->h2context_str($dg_str->{$interface}->{elem}); |
7d66643d837d
impl auto_gen_context toolset
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
573
diff
changeset
|
107 next unless ($dg_str->{$interface}->{impl}); |
7d66643d837d
impl auto_gen_context toolset
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
573
diff
changeset
|
108 for my $impl (sort keys %{$dg_str->{$interface}->{impl}}) { |
7d66643d837d
impl auto_gen_context toolset
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
573
diff
changeset
|
109 $data_struct_str .= Gears::Util->h2context_str($dg_str->{$interface}->{impl}->{$impl}); |
7d66643d837d
impl auto_gen_context toolset
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
573
diff
changeset
|
110 } |
7d66643d837d
impl auto_gen_context toolset
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
573
diff
changeset
|
111 } |
7d66643d837d
impl auto_gen_context toolset
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
573
diff
changeset
|
112 return $data_struct_str; |
7d66643d837d
impl auto_gen_context toolset
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
573
diff
changeset
|
113 } |
7d66643d837d
impl auto_gen_context toolset
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
573
diff
changeset
|
114 |
575 | 115 sub createImplTree_from_header { |
574
7d66643d837d
impl auto_gen_context toolset
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
573
diff
changeset
|
116 my ($self, $dg2path) = @_; |
7d66643d837d
impl auto_gen_context toolset
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
573
diff
changeset
|
117 my %dg_str = (); |
7d66643d837d
impl auto_gen_context toolset
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
573
diff
changeset
|
118 |
7d66643d837d
impl auto_gen_context toolset
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
573
diff
changeset
|
119 my $inters = $dg2path->{interfaces}; |
7d66643d837d
impl auto_gen_context toolset
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
573
diff
changeset
|
120 my $impls = $dg2path->{impl}; |
7d66643d837d
impl auto_gen_context toolset
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
573
diff
changeset
|
121 map { $dg_str{$_}->{elem} = Gears::Util->parse_interface($inters->{$_}) } keys %$inters; |
7d66643d837d
impl auto_gen_context toolset
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
573
diff
changeset
|
122 |
7d66643d837d
impl auto_gen_context toolset
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
573
diff
changeset
|
123 map { |
7d66643d837d
impl auto_gen_context toolset
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
573
diff
changeset
|
124 my $res = Gears::Util->parse($impls->{$_}); |
7d66643d837d
impl auto_gen_context toolset
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
573
diff
changeset
|
125 if ($res->{isa}) { |
7d66643d837d
impl auto_gen_context toolset
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
573
diff
changeset
|
126 $dg_str{$res->{isa}}->{impl}->{$_} = $res; |
7d66643d837d
impl auto_gen_context toolset
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
573
diff
changeset
|
127 } else { |
7d66643d837d
impl auto_gen_context toolset
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
573
diff
changeset
|
128 $dg_str{$_}->{elem} = $res; |
7d66643d837d
impl auto_gen_context toolset
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
573
diff
changeset
|
129 } |
7d66643d837d
impl auto_gen_context toolset
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
573
diff
changeset
|
130 } keys %$impls; |
7d66643d837d
impl auto_gen_context toolset
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
573
diff
changeset
|
131 return \%dg_str; |
7d66643d837d
impl auto_gen_context toolset
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
573
diff
changeset
|
132 } |
7d66643d837d
impl auto_gen_context toolset
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
573
diff
changeset
|
133 |
7d66643d837d
impl auto_gen_context toolset
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
573
diff
changeset
|
134 sub _find_headers { |
7d66643d837d
impl auto_gen_context toolset
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
573
diff
changeset
|
135 my ($search_bash_path, $targets) = @_; |
573
5f4b7ff18a34
set header path each include struct
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
572
diff
changeset
|
136 my %res; |
5f4b7ff18a34
set header path each include struct
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
572
diff
changeset
|
137 map { $res{$_}++ } @$targets; |
5f4b7ff18a34
set header path each include struct
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
572
diff
changeset
|
138 |
5f4b7ff18a34
set header path each include struct
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
572
diff
changeset
|
139 my $header_paths = Gears::Util->find_headers_path($search_bash_path); |
5f4b7ff18a34
set header path each include struct
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
572
diff
changeset
|
140 map { |
5f4b7ff18a34
set header path each include struct
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
572
diff
changeset
|
141 /(\w+)\.h/; |
5f4b7ff18a34
set header path each include struct
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
572
diff
changeset
|
142 my $header_tile = $1; |
5f4b7ff18a34
set header path each include struct
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
572
diff
changeset
|
143 if (exists $res{$header_tile}){ |
5f4b7ff18a34
set header path each include struct
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
572
diff
changeset
|
144 $res{$header_tile} = $_; |
5f4b7ff18a34
set header path each include struct
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
572
diff
changeset
|
145 } |
5f4b7ff18a34
set header path each include struct
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
572
diff
changeset
|
146 } @$header_paths; |
574
7d66643d837d
impl auto_gen_context toolset
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
573
diff
changeset
|
147 return \%res; |
573
5f4b7ff18a34
set header path each include struct
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
572
diff
changeset
|
148 } |
565 | 149 |
150 1; |