unifying register comstants

were in several files with different names
many files touched, but just renames
This commit is contained in:
Torsten Ruger 2015-06-27 21:16:46 +03:00
parent 97b4c469f8
commit ef42abe611
10 changed files with 30 additions and 39 deletions

View File

@ -15,7 +15,7 @@ module Arm
def putstring int_code , codes
codes << ArmMachine.mov( :r1 , 20 ) # String length, obvious TODO
codes << ArmMachine.ldr( :r0 , Virtual::Slot::MESSAGE_REGISTER, Virtual::SELF_INDEX)
codes << ArmMachine.ldr( :r0 , Register::RegisterReference.message_reg, Virtual::SELF_INDEX)
syscall(int_code , codes )
end

View File

@ -12,10 +12,12 @@ module Builtin
function.info.blocks.last.codes.pop # no Method return
#Set up the Space as self upon init
space = Parfait::Space.object_space
function.info.add_code Register::LoadConstant.new( space , Virtual::Slot::SELF_REGISTER)
function.info.add_code Register::LoadConstant.new( space , Register::RegisterReference.self_reg)
message_ind = space.get_layout().index_of( :next_message )
# Load the message to message register (0)
function.info.add_code Register::GetSlot.new( Virtual::Slot::SELF_REGISTER , message_ind , Virtual::Slot::MESSAGE_REGISTER)
function.info.add_code Register::GetSlot.new( Register::RegisterReference.self_reg , message_ind , Register::RegisterReference.new_message_reg)
# And store the space as the new self (so the call can move it back as self)
function.info.add_code Register::SetSlot.new( Register::RegisterReference.self_reg , Register::RegisterReference.new_message_reg , Virtual::SELF_INDEX)
# now we are set up to issue a call to the main
function.info.add_code Virtual::MethodCall.new(Virtual.machine.space.get_main)
emit_syscall( function , :exit )
@ -56,22 +58,22 @@ module Builtin
ind = Parfait::Space.object_space.get_layout().index_of( :syscall_message )
raise "index not found for :syscall_message" unless ind
function.info.add_code Register::LoadConstant.new( Parfait::Space.object_space , space_tmp)
function.info.add_code Register::SetSlot.new( Virtual::Slot::MESSAGE_REGISTER , space_tmp , ind)
function.info.add_code Register::SetSlot.new( Register::RegisterReference.message_reg , space_tmp , ind)
end
def restore_message(function)
# get the sys return out of the way
return_tmp = Register::RegisterReference.tmp_reg
# load the space into the base register
function.info.add_code Register::RegisterTransfer.new( return_tmp , Virtual::Slot::MESSAGE_REGISTER )
function.info.add_code Register::RegisterTransfer.new( return_tmp , Register::RegisterReference.message_reg )
slot = Virtual::Slot
# find the stored message
ind = Parfait::Space.object_space.get_layout().index_of( :syscall_message )
raise "index not found for #{kind}.#{kind.class}" unless ind
# and load it into the base RegisterMachine
function.info.add_code Register::GetSlot.new( slot::MESSAGE_REGISTER , ind , slot::MESSAGE_REGISTER )
function.info.add_code Register::GetSlot.new( Register::RegisterReference.message_reg , ind , Register::RegisterReference.message_reg )
# and "unroll" self and frame
function.info.add_code Register::GetSlot.new( slot::MESSAGE_REGISTER , Virtual::SELF_INDEX, slot::SELF_REGISTER )
function.info.add_code Register::GetSlot.new( slot::MESSAGE_REGISTER , Virtual::FRAME_INDEX, slot::FRAME_REGISTER )
function.info.add_code Register::GetSlot.new( Register::RegisterReference.message_reg , Virtual::SELF_INDEX, Register::RegisterReference.self_reg )
function.info.add_code Register::GetSlot.new( Register::RegisterReference.message_reg , Virtual::FRAME_INDEX, Register::RegisterReference.frame_reg )
end
end
extend ClassMethods

View File

@ -14,9 +14,9 @@ module Register
new_codes = []
slot = Virtual::Slot
# move the current new_message to message
new_codes << RegisterTransfer.new( slot::NEW_MESSAGE_REGISTER , slot::MESSAGE_REGISTER )
new_codes << RegisterTransfer.new( RegisterReference.new_message_reg , RegisterReference.message_reg )
# "roll out" self into its register
new_codes << GetSlot.new( slot::MESSAGE_REGISTER , Virtual::SELF_INDEX, slot::SELF_REGISTER )
new_codes << GetSlot.new( RegisterReference.message_reg , Virtual::SELF_INDEX, RegisterReference.self_reg )
# do the register call
new_codes << FunctionCall.new( code.method )
block.replace(code , new_codes )

