int scheme_generate_alloc_retry(mz_jit_state *jitter, int i) { GC_CAN_IGNORE jit_insn *refr; #ifdef JIT_USE_FP_OPS if (i == 2) { (void)mz_tl_sti_d_fppop(tl_scheme_jit_save_fp, JIT_FPR1, JIT_R2); } #endif JIT_UPDATE_THREAD_RSPTR(); jit_prepare(2); CHECK_LIMIT(); if (i == 1) { jit_pusharg_p(JIT_R1); jit_pusharg_p(JIT_R0); } else { (void)jit_movi_p(JIT_R0, NULL); jit_pusharg_p(JIT_R0); jit_pusharg_p(JIT_R0); } (void)mz_finish_lwe(ts_prepare_retry_alloc, refr); jit_retval(JIT_R0); if (i == 1) { mz_tl_ldi_l(JIT_R1, tl_retry_alloc_r1); } #ifdef JIT_USE_FP_OPS if (i == 2) { (void)mz_tl_ldi_d_fppush(JIT_FPR1, tl_scheme_jit_save_fp, JIT_R2); } #endif return 1; }
int main() { static jit_insn codeBuffer[1024]; static jit_state _jit; pvfi myFunction; /* ptr to generated code */ char *start, *end; /* a couple of labels */ int ofs; /* to get the argument */ myFunction = (pvfi) (jit_set_ip(codeBuffer).vptr); start = jit_get_ip().ptr; jit_prolog(1); ofs = jit_arg_i(); jit_movi_p(JIT_R0, "looks like %d bytes sufficed\n"); jit_getarg_i(JIT_R1, ofs); jit_prepare_i(2); jit_pusharg_i(JIT_R1); /* push in reverse order */ jit_pusharg_p(JIT_R0); jit_finish(display_message); jit_ret(); end = jit_get_ip().ptr; jit_flush_code(codeBuffer, end); #ifdef LIGHTNING_DISASSEMBLE disassemble(stderr, codeBuffer, end); #endif #ifndef LIGHTNING_CROSS /* call the generated code, passing its size as argument */ myFunction(sizeof(codeBuffer)); #endif return 0; }
static stakumilo_t generate_push_pop (void) { static const char msg[] = "we got %i\n"; stakumilo_t result; int arg; int retval; buffer = mmap(NULL, getpagesize(), PROT_READ | PROT_WRITE | PROT_EXEC, MAP_PRIVATE | MAP_ANON, -1, 0); if (buffer == MAP_FAILED) { perror("mmap"); exit(0); } result = (stakumilo_t)(jit_set_ip (buffer).ptr); jit_prolog (1); arg = jit_arg_i (); jit_getarg_i (JIT_R1, arg); /* Save R1 on the stack. */ jit_pushr_i (JIT_R1); /* Save two other registers just for the sake of using the stack. */ jit_movi_i (JIT_R0, -1); jit_movi_i (JIT_R2, -1); jit_pushr_i (JIT_R0); jit_pushr_i (JIT_R2); /* most likely need stack aligned at 16 bytes, dummy push to force align */ jit_pushr_i (JIT_R2); jit_movr_i (JIT_R0, JIT_R1); jit_movi_p (JIT_R1, msg); /* Invoke a function that may modify R1. */ jit_prepare (2); jit_pusharg_i (JIT_R0); jit_pusharg_p (JIT_R1); (void)jit_finish (display_message); /* dummy pop for the sake of calling function with 16 byte aligned stack */ jit_popr_i (JIT_R2); /* Restore the dummy registers. */ jit_popr_i (JIT_R2); jit_popr_i (JIT_R0); /* Restore R1. */ jit_popr_i (JIT_R1); jit_movr_i (JIT_RET, JIT_R1); jit_ret (); jit_flush_code (buffer, jit_get_ip ().ptr); return result; }
int inst_free(Module *state, Token *type, array_t *params) { if(array_length(params) != 1) die(state, "free requires 1 parameters."); if(type) die(state, "Operation free does not take a type."); jit_prepare_i(1); jit_pusharg_p(array_of(Token, params, 0)->value); jit_calli(Allocator_free); return 1; }
int inst_realloc(Module *state, Token *type, array_t *params) { if(array_length(params) != 2) die(state, "realloc requires 2 parameters."); if(type) die(state, "Operation realloc does not take a type."); jit_movi_i(JIT_R0, array_of(Token, params, 1)->value); jit_prepare_i(2); jit_pusharg_i(JIT_R0); jit_pusharg_p(array_of(Token, params, 0)->value); jit_finish(Allocator_realloc); jit_retval(array_of(Token, params, 0)->value); return 1; }
static stakumilo_t generate_push_pop (void) { static const char msg[] = "we got %i\n"; static char buffer[1024]; stakumilo_t result; int arg; result = (stakumilo_t)(jit_set_ip (buffer).ptr); jit_prolog (1); arg = jit_arg_i (); jit_getarg_i (JIT_R1, arg); /* Save R1 on the stack. */ jit_pushr_i (JIT_R1); /* Save two other registers just for the sake of using the stack. */ jit_movi_i (JIT_R0, -1); jit_movi_i (JIT_R2, -1); jit_pushr_i (JIT_R0); jit_pushr_i (JIT_R2); jit_movr_i (JIT_R0, JIT_R1); jit_movi_p (JIT_R1, msg); /* Invoke a function that may modify R1. */ jit_prepare (2); jit_pusharg_i (JIT_R0); jit_pusharg_p (JIT_R1); (void)jit_finish (display_message); /* Restore the dummy registers. */ jit_popr_i (JIT_R2); jit_popr_i (JIT_R0); /* Restore R1. */ jit_popr_i (JIT_R1); jit_movr_i (JIT_RET, JIT_R1); jit_ret (); jit_flush_code (buffer, jit_get_ip ().ptr); return result; }
int main() { pvfi myFunction; /* ptr to generated code */ char *start, *end; /* a couple of labels */ int ofs; /* to get the argument */ codeBuffer = mmap(NULL, getpagesize(), PROT_READ | PROT_WRITE | PROT_EXEC, MAP_PRIVATE | MAP_ANON, -1, 0); if (codeBuffer == MAP_FAILED) { perror("mmap"); exit(0); } myFunction = (pvfi) (jit_set_ip(codeBuffer).vptr); start = jit_get_ip().ptr; jit_prolog(1); ofs = jit_arg_i(); jit_movi_p(JIT_R0, "looks like %d bytes sufficed\n"); jit_getarg_i(JIT_R1, ofs); jit_prepare_i(2); jit_pusharg_i(JIT_R1); /* push in reverse order */ jit_pusharg_p(JIT_R0); jit_finish(display_message); jit_ret(); end = jit_get_ip().ptr; jit_flush_code(codeBuffer, end); #ifdef LIGHTNING_DISASSEMBLE disassemble(stderr, codeBuffer, end); #endif #ifndef LIGHTNING_CROSS /* call the generated code, with a dummy argument */ myFunction(1024); #endif return 0; }