make the instructions jump over the BinaryCode end
This commit is contained in:
@ -24,15 +24,16 @@ module Risc
|
||||
# Taking into account that BinaryCodes only take 13 instructions,
|
||||
# meaning that chain may have to be extended
|
||||
def position_changed(position)
|
||||
fix_binary
|
||||
my_pos = Position.get(@instruction)
|
||||
next_pos = position.at + position.object.byte_length
|
||||
fix_binary_for(next_pos)
|
||||
my_pos = Position.get(@instruction)
|
||||
diff = next_pos - Position.get(@binary).at
|
||||
Position.log.debug "Diff: #{diff.to_s(16)} , next #{next_pos.to_s(16)} , binary #{Position.get(@binary)}"
|
||||
Position.log.debug "Diff: 0x#{diff.to_s(16)} , next 0x#{next_pos.to_s(16)} , binary #{Position.get(@binary)}"
|
||||
raise "Invalid position #{diff.to_s(16)} , next #{next_pos.to_s(16)} #{position}" if diff < 8
|
||||
if( (diff % (@binary.padded_length - @instruction.byte_length)) == 0 )
|
||||
@binary = @binary.ensure_next
|
||||
next_pos = Position.get(@binary).at + Parfait::BinaryCode.byte_offset
|
||||
#Insert/Position the jump (its missing)
|
||||
Position.log.debug "Jump to: #{next_pos.to_s(16)}"
|
||||
end
|
||||
my_pos.set(next_pos)
|
||||
@ -66,24 +67,26 @@ module Risc
|
||||
|
||||
# check that the binary we use is the one where the current position falls
|
||||
# if not move up and register/unregister (soon)
|
||||
def fix_binary
|
||||
#
|
||||
# Because the position for the @instruction may not be set yet,
|
||||
# we use the one that it will be set to (the arg)
|
||||
def fix_binary_for(new_pos)
|
||||
raise "Binary has no position (-1)" if Position.get(@binary).at == -1
|
||||
return if Position.get(@instruction).at == -1
|
||||
count = 0
|
||||
org_pos = Position.get(@binary)
|
||||
return if org_pos.at == -1
|
||||
while( !pos_in_binary)
|
||||
bin_pos = Position.get(@binary)
|
||||
while( !pos_in_binary(new_pos))
|
||||
@binary = @binary.ensure_next
|
||||
count += 1
|
||||
raise "Positions messed #{Position.get(@instruction)}:#{org_pos}"
|
||||
raise "Positions too far out (#{count}) #{Position.get(@instruction)}:#{bin_pos}" if count > 5
|
||||
end
|
||||
end
|
||||
|
||||
def pos_in_binary
|
||||
me = Position.get(@instruction)
|
||||
# check if the given position is inside the @binary
|
||||
# ie not below start or above end
|
||||
def pos_in_binary(new_pos)
|
||||
bin = Position.get(@binary)
|
||||
return false if me < bin
|
||||
return false if me > (bin + @binary.padded_length)
|
||||
return false if bin > new_pos
|
||||
return false if new_pos > (bin + @binary.padded_length)
|
||||
return true
|
||||
end
|
||||
|
||||
|
@ -108,6 +108,12 @@ module Risc
|
||||
"0x#{@at.to_s(16)}"
|
||||
end
|
||||
|
||||
def object_class
|
||||
return :object if @object.is_a?(Parfait::Object)
|
||||
return :object if @object.class.name.include?("Test")
|
||||
:instruction
|
||||
end
|
||||
|
||||
def next_slot
|
||||
return -1 if at < 0
|
||||
self.log.debug "Next Slot @#{at.to_s(16)} for #{object.class} == #{(at + object.byte_length).to_s(16)}"
|
||||
@ -159,12 +165,12 @@ module Risc
|
||||
raise "Mismatch #{position}" if postest and postest != position
|
||||
@reverse_cache.delete(position.at) unless position.object.is_a?(Label)
|
||||
testing = self.at( position.at ) unless position.at < 0
|
||||
if testing and testing.object.class != position.object.class
|
||||
raise "Mismatch (at #{to.to_s(16)}) was:#{position} #{position.class} #{position.object} , should #{testing}#{testing.class}"
|
||||
if testing and testing.object_class != position.object_class
|
||||
raise "Mismatch (at #{to.to_s(16)}) new:#{position} #{position.object.class} , was:#{testing}#{testing.object.class}"
|
||||
end
|
||||
self.positions[position.object] = position
|
||||
@reverse_cache[to] = position unless position.object.is_a?(Label)
|
||||
log.debug "Set #{position} (#{to.to_s(16)}) for #{position.object.class} #{position.object.object_id.to_s(16)}"
|
||||
log.debug "Set #{position} to 0x#{to.to_s(16)} for #{position.object.class} #{position.object.object_id.to_s(16)}"
|
||||
position
|
||||
end
|
||||
end
|
||||
|
Reference in New Issue
Block a user