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

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

Overview

The top of top node

Direct Known Subclasses

ClassTopNode, ExceptionTopNode, MethodTopNode

Constant Summary

Constants inherited from BaseNode

BaseNode::ESCAPE_LEVEL

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 MultipleCodeSpaceUtil

#add_cs_for_signature, #find_cs_by_signature, #get_code_space

Methods included from NodeUtil

#search_class_top, #search_end, #search_frame_info, #search_top

Methods inherited from BaseNode

#add_element_node, #add_element_node_backward, #decide_type, #decide_type_core, #decide_type_once, #gen_type_inference_proc, #get_constant_value, #inference_type, #marge_element_node, #marge_type, #same_type, #set_escape_node, #set_escape_node_backward, #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.



988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
# File 'lib/ytljit/vm.rb', line 988

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

Instance Attribute Details

#end_nodesObject (readonly)

Returns the value of attribute end_nodes.



1004
1005
1006
# File 'lib/ytljit/vm.rb', line 1004

def end_nodes
  @end_nodes
end

#exception_tableObject

Returns the value of attribute exception_table.



1008
1009
1010
# File 'lib/ytljit/vm.rb', line 1008

def exception_table
  @exception_table
end

#nameObject

Returns the value of attribute name.



1003
1004
1005
# File 'lib/ytljit/vm.rb', line 1003

def name
  @name
end

#signature_cacheObject (readonly)

Returns the value of attribute signature_cache.



1007
1008
1009
# File 'lib/ytljit/vm.rb', line 1007

def signature_cache
  @signature_cache
end

#yield_nodeObject (readonly)

Returns the value of attribute yield_node.



1005
1006
1007
# File 'lib/ytljit/vm.rb', line 1005

def yield_node
  @yield_node
end

Instance Method Details

#add_arg_to_args(args, addnum) ⇒ Object



1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
# File 'lib/ytljit/vm.rb', line 1018

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

#collect_candidate_type(context, signode, sig) ⇒ Object



1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
# File 'lib/ytljit/vm.rb', line 1121

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)

  if @exception_table then
    @exception_table.each do |kind, lst|
      lst.each do |st, ed, cnt, body|
        if body then
          context = body.collect_candidate_type(context)
        end
      end
    end
  end

  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



1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
# File 'lib/ytljit/vm.rb', line 1105

def collect_info(context)
  context.yield_node.push []
  context = @body.collect_info(context)
  @yield_node = context.yield_node.pop
  if @exception_table then
    @exception_table.each do |kind, lst|
      lst.each do |st, ed, cnt, body|
        if body then
          context = body.collect_info(context)
        end
      end
    end
  end
  context
end

#compile(context) ⇒ Object



1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
# File 'lib/ytljit/vm.rb', line 1173

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)

    if @exception_table then
      @exception_table.each do |kind, lst|
        lst.each do |st, ed, cnt, body|
          if body then
            context = body.compile(context)
          end
        end
      end
    end
    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



1169
1170
1171
# File 'lib/ytljit/vm.rb', line 1169

def compile_init(context)
  context
end

#construct_frame_info(locals, argnum, args) ⇒ Object



1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
# File 'lib/ytljit/vm.rb', line 1034

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



1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
# File 'lib/ytljit/vm.rb', line 1155

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

#modified_instance_varObject



1010
1011
1012
# File 'lib/ytljit/vm.rb', line 1010

def modified_instance_var
  search_end.modified_instance_var
end

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

Yields:



1014
1015
1016
# File 'lib/ytljit/vm.rb', line 1014

def traverse_childlen
  yield @body
end