Class: YTLJit::VM::Node::TopNode

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

Overview

The top of top node

Direct Known Subclasses

ClassTopNode, MethodTopNode

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, AbsArch::INDIRECT_TMPR3

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, #ti_observee, #ti_observer, #type

Instance Method Summary collapse

Methods included from NodeUtil

#search_class_top, #search_end, #search_frame_info, #search_top

Methods inherited from BaseNode

#add_element_node, #decide_type, #decide_type_core, #decide_type_once, #gen_type_inference_proc, #get_constant_value, #inference_type, #merge_type, #same_type, #ti_add_observer, #ti_changed, #ti_del_link, #ti_reset, #ti_update

Methods included from TypeListWithSignature

#add_type, #set_type_list, #type_list, #type_list_initvar

Methods included from Inspect

#inspect_by_graph

Constructor Details

#initialize(parent, name = nil) ⇒ TopNode

Returns a new instance of TopNode.



712
713
714
715
716
717
718
719
720
721
722
723
724
725
# File 'lib/ytljit/vm.rb', line 712

def initialize(parent, name = nil)
  super(parent)
  @name = name
  @code_spaces = [] # [[nil, CodeSpace.new]]
  @orig_modified_local_var = []
  @yield_node = []
  if @parent then
    @classtop = search_class_top
  else
    @classtop = self
  end
  @end_nodes = []
  @signature_cache = []
end

Instance Attribute Details

#end_nodesObject (readonly)

Returns the value of attribute end_nodes.



728
729
730
# File 'lib/ytljit/vm.rb', line 728

def end_nodes
  @end_nodes
end

#nameObject

Returns the value of attribute name.



727
728
729
# File 'lib/ytljit/vm.rb', line 727

def name
  @name
end

#orig_modified_local_varObject (readonly)

Returns the value of attribute orig_modified_local_var.



729
730
731
# File 'lib/ytljit/vm.rb', line 729

def orig_modified_local_var
  @orig_modified_local_var
end

#signature_cacheObject (readonly)

Returns the value of attribute signature_cache.



732
733
734
# File 'lib/ytljit/vm.rb', line 732

def signature_cache
  @signature_cache
end

#yield_nodeObject (readonly)

Returns the value of attribute yield_node.



730
731
732
# File 'lib/ytljit/vm.rb', line 730

def yield_node
  @yield_node
end

Instance Method Details

#add_cs_for_signature(sig) ⇒ Object



752
753
754
755
756
757
758
759
760
761
762
# File 'lib/ytljit/vm.rb', line 752

def add_cs_for_signature(sig)
  cs = find_cs_by_signature(sig)
  if cs then
    return nil

  else
    cs = CodeSpace.new
    @code_spaces.push [sig, cs]
    return cs
  end
end

#collect_candidate_type(context, signode, sig) ⇒ Object



816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
# File 'lib/ytljit/vm.rb', line 816

def collect_candidate_type(context, signode, sig)
  if add_cs_for_signature(sig) == nil and  
      context.visited_top_node[self] then
    return context
  end

  context.visited_top_node[self] = true

  if !@signature_cache.include?(sig) then
    @signature_cache.push sig
  end
  
  context.push_signature(signode, self)
  context = @body.collect_candidate_type(context)
  context.pop_signature

  @end_nodes.each do |enode|
    same_type(self, enode, sig, sig, context)
    same_type(enode, self, sig, sig, context)
  end
  context
end

#collect_info(context) ⇒ Object



809
810
811
812
813
814
# File 'lib/ytljit/vm.rb', line 809

def collect_info(context)
  context.yield_node.push []
  context = @body.collect_info(context)
  @yield_node = context.yield_node.pop
  context
end

#compile(context) ⇒ Object



852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
# File 'lib/ytljit/vm.rb', line 852

def compile(context)
  oldcs = context.code_space
  @code_spaces.each do |sig, cs|
    context.current_method_signature.push sig
    context.set_code_space(cs)
    context = super(context)
    context.reset_using_reg
    context = gen_method_prologue(context)
    context = @body.compile(context)
    context.current_method_signature.pop
  end

  if oldcs then
    context.set_code_space(oldcs)
  end

  if context.options[:disp_signature] then
    disp_signature
  end

  context.ret_node = self
  context
end

#construct_frame_info(locals, argnum) ⇒ Object



764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
# File 'lib/ytljit/vm.rb', line 764

def construct_frame_info(locals, argnum)
  finfo = LocalFrameInfoNode.new(self)
  finfo.system_num = 4         # BP ON Stack, BP, RET
  
  # 3 means BP, BP and SP
  lsize = locals.size + finfo.system_num
  
  # construct frame
  frame_layout = Array.new(lsize)
  i = 0
  fargstart = lsize - argnum
  argnum.times do
    lnode = LocalVarNode.new(finfo, locals[i], fargstart + i)
    frame_layout[fargstart + i] = lnode
    i += 1
  end
  
  curpos = fargstart - 1
  frame_layout[curpos] = SystemValueNode.new(finfo, 
                                             :RET_ADDR, curpos)
  curpos -= 1
  frame_layout[curpos] = SystemValueNode.new(finfo, 
                                             :OLD_BP, curpos)
  curpos -= 1
  frame_layout[curpos] = SystemValueNode.new(finfo, 
                                             :FRAME_INFO, curpos)
  curpos -= 1
  frame_layout[curpos] = SystemValueNode.new(finfo, 
                                             :OLD_BPSTACK, curpos)

  j = 0
  lvarnum = lsize - finfo.system_num 
  while i < lvarnum do
    lnode = LocalVarNode.new(finfo, locals[i], j)
    frame_layout[j] = lnode
    i += 1
    j += 1
  end
  finfo.frame_layout = frame_layout
  finfo.argument_num = argnum
  
  @body = finfo
  finfo
end

#disp_signatureObject



839
840
841
842
843
844
845
846
847
848
849
850
# File 'lib/ytljit/vm.rb', line 839

def disp_signature
  tcontext = CompileContext.new(self)
  print "#{@classtop.klass_object}##{@name} "
  @code_spaces.each do |sig, cs|
    print sig, " -> "
    tl = type_list(sig).flatten.uniq
    print decide_type_core(tl).inspect, "\n"
    pp tl
#            print "CodeSpace 0x#{cs.base_address.to_s(16)}\n"
    print "CodeSpace #{cs.inspect}\n"
  end
end

#find_cs_by_signature(sig) ⇒ Object



742
743
744
745
746
747
748
749
750
# File 'lib/ytljit/vm.rb', line 742

def find_cs_by_signature(sig)
  @code_spaces.each do |csig, val|
    if csig == sig then
      return val
    end
  end

  nil
end

#modified_instance_varObject



734
735
736
# File 'lib/ytljit/vm.rb', line 734

def modified_instance_var
  search_end.modified_instance_var
end

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

Yields:



738
739
740
# File 'lib/ytljit/vm.rb', line 738

def traverse_childlen
  yield @body
end