diff --git a/lib/risc/position/code_listener.rb b/lib/risc/position/code_listener.rb index 3eaba0e4..f5f511fc 100644 --- a/lib/risc/position/code_listener.rb +++ b/lib/risc/position/code_listener.rb @@ -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 diff --git a/test/risc/position/test_code_listener.rb b/test/risc/position/test_code_listener.rb index 545ac7fc..d8bff78b 100644 --- a/test/risc/position/test_code_listener.rb +++ b/test/risc/position/test_code_listener.rb @@ -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 diff --git a/test/risc/position/test_code_listener1.rb b/test/risc/position/test_code_listener1.rb index ea46ee25..0de1f523 100644 --- a/test/risc/position/test_code_listener1.rb +++ b/test/risc/position/test_code_listener1.rb @@ -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