Class: CastOff::Compiler::Translator::CFG::Condition

Inherits:
Object
  • Object
show all
Includes:
SimpleIR, Util
Defined in:
lib/cast_off/compile/information.rb

Overview

Information

Constant Summary

Constants included from SimpleIR

SimpleIR::SPLATCALL_LIMIT, SimpleIR::SupportLoopInstruction

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

Instance Method Summary collapse

Methods included from SimpleIR

#block_argument_is_unsupported, #generate_ir

Methods included from Util

#bug, #dlog, #todo, #vlog

Constructor Details

#initialize(b, ptrs, a_or_c, tmp = nil) ⇒ Condition

Returns a new instance of Condition.



307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
# File 'lib/cast_off/compile/information.rb', line 307

def initialize(b, ptrs, a_or_c, tmp = nil)
  # 管理が煩雑になるので、alias を内部で保持しないこと。
  # step 時に alias まで進めないと、final_state で古い alias を持つことになる。
  @block = b
  @ptrs = ptrs
  @temporary_condition = tmp
  case a_or_c
  when Alias
    @condition = initialize_condition_from_block(a_or_c)
  when Hash
    # @condition は呼び出し元で dup している
    @condition = a_or_c
    bug() if @condition.keys.find{|v| !v.is_a?(Variable)}
    bug() if @condition.values.find{|p| !p.is_a?(Proc)}
  else
    bug()
  end
end

Instance Attribute Details

#blockObject (readonly)

Returns the value of attribute block.



305
306
307
# File 'lib/cast_off/compile/information.rb', line 305

def block
  @block
end

#conditionObject (readonly)

Returns the value of attribute condition.



305
306
307
# File 'lib/cast_off/compile/information.rb', line 305

def condition
  @condition
end

#temporary_conditionObject (readonly)

Returns the value of attribute temporary_condition.



305
306
307
# File 'lib/cast_off/compile/information.rb', line 305

def temporary_condition
  @temporary_condition
end

Instance Method Details

#==(other) ⇒ Object



391
392
393
# File 'lib/cast_off/compile/information.rb', line 391

def ==(other)
  eql?(other)
end

#dupObject



357
358
359
360
361
# File 'lib/cast_off/compile/information.rb', line 357

def dup()
  # condition は呼び出し元で dup する
  tmp = @temporary_condition ? @temporary_condition.dup() : nil
  Condition.new(@block, @ptrs, @condition.dup, tmp)
end

#eql?(other) ⇒ Boolean

Returns:

  • (Boolean)


385
386
387
388
389
# File 'lib/cast_off/compile/information.rb', line 385

def eql?(other)
  return false unless @block == other.block
  return false unless @temporary_condition == other.temporary_condition
  @condition == other.condition
end

#final_stateObject



363
364
365
366
367
# File 'lib/cast_off/compile/information.rb', line 363

def final_state
  v = dup()
  @block.irs.each{|ir| v.step(ir)}
  v
end

#freezeObject



399
400
401
402
403
404
# File 'lib/cast_off/compile/information.rb', line 399

def freeze()
  super()
  @ptrs.freeze()
  @condition.freeze()
  self
end

#hashObject



395
396
397
# File 'lib/cast_off/compile/information.rb', line 395

def hash
  bug()
end

#step(ir) ⇒ Object



333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
# File 'lib/cast_off/compile/information.rb', line 333

def step(ir)
  promote_temporary_condition()
  bug() if @temporary_condition
  unless ir.result_variable
    bug() if ir.dispatch_method?
    return
  end
  case ir
  when SubIR
    src = ir.src
    dst = ir.dst
    if @condition[src]
      @condition[dst] = @condition[src]
    else
      @condition.delete(dst)
    end
  when CallIR
    return_value = ir.return_value
    bug() unless return_value.is_a?(Variable)
    @condition.delete(return_value)
    @ptrs.each{|p| @condition.delete(p)} if ir.dispatch_method?
  end
end

#to_sObject



406
407
408
409
410
# File 'lib/cast_off/compile/information.rb', line 406

def to_s
  @condition.inject(''){|str, (v, p)|
    str.concat("#{v} => #{p}\n")
  }.chomp
end

#union(other) ⇒ Object



369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
# File 'lib/cast_off/compile/information.rb', line 369

def union(other)
  bug() unless @block.pre.include?(other.block)
  bug() unless other.instance_of?(Condition)
  if @temporary_condition
    tmp = @temporary_condition.dup
    other.condition.each do |(v, p)|
      tmp.delete(v) if !tmp[v] || (tmp[v] && tmp[v] != p)
    end
    (tmp.keys - other.condition.keys).each{|v| tmp.delete(v)}
  else
    tmp = other.condition.dup
  end
  # condition は呼び出し元で dup する
  Condition.new(@block, @ptrs, @condition.dup, tmp)
end

#use(v) ⇒ Object



326
327
328
329
330
331
# File 'lib/cast_off/compile/information.rb', line 326

def use(v)
  promote_temporary_condition()
  bug() if @temporary_condition
  p = @condition[v]
  p ? p.call(v) : false
end