rework binary code positioning setup

dependency chain set up explicitly.
Next have to react to events correctly
This commit is contained in:
Torsten Ruger 2018-06-02 17:29:38 +03:00
parent 91c7903848
commit 3bc35c2275
5 changed files with 30 additions and 9 deletions

View File

@ -117,12 +117,19 @@ module Risc
# #
# start at code_start. # start at code_start.
def position_code(code_start) def position_code(code_start)
first_method = Parfait.object_space.types.values.first.methods prev = nil
before = code_start Parfait.object_space.types.values.each do |type|
Position.set( first_method.binary , code_start , first_method) next unless type.methods
Position.set( first_method.cpu_instructions, code_start + Parfait::BinaryCode.byte_offset , first_method.binary) type.methods.each_method do |method|
log.debug "Method #{first_method.name}:#{before.to_s(16)} len: #{(code_start - before).to_s(16)}" last = Position::CodeListener.init(method.binary , code_start)
log.debug "Instructions #{first_method.cpu_instructions.object_id.to_s(16)}:#{(before+Parfait::BinaryCode.byte_offset).to_s(16)}" last.register_event(:position_changed , prev.object) if prev
prev = last
code_start = last.next_slot
end
end
#Position.set( first_method.cpu_instructions, code_start + Parfait::BinaryCode.byte_offset , first_method.binary)
#log.debug "Method #{first_method.name}:#{before.to_s(16)} len: #{(code_start - before).to_s(16)}"
#log.debug "Instructions #{first_method.cpu_instructions.object_id.to_s(16)}:#{(before+Parfait::BinaryCode.byte_offset).to_s(16)}"
end end
# Create Binary code for all methods and the initial jump # Create Binary code for all methods and the initial jump

View File

@ -72,6 +72,7 @@ module Risc
at += code.padded_length unless at < 0 at += code.padded_length unless at < 0
code = code.next code = code.next
end end
position
end end
end end
end end

View File

@ -40,6 +40,10 @@ module Risc
trigger(:position_changed , self) trigger(:position_changed , self)
true true
end end
def next_slot
return -1 if at < 0
at + object.byte_length
end
def self.init(object , at = -1) def self.init(object , at = -1)
position = ObjectPosition.new(object , at) position = ObjectPosition.new(object , at)
Position.set_to( position , at) Position.set_to( position , at)

View File

@ -12,8 +12,12 @@ module Risc
end end
def test_has_init def test_has_init
CodeListener.init(@binary) pos = CodeListener.init(@binary)
assert Position.get(@binary) assert_equal pos, Position.get(@binary)
end
def test_init_returns_position
assert_equal Position::ObjectPosition , CodeListener.init(@binary).class
end end
def test_init_listner def test_init_listner
@binary.extend_one @binary.extend_one

View File

@ -6,7 +6,12 @@ module Risc
class TestPositionBasic < MiniTest::Test class TestPositionBasic < MiniTest::Test
def test_init def test_init
assert_equal ObjectPosition.init(self) assert ObjectPosition.init(self , -1)
end
def test_next_slot
mov = Arm::ArmMachine.mov(:r1 , :r1)
position = ObjectPosition.new(mov , 0)
assert_equal 4, position.next_slot
end end
def pest_creation_ok def pest_creation_ok
assert ObjectPosition.new(self,0) assert ObjectPosition.new(self,0)