From 6e901e171885b975932664a17ab443d65961c21b Mon Sep 17 00:00:00 2001 From: Torsten Ruger Date: Thu, 22 Mar 2018 18:45:03 +0200 Subject: [PATCH] allow setting the source for slot loads so we can track more exactly which instruction created the risc --- lib/mom/instruction/argument_transfer.rb | 2 +- lib/mom/instruction/message_setup.rb | 6 +++--- lib/mom/instruction/return_sequence.rb | 2 +- lib/mom/instruction/simple_call.rb | 2 +- lib/mom/instruction/slot_load.rb | 16 +++++++++------- 5 files changed, 15 insertions(+), 13 deletions(-) diff --git a/lib/mom/instruction/argument_transfer.rb b/lib/mom/instruction/argument_transfer.rb index ec88cd4d..6c546d2a 100644 --- a/lib/mom/instruction/argument_transfer.rb +++ b/lib/mom/instruction/argument_transfer.rb @@ -29,7 +29,7 @@ module Mom end 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 @arguments.each do |arg| transfer << arg.to_risc(compiler) diff --git a/lib/mom/instruction/message_setup.rb b/lib/mom/instruction/message_setup.rb index d011b440..7b5c8570 100644 --- a/lib/mom/instruction/message_setup.rb +++ b/lib/mom/instruction/message_setup.rb @@ -24,11 +24,11 @@ module Mom # Move method name, frame and arguemnt types from the method to the neext_message # Assumes the message is ready, see class description 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) - 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) - 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) end diff --git a/lib/mom/instruction/return_sequence.rb b/lib/mom/instruction/return_sequence.rb index 9cd02b03..4003bea4 100644 --- a/lib/mom/instruction/return_sequence.rb +++ b/lib/mom/instruction/return_sequence.rb @@ -20,7 +20,7 @@ module Mom # class ReturnSequence < Instruction 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) caller_reg = compiler.use_reg(:int) return_reg = compiler.use_reg(:int) diff --git a/lib/mom/instruction/simple_call.rb b/lib/mom/instruction/simple_call.rb index d4dab021..c2fa339c 100644 --- a/lib/mom/instruction/simple_call.rb +++ b/lib/mom/instruction/simple_call.rb @@ -22,7 +22,7 @@ module Mom def to_risc(compiler) jump_address = compiler.use_reg(:int) 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 << Risc.slot_to_reg(self, :message , :next_message , Risc.message_reg) moves << Risc.load_constant(self , method.binary , jump_address) diff --git a/lib/mom/instruction/slot_load.rb b/lib/mom/instruction/slot_load.rb index faba209d..12153971 100644 --- a/lib/mom/instruction/slot_load.rb +++ b/lib/mom/instruction/slot_load.rb @@ -22,18 +22,20 @@ module Mom # SlotDefinition (see there) # # @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 - attr_reader :left , :right - def initialize(left , right) + attr_reader :left , :right , :original_source + def initialize(left , right, original_source = nil) @left , @right = left , right @left = SlotDefinition.new(@left.shift , @left) if @left.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 ) + @original_source = original_source || self end def to_risc(compiler) - const = @right.to_register(compiler , self) + const = @right.to_register(compiler , original_source) left_slots = @left.slots case @left.known_object when Symbol @@ -42,13 +44,13 @@ module Mom if left_slots.length > 1 # swap the existing target (with a new reg) and update the index 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_index = SlotLoad.resolve_to_index(left_slots[0] , left_slots[1] ,compiler) if left_slots.length > 2 #same again, once more updating target 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_index = SlotLoad.resolve_to_index(left_slots[1] , left_slots[2] ,compiler) end @@ -60,7 +62,7 @@ module Mom else raise "We have left #{@left.known_object}" 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 return const end