static void load_acc_offset(int offset) { acc_const = 0; if (acc_loaded) { if (acc_offset == offset) return; if (acc_dirty) clean_acc(); } acc_offset = offset; if (tape_step > 1) { if (acc_offset) { jit_ldxi_i(REG_ACC, REG_P, acc_offset * tape_step); } else { jit_ldr_i(REG_ACC, REG_P); } } else { if (acc_offset) { jit_ldxi_uc(REG_ACC, REG_P, acc_offset); } else { jit_ldr_uc(REG_ACC, REG_P); } } acc_loaded = 1; acc_dirty = 0; acc_hi_dirty = (tape_step*8 != cell_size); }
void outrun(int ch, int count) { jit_node_t *argp; switch(ch) { case '!': if (bytecell) tape_step = 1; else tape_step = sizeof(int); init_jit(NULL); // argv[0]); _jit = jit_new_state(); start = jit_note(__FILE__, __LINE__); jit_prolog(); /* Get the data area pointer */ argp = jit_arg(); jit_getarg(REG_P, argp); break; case '~': jit_ret(); jit_epilog(); end = jit_note(__FILE__, __LINE__); codeptr = jit_emit(); jit_clear_state(); codeptr(calloc(tape_step, tapelen)); jit_destroy_state(); finish_jit(); codeptr = 0; if (loopstack) { free(loopstack); loopstack = 0; } break; case '>': jit_addi(REG_P, REG_P, count * tape_step); break; case '<': jit_subi(REG_P, REG_P, count * tape_step); break; case '+': if (tape_step>1) jit_ldr_i(REG_ACC, REG_P); else jit_ldr_uc(REG_ACC, REG_P); jit_addi(REG_ACC, REG_ACC, count); if (tape_step>1) jit_str_i(REG_P, REG_ACC); else jit_str_c(REG_P, REG_ACC); break; case '-': if (tape_step>1) jit_ldr_i(REG_ACC, REG_P); else jit_ldr_uc(REG_ACC, REG_P); jit_subi(REG_ACC, REG_ACC, count); if (tape_step>1) jit_str_i(REG_P, REG_ACC); else jit_str_c(REG_P, REG_ACC); break; case '[': if (tape_step>1) jit_ldr_i(REG_ACC, REG_P); else jit_ldr_uc(REG_ACC, REG_P); if (stackptr >= maxstack) { loopstack = realloc(loopstack, ((maxstack+=32)+2)*sizeof(*loopstack)); if (loopstack == 0) { perror("loop stack realloc failure"); exit(1); } } loopstack[stackptr] = jit_beqi(REG_ACC, 0); loopstack[stackptr+1] = jit_label(); stackptr += 2; break; case ']': if (tape_step>1) jit_ldr_i(REG_ACC, REG_P); else jit_ldr_uc(REG_ACC, REG_P); stackptr -= 2; if (stackptr < 0) { fprintf(stderr, "Code gen failure: Stack pointer negative.\n"); exit(1); } { jit_node_t *ref; ref = jit_bnei(REG_ACC, 0); jit_patch_at(ref, loopstack[stackptr+1]); jit_patch(loopstack[stackptr]); } break; case '.': if (tape_step>1) jit_ldr_i(REG_ACC, REG_P); else jit_ldr_uc(REG_ACC, REG_P); jit_prepare(); jit_pushargr(REG_ACC); jit_finishi(putchar); break; case ',': jit_prepare(); jit_pushargr(REG_ACC); jit_finishi(getchar); jit_retval(REG_ACC); if (tape_step>1) jit_str_i(REG_P, REG_ACC); else jit_str_c(REG_P, REG_ACC); break; } }