Module: YTLJit::VM::SendNodeCodeGen

Includes:
AbsArch
Included in:
Node::SendNode
Defined in:
lib/ytljit/vm_codegen.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 Method Summary collapse

Instance Method Details

#dump_context(context) ⇒ Object



410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
# File 'lib/ytljit/vm_codegen.rb', line 410

def dump_context(context)
  print "---- Reg map ----\n"
  context.reg_content.each do |key, value|
    print "#{key}   #{value.class} \n"
  end

  print "---- Stack map ----\n"
  @frame_info.frame_layout.each_with_index do |vinf, i|
    ro = @frame_info.real_offset(i)
    if mlv = @modified_local_var[0][ro] then
      print "    #{mlv.class} \n"
    else
      print "    #{vinf.class} \n"
    end
  end
  context.stack_content.each do |value|
    print "    #{value.class} \n"
  end
end

#gen_call(context, fnc, numarg) ⇒ Object



487
488
489
490
491
492
493
494
495
496
497
498
499
# File 'lib/ytljit/vm_codegen.rb', line 487

def gen_call(context, fnc, numarg)
  casm = context.assembler

  callpos = nil
  casm.with_retry do 
    dmy, callpos = casm.call_with_arg(fnc, numarg)
  end
  @var_return_address = casm.output_stream.var_base_address(callpos)
  if context.options[:dump_context] then
    dump_context(context)
  end
  context
end

#gen_make_argv(context) ⇒ Object



430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
# File 'lib/ytljit/vm_codegen.rb', line 430

def gen_make_argv(context)
  casm = context.assembler
  rarg = @arguments[3..-1]

  # make argv
  casm = context.assembler
  argbyte = rarg.size * AsmType::MACHINE_WORD.size
  casm.with_retry do
    casm.sub(SPR, argbyte)
  end
  context.cpustack_pushn(argbyte)

  rarg.each_with_index do |arg, i|
    context = arg.compile(context)
    context.ret_node.decide_type_once(context.to_key)
    rtype = context.ret_node.type
    context = rtype.gen_boxing(context)
    casm = context.assembler
    dst = OpIndirect.new(SPR, i * AsmType::MACHINE_WORD.size)
    if  context.ret_reg.is_a?(OpRegistor) or 
        context.ret_reg.is_a?(OpImmidiate32) or 
        context.ret_reg.is_a?(OpImmidiate8) then

      casm.with_retry do
        casm.mov(dst, context.ret_reg)
      end

    else
      casm.with_retry do
        casm.mov(TMPR, context.ret_reg)
        casm.mov(dst, TMPR)
      end
    end
    context.cpustack_setn(i * AsmType::MACHINE_WORD.size, context.ret_node)
  end

  # Copy Stack Pointer
  # TMPR2 doesnt need save. Because already saved in outside
  # of send node
  casm.with_retry do
    casm.mov(TMPR2, SPR)
  end
  context.set_reg_content(TMPR2, SPR)

  # stack, generate call ...
  context = yield(context, rarg)

  # adjust stack
  casm = context.assembler
  casm.with_retry do
    casm.add(SPR, argbyte)
  end
  context.cpustack_popn(argbyte)

  context
end