Mercurial > hg > Members > anatofuz > MoarVM
changeset 35:29dd3807070e
new translate cbc_interp.pl
author | Takahiro SHIMIZU <anatofuz@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Wed, 14 Nov 2018 14:09:08 +0900 |
parents | 0853778b49ee |
children | 5577a26e56a9 |
files | cbctools/change_OP_to_cbc.pl cbctools/translate_cbc_interp.pl |
diffstat | 2 files changed, 82 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/cbctools/change_OP_to_cbc.pl Tue Nov 13 17:54:28 2018 +0900 +++ b/cbctools/change_OP_to_cbc.pl Wed Nov 14 14:09:08 2018 +0900 @@ -34,6 +34,13 @@ my @middle = (); for (;$i < scalar(@cbc_lines); $i++){ + + if ($cbc_lines[$i] =~ /#if MVM_CGOTO/ && $cbc_lines[$i+1] =~ /#include/){ + while ( $cbc_lines[$i] !~ /Stash address/){ + $i++; + } + } + push @middle,$cbc_lines[$i]; if ($cbc_lines[$i] =~ /DISPATCH\(NEXT_OP\)/){ # DISPATCHの中身を書き換えるのでそこまで飛ばす $i++; @@ -91,6 +98,7 @@ $cbc_lines[$i] = "}\n"; } } + $cbc_lines[$i] =~ s/GET_(REG|LEX)\((.*?)\)/GET_$1($2,i)/g; push @rewritec,change_i($cbc_lines[$i]); @@ -101,6 +109,7 @@ } my @after = (); +insert_interp_constract(); map { push @after,$cbc_lines[$_]} ($i+1.. scalar(@cbc_lines)-1); #map { print; } (@upside,@rewritec,@middle,@dispatch,@after); map { print; } (@upside,@rewritec,@middle,@after); @@ -110,6 +119,7 @@ my $str = shift; $str =~ s/^op/i->op/g; $str =~ 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; $str =~ s/NEXT;/cbc_next(i);/; @@ -126,3 +136,11 @@ #push @rewritec,"$indent}\n"; push @rewritec,"}\n"; } + +sub insert_interp_constract { +my $msg = <<'EOF'; +INTER inter = {0,NULL,NULL,NULL,NULL,NULL,tc}; +INTERP i = &inter; +EOF + push @after, $msg; +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/cbctools/translate_cbc_interp.pl Wed Nov 14 14:09:08 2018 +0900 @@ -0,0 +1,64 @@ +#!/usr/bin/env perl +use strict; +use warnings; + +my $interpfile = shift or die; + +open my $fh, '<',$interpfile; +my @interp_lines = <$fh>; +close $fh; + + +my @translated = (); +my $none_left_blanket = 0; +my $index = 0; + +while ( $interp_lines[$index] !~ /\/\* This is the interpreter run loop. We have one of these per thread. \*\//){ + if ($interp_lines[$index] =~ /GET_(REG|LEX)/){ + $interp_lines[$index] = insert_i_4_GET_R_L($interp_lines[$index]); + } + + if ($interp_lines[$index] =~ /NEXT_OP/){ + $interp_lines[$index] = change_i($interp_lines[$index]); + } + + # マクロ部分の置き換え + if ( $interp_lines[$index] =~ /#if MVM_CGOTO/){ + while ($interp_lines[$index] !~ /#endif/){ + $index++; + } + $index++; + print insert_CbC_macro(); + } + print "$interp_lines[$index]"; + $index++; +} + +sub change_i { + my $str = shift; + $str =~ s/^op/i->op/g; + $str =~ 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; + $str =~ s/NEXT;/cbc_next(i);/; + $str =~ s/ / /g; + return $str; +} + +sub insert_i_4_GET_R_L { + my $str = shift; + $str =~ s/tc/i->tc/g; + $str =~ s/reg_base/i->reg_base/g; + $str =~ s/GET_(REG|LEX)\((.*?)\)/GET_$1($2,i)/g; + return $str; +} + +sub insert_CbC_macro { + my $msg = << 'EOF'; +#define DISPATCH(op) {goto (CODES[op])(i);} +#define OP(name) OP_ ## name +#define NEXT(i) CODES[NEXT_OP(i)](i) +EOF + return $msg; +}