* Removed all Id tags.
[cacao.git] / src / vm / jit / emit-common.c
index 9358ca4c2b950b50ee0ac2287a858060eeaaa907..aa2f38997165a63b4ce578f3b4a9e64b36c51db3 100644 (file)
    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"
 
@@ -38,6 +37,7 @@
 
 #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"
@@ -247,6 +247,53 @@ void emit_store_dst(jitdata *jd, instruction *iptr, s4 d)
 }
 
 
+/* 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
@@ -270,14 +317,16 @@ void emit_bccz(codegendata *cd, basicblock *target, s4 condition, s4 reg, u4 opt
                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 {
@@ -489,14 +538,16 @@ void emit_label_bccz(codegendata *cd, s4 label, s4 condition, s4 reg, u4 options
                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 */
@@ -558,14 +609,16 @@ void emit_label(codegendata *cd, s4 label)
                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 */