add position tests
and refactor padding out
This commit is contained in:
@ -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
|
||||
|
@ -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
|
||||
|
Reference in New Issue
Block a user