changeset 281:648247c08bbd

merge
author menikon <e165723@ie.u-ryukyu.ac.jp>
date Tue, 21 Jan 2020 15:53:36 +0900
parents 9f28b86fecc5 (current diff) 9d385a07dbfc (diff)
children e2b0a3e0c97a
files
diffstat 4 files changed, 101 insertions(+), 50 deletions(-) [+]
line wrap: on
line diff
--- a/src/gearsTools/generate_context.pl	Tue Jan 21 15:52:07 2020 +0900
+++ b/src/gearsTools/generate_context.pl	Tue Jan 21 15:53:36 2020 +0900
@@ -77,13 +77,13 @@
 
   my $output     = $opt_w ? "context.h" : "stdout";
 
+  use Data::Dumper;
   my @cbc_files;
   map { push(@cbc_files,File::Spec->rel2abs($_)); }  @ARGV;
   my $gears      = Gears::Context->new(compile_sources => \@cbc_files, find_root => "$FindBin::Bin/../", output => $output);
   my $data_gears = $gears->extraction_dg_compile_sources();
-  my $g          = $gears->set_data_gear_header_path();
+  my $g          = $gears->set_data_gear_header_path(keys %{$data_gears->{impl}},keys %{$data_gears->{interfaces}});
 
-  #use DDP {deparse =>1};
   my $dg2path    = $gears->update_dg_each_header_path($data_gears,$g);
   my $tree = $gears->createImplTree_from_header($dg2path);
   $gears->tree2create_context_h($tree);
