changeset 210:ba56dab79dc4

separate code init for each executable
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Tue, 27 Dec 2016 17:13:45 +0900
parents 5708390a9d88
children 962fbfe777bb
files src/parallel_execution/CMakeLists.txt src/parallel_execution/generate_context.pl
diffstat 2 files changed, 59 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
--- a/src/parallel_execution/CMakeLists.txt	Wed Dec 21 22:13:57 2016 +0900
+++ b/src/parallel_execution/CMakeLists.txt	Tue Dec 27 17:13:45 2016 +0900
@@ -6,36 +6,36 @@
 
 set(CMAKE_C_COMPILER $ENV{CBC_COMPILER})
  
-add_custom_command (
-      OUTPUT    c/enumCode.h
-      COMMAND  "perl" "generate_context.pl" 
-)
-
 macro( GearsCommand )
     set( _OPTIONS_ARGS )
     set( _ONE_VALUE_ARGS TARGET )
     set( _MULTI_VALUE_ARGS SOURCES )
     cmake_parse_arguments( _Gears "${_OPTIONS_ARGS}" "${_ONE_VALUE_ARGS}" "${_MULTI_VALUE_ARGS}" ${ARGN} )
-    add_executable(${_Gears_TARGET} ${_Gears_SOURCES} context.c c/enumCode.h)
+    add_custom_command (
+          OUTPUT    c/${_Gears_TARGET}-context.c 
+          COMMAND  "perl" "generate_context.pl" "-o" ${_Gears_TARGET} ${_Gears_SOURCES}
+    )
+    add_executable(${_Gears_TARGET} ${_Gears_SOURCES} c/${_Gears_TARGET}-context.c)
 endmacro()
 
+
 GearsCommand(
   TARGET
       twice
   SOURCES 
-      main.c rb_tree.c stack.c origin_cs.c allocate.c compare.c worker.c dependency.c time.c twice.c test/stack_test.c stack.c test/queue_test.c queue.c
+      main.c rb_tree.c stack.c origin_cs.c allocate.c compare.c worker.c dependency.c time.c twice.c  stack.c  queue.c
 )
 
 GearsCommand(
   TARGET
-      test/stack_test
+      stack_test
   SOURCES 
-      main.c rb_tree.c stack.c origin_cs.c allocate.c compare.c worker.c dependency.c time.c twice.c test/stack_test.c stack.c test/queue_test.c queue.c
+      rb_tree.c stack.c origin_cs.c allocate.c compare.c worker.c dependency.c time.c twice.c test/stack_test.c stack.c  queue.c
 )
 
 GearsCommand(
   TARGET
-      test/queue_test
+      queue_test
   SOURCES 
-      TaskManager.c main.c rb_tree.c stack.c origin_cs.c allocate.c compare.c worker.c dependency.c time.c twice.c test/stack_test.c stack.c test/queue_test.c queue.c
+      TaskManager.c rb_tree.c stack.c origin_cs.c allocate.c compare.c worker.c dependency.c time.c twice.c  stack.c test/queue_test.c queue.c
 )
--- a/src/parallel_execution/generate_context.pl	Wed Dec 21 22:13:57 2016 +0900
+++ b/src/parallel_execution/generate_context.pl	Tue Dec 27 17:13:45 2016 +0900
@@ -1,5 +1,6 @@
 #!/usr/bin/perl
 
+use Getopt::Std;
 
 # CodeGear
 # 
@@ -36,7 +37,19 @@
 system "rm -rf c";
 system "mkdir c";
 
-while (<*.c test/*.c>) {
+our($opt_o);
+getopts('o:');
+
+my $name = $opt_o;
+
+for (@ARGV) {
+    next if (/context.c/);
+    &getStubInfo($_);
+}
+
+my (%mCodeGear) = (%codeGear);
+
+while (<*.c>) {
     next if (/context.c/);
     &getStubInfo($_);
 }
@@ -80,11 +93,41 @@
         print $fd "    C_${code},\n";
     }
     print $fd "};\n";
+   
+    my $code_init = ''; 
+    for my $code ( sort keys %mCodeGear ) {
+        $code_init .=  "    context->code[C_${code}]    = ${code}_stub;\n";
+    }
+
+my $context_c = << "EOFEOF";
+#include <stdlib.h>
+
+#include "../context.h"
+#include "extern.h"
+
+__code initContext(struct Context* context) {
+    context->heapLimit = sizeof(union Data)*ALLOCATE_SIZE;
+    context->code = (__code(**) (struct Context*)) NEWN(ALLOCATE_SIZE, void*);
+    context->data = NEWN(ALLOCATE_SIZE, union Data*);
+    context->heapStart = NEWN(context->heapLimit, char);
+    context->heap = context->heapStart;
+
+    // context->codeNum = Exit;
+
+$code_init
+
+#include "dataGearInit.c"
+
+    // context->data[D_ActiveQueue] = createSynchronizedQueue(context);
+    // context->data[D_WaitQueue]   = createSynchronizedQueue(context);
+
+    context->dataNum = D_Queue;
+}
+EOFEOF
+
+    open my $fd,">","c/$name-context.c" or die("can't open c/$name-context.c $!");
+    print $fd $context_c;
     
-    open my $fd,">","c/codeGearInit.c" or die("can't open c/codeGearInit.c $!");
-    for my $code ( sort keys %codeGear ) {
-        print $fd "    context->code[C_${code}]    = ${code}_stub;\n";
-    }
 
     open my $fd,">","c/enumData.h" or die("can't open c/enumData.h $!");
     print $fd "enum DataType {\n";