static void unroll_op(pTHX_ struct sljit_compiler* compiler, OP* op) { DEBUGf((" ; %s [%p]\n", OP_NAME(op), op)); emit_label(compiler, op); // TODO(dgl): Can we avoid doing this for every op? sljit_emit_ijump(compiler, SLJIT_CALL0, SLJIT_IMM, (sljit_w) op->op_ppaddr); sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM, (sljit_w) &PL_op, SLJIT_RETURN_REG, 0); }
static SLJIT_INLINE int emit_mov_before_return(struct sljit_compiler *compiler, int op, int src, sljit_w srcw) { /* Return if don't need to do anything. */ if (op == SLJIT_UNUSED) return SLJIT_SUCCESS; #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE) if (src == SLJIT_RETURN_REG && op == SLJIT_MOV) return SLJIT_SUCCESS; #else if (src == SLJIT_RETURN_REG && (op == SLJIT_MOV || op == SLJIT_MOV_UI || op == SLJIT_MOV_SI)) return SLJIT_SUCCESS; #endif #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE) || (defined SLJIT_DEBUG && SLJIT_DEBUG) compiler->skip_checks = 1; #endif return sljit_emit_op1(compiler, op, SLJIT_RETURN_REG, 0, src, srcw); }
static int add3(long a, long b, long c) { void *code; unsigned long len; func3_t func; /* Create a SLJIT compiler */ struct sljit_compiler *C = sljit_create_compiler(); /* Start a context(function entry), have 3 arguments, discuss later */ sljit_emit_enter(C, 0, 3, 1, 3, 0, 0, 0); /* The first arguments of function is register SLJIT_S0, 2nd, SLJIT_S1, etc. */ /* R0 = first */ sljit_emit_op1(C, SLJIT_MOV, SLJIT_R0, 0, SLJIT_S0, 0); /* R0 = R0 + second */ sljit_emit_op2(C, SLJIT_ADD, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_S1, 0); /* R0 = R0 + third */ sljit_emit_op2(C, SLJIT_ADD, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_S2, 0); /* This statement mov R0 to RETURN REG and return */ /* in fact, R0 is RETURN REG itself */ sljit_emit_return(C, SLJIT_MOV, SLJIT_R0, 0); /* Generate machine code */ code = sljit_generate_code(C); len = sljit_get_generated_code_size(C); /* Execute code */ func = (func3_t)code; printf("func return %ld\n", func(a, b, c)); /* dump_code(code, len); */ /* Clean up */ sljit_free_compiler(C); sljit_free_code(code); return 0; }