Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301, USA.
- $Id: emitfuncs.c 4398 2006-01-31 23:43:08Z twisti $
-
*/
#include "config.h"
#include <assert.h>
+#include <stdint.h>
#include "vm/types.h"
#include "vm/jit/emit-common.h"
#include "vm/jit/jit.h"
+#include "vm/jit/patcher-common.h"
#include "vmcore/options.h"
#include "vmcore/statistics.h"
}
+/* emit_patcher_traps **********************************************************
+
+ Generates the code for the patcher traps.
+
+*******************************************************************************/
+
+void emit_patcher_traps(jitdata *jd)
+{
+ codegendata *cd;
+ codeinfo *code;
+ patchref_t *pr;
+ u1 *savedmcodeptr;
+ u1 *tmpmcodeptr;
+ uint32_t mcode;
+
+ /* get required compiler data */
+
+ cd = jd->cd;
+ code = jd->code;
+
+ /* generate patcher traps code */
+
+ for (pr = list_first_unsynced(code->patchers); pr != NULL; pr = list_next_unsynced(code->patchers, pr)) {
+
+ /* Calculate the patch position where the original machine
+ code is located and the trap should be placed. */
+
+ tmpmcodeptr = (u1 *) (cd->mcodebase + pr->mpc);
+
+ /* Patch in the trap to call the signal handler (done at
+ compile time). */
+
+ savedmcodeptr = cd->mcodeptr; /* save current mcodeptr */
+ cd->mcodeptr = tmpmcodeptr; /* set mcodeptr to patch position */
+
+ mcode = emit_trap(cd);
+
+ cd->mcodeptr = savedmcodeptr; /* restore the current mcodeptr */
+
+ /* Remember the original machine code which is patched
+ back in later (done at runtime). */
+
+ pr->mcode = mcode;
+ }
+}
+
+
/* emit_bccz *******************************************************************
Emit conditional and unconditional branch instructions on integer
branchmpc = cd->mcodeptr - cd->mcodebase;
disp = target->mpc - branchmpc;
- STATISTICS(count_emit_branch++);
- STATISTICS(if ((int8_t)disp == disp) count_emit_branch_8bit++;
- else if ((int16_t)disp == disp) count_emit_branch_16bit++;
- else if ((int32_t)disp == disp) count_emit_branch_32bit++;
- #if (SIZEOF_VOID_P == 8)
- else if ((int64_t)disp == disp) count_emit_branch_64bit++;
- #endif
- );
+#if defined(ENABLE_STATISTICS)
+ count_emit_branch++;
+ if ((int8_t)disp == disp) count_emit_branch_8bit++;
+ else if ((int16_t)disp == disp) count_emit_branch_16bit++;
+ else if ((int32_t)disp == disp) count_emit_branch_32bit++;
+# if SIZEOF_VOID_P == 8
+ else if ((int64_t)disp == disp) count_emit_branch_64bit++;
+# endif
+#endif
+
emit_branch(cd, disp, condition, reg, options);
}
else {
mpc = cd->mcodeptr - cd->mcodebase;
disp = br->mpc - mpc;
- STATISTICS(count_emit_branch++);
- STATISTICS(if ((int8_t)disp == disp) count_emit_branch_8bit++;
- else if ((int16_t)disp == disp) count_emit_branch_16bit++;
- else if ((int32_t)disp == disp) count_emit_branch_32bit++;
- #if (SIZEOF_VOID_P == 8)
- else if ((int64_t)disp == disp) count_emit_branch_64bit++;
- #endif
- );
+#if defined(ENABLE_STATISTICS)
+ count_emit_branch++;
+ if ((int8_t)disp == disp) count_emit_branch_8bit++;
+ else if ((int16_t)disp == disp) count_emit_branch_16bit++;
+ else if ((int32_t)disp == disp) count_emit_branch_32bit++;
+# if SIZEOF_VOID_P == 8
+ else if ((int64_t)disp == disp) count_emit_branch_64bit++;
+# endif
+#endif
+
emit_branch(cd, disp, condition, reg, options);
/* now remove the branch reference */
mcodeptr = cd->mcodeptr;
cd->mcodeptr = cd->mcodebase + br->mpc;
- STATISTICS(count_emit_branch++);
- STATISTICS(if ((int8_t)disp == disp) count_emit_branch_8bit++;
- else if ((int16_t)disp == disp) count_emit_branch_16bit++;
- else if ((int32_t)disp == disp) count_emit_branch_32bit++;
- #if (SIZEOF_VOID_P == 8)
- else if ((int64_t)disp == disp) count_emit_branch_64bit++;
- #endif
- );
+#if defined(ENABLE_STATISTICS)
+ count_emit_branch++;
+ if ((int8_t)disp == disp) count_emit_branch_8bit++;
+ else if ((int16_t)disp == disp) count_emit_branch_16bit++;
+ else if ((int32_t)disp == disp) count_emit_branch_32bit++;
+# if SIZEOF_VOID_P == 8
+ else if ((int64_t)disp == disp) count_emit_branch_64bit++;
+# endif
+#endif
+
emit_branch(cd, disp, br->condition, br->reg, br->options);
/* restore mcodeptr */