start on redoing instruction positions
using insruction listeners (wip)
This commit is contained in:
@ -14,11 +14,10 @@ module Risc
|
||||
# When propagating positions we have to see that the next position assembles into
|
||||
# the same BinaryCode, or else move it and the code along
|
||||
#
|
||||
class InstructionPosition < ObjectPosition
|
||||
class InstructionListener
|
||||
attr_reader :instruction , :binary
|
||||
def initialize(instruction , binary)
|
||||
pos = 0
|
||||
super(instruction)
|
||||
@instruction = instruction
|
||||
@binary = binary
|
||||
end
|
||||
@ -50,21 +49,26 @@ module Risc
|
||||
|
||||
# initialize the dependency graph for instructions
|
||||
#
|
||||
# starting from the given instruction, create InstructionPositions
|
||||
# for it and the whole chain
|
||||
# starting from the given instruction, create ObjectPositions
|
||||
# for it and the whole chain. Then attach InstructionListeners
|
||||
# for dependency tracking. All positions are initialized with -1
|
||||
# and so setting the first will trigger a chain reaction
|
||||
#
|
||||
# Set the next created to be dependent on the previous
|
||||
def self.init( instruction , code)
|
||||
# return the position for the first instruction which may be used to
|
||||
# set all positions in the chain
|
||||
def self.init( instruction , code )
|
||||
first = nil
|
||||
while(instruction)
|
||||
position = InstructionPosition.new(instruction , code)
|
||||
position = ObjectPosition.new(instruction , -1)
|
||||
first = position unless first
|
||||
nekst = instruction.next
|
||||
if nekst
|
||||
listener = InstructionListener.new( nekst )
|
||||
listener = InstructionListener.new( nekst , code )
|
||||
position.register_event(:position_changed , listener)
|
||||
end
|
||||
instruction = nekst
|
||||
end
|
||||
position
|
||||
first
|
||||
end
|
||||
end
|
||||
end
|
@ -12,10 +12,17 @@ module Risc
|
||||
# Give an integer as the actual position, where -1
|
||||
# which means no legal position known
|
||||
def initialize(object , pos )
|
||||
@at = 0
|
||||
@at = pos
|
||||
@object = object
|
||||
Position.set_to(self , pos)
|
||||
end
|
||||
|
||||
#look for InstructionListener and return its code if found
|
||||
def get_code
|
||||
listener = event_table.find{|one| one.class == InstructionListener}
|
||||
return nil unless listener
|
||||
listener.code
|
||||
end
|
||||
def +(offset)
|
||||
offset = offset.at if offset.is_a?(ObjectPosition)
|
||||
@at + offset
|
||||
|
@ -57,7 +57,7 @@ module Risc
|
||||
end
|
||||
|
||||
def self.set_to( position , to)
|
||||
postest = Position.positions[position.object]
|
||||
postest = Position.positions[position.object] unless to < 0
|
||||
raise "Mismatch #{position}" if postest and postest != position
|
||||
@reverse_cache.delete(position.at) unless position.object.is_a? Label
|
||||
testing = self.at( position.at ) if position.at >= 0
|
||||
@ -73,5 +73,5 @@ module Risc
|
||||
end
|
||||
require_relative "object_position"
|
||||
require_relative "object_listener"
|
||||
require_relative "instruction_position"
|
||||
require_relative "instruction_listener"
|
||||
require_relative "code_listener"
|
||||
|
Reference in New Issue
Block a user