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