View File

@ -6,14 +6,14 @@ module Register
next unless code.is_a? Virtual::MethodReturn
new_codes = []
# move the current message to new_message
new_codes << RegisterTransfer.new( slot::MESSAGE_REGISTER , slot::NEW_MESSAGE_REGISTER )
new_codes << RegisterTransfer.new( RegisterReference.message_reg , RegisterReference.new_message_reg )
# and restore the message from saved value in new_message
new_codes << GetSlot.new( slot::NEW_MESSAGE_REGISTER , Virtual::CALLER_INDEX , slot::MESSAGE_REGISTER)
new_codes << GetSlot.new( RegisterReference.new_message_reg , Virtual::CALLER_INDEX , RegisterReference.message_reg)
# "roll out" self and frame into their registers
new_codes << GetSlot.new( slot::MESSAGE_REGISTER , Virtual::SELF_INDEX , slot::SELF_REGISTER )
new_codes << GetSlot.new( slot::MESSAGE_REGISTER , Virtual::FRAME_INDEX , slot::FRAME_REGISTER )
new_codes << GetSlot.new( RegisterReference.message_reg , Virtual::SELF_INDEX , RegisterReference.self_reg )
new_codes << GetSlot.new( RegisterReference.message_reg , Virtual::FRAME_INDEX , RegisterReference.frame_reg )
#load the return address into pc, affecting return. (other cpus have commands for this, but not arm)
new_codes << FunctionReturn.new( slot::MESSAGE_REGISTER , Virtual::RETURN_INDEX )
new_codes << FunctionReturn.new( RegisterReference.message_reg , Virtual::RETURN_INDEX )
block.replace(code , new_codes )
end
end

View File

@ -48,27 +48,27 @@ module Register
RegisterReference.new( sym )
end
SELF_REG = :r0
MESSAGE_REG = :r1
FRAME_REG = :r2
NEW_MESSAGE_REG = :r3
MESSAGE_REGISTER = :r0
SELF_REGISTER = :r1
FRAME_REGISTER = :r2
NEW_MESSAGE_REGISTER = :r3
TMP_REG = :r4
TMP_REGISTER = :r4
def self.self_reg
new SELF_REG
new SELF_REGISTER
end
def self.message_reg
new MESSAGE_REG
new MESSAGE_REGISTER
end
def self.frame_reg
new FRAME_REG
new FRAME_REGISTER
end
def self.new_message_reg
new NEW_MESSAGE_REG
new NEW_MESSAGE_REGISTER
end
def self.tmp_reg
new TMP_REG
new TMP_REGISTER
end
def sof_reference_name

View File

@ -70,7 +70,7 @@ module Virtual
def locals_at l_block
used =[]
# call assigns the return register, but as it is in l_block, it is not asked.
assigned = [ RegisterReference.new(Virtual::RegisterMachine.instance.return_register) ]
assigned = [ Register::RegisterReference.new(Virtual::RegisterMachine.instance.return_register) ]
l_block.reachable.each do |b|
b.uses.each {|u|
(used << u) unless assigned.include?(u)

View File

@ -36,7 +36,7 @@ module Virtual
locals = {}
expression.params.each_with_index do |param , index|
arg = param.name
register = RegisterReference.new(RegisterMachine.instance.receiver_register).next_reg_use(index + 1)
register = Register::RegisterReference.new(RegisterMachine.instance.receiver_register).next_reg_use(index + 1)
arg_value = Integer.new(register)
locals[arg] = arg_value
args << arg_value

View File

@ -23,13 +23,6 @@ module Virtual
class Message
SELF_REG = :r0
MESSAGE_REG = :r1
FRAME_REG = :r2
NEW_MESSAGE_REG = :r3
TMP_REG = :r4
def initialize me , normal , exceptional
@me = me
@next_normal = normal

View File

@ -7,7 +7,7 @@ module Virtual
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( Virtual::Slot::MESSAGE_REGISTER , Virtual::RETURN_INDEX )
new_codes << Register::SaveReturn.new( Register::RegisterReference.message_reg , Virtual::RETURN_INDEX )
new_codes << Virtual::NewFrame.new
block.replace(code , new_codes )
end

View File

@ -16,10 +16,6 @@ module Virtual
# Names for the slots avoid indexes
class Slot < Object
MESSAGE_REGISTER = :r0
SELF_REGISTER = :r1
FRAME_REGISTER = :r2
NEW_MESSAGE_REGISTER = :r3
attr_accessor :index , :type , :value