2 /**********************************************************************
8 Copyright (C) 2004-2007 Koichi Sasada
10 **********************************************************************/
15 #define DECL_SC_REG(type, r, reg) register type reg_##r
17 #elif __GNUC__ && __x86_64__
18 #define DECL_SC_REG(type, r, reg) register type reg_##r __asm__("r" reg)
20 #elif __GNUC__ && __i386__
21 #define DECL_SC_REG(type, r, reg) register type reg_##r __asm__("e" reg)
24 #define DECL_SC_REG(type, r, reg) register type reg_##r
26 /* #define DECL_SC_REG(r, reg) VALUE reg_##r */
28 #if !OPT_CALL_THREADED_CODE
30 vm_eval(rb_thread_t
*th
, VALUE initial
)
35 #elif __GNUC__ && __x86_64
36 DECL_SC_REG(VALUE
, a
, "12");
37 DECL_SC_REG(VALUE
, b
, "13");
44 #if __GNUC__ && __i386__
45 DECL_SC_REG(VALUE
*, pc
, "di");
46 DECL_SC_REG(rb_control_frame_t
*, cfp
, "si");
47 #define USE_MACHINE_REGS 1
49 #elif __GNUC__ && __x86_64__
50 DECL_SC_REG(VALUE
*, pc
, "14");
51 DECL_SC_REG(rb_control_frame_t
*, cfp
, "15");
52 #define USE_MACHINE_REGS 1
55 register rb_control_frame_t
*reg_cfp
;
62 #define RESTORE_REGS() \
65 reg_pc = reg_cfp->pc; \
71 #define GET_PC() (reg_pc)
73 #define SET_PC(x) (reg_cfp->pc = REG_PC = (x))
76 #if OPT_TOKEN_THREADED_CODE || OPT_DIRECT_THREADED_CODE
80 finish_insn_seq
[0] = (VALUE
)&&LABEL (finish_SC_ax_ax
);
82 finish_insn_seq
[0] = (VALUE
)&&LABEL (finish
);
84 return (VALUE
)insns_address_table
;
100 END_INSNS_DISPATCH();
103 rb_bug("vm_eval: unreachable");
113 get_insns_address_table()
115 return insns_address_table
;
119 vm_eval(rb_thread_t
*th
, VALUE initial
)
121 register rb_control_frame_t
*reg_cfp
= th
->cfp
;
125 reg_cfp
= ((rb_insn_func_t
) (*GET_PC()))(th
, reg_cfp
);
128 VALUE err
= th
->errinfo
;
134 if (VM_FRAME_TYPE(th
->cfp
) != VM_FRAME_MAGIC_FINISH
) {
135 rb_bug("cfp consistency error");
138 ret
= *(th
->cfp
->sp
-1); /* pop */
139 th
->cfp
++; /* pop cf */
145 vm_get_insns_address_table(void)
147 return (const void **)vm_eval(0, 0);