2017-01-19 09:02:29 +02:00
|
|
|
module Risc
|
2016-12-11 14:12:35 +02:00
|
|
|
|
2016-12-25 18:11:58 +02:00
|
|
|
# Getter is a base class for get instructions (SlotToReg and ByteToReg , possibly more coming)
|
2016-12-11 14:12:35 +02: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
|
2018-03-14 17:39:49 +05:30
|
|
|
# - an (array) index
|
|
|
|
# - Register that the data is moved to
|
2016-12-11 14:12:35 +02:00
|
|
|
|
|
|
|
# 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 18:05:39 +02:00
|
|
|
# So SlotToReg means the slot (array and index) moves to the register (last argument)
|
2018-03-14 17:39:49 +05:30
|
|
|
def initialize( source , array , index , register )
|
2016-12-11 14:12:35 +02:00
|
|
|
super(source)
|
|
|
|
@array = array
|
|
|
|
@index = index
|
|
|
|
@register = register
|
2018-05-14 20:50:52 +03:00
|
|
|
raise "index #{index}" if index.is_a?(Numeric) and index < 0
|
2018-06-29 11:39:07 +03:00
|
|
|
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)
|
2016-12-11 14:12:35 +02:00
|
|
|
end
|
|
|
|
attr_accessor :array , :index , :register
|
|
|
|
|
2016-12-16 00:30:26 +02:00
|
|
|
def to_s
|
2018-03-22 18:38:19 +02:00
|
|
|
class_source "#{array}[#{index}] -> #{register}"
|
2016-12-16 00:30:26 +02:00
|
|
|
end
|
|
|
|
|
2016-12-11 14:12:35 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|