Class: RubyVM::RJIT::InsnCompiler

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby_vm/rjit/insn_compiler.rb

Defined Under Namespace

Classes: CallingInfo

Instance Method Summary collapse

Constructor Details

#initialize(cb, ocb, exit_compiler) ⇒ InsnCompiler

Returns a new instance of InsnCompiler.

Parameters:



11
12
13
14
15
16
17
# File 'lib/ruby_vm/rjit/insn_compiler.rb', line 11

def initialize(cb, ocb, exit_compiler)
  @ocb = ocb
  @exit_compiler = exit_compiler

  @cfunc_codegen_table = {}
  register_cfunc_codegen_funcs
end

Instance Method Details

#compile(jit, ctx, asm, insn) ⇒ Object

Parameters:



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
# File 'lib/ruby_vm/rjit/insn_compiler.rb', line 23

def compile(jit, ctx, asm, insn)
  asm.incr_counter(:rjit_insns_count)

  stack = ctx.stack_size.times.map do |stack_idx|
    ctx.get_opnd_type(StackOpnd[ctx.stack_size - stack_idx - 1]).type
  end
  locals = jit.iseq.body.local_table_size.times.map do |local_idx|
    (ctx.local_types[local_idx] || Type::Unknown).type
  end

  insn_idx = format('%04d', (jit.pc.to_i - jit.iseq.body.iseq_encoded.to_i) / C.VALUE.size)
  asm.comment("Insn: #{insn_idx} #{insn.name} (stack: [#{stack.join(', ')}], locals: [#{locals.join(', ')}])")

  # 83/102
  case insn.name
  when :nop then nop(jit, ctx, asm)
  when :getlocal then getlocal(jit, ctx, asm)
  when :setlocal then setlocal(jit, ctx, asm)
  when :getblockparam then getblockparam(jit, ctx, asm)
  # setblockparam
  when :getblockparamproxy then getblockparamproxy(jit, ctx, asm)
  when :getspecial then getspecial(jit, ctx, asm)
  # setspecial
  when :getinstancevariable then getinstancevariable(jit, ctx, asm)
  when :setinstancevariable then setinstancevariable(jit, ctx, asm)
  when :getclassvariable then getclassvariable(jit, ctx, asm)
  when :setclassvariable then setclassvariable(jit, ctx, asm)
  when :opt_getconstant_path then opt_getconstant_path(jit, ctx, asm)
  when :getconstant then getconstant(jit, ctx, asm)
  # setconstant
  when :getglobal then getglobal(jit, ctx, asm)
  # setglobal
  when :putnil then putnil(jit, ctx, asm)
  when :putself then putself(jit, ctx, asm)
  when :putobject then putobject(jit, ctx, asm)
  when :putspecialobject then putspecialobject(jit, ctx, asm)
  when :putstring then putstring(jit, ctx, asm)
  when :putchilledstring then putchilledstring(jit, ctx, asm)
  when :concatstrings then concatstrings(jit, ctx, asm)
  when :anytostring then anytostring(jit, ctx, asm)
  when :toregexp then toregexp(jit, ctx, asm)
  when :intern then intern(jit, ctx, asm)
  when :newarray then newarray(jit, ctx, asm)
  when :duparray then duparray(jit, ctx, asm)
  # duphash
  when :expandarray then expandarray(jit, ctx, asm)
  when :concatarray then concatarray(jit, ctx, asm)
  when :splatarray then splatarray(jit, ctx, asm)
  when :newhash then newhash(jit, ctx, asm)
  when :newrange then newrange(jit, ctx, asm)
  when :pop then pop(jit, ctx, asm)
  when :dup then dup(jit, ctx, asm)
  when :dupn then dupn(jit, ctx, asm)
  when :swap then swap(jit, ctx, asm)
  # opt_reverse
  when :topn then topn(jit, ctx, asm)
  when :setn then setn(jit, ctx, asm)
  when :adjuststack then adjuststack(jit, ctx, asm)
  when :defined then defined(jit, ctx, asm)
  when :definedivar then definedivar(jit, ctx, asm)
  # checkmatch
  when :checkkeyword then checkkeyword(jit, ctx, asm)
  # checktype
  # defineclass
  # definemethod
  # definesmethod
  when :send then send(jit, ctx, asm)
  when :opt_send_without_block then opt_send_without_block(jit, ctx, asm)
  when :objtostring then objtostring(jit, ctx, asm)
  when :opt_str_freeze then opt_str_freeze(jit, ctx, asm)
  when :opt_ary_freeze then opt_ary_freeze(jit, ctx, asm)
  when :opt_hash_freeze then opt_hash_freeze(jit, ctx, asm)
  when :opt_nil_p then opt_nil_p(jit, ctx, asm)
  # opt_str_uminus
  when :opt_newarray_send then opt_newarray_send(jit, ctx, asm)
  when :invokesuper then invokesuper(jit, ctx, asm)
  when :invokeblock then invokeblock(jit, ctx, asm)
  when :leave then leave(jit, ctx, asm)
  when :throw then throw(jit, ctx, asm)
  when :jump then jump(jit, ctx, asm)
  when :branchif then branchif(jit, ctx, asm)
  when :branchunless then branchunless(jit, ctx, asm)
  when :branchnil then branchnil(jit, ctx, asm)
  # once
  when :opt_case_dispatch then opt_case_dispatch(jit, ctx, asm)
  when :opt_plus then opt_plus(jit, ctx, asm)
  when :opt_minus then opt_minus(jit, ctx, asm)
  when :opt_mult then opt_mult(jit, ctx, asm)
  when :opt_div then opt_div(jit, ctx, asm)
  when :opt_mod then opt_mod(jit, ctx, asm)
  when :opt_eq then opt_eq(jit, ctx, asm)
  when :opt_neq then opt_neq(jit, ctx, asm)
  when :opt_lt then opt_lt(jit, ctx, asm)
  when :opt_le then opt_le(jit, ctx, asm)
  when :opt_gt then opt_gt(jit, ctx, asm)
  when :opt_ge then opt_ge(jit, ctx, asm)
  when :opt_ltlt then opt_ltlt(jit, ctx, asm)
  when :opt_and then opt_and(jit, ctx, asm)
  when :opt_or then opt_or(jit, ctx, asm)
  when :opt_aref then opt_aref(jit, ctx, asm)
  when :opt_aset then opt_aset(jit, ctx, asm)
  # opt_aset_with
  # opt_aref_with
  when :opt_length then opt_length(jit, ctx, asm)
  when :opt_size then opt_size(jit, ctx, asm)
  when :opt_empty_p then opt_empty_p(jit, ctx, asm)
  when :opt_succ then opt_succ(jit, ctx, asm)
  when :opt_not then opt_not(jit, ctx, asm)
  when :opt_regexpmatch2 then opt_regexpmatch2(jit, ctx, asm)
  # invokebuiltin
  when :opt_invokebuiltin_delegate then opt_invokebuiltin_delegate(jit, ctx, asm)
  when :opt_invokebuiltin_delegate_leave then opt_invokebuiltin_delegate_leave(jit, ctx, asm)
  when :getlocal_WC_0 then getlocal_WC_0(jit, ctx, asm)
  when :getlocal_WC_1 then getlocal_WC_1(jit, ctx, asm)
  when :setlocal_WC_0 then setlocal_WC_0(jit, ctx, asm)
  when :setlocal_WC_1 then setlocal_WC_1(jit, ctx, asm)
  when :putobject_INT2FIX_0_ then putobject_INT2FIX_0_(jit, ctx, asm)
  when :putobject_INT2FIX_1_ then putobject_INT2FIX_1_(jit, ctx, asm)
  else CantCompile
  end
end