Class: YTLJit::VM::Node::SendElementRefMemoryNode

Inherits:
SendElementRefNode
  • Object
show all
Includes:
SendUtil, X64, X86
Defined in:
lib/ytl/accmem.rb

Instance Method Summary collapse

Instance Method Details

#collect_candidate_type_regident(context, slf) ⇒ Object



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
# File 'lib/ytl/accmem.rb', line 34

def collect_candidate_type_regident(context, slf)
  if slf.ruby_type <= YTL::Memory then
    kind = @arguments[4]
    kvalue = kind.get_constant_value

    if kvalue then
      kvalue =kvalue[0]
      
      case kvalue
      when :char, :word, :dword, :machine_word
        fixtype = RubyType::BaseType.from_ruby_class(Fixnum)
        add_type(context.to_signature, fixtype)
        
      when :float 
        floattype = RubyType::BaseType.from_ruby_class(Float)
        add_type(context.to_signature, floattype)
        
      when AsmType::StructMember
        if kvalue.type.is_a?(AsmType::Scalar) then
          if kvalue.type.kind == :int then
            ttype = RubyType::BaseType.from_ruby_class(Fixnum)
            add_type(context.to_signature, ttype)
          else
            raise "Unkown type #{kvalue.type} #{kvalue.type.kind}"
          end
        else
          raise "Unkown type #{kvalue}"
        end

      when AsmType::Scalar
        if kvalue.kind == :int then
          ttype = RubyType::BaseType.from_ruby_class(Fixnum)
          add_type(context.to_signature, ttype)

        else
          raise "Unkown type"
        end

      else
        raise "Unkown type #{kvalue}"

      end
      
    else
      fixtype = RubyType::BaseType.from_ruby_class(Fixnum)
      add_type(context.to_signature, fixtype)
    end

    context

  elsif slf.ruby_type <= AsmType::Pointer or
      slf.ruby_type <= AsmType::Array then
    tt = AsmType::PointedData
    pointedtype = RubyType::BaseType.from_ruby_class(tt)
    add_type(context.to_signature, pointedtype)
    context

  elsif slf.ruby_type <= AsmType::Struct or
      slf.ruby_type <= AsmType::Union or 
      slf.ruby_type <= AsmType::StructMember then
    tt = AsmType::StructMember
    stmemtype = RubyType::BaseType.from_ruby_class(tt)
    add_type(context.to_signature, stmemtype)
    context

  else
    super
  end
end

#compile(context) ⇒ Object



143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
# File 'lib/ytl/accmem.rb', line 143

def compile(context)
  slf = @arguments[2]
  slf.decide_type_once(context.to_signature)
  if slf.type.ruby_type <= YTL::Memory then
    asm = context.assembler

    kind = @arguments[4]
    kvalue = nil
    case kind
    when LiteralNode
      kvalue = kind.value

    else
      context = kind.compile(context)
      if context.ret_reg.is_a?(OpVarImmidiateAddress) then
        objid = (context.ret_reg.value >> 1)
        kvalue = ObjectSpace._id2ref(objid)
      end
    end

    context = @arguments[3].compile(context)

    case kvalue
    when :machine_word
      asm.with_retry do
        if context.ret_reg != TMPR then
          asm.mov(TMPR, context.ret_reg)
        end
        asm.mov(RETR, INDIRECT_TMPR)
      end
      context.ret_reg = RETR
      
    when :float
      asm.with_retry do
        if context.ret_reg != TMPR then
          asm.mov(TMPR, context.ret_reg)
        end
        asm.mov(RETFR, INDIRECT_TMPR)
      end
      context.ret_reg = RETFR
      
    when AsmType::Scalar
      context = gen_read_mem(context, kvalue.size)
      
    when AsmType::StructMember
      typeobj = kvalue.type
      case typeobj
      when AsmType::Scalar
        context = gen_read_mem(context, typeobj.size)
        
      else
        raise "Unkown Struct Member type #{kvalue}"
      end
    end
    
    context.ret_node = self
    return context
    
  elsif slf.type.ruby_type <= AsmType::TypeCommon then
    context = @arguments[2].compile(context)
    obj = slf.get_constant_value
    
    if obj == nil and 
        context.ret_reg.is_a?(OpVarImmidiateAddress) then
      objid = (context.ret_reg.value >> 1)
      obj = ObjectSpace._id2ref(objid)
    else
      obj = obj[0]
    end
    
    if obj then
      index = @arguments[3].get_constant_value

      if index then
        index = index[0]
        val = obj[index]
        add = lambda { val.address }
        context.ret_reg = OpVarImmidiateAddress.new(add)
        context.ret_node = self
        
        return context
      end
    end
    
    super
  else
    super
  end
end

#compile_ref_scalar(context, typeobj) ⇒ Object



104
105
106
# File 'lib/ytl/accmem.rb', line 104

def compile_ref_scalar(context, typeobj)
  context
end

#fill_result_cache(context) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/ytl/accmem.rb', line 18

def fill_result_cache(context)
  slf = @arguments[2]
  slfval = @arguments[2].get_constant_value
  if slfval then
    slfval =slfval[0]

    idxval = @arguments[3].get_constant_value
    if idxval then
      idxval = idxval[0]
      @result_cache = slfval[idxval]
    end
  end

  context
end

#gen_read_mem(context, size) ⇒ Object



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
# File 'lib/ytl/accmem.rb', line 108

def gen_read_mem(context, size)
  asm = context.assembler
  case size
  when 8
    asm.with_retry do
      if context.ret_reg != RAX then
        asm.mov(RAX, context.ret_reg)
      end
      asm.mov(RAX, INDIRECT_RAX)
    end
    context.ret_reg = RAX
    
  when 4
    asm.with_retry do
      if context.ret_reg != EAX then
        asm.mov(EAX, context.ret_reg)
      end
      asm.mov(EAX, INDIRECT_EAX)
    end
    context.ret_reg = EAX
    
  when 2
    asm.with_retry do
      asm.mov(AL, context.ret_reg)
      asm.mov(AL, INDIRECT_AL)
    end
    context.ret_reg = EAX
    
  else
    raise "Unkown Scalar size #{kvalue}"
  end

  context
end