Mercurial > hg > Members > menikon > CbC_xv6
annotate src/gearsTools/lib/Gears/Context.pm @ 154:343f8f3c8f18
add pipe.h
author | anatofuz |
---|---|
date | Thu, 19 Dec 2019 11:32:40 +0900 |
parents | 2a0de2f8596e |
children | 0ef5c1d852fe |
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 |
154 | 44 #if ($line =~ /^(\w+)(\*)+ *create(\w+)\(([^]]*)\)/) { |
45 # my $interface = $1; | |
46 # my $implementation = $3; | |
47 # $self->{data_gears_with_count}->{$interface}->{caller}->{$cbc_file}++; | |
48 # $self->{data_gears_with_count}->{$implementation}->{caller}->{$cbc_file}++; | |
49 # $counter{interfaces}->{$interface}++; | |
50 # $counter{impl}->{$implementation}++; | |
51 # next; | |
52 #} | |
110
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 = ""; |
133
ae25a4e76377
fix gen_context.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
131
diff
changeset
|
169 |
134 | 170 # 定義順で大変なのでオミット |
171 ##もとのxv6に登録されているものはcontext.hには定義を書かない | |
172 #my $alread_defined_str = _already_defined_struct(); | |
173 #for my $str (sort keys %$dg_str) { | |
174 # if (defined $alread_defined_str->{$str}) { | |
175 # my $str_name = $alread_defined_str->{$str}; | |
176 # $data_struct_str .= "struct $str_name $str_name;\n"; | |
177 # delete $dg_str->{$str_name}; | |
178 # } | |
179 #} | |
133
ae25a4e76377
fix gen_context.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
131
diff
changeset
|
180 |
ae25a4e76377
fix gen_context.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
131
diff
changeset
|
181 #定義されてないものはcontext.hに書くフォーマットに合わせておく |
110
8c7c1ea49f21
impl auto gen context tools
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
182 for my $interface (sort keys %$dg_str) { |
8c7c1ea49f21
impl auto gen context tools
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
183 $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
|
184 next unless ($dg_str->{$interface}->{impl}); |
8c7c1ea49f21
impl auto gen context tools
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
185 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
|
186 $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
|
187 } |
8c7c1ea49f21
impl auto gen context tools
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
188 } |
8c7c1ea49f21
impl auto gen context tools
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
189 return $data_struct_str; |
8c7c1ea49f21
impl auto gen context tools
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
190 } |
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 sub createImplTree_from_header { |
8c7c1ea49f21
impl auto gen context tools
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
193 my ($self, $dg2path) = @_; |
8c7c1ea49f21
impl auto gen context tools
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
194 my %dg_str = (); |
8c7c1ea49f21
impl auto gen context tools
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
195 |
8c7c1ea49f21
impl auto gen context tools
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
196 my $inters = $dg2path->{interfaces}; |
8c7c1ea49f21
impl auto gen context tools
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
197 my $impls = $dg2path->{impl}; |
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 use Data::Dumper; |
8c7c1ea49f21
impl auto gen context tools
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
200 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
|
201 print Dumper $self; |
110
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 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
|
204 |
8c7c1ea49f21
impl auto gen context tools
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
205 map { |
8c7c1ea49f21
impl auto gen context tools
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
206 my $res = Gears::Util->parse($impls->{$_}); |
8c7c1ea49f21
impl auto gen context tools
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
207 if ($res->{isa}) { |
8c7c1ea49f21
impl auto gen context tools
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
208 $dg_str{$res->{isa}}->{impl}->{$_} = $res; |
8c7c1ea49f21
impl auto gen context tools
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
209 } else { |
8c7c1ea49f21
impl auto gen context tools
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
210 $dg_str{$_}->{elem} = $res; |
8c7c1ea49f21
impl auto gen context tools
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
211 } |
8c7c1ea49f21
impl auto gen context tools
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
212 } keys %$impls; |
8c7c1ea49f21
impl auto gen context tools
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
213 return \%dg_str; |
8c7c1ea49f21
impl auto gen context tools
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
214 } |
8c7c1ea49f21
impl auto gen context tools
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
215 |
8c7c1ea49f21
impl auto gen context tools
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
216 sub _find_headers { |
8c7c1ea49f21
impl auto gen context tools
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
217 my ($search_bash_path, $targets) = @_; |
8c7c1ea49f21
impl auto gen context tools
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
218 my %res; |
8c7c1ea49f21
impl auto gen context tools
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
219 map { $res{$_}++ } @$targets; |
8c7c1ea49f21
impl auto gen context tools
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
220 |
8c7c1ea49f21
impl auto gen context tools
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
221 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
|
222 map { |
131 | 223 if (/(\w+)\.(?:h|dg)/) { |
116 | 224 my $header_file = $1; |
225 if (exists $res{$header_file}) { | |
226 if ($res{$header_file} =~ /^\d+$/){ | |
227 $res{$header_file} = $_; | |
228 } elsif (($_ =~ /\.dg$/) && ($res{$header_file} =~ /\.h$/)) { | |
229 $res{$header_file} = $_; | |
230 } | |
231 } | |
110
8c7c1ea49f21
impl auto gen context tools
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
232 } |
112 | 233 } sort @$header_paths; |
110
8c7c1ea49f21
impl auto gen context tools
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
234 return \%res; |
8c7c1ea49f21
impl auto gen context tools
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
235 } |
8c7c1ea49f21
impl auto gen context tools
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
236 |
133
ae25a4e76377
fix gen_context.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
131
diff
changeset
|
237 sub _already_defined_struct { |
ae25a4e76377
fix gen_context.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
131
diff
changeset
|
238 my @struct_list = qw/ |
ae25a4e76377
fix gen_context.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
131
diff
changeset
|
239 __jmp_buf_tag |
ae25a4e76377
fix gen_context.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
131
diff
changeset
|
240 buf |
ae25a4e76377
fix gen_context.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
131
diff
changeset
|
241 cbc_devsw |
ae25a4e76377
fix gen_context.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
131
diff
changeset
|
242 context |
ae25a4e76377
fix gen_context.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
131
diff
changeset
|
243 cpu |
ae25a4e76377
fix gen_context.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
131
diff
changeset
|
244 devsw |
ae25a4e76377
fix gen_context.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
131
diff
changeset
|
245 dinode |
ae25a4e76377
fix gen_context.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
131
diff
changeset
|
246 dirent |
ae25a4e76377
fix gen_context.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
131
diff
changeset
|
247 elfhdr |
ae25a4e76377
fix gen_context.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
131
diff
changeset
|
248 file |
ae25a4e76377
fix gen_context.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
131
diff
changeset
|
249 inode |
ae25a4e76377
fix gen_context.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
131
diff
changeset
|
250 pipe |
ae25a4e76377
fix gen_context.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
131
diff
changeset
|
251 proc |
ae25a4e76377
fix gen_context.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
131
diff
changeset
|
252 proghdr |
ae25a4e76377
fix gen_context.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
131
diff
changeset
|
253 spinlock |
ae25a4e76377
fix gen_context.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
131
diff
changeset
|
254 stat |
ae25a4e76377
fix gen_context.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
131
diff
changeset
|
255 superblock |
ae25a4e76377
fix gen_context.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
131
diff
changeset
|
256 trapframe |
ae25a4e76377
fix gen_context.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
131
diff
changeset
|
257 /; |
ae25a4e76377
fix gen_context.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
131
diff
changeset
|
258 |
ae25a4e76377
fix gen_context.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
131
diff
changeset
|
259 my %def_hash; |
ae25a4e76377
fix gen_context.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
131
diff
changeset
|
260 map { $def_hash{$_} = $_} @struct_list; |
ae25a4e76377
fix gen_context.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
131
diff
changeset
|
261 return \%def_hash; |
ae25a4e76377
fix gen_context.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
131
diff
changeset
|
262 } |
ae25a4e76377
fix gen_context.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
131
diff
changeset
|
263 |
110
8c7c1ea49f21
impl auto gen context tools
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
264 1; |