Mercurial > hg > GearsTemplate
diff 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 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/tmp_tool/parse_cerate_each_context.pl Thu Jan 16 15:12:06 2020 +0900 @@ -0,0 +1,147 @@ +#!/usr/bin/env perl +use strict; +use warnings; +use DDP {deparse => 1}; + +my @already_defined = qw/ +Atomic +Buffer +CodeGear +Executor +Iterator +Lock +Queue +Semaphore +Stack +TaskManager +Timer +Tree +Worker +SingleLinkedStack +SortArray +/; + +my %already_defined_hash; +map { $already_defined_hash{$_}++ } @already_defined; + +my $context = shift // "context.h"; + +open my $fh, '<', $context; +while (my $line = <$fh>) { + if ($line =~ /^union Data \{/) { + last; + } +} + +my @context_cg_str = <$fh>; +close($fh); +chomp @context_cg_str; +my $res = {}; + +while (my $line = shift @context_cg_str) { + if ($line =~ /\s*struct\s*(\w+)\s*\{/) { + my $struct = $1; + if (exists $already_defined_hash{$struct}) { + next; + } + $line = shift @context_cg_str; + while ($line !~ /\}\s*$struct/) { + $line =~ s/\s+([\*\w ]+);/$1/; + push (@{$res->{$struct}},$line); + $line = shift @context_cg_str ; + } + unless (defined $res->{$struct}) { + push (@{$res->{$struct}},""); + } + } +} + +map { print "$_\n" } keys %$res; +my %impl2inter = ( + SpinLock => "Lock", + CUDAWorker => "Worker", + RedBlackTree => "Tree", + AtomicReference => "Atomic", + CPUWoker => "Woker", + MultiDimIterator => "Iterator", + CUDAExecutor => "Executor", + SingleLinkedStack => "Stack", + SingleLinkedQueue => "Queue", + SynchronizedQueue => "Queue", +); + +for my $dg_name (keys %$res) { + if ($dg_name =~ /(\w+)Impl/) { + create_impl_file($dg_name,$res->{$dg_name},$1); + next; + } + + if (exists $impl2inter{$dg_name}) { + create_impl_file($dg_name,$res->{$dg_name},$impl2inter{$dg_name}); + next; + } + create_inter_file($dg_name,$res->{$dg_name}); +} + +sub create_impl_file { + my ($name, $contents,$interface) = @_; + my $str = "typedef struct $name <Type, Isa> impl $interface {\n"; + create_file("impl/$name.h",$contents,$str,$name); +} + +sub create_inter_file { + my ($name, $contents) = @_; + my $str = "typedef struct $name <Type, Impl> {\n"; + create_file("interface/$name.h",$contents,$str,$name); +} + +sub create_file { + my ($file_name, $contents, $str, $name) = @_; + my $space = " "; + for my $co (@$contents) { + if ($co =~ /enum\s*Code\s*(\w+)/) { + $str .= "${space}__code $1(...);\n"; + next; + } + chomp $co; + $str .= "${space}$co;\n"; + } + open my $fh, '>', "$ENV{PWD}/plautogen/$file_name" or die "oops! $file_name\n"; + print $fh $str; + print $fh "} $name;\n"; + close $fh; +} + +sub print_impl { + my ($out, $name, $cg_info) = @_; + print $out "typedef strcut $name<Impl, Bot> {\n"; +} + +__DATA__ +SpinLock +Main +CUDAExecutor +TaskManagerImpl +LockImpl +MultiDim +SynchronizedQueue +ArrayStack +LoopCounter +TimerImpl +Node +CUDAWorker +Memory +SemaphoreImpl +BoundedBuffer +RotateTree +CUDABuffer +Array +Allocate +Meta +SingleLinkedQueue +CPUWorker +Integer +MultiDimIterator +Element +RedBlackTree +