--- a/src/gearsTools/lib/Gears/Context.pm	Tue Jan 21 15:52:07 2020 +0900
+++ b/src/gearsTools/lib/Gears/Context.pm	Tue Jan 21 15:53:36 2020 +0900
@@ -27,17 +27,21 @@
 sub extraction_dg_compile_sources {
   my $self = shift;
   my %counter;
+  my %include_pool = ();
   for my $cbc_file (@{$self->{compile_sources}}) {
     open my $fh , '<', $cbc_file;
     while (my $line = <$fh>) {
         if ($line =~ m|//\s*:skip|) {
-         print "ddddddddd\n";
          next;
         }
 
-       if ($line =~ /#interface\s*"(.*)\.h"/ || $line =~ /^\/\/\s*data_gear\s*"(.*)\.(?:h|dg)?"/) {
-          push(@{$counter{interfaces}->{$1}},$.);
-          push(@{$self->{data_gears_with_count}->{$1}->{caller}->{$cbc_file}},$.);
+       if ($line =~ /#interface\s*"(.*)\.h"/) {
+          push(@{$counter{interfaces}->{$1}->{$cbc_file}},$.);
+          next;
+       }
+
+       if ($line =~ /^\/\/\s*data_gear\s*"(.*)\.(?:h|dg)?"/) {
+          push(@{$include_pool{$1}->{$cbc_file}},$.);
           next;
        }
 
@@ -59,37 +63,32 @@
 
        if ($line =~ /Gearef\(context,\s*(\w+)\)/) {
           my $implementation = $1;
-          push(@{$counter{impl}->{$implementation}},$.);
-          push(@{$self->{data_gears_with_count}->{$implementation}->{caller}->{$cbc_file}},$.);
+          push(@{$counter{impl}->{$implementation}->{$cbc_file}},$.);
           next;
        }
 
     #Element* element = &ALLOCATE(cbc_context, Element)->Element;
        if ($line =~ /ALLOCATE\w*\((?:cbc_)?context,\s*(\w+)\)/) {
           my $implementation = $1;
-          push(@{$counter{impl}->{$implementation}},$.);
-          push(@{$self->{data_gears_with_count}->{$implementation}->{caller}->{$cbc_file}},$.);
+          push(@{$counter{impl}->{$implementation}->{$cbc_file}},$.);
           next;
        }
 
        if ($line =~ /ALLOCATE_(?:PTR_)?ARRAY\((?:cbc_)?context,\s*(\w+),[\s\w]+\)/) {
           my $implementation = $1;
-          push(@{$counter{impl}->{$implementation}},$.);
-          push(@{$self->{data_gears_with_count}->{$implementation}->{caller}->{$cbc_file}},$.);
+          push(@{$counter{impl}->{$implementation}->{$cbc_file}},$.);
           next;
        }
 
        if ($line =~ /new\s+(\w+?)\([\w\s]*\);/) {
           my $implementation = $1;
-          push(@{$counter{impl}->{$implementation}},$.);
-          push(@{$self->{data_gears_with_count}->{$implementation}->{caller}->{$cbc_file}},$.);
+          push(@{$counter{impl}->{$implementation}->{$cbc_file}},$.);
           next;
        }
 
        if ($line =~ /ALLOCATE_DATA_GEAR\((\w+),\s*(\w+)\)/) {
           my $implementation = $2;
-          push(@{$counter{impl}->{$implementation}},$.);
-          push(@{$self->{data_gears_with_count}->{$implementation}->{caller}->{$cbc_file}},$.);
+          push(@{$counter{impl}->{$implementation}->{$cbc_file}},$.);
           next;
        }
 
@@ -97,38 +96,53 @@
        if ($line =~ /\((\w+)\*\)GearImpl\(context,\s*(\w+),\s*(\w+)\)/) {
           my $interface = $2;
           my $implementation = $1;
-          push(@{$counter{impl}->{$implementation}},$.);
-          push(@{$counter{interfaces}->{$interface}},$.);
-          push(@{$self->{data_gears_with_count}->{$interface}->{caller}->{$cbc_file}},$.);
+          push(@{$counter{impl}->{$implementation}->{$cbc_file}},$.);
+          push(@{$counter{interfaces}->{$interface}->{$cbc_file}},$.);
           next;
        }
 
        if ($line =~ /^__code/) {
          while ($line =~ /struct (\w+)\s*\*/g) {
            next if $1 eq "Context";
-           push(@{$self->{data_gears_with_count}->{$1}->{caller}->{$cbc_file}},$.);
            next if (exists $counter{interfaces}->{$1});
-           $counter{impl}->{$1}++;
+           push(@{$counter{impl}->{$1}->{$cbc_file}},$.);
          }
        }
     }
     close $fh;
   }
+  use Data::Dumper;
+
+  for my $cg_name (keys %include_pool) {
+    my @tmp_cbc_file_names  = keys %{$include_pool{$cg_name}};
+    my $tmp_cbc_file_name  = shift @tmp_cbc_file_names;
+    if (exists $counter{interfaces}->{$cg_name}){
+      push(@{$counter{interfaces}->{$cg_name}->{$tmp_cbc_file_name}},$include_pool{$cg_name}->{$tmp_cbc_file_name});
+      delete $include_pool{$cg_name};
+      next;
+    }
+
+    if (exists $counter{impl}->{$cg_name}){
+      push(@{$counter{impl}->{$cg_name}->{$tmp_cbc_file_name}},$include_pool{$cg_name}->{$tmp_cbc_file_name});
+      delete $include_pool{$cg_name};
+      next;
+    }
+    push(@{$counter{interfaces}->{$cg_name}->{$tmp_cbc_file_name}},$include_pool{$cg_name}->{$tmp_cbc_file_name});
+    delete $include_pool{$cg_name};
+  }
+
   $counter{interfaces}->{Meta}++;
   $counter{interfaces}->{TaskManager}++;
-  $self->{data_gears_with_count}->{Meta}++;
-  $self->{data_gears_with_count}->{TaskManager}++;
+  print "-----------\n";
+  print Dumper \%counter;
+  print "-----------\n";
   return \%counter;
 }
 
 sub set_data_gear_header_path {
   my $self = shift;
   my @data_gears_name;
-  if (@_) {
-    @data_gears_name = @_;
-  } else {
-    map { push (@data_gears_name,$_) if $_ ne "Context" } keys %{$self->{data_gears_with_count}};
-  }
+  map { push (@data_gears_name,$_) if $_ ne "Context" } @_;
   return _find_headers($self->{find_root},\@data_gears_name);
 }
 
--- a/src/impl/file_impl_pipe.cbc	Tue Jan 21 15:52:07 2020 +0900
+++ b/src/impl/file_impl_pipe.cbc	Tue Jan 21 15:53:36 2020 +0900
@@ -1,15 +1,30 @@
-#include "../context.h"
+#include "../../context.h"
 #interface "file.h"
 
 // ----
 // typedef struct pipe<Impl, Isa> impl file {
 //     #define PIPESIZE 512
+//     union Data* file;
 //     struct spinlock lock;
 //     char data[PIPESIZE];
 //     uint nread;     // number of bytes read
 //     uint nwrite;    // number of bytes written
 //     int readopen;   // read fd is still open
 //     int writeopen;  // write fd is still open
+//
+//     // interface field
+//     int n;
+//     char* addr;
+//
+//     // private code gear
+//     __code piperead1(Impl* pipe, char* addr, int n, __code next(...));
+//     __code piperead2(Impl* pipe, char* addr, int n, __code next(...));
+//     __code cbc_pipeclose(Impl* pipe, Isa* file, __code next(...));
+//     __code cbc_pipeclose2(Impl* pipe, Isa* file, Isa* ff,  __code next(...));
+//     __code cbc_pipeclose3(Impl* pipe, Isa* file, Isa* ff,  __code next(...));
+//     __code cbc_pipeclose4(Impl* pipe, int writable, __code next(...));
+//     __code cbc_pipe_close_writeopen(Impl* pipe, __code next(...));
+//     __code cbc_pipe_close_readopen(Impl* pipe, __code next(...));
 // } pipe;
 // ----
 
@@ -17,6 +32,7 @@
     struct file* file  = new file();
     struct pipe* pipe = new pipe();
     file->file = (union Data*)pipe;
+    pipe->file = NULL;
     pipe->lock = 0;
     pipe->spinlock  = 0;
     pipe->data  = 0;
@@ -24,17 +40,31 @@
     pipe->nwrite  = 0;
     pipe->readopen  = 0;
     pipe->writeopen  = 0;
+    pipe->n  = 0;
+    pipe->addr = NULL;
+    file->remoe  = 0;
     file->off = 0;
     file->st = NULL;
     file->addr = NULL;
+    file->pipe  = 0;
+    file->inode  = 0;
     file->n  = 0;
+    file->fd  = 0;
+    pipe->piperead1 = C_piperead1pipe;
+    pipe->piperead2 = C_piperead2pipe;
+    pipe->cbc_pipeclose = C_cbc_pipeclosepipe;
+    pipe->cbc_pipeclose2 = C_cbc_pipeclose2pipe;
+    pipe->cbc_pipeclose3 = C_cbc_pipeclose3pipe;
+    pipe->cbc_pipeclose4 = C_cbc_pipeclose4pipe;
+    pipe->cbc_pipe_close_writeopen = C_cbc_pipe_close_writeopenpipe;
+    pipe->cbc_pipe_close_readopen = C_cbc_pipe_close_readopenpipe;
     file->stat = C_statpipe;
     file->read = C_readpipe;
     file->write = C_writepipe;
     file->close = C_closepipe;
     return file;
 }
