Module: YTLJit::VM::SendNodeCodeGen

Includes:
AbsArch
Included in:
Node::ClassTopNode, 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, AbsArch::INDIRECT_TMPR3

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



506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
# File 'lib/ytljit/vm_codegen.rb', line 506

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.last[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



582
583
584
585
586
587
588
589
590
591
592
593
594
595
# File 'lib/ytljit/vm_codegen.rb', line 582

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

  callpos = nil
  casm.with_retry do 
    dmy, callpos = casm.call_with_arg(fnc, numarg)
  end
  context.end_using_reg(fnc)
  @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



526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
# File 'lib/ytljit/vm_codegen.rb', line 526

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_signature)
    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, 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