hand context into position
This commit is contained in:
parent
6b7e1e3932
commit
415df49199
@ -114,7 +114,7 @@ module Risc
|
|||||||
before = at
|
before = at
|
||||||
nekst = method.binary
|
nekst = method.binary
|
||||||
while(nekst)
|
while(nekst)
|
||||||
Position.set_position(nekst , at)
|
Position.set_position(nekst , at , method)
|
||||||
at += nekst.padded_length
|
at += nekst.padded_length
|
||||||
nekst = nekst.next
|
nekst = nekst.next
|
||||||
end
|
end
|
||||||
|
@ -35,7 +35,13 @@ module Risc
|
|||||||
def to_s
|
def to_s
|
||||||
"0x#{@at.to_s(16)}"
|
"0x#{@at.to_s(16)}"
|
||||||
end
|
end
|
||||||
|
def reset_to(pos)
|
||||||
|
if((at - pos).abs > 1000)
|
||||||
|
raise "position set too far off #{pos}!=#{at} for #{object}:#{object.class}"
|
||||||
|
end
|
||||||
|
@at = pos
|
||||||
|
self
|
||||||
|
end
|
||||||
def self.positions
|
def self.positions
|
||||||
@positions
|
@positions
|
||||||
end
|
end
|
||||||
@ -51,15 +57,40 @@ module Risc
|
|||||||
pos
|
pos
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.set_position( object , pos )
|
def self.set_position( object , pos , extra = nil)
|
||||||
# resetting of position used to be error, but since relink and dynamic instruction size it is ok.
|
# resetting of position used to be error, but since relink and dynamic instruction size it is ok.
|
||||||
# in measures (of 32)
|
# in measures (of 32)
|
||||||
#puts "Setting #{pos} for #{self.class}"
|
#puts "Setting #{pos} for #{self.class}"
|
||||||
old = Position.positions[object]
|
old = Position.positions[object]
|
||||||
if old != nil and ((old - pos).abs > 1000)
|
return old.reset_to(pos) if old != nil
|
||||||
raise "position set too far off #{pos}!=#{old} for #{object}:#{object.class}"
|
self.positions[object] = for_at( object , pos , extra)
|
||||||
end
|
end
|
||||||
self.positions[object] = Position.new( pos )
|
|
||||||
|
def self.for_at(object , at , extra)
|
||||||
|
case object
|
||||||
|
when Parfait::BinaryCode
|
||||||
|
BPosition.new(object,at , extra)
|
||||||
|
when Arm::Instruction , Risc::Label
|
||||||
|
IPosition.new(object,at)
|
||||||
|
else
|
||||||
|
Position.new(at)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
# handle event propagation
|
||||||
|
class IPosition < Position
|
||||||
|
attr_reader :instruction
|
||||||
|
def initialize(instruction, pos)
|
||||||
|
super(pos)
|
||||||
|
@instruction = instruction
|
||||||
|
end
|
||||||
|
end
|
||||||
|
class BPosition < Position
|
||||||
|
attr_reader :code , :method
|
||||||
|
def initialize(code, pos , method)
|
||||||
|
super(pos)
|
||||||
|
@code = code
|
||||||
|
@method = method
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -25,6 +25,10 @@ module Risc
|
|||||||
pos = Position.set_position(self , 5)
|
pos = Position.set_position(self , 5)
|
||||||
assert_equal 5 , pos.at
|
assert_equal 5 , pos.at
|
||||||
end
|
end
|
||||||
|
def test_set_instr
|
||||||
|
pos = Position.set_position( Risc::Label.new("hi","ho") , 0)
|
||||||
|
assert_equal IPosition , pos.class
|
||||||
|
end
|
||||||
def tet_tos
|
def tet_tos
|
||||||
assert_equal "0x10" , Position.set_position(self).to_s
|
assert_equal "0x10" , Position.set_position(self).to_s
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user