Author: leo
Date: Sun Feb  5 09:05:12 2006
New Revision: 11424

Modified:
   trunk/src/jit/i386/jit_emit.h
   trunk/src/pic.c
Log:
PIC/JIT - -Ofun

* create a JIT function for .sub __pic_test ; return(42) ; .end
* a lot hardcoded for now, but it works :)


Modified: trunk/src/jit/i386/jit_emit.h
==============================================================================
--- trunk/src/jit/i386/jit_emit.h       (original)
+++ trunk/src/jit/i386/jit_emit.h       Sun Feb  5 09:05:12 2006
@@ -2936,12 +2936,65 @@ Parrot_jit_begin(Parrot_jit_info_t *jit_
 #endif /* JIT_CGP */
 
 static void
-Parrot_jit_begin_sub(Parrot_jit_info_t *jit_info,
+Parrot_jit_begin_sub_regs(Parrot_jit_info_t *jit_info,
                  Interp * interpreter)
 {
+    jit_emit_stack_frame_enter(jit_info->native_ptr);
+    /* stack:
+     *  16   args
+     *  12   sig_bits
+     *   8   interpreter
+     *   4   retaddr
+     *   0   ebp <----- ebp
+     * [ -4   ebx .. preserved regs ]
+     */
+    /*
+     * TODO check register usage of the subroutine
+     *      how many we have to preserve
+     */ 
+#if 0
+    emitm_pushl_r(jit_info->native_ptr, emit_EBX);
+    emitm_pushl_r(jit_info->native_ptr, emit_ESI);
+    emitm_pushl_r(jit_info->native_ptr, emit_EDI);
+#endif
+    /* XXX just a quick test */
+
+    /* mov 16(%ebp), %eax - fetch args ptr */
+    emitm_movl_m_r(jit_info->native_ptr, emit_EAX, emit_EBP, emit_None, 1, 16);
+
+    /* code emitted by set_returns */
+    /* mov 0(%eax), %ecx 
+     * mov $42, (%ecx) - return 42 */
+    emitm_movl_m_r(jit_info->native_ptr, emit_ECX, emit_EAX, emit_None, 1, 0);
+    emitm_movl_i_m(jit_info->native_ptr, 42, emit_ECX, emit_None, 1, 0);
+
+    /* code emitted by returncc */
+    /* fetch retval pc -> %eax i.e. return it */
+    emitm_movl_m_r(jit_info->native_ptr, emit_EAX, emit_EAX, emit_None, 1, 4);
+    jit_emit_stack_frame_leave(jit_info->native_ptr);
+    emitm_ret(jit_info->native_ptr);
 }
 
 
+/*
+ * create a JITted version of a PIR sub, where everything
+ * resided in registers
+ *
+ * The sub is called as
+ *
+ *   opcode_t * func(Interp *i, INTVAL *sig_bits, void **args);
+ *
+ *   args[0] ...    NULL / return value address
+ *   args[1..n] ... addresses of n arguments
+ *   args[n + 1] .. opcode_t* next - ususally just returned
+ */
+
+static void
+Parrot_jit_begin_sub(Parrot_jit_info_t *jit_info,
+                 Interp * interpreter)
+{
+}
+
 static void
 jit_mov_mr_n_offs(Parrot_jit_info_t *jit_info,
         int base_reg, INTVAL offs, int src_reg)
@@ -3526,7 +3579,7 @@ static const jit_arch_info arch_info = {
             0,                  /* ABI sez it's not preserved */
             floatval_map
         },{
-            Parrot_jit_begin_sub,   /* emit code prologue */
+            Parrot_jit_begin_sub_regs,   /* emit code prologue */
             4,                  /* 4 mapped ints */
             2,                  /* first 2 are *non*preserved */
             intval_map_sub,

Modified: trunk/src/pic.c
==============================================================================
--- trunk/src/pic.c     (original)
+++ trunk/src/pic.c     Sun Feb  5 09:05:12 2006
@@ -83,7 +83,12 @@ lookup of the cache has to be done in th
 #  include "parrot/oplib/core_ops_cgp.h"
 #endif
 
-#define PIC_TEST 0
+#if HAS_JIT
+#include "parrot/exec.h"
+#include "parrot/jit.h"
+#endif
+
+#define PIC_TEST 1
 
 /* needs a Makefile dependency */
 /* #include "pmc/pmc_integer.h" */
@@ -563,9 +568,28 @@ is_pic_func(Interp *interpreter, void **
 #if PIC_TEST
     name = VTABLE_get_string(interpreter, sub);
     if (memcmp((char*) name->strstart, "__pic_test", 10) == 0) {
+#if HAS_JIT
+        /*
+         * create JIT code - just a test
+         */
+        Parrot_jit_info_t *jit_info;
+        opcode_t *base, *start, *end;
         
-        mic->lru.f.real_function = (funcptr_t) pic_test_func;
+        base = interpreter->code->base.data;
+        start = base + PMC_sub(sub)->start_offs;
+        end   = base + PMC_sub(sub)->end_offs;
+        /* TODO pass Sub */
+
+        jit_info = parrot_build_asm(interpreter, start, end, NULL,
+            JIT_CODE_SUB_REGS_ONLY);
+        if (!jit_info)
+            return 0;
+        
+        mic->lru.f.real_function = (funcptr_t) jit_info->arena.start;
         return 1;
+#else
+        return 0;
+#endif
     }
 #endif
     return 0;

Reply via email to