Class: CastOff::Compiler::SimpleIR::VMInsnIR

Inherits:
CallIR
  • Object
show all
Defined in:
lib/cast_off/compile/ir/call_ir.rb

Constant Summary

Constants included from Instruction

Instruction::BlockSeparator, Instruction::BranchInstruction, Instruction::IgnoreInstruction, Instruction::JumpOrReturnInstruction, Instruction::SupportInstruction, Instruction::TypeInfoUser, Instruction::VM_CALL_ARGS_BLOCKARG_BIT, Instruction::VM_CALL_ARGS_SPLAT_BIT, Instruction::VM_CALL_FCALL_BIT, Instruction::VM_CALL_OPT_SEND_BIT, Instruction::VM_CALL_SUPER_BIT, Instruction::VM_CALL_TAILCALL_BIT, Instruction::VM_CALL_TAILRECURSION_BIT, Instruction::VM_CALL_VCALL_BIT

Instance Attribute Summary collapse

Attributes inherited from CallIR

#argc, #result_variable, #return_value, #values, #variables, #variables_without_result

Attributes inherited from IR

#alias, #insn

Instance Method Summary collapse

Methods inherited from CallIR

#can_not_unbox, #harmless?, #mark, #param_irs, #param_variables, #propergate_boxed_value, #propergate_exact_class, #sampling_return_value, #sampling_return_value?, #unboxing_prelude

Methods included from Util

#bug, #dlog, #todo, #vlog

Methods inherited from IR

#add_sampling_variable, #alive, #alive?, #dispatch_method?, #generate_guard, #get_definition, #get_definition_str, #get_usage, #get_variable, #inlining_target?, #propergate_boxed_value, #reset, #sampling_variable, #set_info, #standard_guard_target, #unboxing_prelude, #vanish, #vanish?

Constructor Details

#initialize(param, argc, return_value, insn, cfg) ⇒ VMInsnIR

Returns a new instance of VMInsnIR.



120
121
122
123
124
125
# File 'lib/cast_off/compile/ir/call_ir.rb', line 120

def initialize(param, argc, return_value, insn, cfg)
  bug() unless insn.is_a?(InsnInfo)
  super(param, argc, return_value, insn, cfg)
  @opecode = insn.op
  @operands = insn.argv
end

Instance Attribute Details

#argvObject (readonly)

Returns the value of attribute argv.



118
119
120
# File 'lib/cast_off/compile/ir/call_ir.rb', line 118

def argv
  @argv
end

Instance Method Details

#dont_duplicate_if_harmless(obj) ⇒ Object



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
# File 'lib/cast_off/compile/ir/call_ir.rb', line 144

def dont_duplicate_if_harmless(obj)
  return nil if @configuration.force_duplicate_literal?
  usage = get_usage()
  harmless = true
  if usage[:escape]
    harmless = false
  else
    usage.each do |(u, recv_p)|
      u_recv, u_ir = u
      unless u_ir.harmless?(recv_p)
        harmless = false
        break
      end
    end
  end
  if harmless
    return "  #{@return_value} = #{obj};"
  else
    if @configuration.development?
      if usage[:escape]
        u = usage[:escape]
        msg = "escape to #{u.is_a?(ReturnIR) ? 'caller' : 'pointer'}"
      else
        msg = usage.keys.map {|(u_recv, u_ir)|
          bug(u_ir) unless u_ir.is_a?(CallIR)
          if u_ir.dispatch_method?
            "used by #{u_ir.to_verbose_string}"
          else
            s = u_ir.insn.source
            s.empty? ? nil : "used by #{s}"
          end
        }.compact.join("\n")
      end
      @translator.add_literal_suggestion([get_definition_str(obj), msg, @source_line, @source]) if @source
    end
    return nil
  end
  bug()
end

#propergate_guard_usageObject



127
128
129
# File 'lib/cast_off/compile/ir/call_ir.rb', line 127

def propergate_guard_usage()
  bug()
end

#should_be_alive?Boolean

Returns:

  • (Boolean)


192
193
194
# File 'lib/cast_off/compile/ir/call_ir.rb', line 192

def should_be_alive?
  side_effect?
end

#side_effect?Boolean

Returns:

  • (Boolean)


188
189
190
# File 'lib/cast_off/compile/ir/call_ir.rb', line 188

def side_effect?
  bug()
end

#to_c(params) ⇒ Object



131
132
133
134
135
136
137
138
139
140
141
142
# File 'lib/cast_off/compile/ir/call_ir.rb', line 131

def to_c(params)
  case @opecode
  when :putstring, :newarray, :newhash, :duparray, :tostring, :toregexp, :concatstrings, :concatarray, \
       :newrange, :opt_regexpmatch1, :opt_regexpmatch2, :getconstant, :getspecial, :expandarray_pre, \
       :expandarray_loop, :expandarray_splat, :expandarray_post_loop, :expandarray_post_splat, :splatarray, \
       :checkincludearray_pre, :checkincludearray_case, :checkincludearray_when, :cast_off_fetch_args, :defined
    # nothing to do
  else
    bug("unexpected instruction #{@opecode}")
  end
  super(params)
end

#type_propergationObject



184
185
186
# File 'lib/cast_off/compile/ir/call_ir.rb', line 184

def type_propergation()
  super()
end