rubyx/lib/virtual/passes/enter_implementation.rb
Torsten Ruger a16abeb3e6 giving the method to return and save
so they can make decisions
like wether to create a frame or not
2015-06-28 22:03:21 +03:00

20 lines
684 B
Ruby

module Virtual
class EnterImplementation
def run block
block.codes.dup.each do |code|
next unless code.is_a? Virtual::MethodEnter
new_codes = []
# save return register and create a new frame
# lr is link register, ie where arm stores the return address when call is issued
new_codes << Register::SaveReturn.new( Register::RegisterReference.message_reg , Virtual::RETURN_INDEX )
unless code.method.locals.empty? and code.method.tmps.empty?
new_codes << Virtual::NewFrame.new
end
block.replace(code , new_codes )
end
end
end
Virtual.machine.add_pass "Virtual::EnterImplementation"
end