code listener now get platform explicitly
used to grab it from global machine. Now passed in from linker tests fixed accordingly
This commit is contained in:
parent
8952b39446
commit
07a154be70
@ -9,9 +9,14 @@ module Risc
|
||||
#
|
||||
class CodeListener
|
||||
|
||||
# need to pass the platform to translate new jumps
|
||||
def initialize(platform)
|
||||
@platform = Risc::Platform.for(platform)
|
||||
end
|
||||
|
||||
def position_inserted(position)
|
||||
Position.log.debug "extending one at #{position}"
|
||||
pos = CodeListener.init( position.object.next )
|
||||
pos = CodeListener.init( position.object.next , @platform)
|
||||
return unless position.valid?
|
||||
puts "insert #{position.object.next.object_id.to_s(16)}" unless position.valid?
|
||||
pos.set( position + position.object.padded_length)
|
||||
@ -43,7 +48,7 @@ module Risc
|
||||
code = position.object
|
||||
return unless code.next #dont jump beyond and
|
||||
jump = Branch.new("BinaryCode #{at.to_s(16)}" , code.next)
|
||||
translator = Risc.machine.platform.translator
|
||||
translator = @platform.translator
|
||||
cpu_jump = translator.translate(jump)
|
||||
pos = at + code.padded_length - cpu_jump.byte_length
|
||||
Position.create(cpu_jump).set(pos)
|
||||
@ -51,14 +56,15 @@ module Risc
|
||||
end
|
||||
|
||||
# Create Position for the given BinaryCode object
|
||||
# second param is the platform, needed to translate new jumps
|
||||
# return the first position that was created, to set it
|
||||
def self.init( code )
|
||||
def self.init( code , platform)
|
||||
first = nil
|
||||
while code
|
||||
raise "Not Binary Code #{code.class}" unless code.is_a?(Parfait::BinaryCode)
|
||||
position = Position.get_or_create(code)
|
||||
first = position unless first
|
||||
position.position_listener(CodeListener.new)
|
||||
position.position_listener(CodeListener.new(platform))
|
||||
code = code.next
|
||||
end
|
||||
first
|
||||
|
@ -10,22 +10,22 @@ module Risc
|
||||
end
|
||||
|
||||
def test_has_init
|
||||
pos = CodeListener.init(@binary)
|
||||
pos = CodeListener.init(@binary,:interpreter)
|
||||
assert_equal pos, Position.get(@binary)
|
||||
end
|
||||
def test_init_fail
|
||||
assert_raises{ CodeListener.init( @method)}
|
||||
end
|
||||
def test_init_returns_position
|
||||
assert_equal Position , CodeListener.init(@binary).class
|
||||
assert_equal Position , CodeListener.init(@binary , :interpreter).class
|
||||
end
|
||||
def test_not_init_listner
|
||||
pos = CodeListener.init(@binary)
|
||||
pos = CodeListener.init(@binary,:interpreter)
|
||||
assert CodeListener == pos.event_table[:position_changed].last.class
|
||||
end
|
||||
def test_init_listner
|
||||
@binary.extend_one
|
||||
CodeListener.init(@binary)
|
||||
CodeListener.init(@binary, :interpreter)
|
||||
pos = Position.get(@binary)
|
||||
assert_equal CodeListener , pos.event_table[:position_changed].first.class
|
||||
end
|
||||
|
@ -4,31 +4,31 @@ module Risc
|
||||
class TestCodeListenerFull < MiniTest::Test
|
||||
def setup
|
||||
Parfait.boot!
|
||||
@machine = Risc.machine.boot
|
||||
Risc.boot!
|
||||
@linker = Mom::MomCompiler.new.translate(:interpreter)
|
||||
@binary = Parfait::BinaryCode.new(1)
|
||||
@method = Parfait.object_space.types.values.first.methods
|
||||
@label = Risc.label("hi","ho")
|
||||
@machine.translate(:interpreter)
|
||||
@machine.position_all
|
||||
@linker.position_all
|
||||
end
|
||||
def test_listener_after_extend
|
||||
CodeListener.init(@binary).set(10)
|
||||
CodeListener.init(@binary,:interpreter).set(10)
|
||||
@binary.extend_one
|
||||
pos = Position.get(@binary.next)
|
||||
assert_equal CodeListener , pos.event_table[:position_changed].first.class
|
||||
end
|
||||
def test_valid_pos_for_extended
|
||||
@binary.extend_one
|
||||
CodeListener.init(@binary).set(10)
|
||||
CodeListener.init(@binary,:interpreter).set(10)
|
||||
assert Position.get(@binary.next).valid?
|
||||
end
|
||||
def test_extend_sets_next_pos
|
||||
CodeListener.init(@binary).set(10)
|
||||
CodeListener.init(@binary,:interpreter).set(10)
|
||||
@binary.extend_one
|
||||
assert Position.get(@binary.next).valid?
|
||||
end
|
||||
def test_extends_creates_jump
|
||||
CodeListener.init(@binary).set(10)
|
||||
CodeListener.init(@binary,:interpreter).set(10)
|
||||
assert_equal 0 , @binary.get_last
|
||||
@binary.extend_one
|
||||
assert 0 != @binary.get_last
|
||||
|
Loading…
Reference in New Issue
Block a user