PageRenderTime 57ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/vm_exec.h

https://github.com/nazy/ruby
C Header | 184 lines | 114 code | 47 blank | 23 comment | 7 complexity | f4f085858e9f5694e23e550781007187 MD5 | raw file
Possible License(s): GPL-2.0, BSD-3-Clause, AGPL-3.0, 0BSD, Unlicense
  1. /**********************************************************************
  2. vm.h -
  3. $Author$
  4. created at: 04/01/01 16:56:59 JST
  5. Copyright (C) 2004-2007 Koichi Sasada
  6. **********************************************************************/
  7. #ifndef RUBY_VM_EXEC_H
  8. #define RUBY_VM_EXEC_H
  9. typedef long OFFSET;
  10. typedef unsigned long lindex_t;
  11. typedef unsigned long dindex_t;
  12. typedef rb_num_t GENTRY;
  13. typedef rb_iseq_t *ISEQ;
  14. #ifdef COLLECT_USAGE_ANALYSIS
  15. #define USAGE_ANALYSIS_INSN(insn) vm_analysis_insn(insn)
  16. #define USAGE_ANALYSIS_OPERAND(insn, n, op) vm_analysis_operand(insn, n, (VALUE)op)
  17. #define USAGE_ANALYSIS_REGISTER(reg, s) vm_analysis_register(reg, s)
  18. #else
  19. #define USAGE_ANALYSIS_INSN(insn) /* none */
  20. #define USAGE_ANALYSIS_OPERAND(insn, n, op) /* none */
  21. #define USAGE_ANALYSIS_REGISTER(reg, s) /* none */
  22. #endif
  23. #ifdef __GCC__
  24. /* TODO: machine dependent prefetch instruction */
  25. #define PREFETCH(pc)
  26. #else
  27. #define PREFETCH(pc)
  28. #endif
  29. #if VMDEBUG > 0
  30. #define debugs printf
  31. #define DEBUG_ENTER_INSN(insn) \
  32. debug_print_pre(th, GET_CFP());
  33. #if OPT_STACK_CACHING
  34. #define SC_REGS() , reg_a, reg_b
  35. #else
  36. #define SC_REGS()
  37. #endif
  38. #define DEBUG_END_INSN() \
  39. debug_print_post(th, GET_CFP() SC_REGS());
  40. #else
  41. #define debugs
  42. #define DEBUG_ENTER_INSN(insn)
  43. #define DEBUG_END_INSN()
  44. #endif
  45. #define throwdebug if(0)printf
  46. /* #define throwdebug printf */
  47. /************************************************/
  48. #if DISPATCH_XXX
  49. error !
  50. /************************************************/
  51. #elif OPT_CALL_THREADED_CODE
  52. #define LABEL(x) insn_func_##x
  53. #define ELABEL(x)
  54. #define LABEL_PTR(x) &LABEL(x)
  55. #define INSN_ENTRY(insn) \
  56. static rb_control_frame_t * \
  57. FUNC_FASTCALL(LABEL(insn))(rb_thread_t *th, rb_control_frame_t *reg_cfp) {
  58. #define END_INSN(insn) return reg_cfp;}
  59. #define NEXT_INSN() return reg_cfp;
  60. /************************************************/
  61. #elif OPT_TOKEN_THREADED_CODE || OPT_DIRECT_THREADED_CODE
  62. /* threaded code with gcc */
  63. #define LABEL(x) INSN_LABEL_##x
  64. #define ELABEL(x) INSN_ELABEL_##x
  65. #define LABEL_PTR(x) &&LABEL(x)
  66. #define INSN_ENTRY_SIG(insn)
  67. #define INSN_DISPATCH_SIG(insn)
  68. #define INSN_ENTRY(insn) \
  69. LABEL(insn): \
  70. INSN_ENTRY_SIG(insn); \
  71. /* dispather */
  72. #if __GNUC__ && (__i386__ || __x86_64__) && __GNUC__ == 3
  73. #define DISPATCH_ARCH_DEPEND_WAY(addr) \
  74. asm volatile("jmp *%0;\t# -- inseted by vm.h\t[length = 2]" : : "r" (addr))
  75. #else
  76. #define DISPATCH_ARCH_DEPEND_WAY(addr) \
  77. /* do nothing */
  78. #endif
  79. /**********************************/
  80. #if OPT_DIRECT_THREADED_CODE
  81. /* for GCC 3.4.x */
  82. #define TC_DISPATCH(insn) \
  83. INSN_DISPATCH_SIG(insn); \
  84. goto *(void const *)GET_CURRENT_INSN(); \
  85. ;
  86. #else
  87. /* token threade code */
  88. #define TC_DISPATCH(insn) \
  89. DISPATCH_ARCH_DEPEND_WAY(insns_address_table[GET_CURRENT_INSN()]); \
  90. INSN_DISPATCH_SIG(insn); \
  91. goto *insns_address_table[GET_CURRENT_INSN()]; \
  92. rb_bug("tc error");
  93. #endif /* DISPATCH_DIRECT_THREADED_CODE */
  94. #define END_INSN(insn) \
  95. DEBUG_END_INSN(); \
  96. TC_DISPATCH(insn); \
  97. #define INSN_DISPATCH() \
  98. TC_DISPATCH(__START__) \
  99. {
  100. #define END_INSNS_DISPATCH() \
  101. rb_bug("unknown insn: %ld", GET_CURRENT_INSN()); \
  102. } /* end of while loop */ \
  103. #define NEXT_INSN() TC_DISPATCH(__NEXT_INSN__)
  104. /************************************************/
  105. #else /* no threaded code */
  106. /* most common method */
  107. #define INSN_ENTRY(insn) \
  108. case BIN(insn):
  109. #define END_INSN(insn) \
  110. DEBUG_END_INSN(); \
  111. break;
  112. #define INSN_DISPATCH() \
  113. while(1){ \
  114. switch(GET_CURRENT_INSN()){
  115. #define END_INSNS_DISPATCH() \
  116. default: \
  117. SDR(); \
  118. rb_bug("unknown insn: %ld", GET_CURRENT_INSN()); \
  119. } /* end of switch */ \
  120. } /* end of while loop */ \
  121. #define NEXT_INSN() goto first
  122. #endif
  123. #define VM_SP_CNT(th, sp) ((sp) - (th)->stack)
  124. #if OPT_CALL_THREADED_CODE
  125. #define THROW_EXCEPTION(exc) do { \
  126. th->errinfo = (VALUE)(exc); \
  127. return 0; \
  128. } while (0)
  129. #else
  130. #define THROW_EXCEPTION(exc) return (VALUE)(exc)
  131. #endif
  132. #define SCREG(r) (reg_##r)
  133. #endif /* RUBY_VM_EXEC_H */