add position tests

and refactor padding out
This commit is contained in:
Torsten Ruger
2018-05-05 20:11:08 +03:00
parent d65a982454
commit 3244c7d633
5 changed files with 101 additions and 61 deletions

View File

@ -37,12 +37,12 @@ module Elf
if( slot.respond_to? :sof_reference_name )
label = "#{slot.sof_reference_name}"
else
label = "#{slot.class.name}::#{Position.position(slot).to_s(16)}"
label = "#{slot.class.name}::#{Risc::Position.position(slot).to_s(16)}"
end
label += "=#{slot}" if slot.is_a?(Symbol) or slot.is_a?(String)
add_symbol label , Position.position(slot)
add_symbol label , Risc::Position.position(slot)
if slot.is_a?(Parfait::TypedMethod)
add_symbol slot.name.to_s , Position.position(slot.binary)
add_symbol slot.name.to_s , Risc::Position.position(slot.binary)
end
end
end

View File

@ -17,6 +17,23 @@ module Risc
class Position
@positions = {}
attr_reader :at
def initialize( at )
@at = at
raise "not int #{self}-#{at}" unless @at.is_a?(Integer)
end
def +(offset)
@at + offset
end
def -(offset)
@at - offset
end
def to_s
@at.to_s(16)
end
def self.positions
@positions
end
@ -33,15 +50,14 @@ module Risc
end
def self.set_position( object , pos )
raise "Position must be number not :#{pos}:" unless pos.is_a?(Numeric)
# resetting of position used to be error, but since relink and dynamic instruction size it is ok.
# in measures (of 32)
#puts "Setting #{pos} for #{self.class}"
old = Position.positions[object]
if old != nil and ((old - pos).abs > 10000)
raise "position set again #{pos}!=#{old} for #{object}"
if old != nil and ((old - pos).abs > 1000)
raise "position set too far off #{pos}!=#{old} for #{object}"
end
self.positions[object] = pos
self.positions[object] = Position.new( pos )
end
end
end