changeset 11:e08e6dca633f

add switch code
author Takahiro SHIMIZU <anatofuz@cr.ie.u-ryukyu.ac.jp>
date Tue, 09 Oct 2018 16:17:01 +0900
parents 30098d746672
children 618c343f4a17
files cbctools/change_OP_to_cbc.pl
diffstat 1 files changed, 30 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/cbctools/change_OP_to_cbc.pl	Tue Oct 09 13:04:47 2018 +0900
+++ b/cbctools/change_OP_to_cbc.pl	Tue Oct 09 16:17:01 2018 +0900
@@ -13,21 +13,41 @@
 my $none_left_blanket = 0;
 
 my $i = 0;
+
+my @upside = ();
 for (;$i < scalar(@cbc_lines); $i++){
-    push @rewritec,$cbc_lines[$i];
+    push @upside,$cbc_lines[$i];
+    if ($cbc_lines[$i+1] =~ /\/\* This is the interpreter run loop. We have one of these per thread. \*\//){
+        last;
+    }
+}
+
+my @middle = ();
+
+for (;$i < scalar(@cbc_lines); $i++){
+    push @middle,$cbc_lines[$i];
     if ($cbc_lines[$i] =~ /DISPATCH\(NEXT_OP\)/){ # DISPATCHの中身を書き換えるのでそこまで飛ばす
         $i++;
         last;
     }
 }
+my @dispatch = ();
 
 for (;$i < scalar(@cbc_lines); $i++){
     # check OP(.*) {  codes
+
+    if ($cbc_lines[$i] =~ /#if MVM_CGOTO/){
+        $i--;
+        last;
+    }
+
     if ($cbc_lines[$i] =~ /^\s+OP\((.*)\):/ ){
         my $opcode = $1;
+        push @dispatch,"${indent}OP($opcode):\n";
         $none_left_blanket = $cbc_lines[$i] =~ /{/ ? 0 : 1;
         # transrate OP(HOGE) to __code hoge(INTERP *i){
-        $cbc_lines[$i]  = $indent. "__code ".$opcode."(INTERP i){\n";
+        $cbc_lines[$i]  =  "__code ".$opcode."(INTERP i){\n";
+        #$cbc_lines[$i]  = $indent. "__code ".$opcode."(INTERP i){\n";
         push @rewritec,$cbc_lines[$i];
 
         # 次の行に移動
@@ -40,7 +60,8 @@
         # $iの部分の関数定義を次ループでするために一行戻して再ループ
 
         if ($cbc_lines[$i] =~ /^\s+OP\((.*)\):/){
-            push @rewritec,"$indent   goto $1(i);\n";
+            push @rewritec,"    goto $1(i);\n";
+            #push @rewritec,"$indent   goto $1(i);\n";
             insert_right_blanket();
             $i--;
             next;
@@ -64,7 +85,9 @@
     }
 }
 
-map { print; } @rewritec;
+my @after = ();
+map { push @after,$cbc_lines[$_]} ($i+1.. scalar(@cbc_lines)-1);
+map { print; } (@upside,@rewritec,@middle,@dispatch,@after);
 
 
 sub change_i {
@@ -73,9 +96,11 @@
     $str =~ s/tc/i->tc/g;
     $str =~ s/cur_callsite/i->cur_callsite/g;
     $str =~ s/NEXT;/NEXT(i);/;
+    $str =~ s/^\s{16}/    /g;
     return $str;
 }
 
 sub insert_right_blanket {
-    push @rewritec,"$indent}\n";
+    #push @rewritec,"$indent}\n";
+    push @rewritec,"}\n";
 }