write adjusted address
and rename integer to address in label 1k hurray
This commit is contained in:
parent
e39e96f646
commit
67100a3ef8
@ -91,7 +91,7 @@ module Arm
|
||||
if( @left.is_a?(Parfait::Object) or @left.is_a?(Risc::Label) or
|
||||
(@left.is_a?(Symbol) and !Risc::RiscValue.look_like_reg(@left)))
|
||||
left = @left
|
||||
left = @left.integer if left.is_a?(Risc::Label)
|
||||
left = @left.address if left.is_a?(Risc::Label)
|
||||
# do pc relative addressing with the difference to the instuction
|
||||
# 8 is for the funny pipeline adjustment (ie pointing to fetch and not execute)
|
||||
right = Risc::Position.get(left) - Risc::Position.get(self) - 8
|
||||
|
@ -13,7 +13,7 @@ module Arm
|
||||
end
|
||||
|
||||
def translate_Label( code )
|
||||
Risc.label( code.source , code.name , code.integer)
|
||||
Risc.label( code.source , code.name , code.address)
|
||||
end
|
||||
|
||||
# arm indexes are
|
||||
|
@ -7,7 +7,7 @@ module Risc
|
||||
# So branches and Labels are pairs, fan out, fan in
|
||||
#
|
||||
# For a return, the address (position) of the label has to be loaded.
|
||||
# So a Label carries the Integer constant that holds the address (it's own
|
||||
# So a Label carries the ReturnAddress constant that holds the address (it's own
|
||||
# position, again see positioning code).
|
||||
# But currently the label is used in the Risc abstraction layer, and in the
|
||||
# arm/interpreter layer. The integer is only used in the lower layer, but needs
|
||||
@ -15,13 +15,13 @@ module Risc
|
||||
|
||||
class Label < Instruction
|
||||
# See class description. also factory method Risc.label below
|
||||
def initialize( source , name , int , nekst = nil)
|
||||
def initialize( source , name , addr , nekst = nil)
|
||||
super(source , nekst)
|
||||
@name = name
|
||||
@integer = int
|
||||
raise "Not int #{int}" unless int.is_a?(Parfait::Integer)
|
||||
@address = addr
|
||||
raise "Not address #{addr}" unless addr.is_a?(Parfait::ReturnAddress)
|
||||
end
|
||||
attr_reader :name , :integer
|
||||
attr_reader :name , :address
|
||||
|
||||
def to_cpu(translator)
|
||||
@cpu_label ||= super
|
||||
@ -65,9 +65,7 @@ module Risc
|
||||
# An integer is plucked from object_space abd added to the machine constant pool
|
||||
# if none was given
|
||||
def self.label( source , name , position = nil , nekst = nil)
|
||||
unless position
|
||||
position = Risc.machine.get_address
|
||||
end
|
||||
position = Risc.machine.get_address unless position
|
||||
Label.new( source , name , position, nekst )
|
||||
end
|
||||
end
|
||||
|
@ -141,7 +141,7 @@ module Risc
|
||||
def execute_LoadConstant
|
||||
to = @instruction.register
|
||||
value = @instruction.constant
|
||||
value = value.integer if value.is_a?(Label)
|
||||
value = value.address if value.is_a?(Label)
|
||||
set_register( to , value )
|
||||
true
|
||||
end
|
||||
|
@ -24,7 +24,7 @@ module Risc
|
||||
end
|
||||
def init(at, binary)
|
||||
@binary = binary
|
||||
instruction.integer.set_value(at) if instruction.is_a?(Label)
|
||||
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
|
||||
|
@ -90,13 +90,15 @@ module Risc
|
||||
when Parfait::Word, Symbol
|
||||
write_String obj
|
||||
when Parfait::BinaryCode
|
||||
write_BinaryCode obj
|
||||
write_BinaryCode( obj )
|
||||
when Parfait::ReturnAddress
|
||||
write_return_address( obj )
|
||||
when Parfait::Integer
|
||||
write_integer obj
|
||||
write_integer( obj )
|
||||
when Parfait::Data4
|
||||
write_data4 obj
|
||||
write_data4( obj )
|
||||
else
|
||||
write_object obj
|
||||
write_object( obj )
|
||||
end
|
||||
end
|
||||
|
||||
@ -145,6 +147,14 @@ module Risc
|
||||
written
|
||||
end
|
||||
|
||||
def write_return_address( addr )
|
||||
write_ref_for( addr.get_type )
|
||||
write_ref_for( addr.next_integer )
|
||||
write_ref_for( addr.value + @machine.platform.loaded_at )
|
||||
write_ref_for( 0 )
|
||||
log.debug "Integer witten stream 0x#{@stream.length.to_s(16)}"
|
||||
end
|
||||
|
||||
def write_integer( int )
|
||||
write_ref_for( int.get_type )
|
||||
write_ref_for( int.next_integer )
|
||||
|
@ -90,8 +90,8 @@ module Arm
|
||||
end
|
||||
|
||||
def label( pos = 0x12 + 8)
|
||||
l = Risc::Label.new("some" , "Label" , FakeInt.new(2))
|
||||
Risc::Position.set(l.integer , 0x22 + 8)
|
||||
l = Risc::Label.new("some" , "Label" , FakeAddress.new(2))
|
||||
Risc::Position.set(l.address , 0x22 + 8)
|
||||
Risc::Position.set(l , pos , @binary)
|
||||
l
|
||||
end
|
||||
|
@ -16,12 +16,12 @@ module Risc
|
||||
end
|
||||
def test_label_set_int
|
||||
Position.set( @label , 8 , @binary)
|
||||
assert_equal 8 , @label.integer.value
|
||||
assert_equal 8 , @label.address.value
|
||||
end
|
||||
def test_label_reset_int
|
||||
Position.set( @label , 8 , @binary)
|
||||
Position.set( @label , 18 , @binary)
|
||||
assert_equal 18 , @label.integer.value
|
||||
assert_equal 18 , @label.address.value
|
||||
end
|
||||
def test_ins_propagates
|
||||
@label.set_next Arm::ArmMachine.b( @label)
|
||||
|
@ -3,7 +3,7 @@ require_relative "../helper"
|
||||
module Risc
|
||||
class TestInstructions < MiniTest::Test
|
||||
def setup
|
||||
@label = Label.new("test" , "test",FakeInt.new(5))
|
||||
@label = Label.new("test" , "test",FakeAddress.new(5))
|
||||
@branch = Branch.new("test" , @label)
|
||||
@instruction = Instruction.new("test")
|
||||
end
|
||||
@ -19,7 +19,7 @@ module Risc
|
||||
assert @label.to_s.include?("Label")
|
||||
end
|
||||
def test_label_tos2
|
||||
assert Label.new("nil",nil,FakeInt.new(2)).to_s.include?("Label")
|
||||
assert Label.new("nil",nil,FakeAddress.new(2)).to_s.include?("Label")
|
||||
end
|
||||
def test_last_empty
|
||||
assert_equal @instruction, @instruction.last
|
||||
@ -55,7 +55,7 @@ module Risc
|
||||
assert_nil @instruction.next(2)
|
||||
end
|
||||
def test_label_is_method
|
||||
label = Label.new("test" , "Object.test" , FakeInt.new(5))
|
||||
label = Label.new("test" , "Object.test" , FakeAddress.new(5))
|
||||
assert label.is_method
|
||||
end
|
||||
def test_label_is_not_method
|
||||
|
@ -13,3 +13,8 @@ class FakeInt
|
||||
@value = val
|
||||
end
|
||||
end
|
||||
class FakeAddress < FakeInt
|
||||
def is_a?(clazz)
|
||||
clazz == Parfait::ReturnAddress
|
||||
end
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user