allow setting the source for slot loads

so we can track more exactly which instruction created the risc
This commit is contained in:
Torsten Ruger 2018-03-22 18:45:03 +02:00
parent 9932d0bf33
commit 6e901e1718
5 changed files with 15 additions and 13 deletions

View File

@ -29,7 +29,7 @@ module Mom
end end
def to_risc(compiler) def to_risc(compiler)
transfer = SlotLoad.new([:message , :next_message , :receiver] , @receiver).to_risc(compiler) transfer = SlotLoad.new([:message , :next_message , :receiver] , @receiver, self).to_risc(compiler)
compiler.reset_regs compiler.reset_regs
@arguments.each do |arg| @arguments.each do |arg|
transfer << arg.to_risc(compiler) transfer << arg.to_risc(compiler)

View File

@ -24,11 +24,11 @@ module Mom
# Move method name, frame and arguemnt types from the method to the neext_message # Move method name, frame and arguemnt types from the method to the neext_message
# Assumes the message is ready, see class description # Assumes the message is ready, see class description
def to_risc(compiler) def to_risc(compiler)
name_move = SlotLoad.new( [:message , :next_message,:name] , [method , :name]) name_move = SlotLoad.new( [:message , :next_message,:name] , [method , :name],self)
moves = name_move.to_risc(compiler) moves = name_move.to_risc(compiler)
args_move = SlotLoad.new( [:message , :next_message, :arguments,:type] , [method , :arguments, :type]) args_move = SlotLoad.new( [:message , :next_message, :arguments,:type] , [method , :arguments, :type],self)
moves << args_move.to_risc(compiler) moves << args_move.to_risc(compiler)
type_move = SlotLoad.new( [:message , :next_message, :frame,:type] , [method , :frame,:type]) type_move = SlotLoad.new( [:message , :next_message, :frame,:type] , [method , :frame,:type],self)
moves << type_move.to_risc(compiler) moves << type_move.to_risc(compiler)
end end

View File

@ -20,7 +20,7 @@ module Mom
# #
class ReturnSequence < Instruction class ReturnSequence < Instruction
def to_risc(compiler) def to_risc(compiler)
return_move = SlotLoad.new( [:message ,:return_value] , [:message , :next_message, :return_value]) return_move = SlotLoad.new( [:message ,:return_value] , [:message , :next_message, :return_value],self)
moves = return_move.to_risc(compiler) moves = return_move.to_risc(compiler)
caller_reg = compiler.use_reg(:int) caller_reg = compiler.use_reg(:int)
return_reg = compiler.use_reg(:int) return_reg = compiler.use_reg(:int)

View File

@ -22,7 +22,7 @@ module Mom
def to_risc(compiler) def to_risc(compiler)
jump_address = compiler.use_reg(:int) jump_address = compiler.use_reg(:int)
return_label = Risc::Label.new(self,"continue_#{object_id}") return_label = Risc::Label.new(self,"continue_#{object_id}")
save_return = SlotLoad.new([:message,:next_message,:return_address],[return_label]) save_return = SlotLoad.new([:message,:next_message,:return_address],[return_label],self)
moves = save_return.to_risc(compiler) moves = save_return.to_risc(compiler)
moves << Risc.slot_to_reg(self, :message , :next_message , Risc.message_reg) moves << Risc.slot_to_reg(self, :message , :next_message , Risc.message_reg)
moves << Risc.load_constant(self , method.binary , jump_address) moves << Risc.load_constant(self , method.binary , jump_address)

View File

@ -22,18 +22,20 @@ module Mom
# SlotDefinition (see there) # SlotDefinition (see there)
# #
# @right: A SlotDefinition with slots or a Mom::Constant # @right: A SlotDefinition with slots or a Mom::Constant
# # original_source: optinally another mom instrucion that wil be passed down to created
# risc instructions. (Because SlotLoad is often used internally in mom)
class SlotLoad < Instruction class SlotLoad < Instruction
attr_reader :left , :right attr_reader :left , :right , :original_source
def initialize(left , right) def initialize(left , right, original_source = nil)
@left , @right = left , right @left , @right = left , right
@left = SlotDefinition.new(@left.shift , @left) if @left.is_a? Array @left = SlotDefinition.new(@left.shift , @left) if @left.is_a? Array
@right = SlotDefinition.new(@right.shift , @right) if @right.is_a? Array @right = SlotDefinition.new(@right.shift , @right) if @right.is_a? Array
raise "right not Mom, #{@right.to_s}" unless @right.is_a?( SlotDefinition ) raise "right not Mom, #{@right.to_s}" unless @right.is_a?( SlotDefinition )
@original_source = original_source || self
end end
def to_risc(compiler) def to_risc(compiler)
const = @right.to_register(compiler , self) const = @right.to_register(compiler , original_source)
left_slots = @left.slots left_slots = @left.slots
case @left.known_object case @left.known_object
when Symbol when Symbol
@ -42,13 +44,13 @@ module Mom
if left_slots.length > 1 if left_slots.length > 1
# swap the existing target (with a new reg) and update the index # swap the existing target (with a new reg) and update the index
new_left = compiler.use_reg( :int ) new_left = compiler.use_reg( :int )
const << Risc::SlotToReg.new( self , left ,left_index, new_left) const << Risc::SlotToReg.new( original_source , left ,left_index, new_left)
left = new_left left = new_left
left_index = SlotLoad.resolve_to_index(left_slots[0] , left_slots[1] ,compiler) left_index = SlotLoad.resolve_to_index(left_slots[0] , left_slots[1] ,compiler)
if left_slots.length > 2 if left_slots.length > 2
#same again, once more updating target #same again, once more updating target
new_left = compiler.use_reg( :int ) new_left = compiler.use_reg( :int )
const << Risc::SlotToReg.new( self , left ,left_index, new_left) const << Risc::SlotToReg.new( original_source , left ,left_index, new_left)
left = new_left left = new_left
left_index = SlotLoad.resolve_to_index(left_slots[1] , left_slots[2] ,compiler) left_index = SlotLoad.resolve_to_index(left_slots[1] , left_slots[2] ,compiler)
end end
@ -60,7 +62,7 @@ module Mom
else else
raise "We have left #{@left.known_object}" raise "We have left #{@left.known_object}"
end end
const << Risc.reg_to_slot(self, const.register , left, left_index) const << Risc.reg_to_slot(original_source, const.register , left, left_index)
compiler.reset_regs compiler.reset_regs
return const return const
end end