소스 검색

OP_JMP OP_TEST

Hugo Musso Gualandi 5 년 전
부모
커밋
564fb37adb
2개의 변경된 파일20개의 추가작업 그리고 4개의 파일을 삭제
  1. 19 3
      src/luaot.c
  2. 1 1
      src/luaot_header.c

+ 19 - 3
src/luaot.c

@@ -547,6 +547,14 @@ void print_opcode_comment(Proto *f, int pc)
     print("\n");
 }
 
+static
+int jump_target(Proto *p, int pc)
+{
+    Instruction instr = p->code[pc];
+    if (GET_OPCODE(instr) != OP_JMP) { fatal_error("instruction is not a jump"); }
+    return (pc+1) + GETARG_sJ(instr);
+}
+
 static
 void create_function(Proto *p)
 {
@@ -603,7 +611,7 @@ void create_function(Proto *p)
         int next = pc + 1;
         println("  #undef  LUA_AOT_NEXT_JUMP");
         if (next < p->sizecode && GET_OPCODE(p->code[next]) == OP_JMP) {
-            println("  #define LUA_AOT_NEXT_JUMP label_todo");
+            println("  #define LUA_AOT_NEXT_JUMP label_%02d", jump_target(p, next));
         }
 
         int skip1 = pc + 2;
@@ -843,7 +851,11 @@ void create_function(Proto *p)
             }
             // case OP_CLOSE
             // case OP_TBC
-            // case OP_JMP
+            case OP_JMP: {
+                println("    updatetrap(ci);");
+                println("    goto label_%02d;", jump_target(p, pc));
+                break;
+            }
             // case OP_EQ
             // case OP_LT
             // case OP_LE
@@ -853,7 +865,11 @@ void create_function(Proto *p)
             // case OP_LEI
             // case OP_GTI
             // case OP_GEI
-            // case OP_TEST
+            case OP_TEST: {
+                println("    int cond = !l_isfalse(s2v(ra));");
+                println("    docondjump();");
+                break;
+            }
             // case OP_TESTSET
             // case OP_CALL
             // case OP_TAILCAL

+ 1 - 1
src/luaot_header.c

@@ -103,7 +103,7 @@
 #undef dojump
 
 #undef  donextjump
-#define donextjump(ci)	{ goto LUA_AOT_NEXTJUMP; }
+#define donextjump(ci)	{ updatetrap(ci); goto LUA_AOT_NEXT_JUMP; }
 
 #undef  docondjump
 #define docondjump()	if (cond != GETARG_k(i)) goto LUA_AOT_SKIP1; else donextjump(ci);