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-11 17:36:45 +02:00
|
|
|
super(pos,code)
|
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)
|
|
|
|
Position.set( next_meth.cpu_instructions, next_pos + 12 , 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)
|
|
|
|
#puts "Reset (#{changed}) #{instruction}"
|
|
|
|
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
|
|
|
|
#puts "Type now #{@method.for_type.name}"
|
|
|
|
type = next_type(@method.for_type)
|
|
|
|
if type
|
|
|
|
#puts "Position for #{type.name}"
|
|
|
|
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
|