2016-12-11 13:12:35 +01:00
|
|
|
module Register
|
|
|
|
|
2016-12-25 17:11:58 +01:00
|
|
|
# Getter is a base class for get instructions (SlotToReg and ByteToReg , possibly more coming)
|
2016-12-11 13:12:35 +01:00
|
|
|
#
|
|
|
|
# The instruction that is modelled is loading data from an array into a register
|
|
|
|
#
|
|
|
|
# Getter has a
|
|
|
|
# - an array where the data comes from
|
|
|
|
# - and (array) index
|
|
|
|
# - Register that the data is moved to
|
|
|
|
|
|
|
|
# Getter and Setter api follow the pattern from -> to
|
|
|
|
|
|
|
|
class Getter < Instruction
|
|
|
|
|
|
|
|
# If you had a c array and index offset
|
|
|
|
# the instruction would do register = array[index]
|
|
|
|
# The arguments are in the order that makes sense for the Instruction name
|
2016-12-25 17:05:39 +01:00
|
|
|
# So SlotToReg means the slot (array and index) moves to the register (last argument)
|
2016-12-11 13:12:35 +01:00
|
|
|
def initialize source , array , index , register
|
|
|
|
super(source)
|
|
|
|
@array = array
|
|
|
|
@index = index
|
|
|
|
@register = register
|
|
|
|
raise "index 0 " if index == 0
|
|
|
|
raise "Not integer or reg #{index}" unless index.is_a?(Numeric) or RegisterValue.look_like_reg(index)
|
|
|
|
raise "Not register #{register}" unless RegisterValue.look_like_reg(register)
|
|
|
|
raise "Not register #{array}" unless RegisterValue.look_like_reg(array)
|
|
|
|
end
|
|
|
|
attr_accessor :array , :index , :register
|
|
|
|
|
2016-12-15 23:30:26 +01:00
|
|
|
def to_s
|
|
|
|
"#{self.class.name}: #{array}[#{index}] -> #{register}"
|
|
|
|
end
|
|
|
|
|
2016-12-11 13:12:35 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|