rubyx/lib/risc/instructions/slot_to_reg.rb

30 lines
1.1 KiB
Ruby
Raw Normal View History

module Risc
# SlotToReg moves data into a register from memory.
# RegToSlot moves data into memory from a register.
# Both use a base memory (a register)
# This is because that is what cpu's can do. In programming terms this would be accessing
# an element in an array, in the case of SlotToReg setting the value in the array.
2018-03-21 11:18:04 +01:00
# btw: to move data between registers, use Transfer
class SlotToReg < Getter
end
# Produce a SlotToReg instruction.
2020-03-01 11:42:28 +01:00
# Array is a register
# index may be a Symbol in which case is resolves with resolve_index.
2020-03-01 11:42:28 +01:00
# a new regsister will be created as the result, ie the reg part for slot_to_reg
2020-02-29 16:18:27 +01:00
def self.slot_to_reg( source , array , index )
raise "Register #{array}" if RegisterValue.look_like_reg(array.symbol)
new_name = "#{array.symbol}.#{index.to_s.downcase}".to_sym
index = array.resolve_index(index) if index.is_a?(Symbol)
2020-02-29 16:18:27 +01:00
type = array.type_at(index)
#puts "Slot for #{array.symbol}@ index #{index} is #{type}"
to = RegisterValue.new( new_name , type )
SlotToReg.new( source , array , index , to)
end
end