making good headway with register machine implementation in arm

This commit is contained in:
Torsten Ruger 2014-10-05 01:05:18 +03:00
parent 7968cadaf9
commit 3aca3cc33d
7 changed files with 84 additions and 1 deletions

View File

@ -15,5 +15,5 @@ module Arm
end
end
end
Virtual::BootSpace.space.add_pass_after "Arm::CallImplementation" , "Register::SetImplementation"
Virtual::BootSpace.space.add_pass "Arm::CallImplementation"
end

View File

@ -0,0 +1,13 @@
module Arm
class ConstantImplementation
def run block
block.codes.dup.each do |code|
next unless code.is_a? Register::LoadConstant
load = ArmMachine.ldr( code.value , code.constant )
block.replace(code , load )
end
end
end
Virtual::BootSpace.space.add_pass "Arm::ConstantImplementation"
end

View File

@ -0,0 +1,13 @@
module Arm
class GetImplementation
def run block
block.codes.dup.each do |code|
next unless code.is_a? Register::GetSlot
load = ArmMachine.ldr( code.value , code.reference , code.index )
block.replace(code , load )
end
end
end
Virtual::BootSpace.space.add_pass "Arm::GetImplementation"
end

View File

@ -0,0 +1,13 @@
module Arm
class ReturnImplementation
def run block
block.codes.dup.each do |code|
next unless code.is_a? Register::FunctionReturn
load = ArmMachine.ldr( :pc , code.register , code.index )
block.replace(code , load )
end
end
end
Virtual::BootSpace.space.add_pass "Arm::ReturnImplementation"
end

View File

@ -0,0 +1,18 @@
module Arm
# Arm stores the return address in a register (not on the stack)
# The register is called link , or lr for short . Maybe because it provides the "link" back to the caller (?)
# the vm defines a register for the location, so we store it there.
class SaveImplementation
def run block
block.codes.dup.each do |code|
next unless code.is_a? Register::SaveReturn
store = ArmMachine.str( :lr , code.register , code.index )
block.replace(code , store )
end
end
end
Virtual::BootSpace.space.add_pass "Arm::SaveImplementation"
end

View File

@ -0,0 +1,13 @@
module Arm
class SetImplementation
def run block
block.codes.dup.each do |code|
next unless code.is_a? Register::SetSlot
store = ArmMachine.str( code.value , code.reference , code.index )
block.replace(code , store )
end
end
end
Virtual::BootSpace.space.add_pass "Arm::SetImplementation"
end

View File

@ -0,0 +1,13 @@
module Arm
class TransferImplementation
def run block
block.codes.dup.each do |code|
next unless code.is_a? Register::RegisterTransfer
move = ArmMachine.mov( code.from , code.to )
block.replace(code , move )
end
end
end
Virtual::BootSpace.space.add_pass "Arm::TransferImplementation"
end