fix the gapping of instructions
so last binary stays empty and new starts at 8
This commit is contained in:
parent
4ab6d62acf
commit
4789b63fcb
@ -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)
|
||||
|
@ -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)
|
||||
|
@ -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
|
||||
|
@ -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)
|
||||
|
Loading…
x
Reference in New Issue
Block a user