2018-05-05 18:47:18 +02:00
|
|
|
module Risc
|
|
|
|
# Positions are very different during compilation and run-time.
|
|
|
|
# At run-time they are inherrent to the object, and fixed.
|
|
|
|
# While during compilation we can move things about, and do not use the
|
|
|
|
# objects memory position at all.
|
|
|
|
#
|
|
|
|
# Furthermore, there are differnet kind of positions during compilation.
|
|
|
|
# Off course the object position as hinted above, but also instruction
|
|
|
|
# positions, that do not reflect the position of the object, but of the
|
|
|
|
# assembled instruction in the binary.
|
|
|
|
#
|
2018-05-10 19:56:12 +02:00
|
|
|
# The Position module keeps a hash of all compile time positions.
|
2018-05-05 18:47:18 +02:00
|
|
|
#
|
2018-05-10 19:56:12 +02:00
|
|
|
# While the (different)Position objects transmit the change that (re) positioning
|
2018-05-05 18:47:18 +02:00
|
|
|
# entails to affected objects.
|
|
|
|
|
2018-05-10 19:56:12 +02:00
|
|
|
module Position
|
2018-05-05 18:47:18 +02:00
|
|
|
@positions = {}
|
|
|
|
|
|
|
|
def self.positions
|
|
|
|
@positions
|
|
|
|
end
|
|
|
|
|
2018-05-17 19:13:33 +02:00
|
|
|
def self.at( int )
|
|
|
|
self.positions.each do |object , position|
|
|
|
|
next unless position.at == int
|
|
|
|
return position unless position.is_a?(InstructionPosition)
|
|
|
|
return position unless position.instruction.is_a?(Label)
|
|
|
|
end
|
|
|
|
nil
|
|
|
|
end
|
|
|
|
|
2018-05-06 19:04:02 +02:00
|
|
|
def self.set?(object)
|
|
|
|
self.positions.has_key?(object)
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.get(object)
|
2018-05-05 18:47:18 +02:00
|
|
|
pos = self.positions[object]
|
|
|
|
if pos == nil
|
|
|
|
str = "position accessed but not set, "
|
|
|
|
str += "0x#{object.object_id.to_s(16)}\n"
|
|
|
|
str += "for #{object.class} byte_length #{object.byte_length if object.respond_to?(:byte_length)} for #{object.inspect[0...130]}"
|
|
|
|
raise str
|
|
|
|
end
|
|
|
|
pos
|
|
|
|
end
|
|
|
|
|
2018-05-09 19:36:49 +02:00
|
|
|
# set to the same position as before, thus triggering whatever code that propagates
|
|
|
|
# position _must have been set, otherwise raises
|
|
|
|
def self.reset(obj)
|
|
|
|
old = self.get(obj)
|
|
|
|
old.reset_to( old.at )
|
|
|
|
end
|
|
|
|
|
2018-05-06 19:04:02 +02:00
|
|
|
def self.set( object , pos , extra = nil)
|
2018-05-05 18:47:18 +02:00
|
|
|
# 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]
|
2018-05-06 18:56:36 +02:00
|
|
|
if old != nil
|
|
|
|
old.reset_to(pos)
|
|
|
|
return old
|
|
|
|
end
|
2018-05-07 21:30:43 +02:00
|
|
|
position = for_at( object , pos , extra)
|
|
|
|
self.positions[object] = position
|
2018-05-08 18:59:43 +02:00
|
|
|
position.init(pos)
|
2018-05-07 21:30:43 +02:00
|
|
|
position
|
2018-05-05 23:34:59 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
def self.for_at(object , at , extra)
|
|
|
|
case object
|
|
|
|
when Parfait::BinaryCode
|
2018-05-10 19:56:12 +02:00
|
|
|
CodePosition.new(object,at , extra)
|
2018-05-17 08:49:01 +02:00
|
|
|
when Arm::Instruction , Risc::Instruction
|
2018-05-10 19:56:12 +02:00
|
|
|
InstructionPosition.new(object,at , extra)
|
2018-05-05 23:34:59 +02:00
|
|
|
else
|
2018-05-11 17:36:45 +02:00
|
|
|
ObjectPosition.new(at,object)
|
2018-05-05 18:47:18 +02:00
|
|
|
end
|
2018-05-05 23:34:59 +02:00
|
|
|
end
|
|
|
|
end
|
2018-05-05 18:47:18 +02:00
|
|
|
end
|
2018-05-10 19:56:12 +02:00
|
|
|
require_relative "position/object_position"
|
|
|
|
require_relative "position/instruction_position"
|
|
|
|
require_relative "position/code_position"
|