2018-05-10 19:56:12 +02:00
|
|
|
module Risc
|
|
|
|
module Position
|
|
|
|
|
2018-05-11 17:36:45 +02:00
|
|
|
# BinaryCodes form a linked list
|
|
|
|
#
|
|
|
|
# We want to keep all code for a method continous, so we propagate Positions
|
|
|
|
#
|
2018-05-13 14:28:10 +02:00
|
|
|
# At the end of the list the propagation spills into the next methods
|
|
|
|
# binary and so on
|
|
|
|
#
|
2018-05-10 19:56:12 +02:00
|
|
|
class CodePosition < ObjectPosition
|
2018-05-11 17:36:45 +02:00
|
|
|
|
2018-05-10 19:56:12 +02:00
|
|
|
attr_reader :code , :method
|
2018-05-11 17:36:45 +02:00
|
|
|
|
2018-05-10 19:56:12 +02:00
|
|
|
def initialize(code, pos , method)
|
2018-05-23 20:34:49 +02:00
|
|
|
super(code,pos)
|
2018-05-10 19:56:12 +02:00
|
|
|
@code = code
|
|
|
|
@method = method
|
2018-05-13 14:28:10 +02:00
|
|
|
raise "Method nil" unless method
|
2018-05-10 19:56:12 +02:00
|
|
|
end
|
|
|
|
def init(at)
|
2018-05-12 17:36:59 +02:00
|
|
|
next_pos = at + code.padded_length
|
|
|
|
if code.next
|
|
|
|
Position.set(code.next , next_pos, method)
|
|
|
|
else
|
2018-05-13 14:28:10 +02:00
|
|
|
next_meth = next_method
|
|
|
|
return unless next_meth
|
|
|
|
Position.set( next_meth.binary , next_pos , next_meth)
|
2018-05-23 20:34:49 +02:00
|
|
|
next_cpu_pos = next_pos + Parfait::BinaryCode.offset
|
|
|
|
Position.set( next_meth.cpu_instructions, next_cpu_pos , next_meth.binary)
|
2018-05-12 17:36:59 +02:00
|
|
|
end
|
2018-05-10 19:56:12 +02:00
|
|
|
end
|
|
|
|
def reset_to(pos)
|
|
|
|
super(pos)
|
2018-05-23 20:34:49 +02:00
|
|
|
Position.log.debug "Reset (#{pos.to_s(16)}) #{code}"
|
2018-05-10 19:56:12 +02:00
|
|
|
init(pos)
|
|
|
|
end
|
2018-05-13 14:28:10 +02:00
|
|
|
def next_method
|
|
|
|
next_m = @method.next_method
|
|
|
|
return next_m if next_m
|
2018-05-23 20:34:49 +02:00
|
|
|
Position.log.debug "Type now #{@method.for_type.name}"
|
2018-05-13 14:28:10 +02:00
|
|
|
type = next_type(@method.for_type)
|
|
|
|
if type
|
2018-05-23 20:34:49 +02:00
|
|
|
Position.log.debug "Position for #{type.name}"
|
2018-05-13 14:28:10 +02:00
|
|
|
return type.methods
|
|
|
|
else
|
|
|
|
return nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
def next_type(type)
|
|
|
|
nekst = Parfait.object_space.types.next_value(type)
|
|
|
|
return nil unless nekst
|
|
|
|
return nekst if nekst.methods
|
|
|
|
return next_type(nekst)
|
|
|
|
end
|
2018-05-10 19:56:12 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|