diff src/parallel_execution/tmp_tool/parse_cerate_each_context.pl @ 570:1233236c244d

autogen DetaGears
author anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
date Sun, 24 Nov 2019 22:54:35 +0900
parents 077158ea026c
children d9c3bccaa13c
line wrap: on
line diff
--- a/src/parallel_execution/tmp_tool/parse_cerate_each_context.pl	Sat Nov 23 19:39:11 2019 +0900
+++ b/src/parallel_execution/tmp_tool/parse_cerate_each_context.pl	Sun Nov 24 22:54:35 2019 +0900
@@ -3,6 +3,27 @@
 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;
@@ -20,14 +41,107 @@
 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}},"");
+    }
   }
 }
-use Data::Dumper;
+
+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);
+}
 
-print Dumper  $res;
+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
+