dragging the extra through resets

as the binary the instruction is in may change when repositioning
This commit is contained in:
Torsten Ruger 2018-05-25 19:04:48 +03:00
parent ddd408e245
commit 6f0fad0957
8 changed files with 45 additions and 26 deletions

View File

@ -108,7 +108,8 @@ module Arm
# The only target for a call is a Block, so we just need to get the address for the code # The only target for a call is a Block, so we just need to get the address for the code
# and branch to it. # and branch to it.
def translate_Branch( code ) def translate_Branch( code )
ArmMachine.b( code.label.to_cpu(self) ) target = code.label.is_a?(Risc::Label) ? code.label.to_cpu(self) : code.label
ArmMachine.b( target )
end end
def translate_IsPlus( code ) def translate_IsPlus( code )

View File

@ -28,7 +28,7 @@ module Parfait
if Risc::Position.set?(self) if Risc::Position.set?(self)
Risc::Position.log.debug "extending one in #{self}" Risc::Position.log.debug "extending one in #{self}"
my_pos = Risc::Position.get(self) my_pos = Risc::Position.get(self)
Risc::Position.reset(my_pos , my_pos.at) Risc::Position.reset(my_pos , my_pos.at , my_pos.method)
end end
end end

View File

@ -11,7 +11,15 @@ module Risc
attr_reader :label attr_reader :label
def to_s def to_s
class_source "#{label ? label.name : '(no label)'}" case label
when Label
str = label.name
when Parfait::BinaryCode
str = "Code"
else
str = "(no label)"
end
class_source( str )
end end
alias :inspect :to_s alias :inspect :to_s

View File

@ -14,7 +14,7 @@ module Risc
# fire events for changed pc and register contents # fire events for changed pc and register contents
include Util::Eventable include Util::Eventable
include Util::Logging include Util::Logging
log_level :info log_level :debug
attr_reader :instruction , :clock , :pc # current instruction and pc attr_reader :instruction , :clock , :pc # current instruction and pc
attr_reader :registers # the registers, 16 (a hash, sym -> contents) attr_reader :registers # the registers, 16 (a hash, sym -> contents)
@ -48,13 +48,12 @@ module Risc
def set_pc( pos ) def set_pc( pos )
raise "Not int #{pos}" unless pos.is_a? Numeric raise "Not int #{pos}" unless pos.is_a? Numeric
position = Position.at(pos) position = Position.at(pos)
raise "No position #{pos}" unless position raise "No position #{pos.to_s(16)}" unless position
if position.is_a?(Position::CodePosition) if position.is_a?(Position::CodePosition)
log.debug "Setting Position #{clock}-#{position}, #{position.method}" raise "Setting Code #{clock}-#{position}, #{position.method}"
return set_pc(position.at + Parfait::BinaryCode.offset) #return set_pc(position.at + Parfait::BinaryCode.offset)
else
log.debug "Setting Position #{clock}-#{position}, #{position.binary}"
end end
log.debug "Setting Position #{clock}-#{position}, #{position.binary}"
raise "not instruction position #{position}-#{position.class}-#{position.object.class}" unless position.is_a?(Position::InstructionPosition) raise "not instruction position #{position}-#{position.class}-#{position.object.class}" unless position.is_a?(Position::InstructionPosition)
set_instruction( position.instruction ) set_instruction( position.instruction )
@clock += 1 @clock += 1

View File

@ -33,7 +33,8 @@ module Risc
def translate(code) def translate(code)
case code case code
when Branch when Branch
ret = code.class.new(code.source , code.label.to_cpu(self)) new_label = code.label.is_a?(Label) ? code.label.to_cpu(self) : code.label
ret = code.class.new(code.source , new_label)
when LoadConstant when LoadConstant
const = code.constant const = code.constant
const = const.to_cpu(self) if const.is_a?(Label) const = const.to_cpu(self) if const.is_a?(Label)

View File

