MCPcopy Create free account
hub / github.com/DFHack/dfhack / findsetreg

Function findsetreg

depends/lua/src/ldebug.c:386–429  ·  view source on GitHub ↗

** try to find last instruction before 'lastpc' that modified register 'reg' */

Source from the content-addressed store, hash-verified

384** try to find last instruction before 'lastpc' that modified register 'reg'
385*/
386static int findsetreg (Proto *p, int lastpc, int reg) {
387 int pc;
388 int setreg = -1; /* keep last instruction that changed 'reg' */
389 int jmptarget = 0; /* any code before this address is conditional */
390 for (pc = 0; pc < lastpc; pc++) {
391 Instruction i = p->code[pc];
392 OpCode op = GET_OPCODE(i);
393 int a = GETARG_A(i);
394 switch (op) {
395 case OP_LOADNIL: {
396 int b = GETARG_B(i);
397 if (a <= reg && reg <= a + b) /* set registers from 'a' to 'a+b' */
398 setreg = filterpc(pc, jmptarget);
399 break;
400 }
401 case OP_TFORCALL: {
402 if (reg >= a + 2) /* affect all regs above its base */
403 setreg = filterpc(pc, jmptarget);
404 break;
405 }
406 case OP_CALL:
407 case OP_TAILCALL: {
408 if (reg >= a) /* affect all registers above base */
409 setreg = filterpc(pc, jmptarget);
410 break;
411 }
412 case OP_JMP: {
413 int b = GETARG_sBx(i);
414 int dest = pc + 1 + b;
415 /* jump is forward and do not skip 'lastpc'? */
416 if (pc < dest && dest <= lastpc) {
417 if (dest > jmptarget)
418 jmptarget = dest; /* update 'jmptarget' */
419 }
420 break;
421 }
422 default:
423 if (testAMode(op) && reg == a) /* any instruction that set A */
424 setreg = filterpc(pc, jmptarget);
425 break;
426 }
427 }
428 return setreg;
429}
430
431
432static const char *getobjname (Proto *p, int lastpc, int reg,

Callers 1

getobjnameFunction · 0.85

Calls 1

filterpcFunction · 0.85

Tested by

no test coverage detected