Mercurial > hg > GearsTemplate
comparison 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 |
comparison
equal
deleted
inserted
replaced
589:a4cab67624f7 | 590:9146d6017f18 |
---|---|
1 #!/usr/bin/env perl | |
2 use strict; | |
3 use warnings; | |
4 use DDP {deparse => 1}; | |
5 | |
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 | |
27 my $context = shift // "context.h"; | |
28 | |
29 open my $fh, '<', $context; | |
30 while (my $line = <$fh>) { | |
31 if ($line =~ /^union Data \{/) { | |
32 last; | |
33 } | |
34 } | |
35 | |
36 my @context_cg_str = <$fh>; | |
37 close($fh); | |
38 chomp @context_cg_str; | |
39 my $res = {}; | |
40 | |
41 while (my $line = shift @context_cg_str) { | |
42 if ($line =~ /\s*struct\s*(\w+)\s*\{/) { | |
43 my $struct = $1; | |
44 if (exists $already_defined_hash{$struct}) { | |
45 next; | |
46 } | |
47 $line = shift @context_cg_str; | |
48 while ($line !~ /\}\s*$struct/) { | |
49 $line =~ s/\s+([\*\w ]+);/$1/; | |
50 push (@{$res->{$struct}},$line); | |
51 $line = shift @context_cg_str ; | |
52 } | |
53 unless (defined $res->{$struct}) { | |
54 push (@{$res->{$struct}},""); | |
55 } | |
56 } | |
57 } | |
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 } | |
97 | |
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+)/) { | |
103 $str .= "${space}__code $1(...);\n"; | |
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 |