@ -58,9 +58,9 @@ module Risc
# in measures # in measures
# #
# reseting to the same position as before, triggers code that propagates # reseting to the same position as before, triggers code that propagates
def self.reset(position , to) def self.reset(position , to , extra)
log.debug "ReSetting #{position}, to:#{to.to_s(16)}, for #{position.object.class}-#{position.object}" log.debug "ReSetting #{position}, to:#{to.to_s(16)}, for #{position.object.class}-#{position.object}"
position.reset_to(to) position.reset_to(to, extra)
if testing = @reverse_cache[ to ] if testing = @reverse_cache[ to ]
if testing.class != position.class if testing.class != position.class
raise "Mismatch (at #{to.to_s(16)}) new:#{position}:#{position.class} , was #{testing}:#{testing.class}" raise "Mismatch (at #{to.to_s(16)}) new:#{position}:#{position.class} , was #{testing}:#{testing.class}"
@ -76,13 +76,13 @@ module Risc
def self.set( object , pos , extra = nil) def self.set( object , pos , extra = nil)
old = Position.positions[object] old = Position.positions[object]
return self.reset(old , pos) if old return self.reset(old , pos , extra) if old
log.debug "Setting #{pos.to_s(16)} for #{object.class}-#{object}" log.debug "Setting #{pos.to_s(16)} for #{object.class}-#{object}"
testing = self.at( pos ) testing = self.at( pos )
position = for_at( object , pos , extra) position = for_at( object , pos , extra)
raise "Mismatch (at #{pos.to_s(16)}) was:#{position} #{position.class} #{position.object} , should #{testing}#{testing.class}" if testing and testing.class != position.class raise "Mismatch (at #{pos.to_s(16)}) was:#{position} #{position.class} #{position.object} , should #{testing}#{testing.class}" if testing and testing.class != position.class
self.positions[object] = position self.positions[object] = position
position.init(pos) position.init(pos , extra)
@reverse_cache[position.at] = position unless object.is_a? Label @reverse_cache[position.at] = position unless object.is_a? Label
log.debug "Set #{position} (#{pos.to_s(16)}) for #{position.class}" log.debug "Set #{position} (#{pos.to_s(16)}) for #{position.class}"
position position

View File

@ -22,9 +22,9 @@ module Risc
"0x#{@at.to_s(16)}" "0x#{@at.to_s(16)}"
end end
# just a callback after creation AND insertion # just a callback after creation AND insertion
def init(pos) def init(pos , is_nil)
end end
def reset_to(pos) def reset_to(pos , guaranteed_nil )
return false if pos == at return false if pos == at
if((at - pos).abs > 1000) if((at - pos).abs > 1000)
raise "position set too far off #{pos}!=#{at} for #{object}:#{object.class}" raise "position set too far off #{pos}!=#{at} for #{object}:#{object.class}"

View File

@ -13,16 +13,6 @@ module Risc
pos = Position.set( @binary , 0 , @method) pos = Position.set( @binary , 0 , @method)
assert_equal Position::CodePosition , pos.class assert_equal Position::CodePosition , pos.class
end end
def test_bin_propagates_existing
@binary.extend_to(16)
Position.set( @binary , 0 , @method)
assert_equal @binary.padded_length , Position.get(@binary.next).at
end
def test_bin_propagates_after
Position.set( @binary , 0 , Parfait.object_space.get_main)
@binary.extend_to(16)
assert_equal @binary.padded_length , Position.get(@binary.next).at
end
def test_type def test_type
pos = Position.set( @binary , 0 , @method) pos = Position.set( @binary , 0 , @method)
assert_equal "Word_Type" , pos.method.for_type.name assert_equal "Word_Type" , pos.method.for_type.name
@ -33,4 +23,24 @@ module Risc
assert_equal "Integer_Type" , type.name assert_equal "Integer_Type" , type.name
end end
end end
class TestPositionTranslated < MiniTest::Test
def setup
machine = Risc.machine.boot
machine.translate(:interpreter)
@binary = Parfait::BinaryCode.new(1)
@method = Parfait.object_space.types.values.first.methods
@label = Label.new("hi","ho")
end
def test_bin_propagates_existing
@binary.extend_to(16)
Position.set( @binary , 0 , @method)
assert_equal @binary.padded_length , Position.get(@binary.next).at
end
def test_bin_propagates_after
Position.set( @binary , 0 , Parfait.object_space.get_main)
@binary.extend_to(16)
assert_equal @binary.padded_length , Position.get(@binary.next).at
end
end
end end