From 4789b63fcb1ce01cf58fad081122409c7d441374 Mon Sep 17 00:00:00 2001 From: Torsten Ruger Date: Wed, 6 Jun 2018 01:16:00 +0300 Subject: [PATCH] fix the gapping of instructions so last binary stays empty and new starts at 8 --- lib/risc/position/instruction_listener.rb | 31 +++++++------------ lib/risc/position/position.rb | 4 +++ .../position/test_instruction_listener.rb | 1 + test/risc/position/test_position.rb | 3 ++ 4 files changed, 19 insertions(+), 20 deletions(-) diff --git a/lib/risc/position/instruction_listener.rb b/lib/risc/position/instruction_listener.rb index c783e146..02ac01c0 100644 --- a/lib/risc/position/instruction_listener.rb +++ b/lib/risc/position/instruction_listener.rb @@ -18,35 +18,26 @@ module Risc @instruction = instruction @binary = binary end - def old_code(at, binary) - @binary = binary - instruction.address.set_value(at) if instruction.is_a?(Label) - return if at == 0 and binary.nil? - raise "faux pas" if at < Position.get(binary).at - return unless @instruction.next - nekst = at + @instruction.byte_length - diff = nekst - Position.get(@binary).at - Position.log.debug "Diff: #{diff.to_s(16)} , next #{nekst.to_s(16)} , binary #{Position.get(@binary)}" - raise "Invalid position #{diff.to_s(16)} , next #{nekst.to_s(16)} #{self}" if diff < 8 - if( (diff % (binary.padded_length - @instruction.byte_length)) == 0 ) - binary.extend_one unless binary.next - binary = binary.next - raise "end of line " unless binary - nekst = Position.get(binary).at + Parfait::BinaryCode.byte_offset - Position.log.debug "Jump to: #{nekst.to_s(16)}" - end - Position.set(@instruction.next, nekst , binary) - end def position_changed(position) fix_binary my_pos = Position.get(@instruction) - my_pos.set(position.at + position.object.byte_length) + next_pos = position.at + position.object.byte_length + diff = next_pos - Position.get(@binary).at + Position.log.debug "Diff: #{diff.to_s(16)} , next #{next_pos.to_s(16)} , binary #{Position.get(@binary)}" + raise "Invalid position #{diff.to_s(16)} , next #{next_pos.to_s(16)} #{position}" if diff < 8 + if( (diff % (@binary.padded_length - @instruction.byte_length)) == 0 ) + @binary = @binary.ensure_next + next_pos = Position.get(@binary).at + Parfait::BinaryCode.byte_offset + Position.log.debug "Jump to: #{next_pos.to_s(16)}" + end + my_pos.set(next_pos) end # check that the binary we use is the one where the current position falls # if not move up and register/unregister (soon) def fix_binary + raise "Binary has no position (-1)" if Position.get(@binary).at == -1 return if Position.get(@instruction).at == -1 count = 0 org_pos = Position.get(@binary) diff --git a/lib/risc/position/position.rb b/lib/risc/position/position.rb index c25f5b85..3bbd2223 100644 --- a/lib/risc/position/position.rb +++ b/lib/risc/position/position.rb @@ -56,6 +56,10 @@ module Risc listener.code end + def valid? + @at != -1 + end + def set(int) return int if int == self.at Position.set_to(self , int) diff --git a/test/risc/position/test_instruction_listener.rb b/test/risc/position/test_instruction_listener.rb index cc807877..691742b7 100644 --- a/test/risc/position/test_instruction_listener.rb +++ b/test/risc/position/test_instruction_listener.rb @@ -23,6 +23,7 @@ module Risc assert_raises {InstructionListener.init(nil , @binary)} end def test_listener_method + @position.set(8) listener = InstructionListener.new( @instruction , @binary ) listener.position_changed(@position) end diff --git a/test/risc/position/test_position.rb b/test/risc/position/test_position.rb index fe228115..a17e00a2 100644 --- a/test/risc/position/test_position.rb +++ b/test/risc/position/test_position.rb @@ -10,6 +10,9 @@ module Risc def test_new assert @pos end + def test_invalid + assert !@pos.valid? + end def test_next_slot mov = Arm::ArmMachine.mov(:r1 , :r1) position = Position.new(mov , 0)