示例#1
0
/* Instruction dispatch. Used by instr/line/return hooks or when recording. */
void LJ_FASTCALL lj_dispatch_ins(lua_State *L, const BCIns *pc)
{
  GCfunc *fn = curr_func(L);
  GCproto *pt = funcproto(fn);
  void *cf = cframe_raw(L->cframe);
  const BCIns *oldpc = cframe_pc(cf);
  global_State *g = G(L);
  BCReg slots;
  setcframe_pc(cf, pc);
  slots = cur_topslot(pt, pc, cframe_multres_n(cf));
  L->top = L->base + slots;  /* Fix top. */
#if LJ_HASJIT
  {
    jit_State *J = G2J(g);
    if (J->state != LJ_TRACE_IDLE) {
      J->L = L;
      lj_trace_ins(J, pc-1);  /* The interpreter bytecode PC is offset by 1. */
    }
  }
#endif
  if ((g->hookmask & LUA_MASKCOUNT) && g->hookcount == 0) {
    g->hookcount = g->hookcstart;
    callhook(L, LUA_HOOKCOUNT, -1);
    L->top = L->base + slots;  /* Fix top again. */
  }
  if ((g->hookmask & LUA_MASKLINE)) {
    BCPos npc = proto_bcpos(pt, pc) - 1;
    BCPos opc = proto_bcpos(pt, oldpc) - 1;
    BCLine line = proto_line(pt, npc);
    if (pc <= oldpc || opc >= pt->sizebc || line != proto_line(pt, opc)) {
      callhook(L, LUA_HOOKLINE, line);
      L->top = L->base + slots;  /* Fix top again. */
    }
  }
  if ((g->hookmask & LUA_MASKRET) && bc_isret(bc_op(pc[-1])))
    callhook(L, LUA_HOOKRET, -1);
}
示例#2
0
/* Instruction dispatch callback for instr/line hooks or when recording. */
void lj_dispatch_ins(lua_State *L, const BCIns *pc, uint32_t nres)
{
  GCfunc *fn = curr_func(L);
  GCproto *pt = funcproto(fn);
  BCReg slots = cur_topslot(pt, pc, nres);
  global_State *g = G(L);
  const BCIns *oldpc = cframe_Lpc(L);
  cframe_Lpc(L) = pc;
  L->top = L->base + slots;  /* Fix top. */
#if LJ_HASJIT
  {
    jit_State *J = G2J(g);
    if (J->state != LJ_TRACE_IDLE) {
      J->L = L;
      J->pc = pc-1;
      J->fn = fn;
      J->pt = pt;
      lj_trace_ins(J);
    }
  }
#endif
  if ((g->hookmask & LUA_MASKCOUNT) && g->hookcount == 0) {
    g->hookcount = g->hookcstart;
    callhook(L, LUA_HOOKCOUNT, -1);
  }
  if ((g->hookmask & LUA_MASKLINE) && pt->lineinfo) {
    BCPos npc = (BCPos)(pc - pt->bc)-1;
    BCPos opc = (BCPos)(oldpc - pt->bc)-1;
    BCLine line = pt->lineinfo[npc];
    if (npc == 0 || pc <= oldpc ||
	opc >= pt->sizebc || line != pt->lineinfo[opc]) {
      L->top = L->base + slots;  /* Fix top again after instruction hook. */
      callhook(L, LUA_HOOKLINE, line);
    }
  }
}