Permalink
Cannot retrieve contributors at this time
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
35 lines (29 sloc)
1.32 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. | |
# btw: to move data between registers, use Transfer | |
class SlotToReg < Getter | |
end | |
# Produce a SlotToReg instruction. | |
# Array is a register | |
# index may be a Symbol in which case is resolves with resolve_index. | |
# a new regsister will be created as the result, ie the reg part for slot_to_reg | |
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) | |
if( index.is_a?(Integer)) | |
type = array.type_at(index) | |
else | |
raise "must be integer index #{index}" unless index.type.name == "Integer_Type" | |
type = Parfait.object_space.get_type_by_class_name(:Object) | |
new_name = "#{array.symbol}.indexed".to_sym | |
end | |
#puts "Slot for #{array.symbol}@ index #{index} is #{type}" | |
to = RegisterValue.new( new_name , type ) | |
SlotToReg.new( source , array , index , to) | |
end | |
end |