-//Skip: generate_context
+
 __code statpipe(struct pipe* file, struct stat* st, __code next(...)) { //:skip
 
     goto next(...);
@@ -62,7 +92,6 @@
 }
 
 
-//Skip: generate_context
 __code cbc_sleep(struct pipe* p, unit* nread, struct spinlock* lock, __code next(...), __code pread(...)){ //:skip
     if(proc == 0) {
         goto cbc_context->panic("sleep");
@@ -79,7 +108,6 @@
     goto cbc_sched(cbc_sleep1);
 }
 
-//Skip: generate_context
 __code cbc_sched_stub(struct pipe* p, unit* nread, struct spinlock* lock, __code next(...), __code pread(...)){ //:skip
     proc->chan = chan;
     proc->state = SLEEPING;
@@ -92,55 +120,57 @@
     goto next(...);
 }
 
-__code closepipe(struct pipe* file,int fd,__code next(...)) {
+__code pipeclose(struct pipe* file,int fd,__code next(...)) {
     proc->ofile[fd] = 0;
-    goto cbc_fileclose(f,next);
+    goto file->cbc_pipeclose(file->file, next);
 }
 
 
-__code cbc_fileclose(struct file* file, __code next(...)) {
+__code cbc_pipeclose(struct pipe* pipe, struct file* file, __code next(...)) {
     struct file ff;
     acquire(*ftable.loc)
 
     if (f->ref < 1) {
         goto cbc_context->kernel_error->panic("file close");
     }
-    goto cbc_fileclose2(f,ff,next);
+    goto pipe->cbc_pipeclose2(f,ff,next);
 }
 
-__code cbc_fileclose2(struct file* file, struct file* ff,__code next(...)) {
+__code cbc_pipeclose2(struct pipe* pipe,struct file* file, struct file* ff,__code next(...)) {
     if (--f->ref > 0) {
         release(&ftable.lock);
         goto cbc_context->return();
     }
-    goto cbc_fileclose3(f,ff,next);
+    goto pipe->cbc_pipeclose3(f,ff,next);
 }
 
-__code cbc_fileclose3(struct file* file, struct file* ff,__code next(...)) {
+__code cbc_pipeclose3(struct pipe* pipe,struct file* file, struct file* ff,__code next(...)) {
     *ff = *f;
     f->ref = 0;
     f->type = FD_NONE;
     relsease(&ftable.lock);
+    struct pipe* p = ff.pipe;
+    int writable = ff.writable;
     
-    goto cbc_pipe_close(ff.pipe,ff.writable,next);
+    goto pipe->cbc_pipeclose4(p,writable,next);
 }
 
-__code cbc_pipe_close(struct pipe* p, int writable, __code next(...)) {
-    acquire(&p->lock);
+__code cbc_pipeclose4(struct pipe* pipe, int writable, __code next(...)) {
+    acquire(&pipe->lock);
     if (writable) {
-        goto cbc_pipe_close_writeopen(p,next);
+        goto pipe->cbc_pipe_close_writeopen(next);
     }
-    goto cbc_pipe_close_readopen(p,next);
+    goto pipe->cbc_pipe_close_readopen(next);
 }
 
 
-__code cbc_pipe_close_writeopen(struct pipe* p, __code next(...)) {
-    p->writeopen = 0;
-    goto cbc_wakeup(&p->nread,p,cbc_pipe_release,next);
+__code cbc_pipe_close_writeopen(struct pipe* pipe, __code next(...)) {
+    pipe->writeopen = 0;
+    goto cbc_wakeup(&pipe->nread,pipe,cbc_pipe_release,next);
 }
 
-__code cbc_pipe_close_readopen(struct pipe* p, __code next(...)) {
-    p->writeopen = 0;
-    goto cbc_->wakeup(&p->nwrite,p,cbc_pipe_release,next);
+__code cbc_pipe_close_readopen(struct pipe* pipe, __code next(...)) {
+    pipe->readopen = 0;
+    goto cbc_context->wakeup(&pipe->nwrite,pipe,cbc_pipe_release,next);
 }
 
--- a/src/impl/pipe.h	Tue Jan 21 15:52:07 2020 +0900
+++ b/src/impl/pipe.h	Tue Jan 21 15:53:36 2020 +0900
@@ -1,5 +1,6 @@
 typedef struct pipe<Impl, Isa> impl file {
     #define PIPESIZE 512
+    union Data* file;
     struct spinlock lock;
     char data[PIPESIZE];
     uint nread;     // number of bytes read
@@ -14,4 +15,10 @@
     // private code gear
     __code piperead1(Impl* pipe, char* addr, int n, __code next(...));
     __code piperead2(Impl* pipe, char* addr, int n, __code next(...));
+    __code cbc_pipeclose(Impl* pipe, Isa* file, __code next(...));
+    __code cbc_pipeclose2(Impl* pipe, Isa* file, Isa* ff,  __code next(...));
+    __code cbc_pipeclose3(Impl* pipe, Isa* file, Isa* ff,  __code next(...));
+    __code cbc_pipeclose4(Impl* pipe, int writable, __code next(...));
+    __code cbc_pipe_close_writeopen(Impl* pipe, __code next(...));
+    __code cbc_pipe_close_readopen(Impl* pipe, __code next(...));
 } pipe;