Mercurial > hg > CbC > CbC_xv6
annotate src/gearsTools/lib/Gears/Context.pm @ 131:c690327cabc8
using dg file
author | anatofuz |
---|---|
date | Wed, 04 Dec 2019 20:44:29 +0900 |
parents | e45b8d57b9e8 |
children | ae25a4e76377 |
rev | line source |
---|---|
110
8c7c1ea49f21
impl auto gen context tools
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1 package Gears::Context; |
8c7c1ea49f21
impl auto gen context tools
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
2 |
8c7c1ea49f21
impl auto gen context tools
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
3 use strict; |
8c7c1ea49f21
impl auto gen context tools
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
4 use warnings; |
8c7c1ea49f21
impl auto gen context tools
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
5 |
8c7c1ea49f21
impl auto gen context tools
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
6 use Gears::Util; |
8c7c1ea49f21
impl auto gen context tools
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
7 use Gears::Context::Template::XV6; |
8c7c1ea49f21
impl auto gen context tools
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
8 use Carp qw/croak/; |
8c7c1ea49f21
impl auto gen context tools
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
9 |
8c7c1ea49f21
impl auto gen context tools
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
10 sub new { |
8c7c1ea49f21
impl auto gen context tools
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
11 my ($class, %args) = @_; |
8c7c1ea49f21
impl auto gen context tools
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
12 my $self = { |
8c7c1ea49f21
impl auto gen context tools
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
13 data_gears_with_count => {}, |
8c7c1ea49f21
impl auto gen context tools
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
14 find_root => $args{find_root} // ".", |
8c7c1ea49f21
impl auto gen context tools
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
15 output => $args{output}, |
8c7c1ea49f21
impl auto gen context tools
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
16 }; |
8c7c1ea49f21
impl auto gen context tools
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
17 |
8c7c1ea49f21
impl auto gen context tools
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
18 if ($args{compile_sources}) { |
8c7c1ea49f21
impl auto gen context tools
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
19 $self->{compile_sources} = $args{compile_sources}; |
8c7c1ea49f21
impl auto gen context tools
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
20 map { Gears::Util->file_checking($_); } @{$self->{compile_sources}}; |
8c7c1ea49f21
impl auto gen context tools
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
21 } |
8c7c1ea49f21
impl auto gen context tools
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
22 |
8c7c1ea49f21
impl auto gen context tools
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
23 return bless $self, $class; |
8c7c1ea49f21
impl auto gen context tools
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
24 } |
8c7c1ea49f21
impl auto gen context tools
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
25 |
8c7c1ea49f21
impl auto gen context tools
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
26 |
8c7c1ea49f21
impl auto gen context tools
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
27 sub extraction_dg_compile_sources { |
8c7c1ea49f21
impl auto gen context tools
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
28 my $self = shift; |
8c7c1ea49f21
impl auto gen context tools
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
29 my %counter; |
8c7c1ea49f21
impl auto gen context tools
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
30 for my $cbc_file (@{$self->{compile_sources}}) { |
8c7c1ea49f21
impl auto gen context tools
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
31 open my $fh , '<', $cbc_file; |
8c7c1ea49f21
impl auto gen context tools
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
32 while (my $line = <$fh>) { |
131 | 33 if ($line =~ /#interface\s*"(.*)\.h"/ || $line =~ /^\/\/\s*data_gear\s*"(.*)\.(?:h|dg)?"/) { |
110
8c7c1ea49f21
impl auto gen context tools
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
34 $self->{data_gears_with_count}->{$1}->{caller}->{$cbc_file}++; |
8c7c1ea49f21
impl auto gen context tools
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
35 $counter{interfaces}->{$1}++; |
8c7c1ea49f21
impl auto gen context tools
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
36 next; |
8c7c1ea49f21
impl auto gen context tools
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
37 } |
8c7c1ea49f21
impl auto gen context tools
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
38 |
111
239bd73abac6
add gen context.h at generate_context.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
110
diff
changeset
|
39 if ($line =~ m|//\s*Skip:\s*generate_context|) { |
239bd73abac6
add gen context.h at generate_context.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
110
diff
changeset
|
40 $line = <$fh>; |
239bd73abac6
add gen context.h at generate_context.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
110
diff
changeset
|
41 next; |
239bd73abac6
add gen context.h at generate_context.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
110
diff
changeset
|
42 } |
239bd73abac6
add gen context.h at generate_context.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
110
diff
changeset
|
43 |
110
8c7c1ea49f21
impl auto gen context tools
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
44 if ($line =~ /^(\w+)(\*)+ *create(\w+)\(([^]]*)\)/) { |
8c7c1ea49f21
impl auto gen context tools
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
45 my $interface = $1; |
8c7c1ea49f21
impl auto gen context tools
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
46 my $implementation = $3; |
8c7c1ea49f21
impl auto gen context tools
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
47 $self->{data_gears_with_count}->{$interface}->{caller}->{$cbc_file}++; |
8c7c1ea49f21
impl auto gen context tools
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
48 $self->{data_gears_with_count}->{$implementation}->{caller}->{$cbc_file}++; |
8c7c1ea49f21
impl auto gen context tools
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
49 $counter{interfaces}->{$interface}++; |
8c7c1ea49f21
impl auto gen context tools
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
50 $counter{impl}->{$implementation}++; |
8c7c1ea49f21
impl auto gen context tools
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
51 next; |
8c7c1ea49f21
impl auto gen context tools
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
52 } |
8c7c1ea49f21
impl auto gen context tools
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
53 |
8c7c1ea49f21
impl auto gen context tools
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
54 if ($line =~ /Gearef\(context,\s*(\w+)\)/) { |
8c7c1ea49f21
impl auto gen context tools
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
55 my $implementation = $1; |
8c7c1ea49f21
impl auto gen context tools
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
56 $counter{impl}->{$implementation}++; |
8c7c1ea49f21
impl auto gen context tools
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
57 $self->{data_gears_with_count}->{$implementation}->{caller}->{$cbc_file}++; |
8c7c1ea49f21
impl auto gen context tools
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
58 next; |
8c7c1ea49f21
impl auto gen context tools
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
59 } |
8c7c1ea49f21
impl auto gen context tools
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
60 |
116 | 61 #Element* element = &ALLOCATE(cbc_context, Element)->Element; |
62 if ($line =~ /ALLOCATE\w*\((?:cbc_)?context,\s*(\w+)\)/) { | |
63 my $implementation = $1; | |
64 $counter{impl}->{$implementation}++; | |
65 $self->{data_gears_with_count}->{$implementation}->{caller}->{$cbc_file}++; | |
66 next; | |
67 } | |
68 | |
69 if ($line =~ /ALLOCATE_(?:PTR_)?ARRAY\((?:cbc_)?context,\s*(\w+),[\s\w]+\)/) { | |
70 my $implementation = $1; | |
71 $counter{impl}->{$implementation}++; | |
72 $self->{data_gears_with_count}->{$implementation}->{caller}->{$cbc_file}++; | |
73 next; | |
74 } | |
75 | |
76 if ($line =~ /new\s+(\w+?)\([\w\s]*\);/) { | |
110
8c7c1ea49f21
impl auto gen context tools
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
77 my $implementation = $1; |
8c7c1ea49f21
impl auto gen context tools
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
78 $counter{impl}->{$implementation}++; |
8c7c1ea49f21
impl auto gen context tools
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
79 $self->{data_gears_with_count}->{$implementation}->{caller}->{$cbc_file}++; |
8c7c1ea49f21
impl auto gen context tools
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
80 next; |
8c7c1ea49f21
impl auto gen context tools
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
81 } |
8c7c1ea49f21
impl auto gen context tools
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
82 |
8c7c1ea49f21
impl auto gen context tools
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
83 if ($line =~ /ALLOCATE_DATA_GEAR\((\w+),\s*(\w+)\)/) { |
8c7c1ea49f21
impl auto gen context tools
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
84 my $implementation = $2; |
8c7c1ea49f21
impl auto gen context tools
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
85 $counter{impl}->{$implementation}++; |
8c7c1ea49f21
impl auto gen context tools
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
86 $self->{data_gears_with_count}->{$implementation}->{caller}->{$cbc_file}++; |
8c7c1ea49f21
impl auto gen context tools
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
87 next; |
8c7c1ea49f21
impl auto gen context tools
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
88 } |
8c7c1ea49f21
impl auto gen context tools
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
89 |
8c7c1ea49f21
impl auto gen context tools
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
90 #TaskManagerImpl* taskManager = (TaskManagerImpl*)GearImpl(context, TaskManager, taskManager); |
8c7c1ea49f21
impl auto gen context tools
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
91 if ($line =~ /\((\w+)\*\)GearImpl\(context,\s*(\w+),\s*(\w+)\)/) { |
8c7c1ea49f21
impl auto gen context tools
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
92 my $interface = $2; |
8c7c1ea49f21
impl auto gen context tools
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
93 my $implementation = $1; |
8c7c1ea49f21
impl auto gen context tools
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
94 $self->{data_gears_with_count}->{$interface}->{caller}->{$cbc_file}++; |
8c7c1ea49f21
impl auto gen context tools
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
95 $counter{interfaces}->{$interface}++; |
8c7c1ea49f21
impl auto gen context tools
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
96 $counter{impl}->{$implementation}++; |
8c7c1ea49f21
impl auto gen context tools
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
97 next; |
8c7c1ea49f21
impl auto gen context tools
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
98 } |
8c7c1ea49f21
impl auto gen context tools
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
99 |
8c7c1ea49f21
impl auto gen context tools
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
100 if ($line =~ /^__code/) { |
8c7c1ea49f21
impl auto gen context tools
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
101 while ($line =~ /struct (\w+)\s*\*/g) { |
8c7c1ea49f21
impl auto gen context tools
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
102 next if $1 eq "Context"; |
8c7c1ea49f21
impl auto gen context tools
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
103 $self->{data_gears_with_count}->{$1}->{caller}->{$cbc_file}++; |
8c7c1ea49f21
impl auto gen context tools
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
104 next if (exists $counter{interfaces}->{$1}); |
8c7c1ea49f21
impl auto gen context tools
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
105 $counter{impl}->{$1}++; |
8c7c1ea49f21
impl auto gen context tools
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
106 } |
8c7c1ea49f21
impl auto gen context tools
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
107 } |
8c7c1ea49f21
impl auto gen context tools
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
108 } |
8c7c1ea49f21
impl auto gen context tools
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
109 close $fh; |
8c7c1ea49f21
impl auto gen context tools
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
110 } |
8c7c1ea49f21
impl auto gen context tools
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
111 $counter{interfaces}->{Meta}++; |
8c7c1ea49f21
impl auto gen context tools
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
112 $counter{interfaces}->{TaskManager}++; |
8c7c1ea49f21
impl auto gen context tools
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
113 $self->{data_gears_with_count}->{Meta}++; |
8c7c1ea49f21
impl auto gen context tools
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
114 $self->{data_gears_with_count}->{TaskManager}++; |
8c7c1ea49f21
impl auto gen context tools
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
115 return \%counter; |
8c7c1ea49f21
impl auto gen context tools
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
116 } |
8c7c1ea49f21
impl auto gen context tools
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
117 |
8c7c1ea49f21
impl auto gen context tools
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
118 sub set_data_gear_header_path { |
8c7c1ea49f21
impl auto gen context tools
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
119 my $self = shift; |
8c7c1ea49f21
impl auto gen context tools
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
120 my @data_gears_name; |
8c7c1ea49f21
impl auto gen context tools
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
121 if (@_) { |
8c7c1ea49f21
impl auto gen context tools
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
122 @data_gears_name = @_; |
8c7c1ea49f21
impl auto gen context tools
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
123 } else { |
8c7c1ea49f21
impl auto gen context tools
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
124 map { push (@data_gears_name,$_) if $_ ne "Context" } keys %{$self->{data_gears_with_count}}; |
8c7c1ea49f21
impl auto gen context tools
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
125 } |
8c7c1ea49f21
impl auto gen context tools
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
126 return _find_headers($self->{find_root},\@data_gears_name); |
8c7c1ea49f21
impl auto gen context tools
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
127 } |
8c7c1ea49f21
impl auto gen context tools
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
128 |
8c7c1ea49f21
impl auto gen context tools
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
129 sub update_dg_each_header_path { |
8c7c1ea49f21
impl auto gen context tools
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
130 my ($self, $dgs, $dg2path) = @_; |
8c7c1ea49f21
impl auto gen context tools
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
131 my $new_dgs; |
8c7c1ea49f21
impl auto gen context tools
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
132 for my $kind (keys %$dgs) { |
8c7c1ea49f21
impl auto gen context tools
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
133 for my $dg_name (keys %{$dgs->{$kind}}) { |
8c7c1ea49f21
impl auto gen context tools
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
134 if ($dg2path->{$dg_name}) { |
8c7c1ea49f21
impl auto gen context tools
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
135 $new_dgs->{$kind}->{$dg_name} = $dg2path->{$dg_name}; |
8c7c1ea49f21
impl auto gen context tools
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
136 } else { |
8c7c1ea49f21
impl auto gen context tools
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
137 croak "failed trans header $dg_name\n"; |
8c7c1ea49f21
impl auto gen context tools
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
138 } |
8c7c1ea49f21
impl auto gen context tools
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
139 } |
8c7c1ea49f21
impl auto gen context tools
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
140 } |
8c7c1ea49f21
impl auto gen context tools
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
141 return $new_dgs; |
8c7c1ea49f21
impl auto gen context tools
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
142 } |
8c7c1ea49f21
impl auto gen context tools
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
143 |
8c7c1ea49f21
impl auto gen context tools
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
144 sub tree2create_context_h { |
8c7c1ea49f21
impl auto gen context tools
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
145 my ($self, $dg2path) = @_; |
8c7c1ea49f21
impl auto gen context tools
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
146 |
8c7c1ea49f21
impl auto gen context tools
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
147 my $data_struct_str = $dg2path ? $self->tree2data_struct_str($dg2path) : "\n"; |
8c7c1ea49f21
impl auto gen context tools
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
148 |
8c7c1ea49f21
impl auto gen context tools
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
149 my $output = $self->_select_output(); |
8c7c1ea49f21
impl auto gen context tools
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
150 Gears::Context::Template::XV6->emit_top_header($output); |
8c7c1ea49f21
impl auto gen context tools
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
151 Gears::Context::Template::XV6->emit_data_gears($output,$data_struct_str); |
8c7c1ea49f21
impl auto gen context tools
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
152 Gears::Context::Template::XV6->emit_last_header($output); |
8c7c1ea49f21
impl auto gen context tools
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
153 close $output; |
8c7c1ea49f21
impl auto gen context tools
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
154 } |
8c7c1ea49f21
impl auto gen context tools
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
155 |
8c7c1ea49f21
impl auto gen context tools
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
156 sub _select_output { |
8c7c1ea49f21
impl auto gen context tools
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
157 my $self = shift; |
8c7c1ea49f21
impl auto gen context tools
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
158 print "$self->{output}\n"; |
8c7c1ea49f21
impl auto gen context tools
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
159 if ($self->{output} eq 'stdout') { |
8c7c1ea49f21
impl auto gen context tools
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
160 return *STDOUT; |
8c7c1ea49f21
impl auto gen context tools
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
161 } |
8c7c1ea49f21
impl auto gen context tools
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
162 open my $fh, '>', $self->{output}; |
8c7c1ea49f21
impl auto gen context tools
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
163 return $fh; |
8c7c1ea49f21
impl auto gen context tools
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
164 } |
8c7c1ea49f21
impl auto gen context tools
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
165 |
8c7c1ea49f21
impl auto gen context tools
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
166 sub tree2data_struct_str { |
8c7c1ea49f21
impl auto gen context tools
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
167 my ($self, $dg_str) = @_; |
8c7c1ea49f21
impl auto gen context tools
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
168 my $data_struct_str = ""; |
8c7c1ea49f21
impl auto gen context tools
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
169 for my $interface (sort keys %$dg_str) { |
8c7c1ea49f21
impl auto gen context tools
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
170 $data_struct_str .= Gears::Util->h2context_str($dg_str->{$interface}->{elem}); |
8c7c1ea49f21
impl auto gen context tools
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
171 next unless ($dg_str->{$interface}->{impl}); |
8c7c1ea49f21
impl auto gen context tools
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
172 for my $impl (sort keys %{$dg_str->{$interface}->{impl}}) { |
8c7c1ea49f21
impl auto gen context tools
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
173 $data_struct_str .= Gears::Util->h2context_str($dg_str->{$interface}->{impl}->{$impl}); |
8c7c1ea49f21
impl auto gen context tools
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
174 } |
8c7c1ea49f21
impl auto gen context tools
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
175 } |
8c7c1ea49f21
impl auto gen context tools
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
176 return $data_struct_str; |
8c7c1ea49f21
impl auto gen context tools
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
177 } |
8c7c1ea49f21
impl auto gen context tools
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
178 |
8c7c1ea49f21
impl auto gen context tools
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
179 sub createImplTree_from_header { |
8c7c1ea49f21
impl auto gen context tools
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
180 my ($self, $dg2path) = @_; |
8c7c1ea49f21
impl auto gen context tools
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
181 my %dg_str = (); |
8c7c1ea49f21
impl auto gen context tools
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
182 |
8c7c1ea49f21
impl auto gen context tools
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
183 my $inters = $dg2path->{interfaces}; |
8c7c1ea49f21
impl auto gen context tools
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
184 my $impls = $dg2path->{impl}; |
8c7c1ea49f21
impl auto gen context tools
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
185 |
8c7c1ea49f21
impl auto gen context tools
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
186 use Data::Dumper; |
8c7c1ea49f21
impl auto gen context tools
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
187 print Dumper $dg2path; |
111
239bd73abac6
add gen context.h at generate_context.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
110
diff
changeset
|
188 print Dumper $self; |
110
8c7c1ea49f21
impl auto gen context tools
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
189 |
8c7c1ea49f21
impl auto gen context tools
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
190 map { $dg_str{$_}->{elem} = Gears::Util->parse_interface($inters->{$_}) } keys %$inters; |
8c7c1ea49f21
impl auto gen context tools
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
191 |
8c7c1ea49f21
impl auto gen context tools
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
192 map { |
8c7c1ea49f21
impl auto gen context tools
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
193 my $res = Gears::Util->parse($impls->{$_}); |
8c7c1ea49f21
impl auto gen context tools
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
194 if ($res->{isa}) { |
8c7c1ea49f21
impl auto gen context tools
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
195 $dg_str{$res->{isa}}->{impl}->{$_} = $res; |
8c7c1ea49f21
impl auto gen context tools
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
196 } else { |
8c7c1ea49f21
impl auto gen context tools
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
197 $dg_str{$_}->{elem} = $res; |
8c7c1ea49f21
impl auto gen context tools
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
198 } |
8c7c1ea49f21
impl auto gen context tools
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
199 } keys %$impls; |
8c7c1ea49f21
impl auto gen context tools
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
200 return \%dg_str; |
8c7c1ea49f21
impl auto gen context tools
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
201 } |
8c7c1ea49f21
impl auto gen context tools
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
202 |
8c7c1ea49f21
impl auto gen context tools
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
203 sub _find_headers { |
8c7c1ea49f21
impl auto gen context tools
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
204 my ($search_bash_path, $targets) = @_; |
8c7c1ea49f21
impl auto gen context tools
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
205 my %res; |
8c7c1ea49f21
impl auto gen context tools
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
206 map { $res{$_}++ } @$targets; |
8c7c1ea49f21
impl auto gen context tools
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
207 |
8c7c1ea49f21
impl auto gen context tools
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
208 my $header_paths = Gears::Util->find_headers_path($search_bash_path); |
8c7c1ea49f21
impl auto gen context tools
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
209 map { |
131 | 210 if (/(\w+)\.(?:h|dg)/) { |
116 | 211 my $header_file = $1; |
212 if (exists $res{$header_file}) { | |
213 if ($res{$header_file} =~ /^\d+$/){ | |
214 $res{$header_file} = $_; | |
215 } elsif (($_ =~ /\.dg$/) && ($res{$header_file} =~ /\.h$/)) { | |
216 $res{$header_file} = $_; | |
217 } | |
218 } | |
110
8c7c1ea49f21
impl auto gen context tools
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
219 } |
112 | 220 } sort @$header_paths; |
110
8c7c1ea49f21
impl auto gen context tools
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
221 return \%res; |
8c7c1ea49f21
impl auto gen context tools
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
222 } |
8c7c1ea49f21
impl auto gen context tools
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
223 |
8c7c1ea49f21
impl auto gen context tools
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
224 1; |