cvsuser     02/11/29 05:11:22

  Modified:    .        build_nativecall.pl call_list.txt
               jit/i386 jit_emit.h
  Added:       t/pmc    nci.t
  Log:
  experimental native native call interface i386
  
  Revision  Changes    Path
  1.4       +4 -4      parrot/build_nativecall.pl
  
  Index: build_nativecall.pl
  ===================================================================
  RCS file: /cvs/public/parrot/build_nativecall.pl,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -w -r1.3 -r1.4
  --- build_nativecall.pl       26 Nov 2002 01:36:36 -0000      1.3
  +++ build_nativecall.pl       29 Nov 2002 13:11:18 -0000      1.4
  @@ -65,7 +65,7 @@
   /* nci.c
    *  Copyright: 2001, 2002 Yet Another Society
    *  CVS Info
  - *     $Id: build_nativecall.pl,v 1.3 2002/11/26 01:36:36 dan Exp $
  + *     $Id: build_nativecall.pl,v 1.4 2002/11/29 13:11:18 leo Exp $
    *  Overview:
    *     Native Call Interface routines. The code needed to build a
    *     parrot to C call frame is in here
  @@ -202,7 +202,7 @@
   
     push @icky_global_variable, <<CALL;
     if (!string_compare(interpreter, signature,
  -    string_from_c_string(interpreter, "$return$params", 1)))
  +    string_from_c_string(interpreter, "$return$params", 0)))
           return pcf_${return}_$params;
   CALL
   
  
  
  
  1.6       +2 -1      parrot/call_list.txt
  
  Index: call_list.txt
  ===================================================================
  RCS file: /cvs/public/parrot/call_list.txt,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -w -r1.5 -r1.6
  --- call_list.txt     26 Nov 2002 01:40:01 -0000      1.5
  +++ call_list.txt     29 Nov 2002 13:11:18 -0000      1.6
  @@ -16,6 +16,7 @@
   #
   #Return params
   i    i
  +i    d
   i    ii
   f    is
   d    d
  
  
  
  1.29      +77 -2     parrot/jit/i386/jit_emit.h
  
  Index: jit_emit.h
  ===================================================================
  RCS file: /cvs/public/parrot/jit/i386/jit_emit.h,v
  retrieving revision 1.28
  retrieving revision 1.29
  diff -u -w -r1.28 -r1.29
  --- jit_emit.h        29 Nov 2002 09:00:36 -0000      1.28
  +++ jit_emit.h        29 Nov 2002 13:11:20 -0000      1.29
  @@ -3,7 +3,7 @@
    *
    * i386
    *
  - * $Id: jit_emit.h,v 1.28 2002/11/29 09:00:36 leo Exp $
  + * $Id: jit_emit.h,v 1.29 2002/11/29 13:11:20 leo Exp $
    */
   
   #include <assert.h>
  @@ -1648,7 +1648,7 @@
        * the stack this will stop working !!! */
       emitm_pushl_i(jit_info->native_ptr, interpreter);
   
  -    /* get the pc from stack:  mov 12(%ebx), %eax */
  +    /* get the pc from stack:  mov 12(%ebp), %eax */
       emitm_movl_m_r(jit_info->native_ptr, emit_EAX, emit_EBP, emit_None, 1, 12);
   
       /* Point EBP to the opcode-native code map array - this destroy above
  @@ -2086,6 +2086,81 @@
       Parrot_emit_jump_to_eax(jit_info, interpreter);
   }
   
  +void *
  +Parrot_jit_build_call_func(struct Parrot_Interp *interpreter,
  +        String *signature) {
  +
  +    Parrot_jit_info_t jit_info, *pj;
  +    char *sig;
  +    int next_n = 5;
  +    int next_i = 5;
  +    int st = 0;
  +
  +    jit_info.native_ptr = jit_info.arena.start =
  +        mem_sys_allocate_zeroed((size_t)1024);
  +    pj = &jit_info;
  +
  +    /* make stack frame */
  +    jit_emit_stack_frame_enter(pj);
  +    /* get left most param, assume ascii chars */
  +    sig = (char *)signature->bufstart + signature->bufused - 1;
  +    /* as long as there are params */
  +    while (sig > (char *)signature->strstart) {
  +        switch (*sig) {
  +            case 'd':
  +                /* get a double from next num reg and push it on stack */
  +                jit_emit_fload_m_n(pj->native_ptr,
  +                        &interpreter->ctx.num_reg.registers[next_n++]);
  +                /* make room for double */
  +                emitm_addb_i_r(pj->native_ptr, -8, emit_ESP);
  +                emitm_fstpl(pj->native_ptr, emit_ESP, emit_None, 1, 0);
  +                st += 4;
  +                break;
  +            case 'i':
  +                jit_emit_mov_rm_i(pj->native_ptr, emit_EAX,
  +                        &interpreter->ctx.int_reg.registers[next_i++]);
  +                emitm_pushl_r(pj->native_ptr, emit_EAX);
  +                break;
  +            default:
  +                internal_exception(1, "Parrot_jit_build_call_func: unimp\n");
  +                break;
  +        }
  +        /* stack */
  +        st += 4;
  +        --sig;
  +    }
  +    /* get the pmc from stack */
  +    emitm_movl_m_r(pj->native_ptr, emit_EAX, emit_EBP, 0, 1, 12);
  +    /* call the thing in struct_val, i.e. offset 12 */
  +    emitm_callm(pj->native_ptr, emit_EAX, emit_None, emit_None, 12);
  +    /* adjust stack */
  +    emitm_addb_i_r(pj->native_ptr, st, emit_ESP);
  +
  +    /* now place return values in registers */
  +    next_i = next_n = 5;
  +    switch (*sig) {
  +        case 'd':
  +            /* pop num from st(0) and mov to reg */
  +            jit_emit_fstore_m_n(pj->native_ptr,
  +                    &interpreter->ctx.num_reg.registers[next_n++]);
  +            break;
  +        case 'i':
  +            jit_emit_mov_mr_i(pj->native_ptr,
  +                    &interpreter->ctx.int_reg.registers[next_i++], emit_EAX);
  +            break;
  +    }
  +    /* set regs passed on stack */
  +    jit_emit_mov_mi_i(pj->native_ptr, &interpreter->ctx.int_reg.registers[0], 0);
  +    jit_emit_mov_mi_i(pj->native_ptr, &interpreter->ctx.int_reg.registers[1], 
next_i-5);
  +    jit_emit_mov_mi_i(pj->native_ptr, &interpreter->ctx.int_reg.registers[2], 0);
  +    jit_emit_mov_mi_i(pj->native_ptr, &interpreter->ctx.int_reg.registers[3], 0);
  +    jit_emit_mov_mi_i(pj->native_ptr, &interpreter->ctx.int_reg.registers[4], 
next_n-5);
  +
  +    jit_emit_stack_frame_leave(pj);
  +    emitm_ret(pj->native_ptr);
  +
  +    return (jit_f)D2FPTR(jit_info.arena.start);
  +}
   
   #else /* JIT_EMIT */
   
  
  
  
  1.1                  parrot/t/pmc/nci.t
  
  Index: nci.t
  ===================================================================
  use Parrot::Test tests => 2;
  
  TODO: {
      local $TODO="t/pmc/nci doesn't work on Windows" if $^O =~ /Win32/;
      $TODO=$TODO;  #warnings
  
  output_is(<<'CODE', <<'OUTPUT', "nic_d_d");
    loadlib P1, "libm.so"
    print "loaded\n"
    dlfunc P0, P1, "sqrt", "dd"
    print "dlfunced\n"
    set N5, 4.0
    invoke
    ne N5, 2.0, nok_1
    print "ok 1\n"
    end
  nok_1: print "nok 1\n"
    print N5
    print "\n"
    end
  
  CODE
  loaded
  dlfunced
  ok 1
  OUTPUT
  
  output_is(<<'CODE', <<'OUTPUT', "nic_i_d");
    loadlib P1, "libm.so"
    print "loaded\n"
    dlfunc P0, P1, "lrint", "id"
    print "dlfunced\n"
    set N5, 4.1
    invoke
    ne I5, 4, nok_1
    print "ok 1\n"
    end
  nok_1: print "nok 1\n"
    print I5
    print "\n"
    end
  
  CODE
  loaded
  dlfunced
  ok 1
  OUTPUT
  
  } # TODO
  
  
  
  


Reply via email to