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, #add_element_node_backward_aux, #collect_candidate_type, #decide_type, #decide_type_core, #decide_type_once, #gen_type_inference_proc, #get_constant_value, #inference_type, #marge_element_node, #marge_type, #same_type, #search_valid_signature, #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.



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

def initialize(parent, name = nil)
  super(parent)
  @name = name
  @code_spaces = [] # [[nil, CodeSpace.new]]
  @code_space_from_signature = {}  # return type -> codespace
  @yield_node = []
  if @parent then
    @classtop = search_class_top
  else
    @classtop = self
  end
  @end_nodes = []
  @signature_cache = []
  @current_signature = []
  @exception_table = nil
  @send_nodes_with_block = nil

  @escape_info_tab = {}
  @escape_info = nil
end

Instance Attribute Details

#classtopObject (readonly)

Returns the value of attribute classtop.



1132
1133
1134
# File 'lib/ytljit/vm.rb', line 1132

def classtop
  @classtop
end

#code_space_from_signatureObject (readonly)

Returns the value of attribute code_space_from_signature.



1126
1127
1128
# File 'lib/ytljit/vm.rb', line 1126

def code_space_from_signature
  @code_space_from_signature
end

#current_signatureObject (readonly)

Returns the value of attribute current_signature.



1131
1132
1133
# File 'lib/ytljit/vm.rb', line 1131

def current_signature
  @current_signature
end

#end_nodesObject (readonly)

Returns the value of attribute end_nodes.



1127
1128
1129
# File 'lib/ytljit/vm.rb', line 1127

def end_nodes
  @end_nodes
end

#escape_infoObject (readonly)

Returns the value of attribute escape_info.



1135
1136
1137
# File 'lib/ytljit/vm.rb', line 1135

def escape_info
  @escape_info
end

#exception_tableObject

Returns the value of attribute exception_table.



1133
1134
1135
# File 'lib/ytljit/vm.rb', line 1133

def exception_table
  @exception_table
end

#nameObject

Returns the value of attribute name.



1125
1126
1127
# File 'lib/ytljit/vm.rb', line 1125

def name
  @name
end

#send_nodes_with_blockObject

Returns the value of attribute send_nodes_with_block.



1134
1135
1136
# File 'lib/ytljit/vm.rb', line 1134

def send_nodes_with_block
  @send_nodes_with_block
end

#signature_cacheObject (readonly)

Returns the value of attribute signature_cache.



1130
1131
1132
# File 'lib/ytljit/vm.rb', line 1130

def signature_cache
  @signature_cache
end

#yield_nodeObject (readonly)

Returns the value of attribute yield_node.



1128
1129
1130
# File 'lib/ytljit/vm.rb', line 1128

def yield_node
  @yield_node
end

Instance Method Details

#add_arg_to_args(args, addnum) ⇒ Object



1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
# File 'lib/ytljit/vm.rb', line 1145

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_common(context, signode, sig) ⇒ Object



1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
# File 'lib/ytljit/vm.rb', line 1254

def collect_candidate_type_common(context, signode, sig)
  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
  @current_signature = nil
  context
end

#collect_info(context) ⇒ Object



1250
1251
1252
# File 'lib/ytljit/vm.rb', line 1250

def collect_info(context)
  collect_info_top(context)
end

#collect_info_top(context) ⇒ Object



1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
# File 'lib/ytljit/vm.rb', line 1234

def collect_info_top(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



1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
# File 'lib/ytljit/vm.rb', line 1312

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
    @code_space_from_signature[sig] = cs
  end

  if oldcs then
    context.set_code_space(oldcs)
  end

  if context.options[:disp_signature] then
    disp_signature
  end

  if context.options[:insert_signature_comment] then
    gen_comment(context)
  end

  context.ret_node = self
  context
end

#compile_init(context) ⇒ Object



1308
1309
1310
# File 'lib/ytljit/vm.rb', line 1308

def compile_init(context)
  context
end

#construct_frame_info(locals, argnum, args) ⇒ Object



1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
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
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
# File 'lib/ytljit/vm.rb', line 1161

def construct_frame_info(locals, argnum, args)
  finfo = LocalFrameInfoNode.new(self)
  # 5means BP on Stack, HP, Exception Tag, BP and SP
  finfo.system_num = 5

  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, opt_label, post_len, post_start, 
      rest_index, block_index, simple = args
    finfo.opt_label = opt_label
    finfo.post_len = post_len
    finfo.post_start = post_start
    finfo.rest_index = rest_index
    finfo.block_index = block_index
    finfo.simple = simple
  end
  finfo.argc = argc
  
  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



1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
# File 'lib/ytljit/vm.rb', line 1276

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

#gen_comment(context) ⇒ Object



1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
# File 'lib/ytljit/vm.rb', line 1290

def gen_comment(context)
  if debug_info then
    lineno = debug_info[3]
    fname = debug_info[0]
    entry = [1, @name]
    @code_spaces.each do |sig, cs|
      ent2 = []
      ent2.push sig
      ent2.push decide_type_once(sig)
      entry.push ent2
    end

    context.comment[fname] ||= {}
    context.comment[fname][lineno] ||= []
    context.comment[fname][lineno].push entry
  end
end

#modified_instance_varObject



1137
1138
1139
# File 'lib/ytljit/vm.rb', line 1137

def modified_instance_var
  search_end.modified_instance_var
end

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

Yields:



1141
1142
1143
# File 'lib/ytljit/vm.rb', line 1141

def traverse_childlen
  yield @body
end