move passes to own dir
This commit is contained in:
19
lib/register/passes/call_implementation.rb
Normal file
19
lib/register/passes/call_implementation.rb
Normal file
@ -0,0 +1,19 @@
|
||||
module Register
|
||||
# This implements call logic, which is simply like a c call (not send, that involves lookup and all sorts)
|
||||
#
|
||||
# The only target for a call is a CompiledMethod, so we just need to get the address for the code
|
||||
# and call it.
|
||||
#
|
||||
# The only slight snag is that we would need to assemble before getting the address, but to assemble
|
||||
# we'd have to have finished compiling. So we need a reference.
|
||||
class CallImplementation
|
||||
def run block
|
||||
block.codes.dup.each do |code|
|
||||
next unless code.is_a? Virtual::FunctionCall
|
||||
call = RegisterMachine.instance.call( code.method )
|
||||
block.replace(code , call )
|
||||
end
|
||||
end
|
||||
end
|
||||
Virtual::BootSpace.space.add_pass_after CallImplementation , SetImplementation
|
||||
end
|
17
lib/register/passes/enter_implementation.rb
Normal file
17
lib/register/passes/enter_implementation.rb
Normal file
@ -0,0 +1,17 @@
|
||||
module Register
|
||||
|
||||
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 << RegisterMachine.instance.str( :lr , Virtual::Slot::MESSAGE_REGISTER , Virtual::Slot::MESSAGE_RETURN_ADDRESS )
|
||||
new_codes << Virtual::NewFrame.new
|
||||
block.replace(code , new_codes )
|
||||
end
|
||||
end
|
||||
end
|
||||
Virtual::BootSpace.space.add_pass_after EnterImplementation , CallImplementation
|
||||
end
|
23
lib/register/passes/return_implementation.rb
Normal file
23
lib/register/passes/return_implementation.rb
Normal file
@ -0,0 +1,23 @@
|
||||
module Register
|
||||
class ReturnImplementation
|
||||
def run block
|
||||
block.codes.dup.each do |code|
|
||||
next unless code.is_a? Virtual::MethodReturn
|
||||
new_codes = []
|
||||
machine = RegisterMachine.instance
|
||||
slot = Virtual::Slot
|
||||
# move the current message to new_message
|
||||
new_codes << machine.mov( slot::MESSAGE_REGISTER , slot::NEW_MESSAGE_REGISTER )
|
||||
# and restore the message from saved value in new_message
|
||||
new_codes << machine.ldr( slot::MESSAGE_REGISTER ,slot::NEW_MESSAGE_REGISTER , slot::MESSAGE_CALLER )
|
||||
# "roll out" self and frame into their registers
|
||||
new_codes << machine.ldr( slot::SELF_REGISTER ,slot::MESSAGE_REGISTER , slot::MESSAGE_SELF )
|
||||
new_codes << machine.ldr( slot::FRAME_REGISTER ,slot::MESSAGE_REGISTER , slot::MESSAGE_FRAME )
|
||||
#load the return address into pc, affecting return. (other cpus have commands for this, but not arm)
|
||||
new_codes << machine.ldr( :pc ,slot::MESSAGE_REGISTER , slot::MESSAGE_RETURN_ADDRESS )
|
||||
block.replace(code , new_codes )
|
||||
end
|
||||
end
|
||||
end
|
||||
Virtual::BootSpace.space.add_pass_after ReturnImplementation , CallImplementation
|
||||
end
|
46
lib/register/passes/set_implementation.rb
Normal file
46
lib/register/passes/set_implementation.rb
Normal file
@ -0,0 +1,46 @@
|
||||
Virtual::MessageSlot.class_eval do
|
||||
def reg
|
||||
Register::RegisterReference.new(Virtual::Message::MESSAGE_REG )
|
||||
end
|
||||
end
|
||||
Virtual::FrameSlot.class_eval do
|
||||
def reg
|
||||
Register::RegisterReference.new(Virtual::Message::FRAME_REG )
|
||||
end
|
||||
end
|
||||
Virtual::SelfSlot.class_eval do
|
||||
def reg
|
||||
Register::RegisterReference.new(Virtual::Message::SELF_REG )
|
||||
end
|
||||
end
|
||||
Virtual::NewMessageSlot.class_eval do
|
||||
def reg
|
||||
Register::RegisterReference.new(Virtual::Message::NEW_MESSAGE_REG )
|
||||
end
|
||||
end
|
||||
|
||||
module Register
|
||||
# This implements setting of the various slot variables the vm defines.
|
||||
# Basic mem moves, but have to shuffle the type nibbles
|
||||
|
||||
class SetImplementation
|
||||
def run block
|
||||
block.codes.dup.each do |code|
|
||||
next unless code.is_a? Virtual::Set
|
||||
# resolve the register and offset that we need to move to
|
||||
to = code.to.reg
|
||||
# need a temporay place because of indexed load/store
|
||||
tmp = RegisterReference.new(Virtual::Message::TMP_REG)
|
||||
# for constants we have to "move" the constants value
|
||||
if( code.from.is_a? Virtual::Constant)
|
||||
move1 = RegisterMachine.instance.mov( tmp , code.from )
|
||||
else # while otherwise we "load"
|
||||
move1 = RegisterMachine.instance.ldr( tmp , code.from.reg , code.from.index )
|
||||
end
|
||||
move2 = RegisterMachine.instance.str( tmp , to , code.to.index )
|
||||
block.replace(code , [move1,move2] )
|
||||
end
|
||||
end
|
||||
end
|
||||
Virtual::BootSpace.space.add_pass_after SetImplementation , Virtual::GetImplementation
|
||||
end
|
Reference in New Issue
Block a user