changeset 549:05fd14d8edbe

add update_context.pl
author anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
date Wed, 13 Nov 2019 16:04:34 +0900
parents 4fdeb0afc187
children 91c8f5613a49
files src/parallel_execution/CMakeLists.txt src/parallel_execution/context.h src/parallel_execution/update_context.pl
diffstat 3 files changed, 99 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/src/parallel_execution/CMakeLists.txt	Fri Oct 11 17:37:56 2019 +0900
+++ b/src/parallel_execution/CMakeLists.txt	Wed Nov 13 16:04:34 2019 +0900
@@ -134,9 +134,9 @@
       SingleLinkedQueue.cbc test/rbTree_test.cbc RedBlackTree.cbc SingleLinkedStack.cbc compare.c
 )
 
-#GearsCommand(
-#  TARGET
-#      boundedBuffer
-#  SOURCES
-#  examples/boundedBuffer/main.cbc examples/boundedBuffer/initBuffer.cbc examples/boundedBuffer/SemaphoreImpl.cbc examples/boundedBuffer/BoundedBuffer.cbc examples/boundedBuffer/consumer.cbc examples/boundedBuffer/producer.cbc SpinLock.cbc CPUWorker.cbc TaskManagerImpl.cbc SingleLinkedQueue.cbc SynchronizedQueue.cbc MultiDimIterator.cbc AtomicReference.cbc
-#)
+GearsCommand(
+  TARGET
+      boundedBuffer
+  SOURCES
+  examples/boundedBuffer/main.cbc examples/boundedBuffer/initBuffer.cbc examples/boundedBuffer/SemaphoreImpl.cbc examples/boundedBuffer/BoundedBuffer.cbc examples/boundedBuffer/consumer.cbc examples/boundedBuffer/producer.cbc SpinLock.cbc CPUWorker.cbc TaskManagerImpl.cbc SingleLinkedQueue.cbc SynchronizedQueue.cbc MultiDimIterator.cbc AtomicReference.cbc
+)
--- a/src/parallel_execution/context.h	Fri Oct 11 17:37:56 2019 +0900
+++ b/src/parallel_execution/context.h	Wed Nov 13 16:04:34 2019 +0900
@@ -437,6 +437,7 @@
         struct Atomic* atomic;
         struct Context* lockContext;
     } SpinLock;
+    //INFO: NEXT_CONTEXT
 }; // union Data end       this is necessary for context generator
 typedef union Data Data;
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/parallel_execution/update_context.pl	Wed Nov 13 16:04:34 2019 +0900
@@ -0,0 +1,92 @@
+#!/usr/bin/env perl
+use strict;
+use warnings;
+
+my $interface_file = shift or die "require itnerface file";
+my $h2context = parse_interface($interface_file);
+my $context = dump_h2context($h2context);
+my ($first,$last) = slup_context_h($h2context->{name});
+print "@{$first}";
+print "$context";
+print "    //INFO: NEXT_CONTEXT\n";
+print "@{$last}";
+
+
+
+sub slup_context_h {
+  open my $fh, '<', 'context.h';
+  
+  my $data_gear_name = shift;
+
+  my @first_context_headers = ();
+  my @last_context_headers = ();
+  
+  while (my $line = <$fh>) {
+    if ( $line =~ /INFO: NEXT_CONTEXT/) {
+      push(@last_context_headers, <$fh>);
+      last;
+    }
+    if ( $line =~ /struct $data_gear_name/) {
+      print "WARN! This struct already exists\n";
+      exit 1;
+    }
+    push(@first_context_headers, $line);
+  }
+  
+  close $fh;
+  
+  print "@first_context_headers\n";
+  print "@last_context_headers\n";
+  return (\@first_context_headers,\@last_context_headers);
+}
+
+sub parse_interface {
+  my $file_name = shift;
+
+  open my $fh, '<', $file_name;
+
+  my $h2context = {};
+
+  while (my $line = <$fh>) {
+    if ($line =~ /typedef struct (\w+)\s?<.*/) {
+      die "invalied struct name $1" unless $1;
+      $h2context->{name} = $1;
+      next;
+    }
+
+    if ($line =~ m[/\*|//|}]) {
+      next;
+    }
+
+    if ($line =~ /__code (\w+)\(.*/) {
+      push(@{$h2context->{codes}},$1);
+      next;
+    }
+
+    $line =~ s/\s*([\w\s\*]+);\s*/$1/;
+    push(@{$h2context->{data}},$1);
+  }
+
+  close $fh;
+  return $h2context;
+}
+
+
+sub dump_h2context {
+  my $h2context = shift;
+  my $context = '';
+  my $space = '    ';
+  #print "${space}struct $h2context->{name} {\n";
+  $context =  "${space}struct $h2context->{name} {\n";
+  for my $datum (@{$h2context->{data}}) {
+    #print "${space}${space}$datum; \n";
+    $context .= "${space}${space}$datum; \n";
+  }
+  for my $code (@{$h2context->{codes}}) {
+    #print "${space}${space}enum Code $code;\n";
+    $context .= "${space}${space}enum Code $code;\n";
+  }
+  #print "${space}} $h2context->{name};\n";
+  $context .= "${space}} $h2context->{name};\n";
+  return $context;
+}