dragging the extra through resets
as the binary the instruction is in may change when repositioning
This commit is contained in:
parent
ddd408e245
commit
6f0fad0957
@ -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
|
||||
# and branch to it.
|
||||
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
|
||||
|
||||
def translate_IsPlus( code )
|
||||
|
@ -28,7 +28,7 @@ module Parfait
|
||||
if Risc::Position.set?(self)
|
||||
Risc::Position.log.debug "extending one in #{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
|
||||
|
||||
|
@ -11,7 +11,15 @@ module Risc
|
||||
attr_reader :label
|
||||
|
||||
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
|
||||
alias :inspect :to_s
|
||||
|
||||
|
@ -14,7 +14,7 @@ module Risc
|
||||
# fire events for changed pc and register contents
|
||||
include Util::Eventable
|
||||
include Util::Logging
|
||||
log_level :info
|
||||
log_level :debug
|
||||
|
||||
attr_reader :instruction , :clock , :pc # current instruction and pc
|
||||
attr_reader :registers # the registers, 16 (a hash, sym -> contents)
|
||||
@ -48,13 +48,12 @@ module Risc
|
||||
def set_pc( pos )
|
||||
raise "Not int #{pos}" unless pos.is_a? Numeric
|
||||
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)
|
||||
log.debug "Setting Position #{clock}-#{position}, #{position.method}"
|
||||
return set_pc(position.at + Parfait::BinaryCode.offset)
|
||||
else
|
||||
log.debug "Setting Position #{clock}-#{position}, #{position.binary}"
|
||||
raise "Setting Code #{clock}-#{position}, #{position.method}"
|
||||
#return set_pc(position.at + Parfait::BinaryCode.offset)
|
||||
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)
|
||||
set_instruction( position.instruction )
|
||||
@clock += 1
|
||||
|
@ -33,7 +33,8 @@ module Risc
|
||||
def translate(code)
|
||||
case code
|
||||
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
|
||||
const = code.constant
|
||||
const = const.to_cpu(self) if const.is_a?(Label)
|
||||
|
@ -58,9 +58,9 @@ module Risc
|
||||
# in measures
|
||||
#
|
||||
# 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}"
|
||||
position.reset_to(to)
|
||||
position.reset_to(to, extra)
|
||||
if testing = @reverse_cache[ to ]
|
||||
if testing.class != position.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)
|
||||
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}"
|
||||
testing = self.at( pos )
|
||||
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
|
||||
self.positions[object] = position
|
||||
position.init(pos)
|
||||
position.init(pos , extra)
|
||||
@reverse_cache[position.at] = position unless object.is_a? Label
|
||||
log.debug "Set #{position} (#{pos.to_s(16)}) for #{position.class}"
|
||||
position
|
||||
|
@ -22,9 +22,9 @@ module Risc
|
||||
"0x#{@at.to_s(16)}"
|
||||
end
|
||||
# just a callback after creation AND insertion
|
||||
def init(pos)
|
||||
def init(pos , is_nil)
|
||||
end
|
||||
def reset_to(pos)
|
||||
def reset_to(pos , guaranteed_nil )
|
||||
return false if pos == at
|
||||
if((at - pos).abs > 1000)
|
||||
raise "position set too far off #{pos}!=#{at} for #{object}:#{object.class}"
|
||||
|
@ -13,16 +13,6 @@ module Risc
|
||||
pos = Position.set( @binary , 0 , @method)
|
||||
assert_equal Position::CodePosition , pos.class
|
||||
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
|
||||
pos = Position.set( @binary , 0 , @method)
|
||||
assert_equal "Word_Type" , pos.method.for_type.name
|
||||
@ -33,4 +23,24 @@ module Risc
|
||||
assert_equal "Integer_Type" , type.name
|
||||
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
|
||||
|
Loading…
Reference in New Issue
Block a user