浏览代码

Remove LUAOT_PC

Transform it back into a variable, because we will need to pass it
around as a parameter and so on. This version is simpler.
Hugo Musso Gualandi 3 年之前
父节点
当前提交
b794808cef
共有 2 个文件被更改,包括 7 次插入8 次删除
  1. 2 3
      src/functions_header.c
  2. 5 5
      src/luaot_functions.c

+ 2 - 3
src/functions_header.c

@@ -19,7 +19,6 @@ typedef struct {
     LClosure *cl;
     LClosure *cl;
     TValue *k;
     TValue *k;
     StkId base;
     StkId base;
-    const Instruction *pc;
     int trap;
     int trap;
 } LuaotExecuteState;
 } LuaotExecuteState;
 
 
@@ -139,7 +138,7 @@ typedef struct {
 //
 //
 
 
 #undef  savepc
 #undef  savepc
-#define savepc(L)	(ctx->ci->u.l.savedpc = LUAOT_PC)
+#define savepc(L)	(ctx->ci->u.l.savedpc = pc)
 
 
 //
 //
 
 
@@ -160,7 +159,7 @@ typedef struct {
 #undef  vmfetch
 #undef  vmfetch
 #define aot_vmfetch(instr)	{ \
 #define aot_vmfetch(instr)	{ \
   if (l_unlikely(ctx->trap)) {  /* stack reallocation or hooks? */ \
   if (l_unlikely(ctx->trap)) {  /* stack reallocation or hooks? */ \
-    luaot_vmfetch_trap(L, ctx, LUAOT_PC-1); \
+    luaot_vmfetch_trap(L, ctx, pc-1); \
   } \
   } \
   i = instr; \
   i = instr; \
   ra = RA(i); /* WARNING: any stack reallocation invalidates 'ra' */ \
   ra = RA(i); /* WARNING: any stack reallocation invalidates 'ra' */ \

+ 5 - 5
src/luaot_functions.c

@@ -48,9 +48,9 @@ void create_function(Proto *f)
     println("  ctx->trap = L->hookmask;");
     println("  ctx->trap = L->hookmask;");
     println("  ctx->cl = clLvalue(s2v(ctx->ci->func));");
     println("  ctx->cl = clLvalue(s2v(ctx->ci->func));");
     println("  ctx->k = ctx->cl->p->k;");
     println("  ctx->k = ctx->cl->p->k;");
-    println("  ctx->pc = ctx->ci->u.l.savedpc;");
+    println("  const Instruction *pc = ctx->ci->u.l.savedpc;");
     println("  if (l_unlikely(ctx->trap)) {");
     println("  if (l_unlikely(ctx->trap)) {");
-    println("    if (ctx->pc == ctx->cl->p->code) {  /* first instruction (not resuming)? */");
+    println("    if (pc == ctx->cl->p->code) {  /* first instruction (not resuming)? */");
     println("      if (ctx->cl->p->is_vararg)");
     println("      if (ctx->cl->p->is_vararg)");
     println("        ctx->trap = 0;  /* hooks will start after VARARGPREP instruction */");
     println("        ctx->trap = 0;  /* hooks will start after VARARGPREP instruction */");
     println("      else  /* check 'call' hook */");
     println("      else  /* check 'call' hook */");
@@ -67,7 +67,7 @@ void create_function(Proto *f)
 
 
     // If we are returning from another function, or resuming a coroutine,
     // If we are returning from another function, or resuming a coroutine,
     // jump back to where left.
     // jump back to where left.
-    println("  switch (ctx->pc - code) {");
+    println("  switch (pc - code) {");
     for (int pc = 0; pc < f->sizecode; pc++) {
     for (int pc = 0; pc < f->sizecode; pc++) {
         println("    case %d: goto label_%02d;", pc, pc);
         println("    case %d: goto label_%02d;", pc, pc);
     }
     }
@@ -84,8 +84,7 @@ void create_function(Proto *f)
         // points towards the next instruction. There are some corner cases
         // points towards the next instruction. There are some corner cases
         // where the program counter getss adjusted mid-instruction, but I
         // where the program counter getss adjusted mid-instruction, but I
         // am not breaking anything because of those...
         // am not breaking anything because of those...
-        println("  #undef  LUAOT_PC");
-        println("  #define LUAOT_PC (code + %d)", pc+1);
+        println("  pc = (code + %d);", pc+1);
 
 
         int next = pc + 1;
         int next = pc + 1;
         println("  #undef  LUAOT_NEXT_JUMP");
         println("  #undef  LUAOT_NEXT_JUMP");
@@ -100,6 +99,7 @@ void create_function(Proto *f)
         }
         }
 
 
         println("  label_%02d: {", pc);
         println("  label_%02d: {", pc);
+        //println("    fprintf(stderr, \"OP=%%d\\n\", %d);", pc);
         println("    aot_vmfetch(0x%08x);", instr);
         println("    aot_vmfetch(0x%08x);", instr);
 
 
         switch (op) {
         switch (op) {