Class: CastOff::Compiler::Translator::CFG::Alias

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

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 Util

#bug, #dlog, #todo, #vlog

Methods included from SimpleIR

#block_argument_is_unsupported, #generate_ir

Constructor Details

#initialize(b, a, all, ptrs) ⇒ Alias



474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
# File 'lib/cast_off/compile/information.rb', line 474

def initialize(b, a, all, ptrs)
  bug() unless b.instance_of?(BasicBlock)
  @block = b
  @all = all
  @ptrs = ptrs
  case a
  when NilClass
    a = all.dup()
    bug() if a.find{|v| not v.is_a?(Variable)}
    @set = [a]
  when Array
    bug() if a.find{|v| not v.is_a?(Variable)}
    @set = a.map{|v| [v]}
  when Alias
    @set = a.set.map{|s| s.dup()}
  else
    bug()
  end
  validate()
end

Instance Attribute Details

#setObject (readonly)

Returns the value of attribute set.



472
473
474
# File 'lib/cast_off/compile/information.rb', line 472

def set
  @set
end

Instance Method Details

#==(other) ⇒ Object



549
550
551
# File 'lib/cast_off/compile/information.rb', line 549

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

#__union(other) ⇒ Object



553
554
555
556
557
558
559
560
561
562
563
564
565
566
# File 'lib/cast_off/compile/information.rb', line 553

def __union(other)
  a = @all.dup()
  new_set = []
  until a.empty?
    var = a.pop()
    s0 = find_set(var)
    s1 = other.find_set(var)
    s = s0 & s1
    new_set << s
    a -= s
  end
  @set = new_set
  validate()
end

#dupObject



523
524
525
# File 'lib/cast_off/compile/information.rb', line 523

def dup()
  Alias.new(@block, self, @all, @ptrs)
end

#eql?(other) ⇒ Boolean



542
543
544
545
546
547
# File 'lib/cast_off/compile/information.rb', line 542

def eql?(other)
  other_set = other.set.dup()
  @set.each{|s| other_set.delete(s){return false}}
  bug() unless other_set.empty?
  return true
end

#final_stateObject



503
504
505
506
507
# File 'lib/cast_off/compile/information.rb', line 503

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

#find_set(var) ⇒ Object



527
528
529
530
531
# File 'lib/cast_off/compile/information.rb', line 527

def find_set(var)
  bug() unless var.is_a?(Variable)
  set.each{|s| return s if s.include?(var)}
  bug("set = #{set}, var = #{var}, #{var.class}")
end

#freezeObject



495
496
497
498
499
500
501
# File 'lib/cast_off/compile/information.rb', line 495

def freeze()
  super()
  @all.freeze()
  @set.freeze()
  @ptrs.freeze()
  self
end

#step(ir) ⇒ Object



509
510
511
512
513
514
515
516
517
518
519
520
521
# File 'lib/cast_off/compile/information.rb', line 509

def step(ir)
  case ir
  when SubIR
    src = ir.src
    dst = ir.dst
    src.is_a?(Variable) ? sub(src, dst) : isolate(dst)
  when CallIR
    return_value = ir.return_value
    bug() unless return_value.is_a?(Variable)
    isolate(return_value)
    @ptrs.each{|p| isolate(p)} if ir.dispatch_method?
  end
end

#to_sObject



574
575
576
577
578
# File 'lib/cast_off/compile/information.rb', line 574

def to_s
  @set.inject(''){|str, s|
    str.concat(s.map{|v| v.to_debug_string}.join(", ")).concat("\n")
  }.chomp
end

#union(other) ⇒ Object



568
569
570
571
572
# File 'lib/cast_off/compile/information.rb', line 568

def union(other)
  a = dup()
  a.__union(other)
  a
end

#validateObject



533
534
535
536
537
538
539
540
# File 'lib/cast_off/compile/information.rb', line 533

def validate()
  a = @set.inject([]) do |ary, s|
    bug() unless (ary & s).empty?
    ary + s
  end
  size = @all.size()
  bug() unless a.size() == size && (a & @all).size() == size
end