propagate instruction positions
still overlapping onto binaries, but a start
This commit is contained in:
@ -82,7 +82,7 @@ module Arm
|
||||
end
|
||||
def test_too_big_add
|
||||
code = @machine.add :r1 , :r1, 0x222
|
||||
Risc::Position.set(code,0,nil)
|
||||
Risc::Position.new(code,0)
|
||||
# add 0x02 (first instruction) and then 0x220 shifted
|
||||
assert_code code , :add , [0x02,0x1c,0x91,0xe2] #e2 91 1e 02
|
||||
# added extra instruction to add "extra"
|
||||
@ -90,15 +90,16 @@ module Arm
|
||||
end
|
||||
|
||||
def label( pos = 0x12 + 8)
|
||||
l = Risc::Label.new("some" , "Label" , FakeAddress.new(2))
|
||||
Risc::Position.set(l.address , 0x22 + 8)
|
||||
Risc::Position.set(l , pos , @binary)
|
||||
addr = Risc::Position.new(FakeAddress.new(2) , 2)
|
||||
l = Risc::Label.new("some" , "Label" , addr.object)
|
||||
Risc::Position.new(l , 0x22 + 8)
|
||||
#Risc::Position.set(l , pos , @binary)
|
||||
l
|
||||
end
|
||||
|
||||
def test_move_object
|
||||
code = @machine.add( :r1 , label)
|
||||
Risc::Position.set(code,0,@binary)
|
||||
Risc::Position.new(code,0)
|
||||
assert_code code , :add , [0x22,0x10,0x9f,0xe2] #e2 9f 10 22
|
||||
end
|
||||
|
||||
|
@ -26,6 +26,9 @@ module Parfait
|
||||
def test_data_length
|
||||
assert_equal 13 , @code.data_length
|
||||
end
|
||||
def test_padded_length
|
||||
assert_equal 16*4 , @code.padded_length
|
||||
end
|
||||
def test_byte_length
|
||||
assert_equal 13*4 , @code.byte_length
|
||||
end
|
||||
|
@ -5,8 +5,14 @@ module Risc
|
||||
def padded_length
|
||||
4
|
||||
end
|
||||
def byte_length
|
||||
4
|
||||
end
|
||||
end
|
||||
class DummyInstruction < Dummy
|
||||
include Util::List
|
||||
def initialize(nekst = nil)
|
||||
@next = nekst
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -1,28 +1,6 @@
|
||||
require_relative "helper"
|
||||
|
||||
module Risc
|
||||
# tests that require a boot and test propagation
|
||||
class TestPositionBasic < MiniTest::Test
|
||||
def setup
|
||||
Risc.machine.boot
|
||||
@binary = Parfait::BinaryCode.new(1)
|
||||
@method = Parfait.object_space.types.values.first.methods
|
||||
@label = Risc.label("hi","ho")
|
||||
end
|
||||
def test_set_bin
|
||||
pos = Position.set( @binary , 0 , @method)
|
||||
assert_equal CodePosition , pos.class
|
||||
end
|
||||
def test_type
|
||||
pos = Position.set( @binary , 0 , @method)
|
||||
assert_equal "Word_Type" , pos.method.for_type.name
|
||||
end
|
||||
def test_next
|
||||
pos = Position.set( @binary , 0 , @method)
|
||||
type = pos.next_type(pos.method.for_type)
|
||||
assert_equal "Integer_Type" , type.name
|
||||
end
|
||||
end
|
||||
class TestPositionTranslated < MiniTest::Test
|
||||
def setup
|
||||
machine = Risc.machine.boot
|
||||
@ -34,11 +12,11 @@ module Risc
|
||||
|
||||
def test_bin_propagates_existing
|
||||
@binary.extend_to(16)
|
||||
Position.set( @binary , 0 , @method)
|
||||
CodeListener.init( @binary , 0 )
|
||||
assert_equal @binary.padded_length , Position.get(@binary.next).at
|
||||
end
|
||||
def test_bin_propagates_after
|
||||
Position.set( @binary , 0 , Parfait.object_space.get_main)
|
||||
CodeListener.init( @binary , 0 )
|
||||
@binary.extend_to(16)
|
||||
assert_equal @binary.padded_length , Position.get(@binary.next).at
|
||||
end
|
||||
|
@ -6,40 +6,40 @@ module Risc
|
||||
def setup
|
||||
Risc.machine.boot
|
||||
@binary = Parfait::BinaryCode.new(1)
|
||||
#Position.set(@binary , 0 , Parfait.object_space.get_main)
|
||||
@label = DummyInstruction.new
|
||||
@instruction = DummyInstruction.new(DummyInstruction.new)
|
||||
@position = InstructionListener.init(@instruction , @binary)
|
||||
end
|
||||
def test_init
|
||||
assert InstructionListener.init(@label , @binary)
|
||||
assert InstructionListener.init(@instruction , @binary)
|
||||
end
|
||||
def test_pos_not_set
|
||||
assert_equal (-1), @position.at
|
||||
end
|
||||
def test_init_fail
|
||||
assert_raises {InstructionListener.init(@label , nil)}
|
||||
assert_raises {InstructionListener.init(@instruction , nil)}
|
||||
end
|
||||
def pest_set_instr
|
||||
pos = Position.set( @label , 8 , @binary)
|
||||
assert_equal InstructionPosition , pos.class
|
||||
def test_init_fail_nil
|
||||
assert_raises {InstructionListener.init(nil , @binary)}
|
||||
end
|
||||
def pest_label_set_int
|
||||
Position.set( @label , 8 , @binary)
|
||||
assert_equal 8 , @label.address.value
|
||||
def test_listener_method
|
||||
listener = InstructionListener.new( @instruction , @binary )
|
||||
listener.position_changed(@position)
|
||||
end
|
||||
def pest_label_reset_int
|
||||
Position.set( @label , 8 , @binary)
|
||||
Position.set( @label , 18 , @binary)
|
||||
assert_equal 18 , @label.address.value
|
||||
def test_ins_propagates
|
||||
assert_equal (-1) , Position.get(@instruction.next).at
|
||||
@position.set( 8 )
|
||||
assert_equal 12 , Position.get(@instruction.next).at
|
||||
end
|
||||
def pest_ins_propagates
|
||||
@label.set_next Arm::ArmMachine.b( @label)
|
||||
Position.set( @label , 8 , @binary)
|
||||
assert_equal 8 , Position.get(@label.next).at
|
||||
def test_ins_propagates_again
|
||||
test_ins_propagates
|
||||
@position.set( 12 )
|
||||
assert_equal 16 , Position.get(@instruction.next).at
|
||||
end
|
||||
def pest_ins_propagates_again
|
||||
second = Arm::ArmMachine.b( @label)
|
||||
@label.set_next(second)
|
||||
Position.set( @label , 8 , @binary)
|
||||
Position.set(second , 12 , @binary)
|
||||
Position.set( @label , 8 , @binary)
|
||||
assert_equal 8 , Position.get(@label.next).at
|
||||
def test_label_has_no_length
|
||||
label = Label.new("Hi","Ho" , FakeAddress.new(5) , @instruction)
|
||||
InstructionListener.init(label , @binary)
|
||||
Position.get(label).set(10)
|
||||
assert_equal 10 , Position.get(@instruction).at
|
||||
end
|
||||
def pest_label_at
|
||||
branch = Branch.new("b" , @label)
|
||||
|
@ -64,7 +64,7 @@ module Risc
|
||||
class TestPositionEvents < MiniTest::Test
|
||||
def setup
|
||||
Position.clear_positions
|
||||
@instruciton = DummyInstruction.new
|
||||
@instruction = DummyInstruction.new
|
||||
@position = Position.new(@instruction , 0)
|
||||
@listener = PositionListener.new( @instruction )
|
||||
end
|
||||
|
@ -45,7 +45,7 @@ module Risc
|
||||
assert_equal 0 , Position.get(@machine.cpu_init).at
|
||||
end
|
||||
def test_cpu_at
|
||||
assert_equal "0x5ed4" , Position.get(@machine.cpu_init.first).to_s
|
||||
assert_equal "0x5e08" , Position.get(@machine.cpu_init.first).to_s
|
||||
end
|
||||
def pest_cpu_bin
|
||||
assert_equal "0x5ecc" , Position.get(@machine.cpu_init).to_s
|
||||
|
Reference in New Issue
Block a user