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, #debug_info, #element_node_list, #id, #is_escape, #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.



778
779
780
781
782
783
784
785
786
787
788
789
790
791
# File 'lib/ytljit/vm.rb', line 778

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.



794
795
796
# File 'lib/ytljit/vm.rb', line 794

def end_nodes
  @end_nodes
end

#nameObject

Returns the value of attribute name.



793
794
795
# File 'lib/ytljit/vm.rb', line 793

def name
  @name
end

#orig_modified_local_varObject (readonly)

Returns the value of attribute orig_modified_local_var.



795
796
797
# File 'lib/ytljit/vm.rb', line 795

def orig_modified_local_var
  @orig_modified_local_var
end

#signature_cacheObject (readonly)

Returns the value of attribute signature_cache.



798
799
800
# File 'lib/ytljit/vm.rb', line 798

def signature_cache
  @signature_cache
end

#yield_nodeObject (readonly)

Returns the value of attribute yield_node.



796
797
798
# File 'lib/ytljit/vm.rb', line 796

def yield_node
  @yield_node
end

Instance Method Details

#add_arg_to_args(args, addnum) ⇒ Object



830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
# File 'lib/ytljit/vm.rb', line 830

def add_arg_to_args(args, addnum)
  if args.is_a?(Integer) then
    args = args + addnum
  elsif args.is_a?(Array) then
    args = args.dup
    args[0] += addnum
    args[3] += addnum if args[3] >= 0
    args[4] += addnum if args[4] >= 0
    args[5] += addnum if args[5] >= 0
  else
    raise "Unkonwn args #{args}"
  end

  args
end

#add_cs_for_signature(sig) ⇒ Object



818
819
820
821
822
823
824
825
826
827
828
# File 'lib/ytljit/vm.rb', line 818

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



924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
# File 'lib/ytljit/vm.rb', line 924

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



917
918
919
920
921
922
# File 'lib/ytljit/vm.rb', line 917

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

#compile(context) ⇒ Object



964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
# File 'lib/ytljit/vm.rb', line 964

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 = compile_init(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

#compile_init(context) ⇒ Object



960
961
962
# File 'lib/ytljit/vm.rb', line 960

def compile_init(context)
  context
end

#construct_frame_info(locals, argnum, args) ⇒ Object



846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
# File 'lib/ytljit/vm.rb', line 846

def construct_frame_info(locals, argnum, args)
  finfo = LocalFrameInfoNode.new(self)
  finfo.system_num = 5         # BP ON Stack, HP, ET, BP, RET

  argc = args
  opt_label = []
  rest_index = -1
  post_len = -1
  post_start = -1
  block_index = -1
  simple = -1
  if args.is_a?(Array) then
    argc = args[0]
    opt_label = args[1]
    post_len = args[2]
    post_start = args[3]
    rest_index = args[4]
    block_index = args[5]
    simple = args[6]
  end
  
  # 5means BP, HP, Exception Tag, BP and SP
  lsize = locals.size + finfo.system_num
  
  # construct frame
  frame_layout = Array.new(lsize)
  fargstart = lsize - argnum
  i = 0
  argnum.times do
    kind = :arg
    if i == rest_index then
      kind = :rest_arg
    end
    lnode = LocalVarNode.new(finfo, locals[i], fargstart + i,
                             kind)
    frame_layout[fargstart + i] = lnode
    i = 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, 
                                             :EXPTAG, curpos)
  curpos -= 1
  frame_layout[curpos] = SystemValueNode.new(finfo, 
                                             :TMPHEAP, 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, :local_var)
    frame_layout[j] = lnode
    i += 1
    j += 1
  end
  finfo.frame_layout = frame_layout
  finfo.argument_num = argnum
  
  @body = finfo
  finfo.init_after_construct
  finfo
end

#disp_signatureObject



947
948
949
950
951
952
953
954
955
956
957
958
# File 'lib/ytljit/vm.rb', line 947

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



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

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



800
801
802
# File 'lib/ytljit/vm.rb', line 800

def modified_instance_var
  search_end.modified_instance_var
end

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

Yields:



804
805
806
# File 'lib/ytljit/vm.rb', line 804

def traverse_childlen
  yield @body
end