Class: YTLJit::VM::Node::LocalFrameInfoNode

Inherits:
BaseNode show all
Includes:
HaveChildlenMixin
Defined in:
lib/ytljit/vm.rb

Constant Summary

Constants included from AbsArch

AbsArch::AL, AbsArch::BL, AbsArch::CL, AbsArch::DL, AbsArch::FUNC_ARG, AbsArch::FUNC_ARG_YTL, AbsArch::FUNC_FLOAT_ARG, AbsArch::FUNC_FLOAT_ARG_YTL, AbsArch::INDIRECT_BPR, AbsArch::INDIRECT_RETR, AbsArch::INDIRECT_SPR, AbsArch::INDIRECT_TMPR, AbsArch::INDIRECT_TMPR2

Constants included from SSE

SSE::XMM0, SSE::XMM1, SSE::XMM2, SSE::XMM3, SSE::XMM4, SSE::XMM5, SSE::XMM6, SSE::XMM7

Instance Attribute Summary collapse

Attributes included from HaveChildlenMixin

#body

Attributes inherited from BaseNode

#code_space, #element_node_list, #id, #parent, #type

Instance Method Summary collapse

Methods inherited from BaseNode

#add_element_node, #add_type, #collect_info, #decide_type, #decide_type_core, #decide_type_once, #gen_type_inference_proc, #inference_type, #merge_type, #same_type, #set_type_list, #ti_add_observer, #ti_changed, #ti_update, #type_list

Methods included from Inspect

#inspect_by_graph

Constructor Details

#initialize(parent) ⇒ LocalFrameInfoNode

Returns a new instance of LocalFrameInfoNode.



638
639
640
641
642
643
644
645
# File 'lib/ytljit/vm.rb', line 638

def initialize(parent)
  super(parent)
  @frame_layout = []
  @argument_num = nil
  @system_num = nil
  @previous_frame = search_previous_frame(parent)
  @offset_cache = {}
end

Instance Attribute Details

#argument_numObject

Returns the value of attribute argument_num.



665
666
667
# File 'lib/ytljit/vm.rb', line 665

def argument_num
  @argument_num
end

#frame_layoutObject

Returns the value of attribute frame_layout.



664
665
666
# File 'lib/ytljit/vm.rb', line 664

def frame_layout
  @frame_layout
end

#previous_frameObject (readonly)

Returns the value of attribute previous_frame.



667
668
669
# File 'lib/ytljit/vm.rb', line 667

def previous_frame
  @previous_frame
end

#system_numObject

Returns the value of attribute system_num.



666
667
668
# File 'lib/ytljit/vm.rb', line 666

def system_num
  @system_num
end

Instance Method Details

#collect_candidate_type(context) ⇒ Object



722
723
724
725
726
727
# File 'lib/ytljit/vm.rb', line 722

def collect_candidate_type(context)
  traverse_childlen {|rec|
    context = rec.collect_candidate_type(context)
  }
  @body.collect_candidate_type(context)
end

#compile(context) ⇒ Object



729
730
731
732
733
734
735
736
737
738
739
740
741
# File 'lib/ytljit/vm.rb', line 729

def compile(context)
  context = super(context)
  siz = local_area_size
  if  siz != 0 then
    asm = context.assembler
    asm.with_retry do
      asm.sub(SPR, siz)
    end
    context.cpustack_pushn(siz)
  end
  context = @body.compile(context)
  context
end

#copy_frame_layoutObject



660
661
662
# File 'lib/ytljit/vm.rb', line 660

def copy_frame_layout
  @frame_layout.each { |ele| ele.dup }
end

#frame_sizeObject



676
677
678
# File 'lib/ytljit/vm.rb', line 676

def frame_size
  @frame_layout.inject(0) {|sum, slot| sum += slot.size}
end

#local_area_sizeObject



680
681
682
683
# File 'lib/ytljit/vm.rb', line 680

def local_area_size
  localnum = @frame_layout.size - @argument_num - @system_num
  @frame_layout[0, localnum].inject(0) {|sum, slot| sum += slot.size}
end

#offset_arg(n, basereg) ⇒ Object



706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
# File 'lib/ytljit/vm.rb', line 706

def offset_arg(n, basereg)
  rc = nil
  if basereg == BPR then
    rc = @offset_cache[n]
    unless rc
      off = offset_by_byte(n)
      rc = @offset_cache[n] = OpIndirect.new(basereg, off)
    end
  else
    off = offset_by_byte(n)
    rc = OpIndirect.new(basereg, off)
  end

  rc
end

#offset_by_byte(off) ⇒ Object



695
696
697
698
699
700
701
702
703
704
# File 'lib/ytljit/vm.rb', line 695

def offset_by_byte(off)
  off = real_offset(off)

  obyte = 0
  off.times do |i|
    obyte += @frame_layout[i].size
  end
  
  obyte - local_area_size
end

#real_offset(off) ⇒ Object



685
686
687
688
689
690
691
692
693
# File 'lib/ytljit/vm.rb', line 685

def real_offset(off)
  if off >=  @argument_num then
    off = off - @argument_num
  else
    off = off + (@frame_layout.size - @argument_num)
  end

  off
end

#search_previous_frame(mtop) ⇒ Object



647
648
649
650
651
652
653
654
655
656
657
658
# File 'lib/ytljit/vm.rb', line 647

def search_previous_frame(mtop)
  cnode = mtop.parent
  while !cnode.is_a?(TopNode)
    if cnode then
      cnode = cnode.parent
    else
      return nil
    end
  end

  return cnode.body
end

#traverse_childlen {|@body| ... } ⇒ Object

Yields:



669
670
671
672
673
674
# File 'lib/ytljit/vm.rb', line 669

def traverse_childlen
  @frame_layout.each do |vinf|
    yield vinf
  end
  yield @body
end