Mercurial > hg > Members > anatofuz > MoarVM
changeset 37:5b66cfffe9cd
update regex
author | Takahiro SHIMIZU <anatofuz@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Fri, 16 Nov 2018 17:55:10 +0900 |
parents | 5577a26e56a9 |
children | 2c51389684ca |
files | cbctools/change_OP_to_cbc.pl |
diffstat | 1 files changed, 27 insertions(+), 7 deletions(-) [+] |
line wrap: on
line diff
--- a/cbctools/change_OP_to_cbc.pl Fri Nov 16 15:29:46 2018 +0900 +++ b/cbctools/change_OP_to_cbc.pl Fri Nov 16 17:55:10 2018 +0900 @@ -13,6 +13,7 @@ my $none_left_blanket = 0; my $i = 0; +our @regex_targets = qw/op cu cur_op tc cur_callsite bytecode_start/; my @upside = (); for (;$i < scalar(@cbc_lines); $i++){ @@ -115,20 +116,39 @@ map { print; } (@upside,@rewritec,@middle,@after); + + sub change_i { my $str = shift; - #$str =~ s/^op/i->op/g; - $str =~ s/(\A)op|([\s,(])op/$2 i->op/g; - $str =~ s/(\A)cu|([\s,(])cu/$2 i->cu/g; - $str =~ s/(\A)cur_op|([\s,(])cur_op/i->cur_op/g; - $str =~ s/([,(])cu/$1i->tc/g; - $str =~ s/tc/i->tc/g; - $str =~ s/cur_callsite/i->cur_callsite/g; + map { $str = substitution_regex($str,$_); } @regex_targets; + # + #for my $reg (@regex_targets){ + # $str = substitution_regex($str,$reg); + #} + #$str =~ s/(\A)op|([\s,(])op/$2i->op/g; + #$str =~ s/(\A)cu|([\s,(])cu/$2i->cu/g; + #$str =~ s/(\A)cur_op|([\s,(])cur_op/$2i->cur_op/g; + #$str =~ s/(\A)tc|([\s,(&])tc/$2i->tc/g; + #$str =~ s/(\A)cur_callsite|([\s,(&])cur_callsite/$2i->cur_callsite/g; + #$str =~ s/(\A)bytecode_start|([\s,(&])bytecode_start/$2i->bytecode_start/g; $str =~ s/NEXT;/cbc_next(i);/; $str =~ s/ / /g; return $str; } +sub substitution_regex { + my ($str,$target) = @_; + if ($str =~ /(\A)$target/){ + $str =~ s/(\A)$target/i->$target/g; + return $str; + } + if ($str =~ /([\s,(&])$target/){ + $str =~ s/([\s,(&])$target/$1i->$target/g; + return $str; + } + return $str; +} + sub insert_cbc_next{ #push @rewritec,"$indent}\n"; push @rewritec," goto cbc_next(i);\n";