Mercurial > hg > GearsTemplate
changeset 556:a0b7eb5e58c0
add Gears::Util module
author | anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Mon, 18 Nov 2019 21:00:11 +0900 |
parents | bcc137ca91da |
children | 1eb2a22ec1e3 |
files | src/parallel_execution/lib/Gears/Util.pm src/parallel_execution/trans_impl.pl src/parallel_execution/update_context.pl |
diffstat | 3 files changed, 90 insertions(+), 47 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/parallel_execution/lib/Gears/Util.pm Mon Nov 18 21:00:11 2019 +0900 @@ -0,0 +1,80 @@ +package Gears::Util; +use strict; +use warnings; +use Carp qw/croak/; + +sub parse { + my ($class, $file_name) = @_; + my $ir = _parse_base($file_name); + return $ir; +} + +sub parse_interface { + my ($class, $file_name) = @_; + my $ir = _parse_base($file_name); + + unless ($ir->{name}) { + croak 'invalid struct name'; + } + return $ir; +} + + +sub parse_impl { + my ($class, $file_name) = @_; + my $ir = _parse_base($file_name); + + unless ($ir->{isa} && $ir->{name}) { + croak 'invalid struct name'; + } + return $ir; +} + +sub _parse_base { + my ($file) = @_; + my $ir = {}; + + _file_checking($file); + open my $fh, '<', $file; + my $line = <$fh>; + + if ($line =~ /typedef struct (\w+)\s?<.*>([\s\w{]+)/) { + die "invalied struct name $1" unless $1; + $ir->{name} = $1; + + if ($2 =~ m|\s*impl\s*([\w+]+)\s*{|) { + $ir->{isa} = $1; + } + } + + while ($line = <$fh>) { + if ($line =~ m|\s*/\*|) { + while ( $line !~ m|\*/|) { + $line = <$fh>; + next; + } + next; + } + next if ($line =~ /^\s+$/); + next if ($line =~ m[//|}]); + + if ($line =~ /__code (\w+)\(.*/) { + push(@{$ir->{codes}},$1); + next; + } + + $line =~ s/\s*([\w\s\*]+);\s*/$1/; + push(@{$ir->{deta}},$1); + } + + return $ir; +} + +sub _file_checking { + my $file_name = shift; + unless (-f $file_name) { + croak "invalid filepath :$file_name\n"; + } +} + +1;
--- a/src/parallel_execution/trans_impl.pl Mon Nov 18 20:05:43 2019 +0900 +++ b/src/parallel_execution/trans_impl.pl Mon Nov 18 21:00:11 2019 +0900 @@ -2,14 +2,13 @@ use strict; use warnings; use DDP { deparse => 1}; +use CbC::Util; -my $impl_file = shift or die 'require impl file'; -my $impl = parse_impl($impl_file); -p $impl; +#my $impl_file = shift or die 'require impl file'; +#my $impl = parse_impl($impl_file); -#my $context_h = shift // './context.h'; -#my $context = slup($context_h); - +my $hoge = CbC::Util->parse_impl(shift); +p $hoge; sub slup { my $file = shift;
--- a/src/parallel_execution/update_context.pl Mon Nov 18 20:05:43 2019 +0900 +++ b/src/parallel_execution/update_context.pl Mon Nov 18 21:00:11 2019 +0900 @@ -3,11 +3,15 @@ use warnings; use Getopt::Std; +use FindBin; +use lib "$FindBin::Bin/lib"; +use Gears::Util; + my %opt; getopts("wc" => \%opt); my $interface_file = shift or die "require itnerface file"; -my $h2context = parse_interface($interface_file); +my $h2context = Gears::Util->parse_interface($interface_file); my $context = dump_h2context($h2context); if ($opt{c}) { @@ -52,46 +56,6 @@ return (\@first_context_headers,\@last_context_headers); } -sub parse_interface { - my $file_name = shift; - - unless (-f $file_name) { - die 'invalid file path'; - } - - 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; - } - - if ($line =~ /^\s+$/) { - next; - } - - $line =~ s/\s*([\w\s\*]+);\s*/$1/; - push(@{$h2context->{data}},$1); - } - - close $fh; - return $h2context; -} - - sub dump_h2context { my $h2context = shift; my $context = '';