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-20 14:52:13 +02:00
|
|
|
include Util::Logging
|
2018-05-24 13:27:53 +02:00
|
|
|
log_level :info
|
2018-05-20 14:52:13 +02:00
|
|
|
|
2018-05-05 18:47:18 +02:00
|
|
|
@positions = {}
|
2018-05-24 13:27:53 +02:00
|
|
|
@reverse_cache = {}
|
2018-05-05 18:47:18 +02:00
|
|
|
|
|
|
|
def self.positions
|
|
|
|
@positions
|
|
|
|
end
|
|
|
|
|
2018-05-24 13:27:53 +02:00
|
|
|
def self.clear_positions
|
|
|
|
@positions = {}
|
|
|
|
@reverse_cache = {}
|
|
|
|
end
|
2018-05-24 15:26:56 +02:00
|
|
|
|
2018-05-17 19:13:33 +02:00
|
|
|
def self.at( int )
|
2018-05-24 13:27:53 +02:00
|
|
|
@reverse_cache[int]
|
2018-05-17 19:13:33 +02:00
|
|
|
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"
|
2018-05-30 09:29:38 +02:00
|
|
|
str += "for #{object.class} "
|
|
|
|
str += "byte_length #{object.byte_length}" if object.respond_to?(:byte_length)
|
|
|
|
str += " for #{object.to_s[0...130]}"
|
2018-05-05 18:47:18 +02:00
|
|
|
raise str
|
|
|
|
end
|
|
|
|
pos
|
|
|
|
end
|
|
|
|
|
2018-05-09 19:36:49 +02:00
|
|
|
def self.reset(obj)
|
|
|
|
old = self.get(obj)
|
|
|
|
old.reset_to( old.at )
|
|
|
|
end
|
|
|
|
|
2018-06-02 15:12:01 +02:00
|
|
|
def self.set_to( position , to)
|
|
|
|
postest = Position.positions[position.object]
|
|
|
|
raise "Mismatch #{position}" if postest and postest != position
|
|
|
|
@reverse_cache.delete(position.at) unless position.object.is_a? Label
|
|
|
|
testing = self.at( position.at ) if position.at >= 0
|
2018-05-31 18:01:10 +02:00
|
|
|
if testing and testing.class != position.class
|
|
|
|
raise "Mismatch (at #{pos.to_s(16)}) was:#{position} #{position.class} #{position.object} , should #{testing}#{testing.class}"
|
|
|
|
end
|
2018-06-02 15:12:01 +02:00
|
|
|
self.positions[position.object] = position
|
|
|
|
@reverse_cache[to] = position unless position.object.is_a? Label
|
|
|
|
log.debug "Set #{position} (#{to.to_s(16)}) for #{position.class}"
|
2018-05-07 21:30:43 +02:00
|
|
|
position
|
2018-05-05 23:34:59 +02:00
|
|
|
end
|
|
|
|
end
|
2018-05-05 18:47:18 +02:00
|
|
|
end
|
2018-05-31 18:01:10 +02:00
|
|
|
require_relative "object_position"
|
2018-05-31 19:41:04 +02:00
|
|
|
require_relative "object_listener"
|
2018-05-31 18:01:10 +02:00
|
|
|
require_relative "instruction_position"
|
2018-06-02 15:34:44 +02:00
|
|
|
require_relative "code_listener"
|