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