changeset 555:bcc137ca91da

add trans_impl.pl
author anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
date Mon, 18 Nov 2019 20:05:43 +0900
parents bb0c841aeb8f
children a0b7eb5e58c0
files src/parallel_execution/trans_impl.pl src/parallel_execution/update_context.pl
diffstat 2 files changed, 70 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/parallel_execution/trans_impl.pl	Mon Nov 18 20:05:43 2019 +0900
@@ -0,0 +1,66 @@
+#!/usr/bin/env perl
+use strict;
+use warnings;
+use DDP { deparse => 1};
+
+my $impl_file = shift or die 'require impl file';
+my $impl = parse_impl($impl_file);
+p $impl;
+
+#my $context_h = shift // './context.h';
+#my $context = slup($context_h);
+
+
+sub slup {
+  my $file = shift;
+  open my $fh, '<', $file;
+  local $/;
+  my $f = <$fh>;
+  return $f;
+}
+
+
+sub parse_impl {
+  my $file = shift;
+
+  unless (-f $file) {
+    die "invlid file path: $file\n";
+  }
+
+  open my $fh, '<', $file;
+  my $impl = { 
+    impl  => undef,
+    isa   => undef,
+    codes => [],
+    deta  => [],
+  };
+
+  while (my $line = <$fh>) {
+    if ($line =~ m|^/\*|) {
+        while ( $line !~ m|\*/|) {
+            $line = <$fh>;
+            next; 
+        }
+        next;
+    }
+
+    if ($line =~ m|typedef struct ([\w]+)\s*<Type,\s*Isa>\s*impl\s*([\w+]+)\s*{|) {
+      $impl->{impl} = $1;
+      $impl->{isa}  = $2;
+      next;
+    }
+
+    next if ($line =~ /^\s+$/);
+    next if ($line =~ m[//|}]);
+
+    if ($line =~ /__code (\w+)\(.*/) {
+      push(@{$impl->{codes}},$1);
+      next;
+    }
+
+    $line =~ s/\s*([\w\s\*]+);\s*/$1/;
+    push(@{$impl->{deta}},$1);
+  }
+  return $impl;
+}
+
--- a/src/parallel_execution/update_context.pl	Mon Nov 18 18:25:37 2019 +0900
+++ b/src/parallel_execution/update_context.pl	Mon Nov 18 20:05:43 2019 +0900
@@ -55,6 +55,10 @@
 sub parse_interface {
   my $file_name = shift;
 
+  unless (-f $file_name) {
+    die 'invalid file path';
+  }
+
   open my $fh, '<', $file_name;
 
   my $h2context = {};