fix label positioning bug
where a label at the end of a binary code resulted in the label actually taking up a position, instead of sharing it with it's next
This commit is contained in:
parent
0513cd504f
commit
e1683938ed
@ -25,11 +25,11 @@ module Risc
|
|||||||
# Taking into account that BinaryCodes only take 13 instructions,
|
# Taking into account that BinaryCodes only take 13 instructions,
|
||||||
# meaning that chain may have to be extended
|
# meaning that chain may have to be extended
|
||||||
def position_changing(position , to)
|
def position_changing(position , to)
|
||||||
Position.log.debug "Changing #{position} to #{to.to_s(16)}, bin #{Position.get(@binary)}"
|
Position.log.debug "Changing #{position} to 0x#{to.to_s(16)}, bin #{Position.get(@binary)}"
|
||||||
update_index(to)
|
update_index(to)
|
||||||
instruction = position.object
|
instruction = position.object
|
||||||
return unless instruction.next
|
return unless instruction.next
|
||||||
if @index == (Parfait::BinaryCode.data_length - 1 )
|
if @index == (Parfait::BinaryCode.data_length - 1 ) and !instruction.is_a?(Label)
|
||||||
nekst_pos_diff = @binary.padded_length
|
nekst_pos_diff = @binary.padded_length
|
||||||
else
|
else
|
||||||
nekst_pos_diff = @index * 4 + instruction.byte_length
|
nekst_pos_diff = @index * 4 + instruction.byte_length
|
||||||
|
@ -33,5 +33,31 @@ module Risc
|
|||||||
@position.set(12)
|
@position.set(12)
|
||||||
assert_equal 80 , Position.get(@instruction.last).at
|
assert_equal 80 , Position.get(@instruction.last).at
|
||||||
end
|
end
|
||||||
|
def test_label_last_in_binary
|
||||||
|
before = get(11)
|
||||||
|
assert_equal 52 , Position.get(before).at
|
||||||
|
label = Label.new("HI","Ho" , FakeAddress.new(0))
|
||||||
|
before.insert( label )
|
||||||
|
assert_equal 56 , Position.get(label).at
|
||||||
|
label
|
||||||
|
end
|
||||||
|
def test_after_last_label
|
||||||
|
after = get(12)
|
||||||
|
label = test_label_last_in_binary
|
||||||
|
assert_equal 56 , Position.get(label).at
|
||||||
|
assert_equal 56 , Position.get(after).at
|
||||||
|
assert_equal label.next , after
|
||||||
|
end
|
||||||
|
def test_but_last
|
||||||
|
assert_equal 56 , Position.get(get(12)).at
|
||||||
|
end
|
||||||
|
def get(n)
|
||||||
|
ins = @instruction
|
||||||
|
while( n > 0 )
|
||||||
|
ins = ins.next
|
||||||
|
n -= 1
|
||||||
|
end
|
||||||
|
ins
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -2,22 +2,28 @@ require_relative "helper"
|
|||||||
|
|
||||||
module Risc
|
module Risc
|
||||||
class TestMachinePositions < MiniTest::Test
|
class TestMachinePositions < MiniTest::Test
|
||||||
def setup
|
def setup_for(platform)
|
||||||
@machine = Risc.machine.boot
|
@machine = Risc.machine.boot
|
||||||
|
@machine.translate(platform)
|
||||||
|
@machine.position_all
|
||||||
end
|
end
|
||||||
def test_cpu_init
|
def test_cpu_init
|
||||||
@machine.translate(:interpreter)
|
setup_for(:interpreter)
|
||||||
@machine.position_all
|
|
||||||
assert Position.get @machine.cpu_init
|
assert Position.get @machine.cpu_init
|
||||||
end
|
end
|
||||||
def test_cpu_label
|
def test_cpu_label
|
||||||
@machine.translate(:interpreter)
|
setup_for(:interpreter)
|
||||||
@machine.position_all
|
|
||||||
assert Position.get( @machine.cpu_init.label )
|
assert Position.get( @machine.cpu_init.label )
|
||||||
end
|
end
|
||||||
|
def test_label_positions_match
|
||||||
|
setup_for(:interpreter)
|
||||||
|
Position.positions.each do |object , position|
|
||||||
|
next unless object.is_a?(Label) and object.next
|
||||||
|
assert_equal position.at , Position.get(object.next).at
|
||||||
|
end
|
||||||
|
end
|
||||||
def test_cpu_first_arm
|
def test_cpu_first_arm
|
||||||
@machine.translate(:arm)
|
setup_for(:arm)
|
||||||
@machine.position_all
|
|
||||||
assert Position.get( @machine.cpu_init.first )
|
assert Position.get( @machine.cpu_init.first )
|
||||||
end
|
end
|
||||||
def test_has_arm_pos
|
def test_has_arm_pos
|
||||||
@ -27,8 +33,7 @@ module Risc
|
|||||||
has_positions(:interpreter)
|
has_positions(:interpreter)
|
||||||
end
|
end
|
||||||
def has_positions(platform)
|
def has_positions(platform)
|
||||||
@machine.translate(:arm)
|
setup_for(platform)
|
||||||
@machine.position_all
|
|
||||||
@machine.objects.each do |id,obj|
|
@machine.objects.each do |id,obj|
|
||||||
assert Position.get(obj)
|
assert Position.get(obj)
|
||||||
end
|
end
|
||||||
@ -40,8 +45,7 @@ module Risc
|
|||||||
meth_positions(:interpreter)
|
meth_positions(:interpreter)
|
||||||
end
|
end
|
||||||
def meth_positions(platform)
|
def meth_positions(platform)
|
||||||
@machine.translate(:arm)
|
setup_for(platform)
|
||||||
@machine.position_all
|
|
||||||
Parfait.object_space.each_type do |type|
|
Parfait.object_space.each_type do |type|
|
||||||
type.each_method do |method|
|
type.each_method do |method|
|
||||||
assert Position.get(method.binary)
|
assert Position.get(method.binary)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user