Mercurial > hg > GearsTemplate
annotate src/tmp_tool/parse_cerate_each_context.pl @ 590:9146d6017f18 default tip
hg mv parallel_execution/* ..
author | anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Thu, 16 Jan 2020 15:12:06 +0900 |
parents | src/parallel_execution/tmp_tool/parse_cerate_each_context.pl@d9c3bccaa13c |
children |
rev | line source |
---|---|
568
840597c5d242
add_parse_create_each_context.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1 #!/usr/bin/env perl |
840597c5d242
add_parse_create_each_context.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
2 use strict; |
840597c5d242
add_parse_create_each_context.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
3 use warnings; |
840597c5d242
add_parse_create_each_context.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
4 use DDP {deparse => 1}; |
840597c5d242
add_parse_create_each_context.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
5 |
570 | 6 my @already_defined = qw/ |
7 Atomic | |
8 Buffer | |
9 CodeGear | |
10 Executor | |
11 Iterator | |
12 Lock | |
13 Queue | |
14 Semaphore | |
15 Stack | |
16 TaskManager | |
17 Timer | |
18 Tree | |
19 Worker | |
20 SingleLinkedStack | |
21 SortArray | |
22 /; | |
23 | |
24 my %already_defined_hash; | |
25 map { $already_defined_hash{$_}++ } @already_defined; | |
26 | |
568
840597c5d242
add_parse_create_each_context.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
27 my $context = shift // "context.h"; |
840597c5d242
add_parse_create_each_context.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
28 |
569 | 29 open my $fh, '<', $context; |
568
840597c5d242
add_parse_create_each_context.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
30 while (my $line = <$fh>) { |
840597c5d242
add_parse_create_each_context.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
31 if ($line =~ /^union Data \{/) { |
840597c5d242
add_parse_create_each_context.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
32 last; |
840597c5d242
add_parse_create_each_context.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
33 } |
840597c5d242
add_parse_create_each_context.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
34 } |
840597c5d242
add_parse_create_each_context.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
35 |
840597c5d242
add_parse_create_each_context.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
36 my @context_cg_str = <$fh>; |
840597c5d242
add_parse_create_each_context.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
37 close($fh); |
840597c5d242
add_parse_create_each_context.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
38 chomp @context_cg_str; |
840597c5d242
add_parse_create_each_context.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
39 my $res = {}; |
840597c5d242
add_parse_create_each_context.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
40 |
840597c5d242
add_parse_create_each_context.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
41 while (my $line = shift @context_cg_str) { |
840597c5d242
add_parse_create_each_context.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
42 if ($line =~ /\s*struct\s*(\w+)\s*\{/) { |
840597c5d242
add_parse_create_each_context.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
43 my $struct = $1; |
570 | 44 if (exists $already_defined_hash{$struct}) { |
45 next; | |
46 } | |
568
840597c5d242
add_parse_create_each_context.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
47 $line = shift @context_cg_str; |
840597c5d242
add_parse_create_each_context.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
48 while ($line !~ /\}\s*$struct/) { |
569 | 49 $line =~ s/\s+([\*\w ]+);/$1/; |
50 push (@{$res->{$struct}},$line); | |
568
840597c5d242
add_parse_create_each_context.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
51 $line = shift @context_cg_str ; |
840597c5d242
add_parse_create_each_context.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
52 } |
570 | 53 unless (defined $res->{$struct}) { |
54 push (@{$res->{$struct}},""); | |
55 } | |
568
840597c5d242
add_parse_create_each_context.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
56 } |
840597c5d242
add_parse_create_each_context.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
57 } |
570 | 58 |
59 map { print "$_\n" } keys %$res; | |
60 my %impl2inter = ( | |
61 SpinLock => "Lock", | |
62 CUDAWorker => "Worker", | |
63 RedBlackTree => "Tree", | |
64 AtomicReference => "Atomic", | |
65 CPUWoker => "Woker", | |
66 MultiDimIterator => "Iterator", | |
67 CUDAExecutor => "Executor", | |
68 SingleLinkedStack => "Stack", | |
69 SingleLinkedQueue => "Queue", | |
70 SynchronizedQueue => "Queue", | |
71 ); | |
72 | |
73 for my $dg_name (keys %$res) { | |
74 if ($dg_name =~ /(\w+)Impl/) { | |
75 create_impl_file($dg_name,$res->{$dg_name},$1); | |
76 next; | |
77 } | |
78 | |
79 if (exists $impl2inter{$dg_name}) { | |
80 create_impl_file($dg_name,$res->{$dg_name},$impl2inter{$dg_name}); | |
81 next; | |
82 } | |
83 create_inter_file($dg_name,$res->{$dg_name}); | |
84 } | |
85 | |
86 sub create_impl_file { | |
87 my ($name, $contents,$interface) = @_; | |
88 my $str = "typedef struct $name <Type, Isa> impl $interface {\n"; | |
89 create_file("impl/$name.h",$contents,$str,$name); | |
90 } | |
91 | |
92 sub create_inter_file { | |
93 my ($name, $contents) = @_; | |
94 my $str = "typedef struct $name <Type, Impl> {\n"; | |
95 create_file("interface/$name.h",$contents,$str,$name); | |
96 } | |
568
840597c5d242
add_parse_create_each_context.pl
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
97 |
570 | 98 sub create_file { |
99 my ($file_name, $contents, $str, $name) = @_; | |
100 my $space = " "; | |
101 for my $co (@$contents) { | |
102 if ($co =~ /enum\s*Code\s*(\w+)/) { | |
571 | 103 $str .= "${space}__code $1(...);\n"; |
570 | 104 next; |
105 } | |
106 chomp $co; | |
107 $str .= "${space}$co;\n"; | |
108 } | |
109 open my $fh, '>', "$ENV{PWD}/plautogen/$file_name" or die "oops! $file_name\n"; | |
110 print $fh $str; | |
111 print $fh "} $name;\n"; | |
112 close $fh; | |
113 } | |
114 | |
115 sub print_impl { | |
116 my ($out, $name, $cg_info) = @_; | |
117 print $out "typedef strcut $name<Impl, Bot> {\n"; | |
118 } | |
119 | |
120 __DATA__ | |
121 SpinLock | |
122 Main | |
123 CUDAExecutor | |
124 TaskManagerImpl | |
125 LockImpl | |
126 MultiDim | |
127 SynchronizedQueue | |
128 ArrayStack | |
129 LoopCounter | |
130 TimerImpl | |
131 Node | |
132 CUDAWorker | |
133 Memory | |
134 SemaphoreImpl | |
135 BoundedBuffer | |
136 RotateTree | |
137 CUDABuffer | |
138 Array | |
139 Allocate | |
140 Meta | |
141 SingleLinkedQueue | |
142 CPUWorker | |
143 Integer | |
144 MultiDimIterator | |
145 Element | |
146 RedBlackTree | |
147 |