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:
Torsten Ruger
2018-07-02 09:39:07 +03:00
parent 8952b39446
commit 07a154be70
3 changed files with 21 additions and 15 deletions

View File

@ -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