@@ -348,9 +348,9 @@ yjit_gen_block(ctx_t *ctx, block_t *block, rb_execution_context_t *ec)
348348 break ;
349349 }
350350
351- if (0 ) {
351+ if (1 ) {
352352 fprintf (stderr , "compiling %d: %s\n" , insn_idx , insn_name (opcode ));
353- print_str (cb , insn_name (opcode ));
353+ // print_str(cb, insn_name(opcode));
354354 }
355355
356356 // :count-placement:
@@ -515,19 +515,47 @@ gen_putself(jitstate_t* jit, ctx_t* ctx)
515515static codegen_status_t
516516gen_getlocal_wc0 (jitstate_t * jit , ctx_t * ctx )
517517{
518- // Load environment pointer EP from CFP
519- mov (cb , REG0 , member_opnd (REG_CFP , rb_control_frame_t , ep ));
520-
521518 // Compute the offset from BP to the local
522519 int32_t local_idx = (int32_t )jit_get_arg (jit , 0 );
523520 const int32_t offs = - (SIZEOF_VALUE * local_idx );
524521
522+
523+
524+ /*
525+ if (local_idx < 8)
526+ {
527+ val_type_t local_type = ctx->local_types[local_idx];
528+
529+ if (local_type.type == ETYPE_FIXNUM) {
530+ fprintf(stderr, "local_idx=%d is fixnum\n", local_idx);
531+ ADD_COMMENT(cb, "local is fixnum");
532+ }
533+ else {
534+ fprintf(stderr, "local_idx=%d not fixnum\n", local_idx);
535+ ADD_COMMENT(cb, "local not fixnum");
536+ }
537+ }
538+ else
539+ {
540+ fprintf(stderr, "local_idx=%d\n", local_idx);
541+ }
542+ */
543+
544+
545+ fprintf (stderr , "local_idx=%d\n" , local_idx );
546+
547+
548+
549+
550+
551+ // Load environment pointer EP from CFP
552+ mov (cb , REG0 , member_opnd (REG_CFP , rb_control_frame_t , ep ));
553+
525554 // Load the local from the EP
526555 mov (cb , REG0 , mem_opnd (64 , REG0 , offs ));
527556
528557 // Write the local at SP
529558 x86opnd_t stack_top = ctx_stack_push_local (ctx , local_idx );
530- //x86opnd_t stack_top = ctx_stack_push(ctx, TYPE_UNKNOWN);
531559 mov (cb , stack_top , REG0 );
532560
533561 return YJIT_KEEP_COMPILING ;
@@ -1739,6 +1767,43 @@ gen_oswb_iseq(jitstate_t *jit, ctx_t *ctx, const struct rb_callinfo *ci, const r
17391767 // Stub so we can return to JITted code
17401768 blockid_t return_block = { jit -> iseq , jit_next_insn_idx (jit ) };
17411769
1770+
1771+ // Create a context for the callee
1772+ ctx_t callee_ctx = DEFAULT_CTX ;
1773+
1774+ // Set the argument type in the callee's context
1775+ for (int32_t arg_idx = 0 ; arg_idx < argc ; ++ arg_idx ) {
1776+ fprintf (stderr , "set arg type, arg_idx=%d\n" , arg_idx );
1777+
1778+ // x is arg0, but pushed last
1779+
1780+ val_type_t arg_type = ctx_get_opnd_type (ctx , OPND_STACK (argc - arg_idx - 1 ));
1781+
1782+ if (arg_type .type == ETYPE_FIXNUM )
1783+ fprintf (stderr , "is fixnum\n" );
1784+ else
1785+ fprintf (stderr , "not fixnum\n" );
1786+
1787+ ctx_set_local_type (& callee_ctx , arg_idx , arg_type );
1788+ }
1789+
1790+
1791+
1792+ fprintf (stderr , "local types\n" );
1793+ for (int32_t local_idx = 0 ; local_idx < argc ; ++ local_idx ) {
1794+ fprintf (stderr , "local_idx=%d\n" , local_idx );
1795+
1796+ val_type_t type = callee_ctx .local_types [local_idx ];
1797+
1798+ if (type .type == ETYPE_FIXNUM )
1799+ fprintf (stderr , "is fixnum\n" );
1800+ else
1801+ fprintf (stderr , "not fixnum\n" );
1802+ }
1803+
1804+
1805+
1806+
17421807 // Pop arguments and receiver in return context, push the return value
17431808 // After the return, the JIT and interpreter SP will match up
17441809 ctx_t return_ctx = * ctx ;
@@ -1760,12 +1825,12 @@ gen_oswb_iseq(jitstate_t *jit, ctx_t *ctx, const struct rb_callinfo *ci, const r
17601825 //print_str(cb, "calling Ruby func:");
17611826 //print_str(cb, rb_id2name(vm_ci_mid(ci)));
17621827
1763- // Load the updated SP
1828+ // Load the updated SP from the CFP
17641829 mov (cb , REG_SP , member_opnd (REG_CFP , rb_control_frame_t , sp ));
17651830
17661831 // Directly jump to the entry point of the callee
17671832 gen_direct_jump (
1768- & DEFAULT_CTX ,
1833+ & callee_ctx ,
17691834 (blockid_t ){ iseq , 0 }
17701835 );
17711836
@@ -1909,6 +1974,7 @@ gen_leave(jitstate_t* jit, ctx_t* ctx)
19091974 mov (cb , REG0 , member_opnd (REG_CFP , rb_control_frame_t , ep ));
19101975
19111976 // if (flags & VM_FRAME_FLAG_FINISH) != 0
1977+ ADD_COMMENT (cb , "check for finish frame" );
19121978 x86opnd_t flags_opnd = mem_opnd (64 , REG0 , sizeof (VALUE ) * VM_ENV_DATA_INDEX_FLAGS );
19131979 test (cb , flags_opnd , imm_opnd (VM_FRAME_FLAG_FINISH ));
19141980 jnz_ptr (cb , COUNTED_EXIT (side_exit , leave_se_finish_frame ));
@@ -1934,6 +2000,7 @@ gen_leave(jitstate_t* jit, ctx_t* ctx)
19342000 mov (cb , mem_opnd (64 , REG_SP , - SIZEOF_VALUE ), REG0 );
19352001
19362002 // If the return address is NULL, fall back to the interpreter
2003+ ADD_COMMENT (cb , "check for jit return" );
19372004 int FALLBACK_LABEL = cb_new_label (cb , "FALLBACK" );
19382005 test (cb , REG1 , REG1 );
19392006 jz_label (cb , FALLBACK_LABEL );
0 commit comments