dragging the extra through resets
as the binary the instruction is in may change when repositioning
This commit is contained in:
@ -11,7 +11,15 @@ module Risc
|
||||
attr_reader :label
|
||||
|
||||
def to_s
|
||||
class_source "#{label ? label.name : '(no label)'}"
|
||||
case label
|
||||
when Label
|
||||
str = label.name
|
||||
when Parfait::BinaryCode
|
||||
str = "Code"
|
||||
else
|
||||
str = "(no label)"
|
||||
end
|
||||
class_source( str )
|
||||
end
|
||||
alias :inspect :to_s
|
||||
|
||||
|
@ -14,7 +14,7 @@ module Risc
|
||||
# fire events for changed pc and register contents
|
||||
include Util::Eventable
|
||||
include Util::Logging
|
||||
log_level :info
|
||||
log_level :debug
|
||||
|
||||
attr_reader :instruction , :clock , :pc # current instruction and pc
|
||||
attr_reader :registers # the registers, 16 (a hash, sym -> contents)
|
||||
@ -48,13 +48,12 @@ module Risc
|
||||
def set_pc( pos )
|
||||
raise "Not int #{pos}" unless pos.is_a? Numeric
|
||||
position = Position.at(pos)
|
||||
raise "No position #{pos}" unless position
|
||||
raise "No position #{pos.to_s(16)}" unless position
|
||||
if position.is_a?(Position::CodePosition)
|
||||
log.debug "Setting Position #{clock}-#{position}, #{position.method}"
|
||||
return set_pc(position.at + Parfait::BinaryCode.offset)
|
||||
else
|
||||
log.debug "Setting Position #{clock}-#{position}, #{position.binary}"
|
||||
raise "Setting Code #{clock}-#{position}, #{position.method}"
|
||||
#return set_pc(position.at + Parfait::BinaryCode.offset)
|
||||
end
|
||||
log.debug "Setting Position #{clock}-#{position}, #{position.binary}"
|
||||
raise "not instruction position #{position}-#{position.class}-#{position.object.class}" unless position.is_a?(Position::InstructionPosition)
|
||||
set_instruction( position.instruction )
|
||||
@clock += 1
|
||||
|
@ -33,7 +33,8 @@ module Risc
|
||||
def translate(code)
|
||||
case code
|
||||
when Branch
|
||||
ret = code.class.new(code.source , code.label.to_cpu(self))
|
||||
new_label = code.label.is_a?(Label) ? code.label.to_cpu(self) : code.label
|
||||
ret = code.class.new(code.source , new_label)
|
||||
when LoadConstant
|
||||
const = code.constant
|
||||
const = const.to_cpu(self) if const.is_a?(Label)
|
||||
|
@ -58,9 +58,9 @@ module Risc
|
||||
# in measures
|
||||
#
|
||||
# reseting to the same position as before, triggers code that propagates
|
||||
def self.reset(position , to)
|
||||
def self.reset(position , to , extra)
|
||||
log.debug "ReSetting #{position}, to:#{to.to_s(16)}, for #{position.object.class}-#{position.object}"
|
||||
position.reset_to(to)
|
||||
position.reset_to(to, extra)
|
||||
if testing = @reverse_cache[ to ]
|
||||
if testing.class != position.class
|
||||
raise "Mismatch (at #{to.to_s(16)}) new:#{position}:#{position.class} , was #{testing}:#{testing.class}"
|
||||
@ -76,13 +76,13 @@ module Risc
|
||||
|
||||
def self.set( object , pos , extra = nil)
|
||||
old = Position.positions[object]
|
||||
return self.reset(old , pos) if old
|
||||
return self.reset(old , pos , extra) if old
|
||||
log.debug "Setting #{pos.to_s(16)} for #{object.class}-#{object}"
|
||||
testing = self.at( pos )
|
||||
position = for_at( object , pos , extra)
|
||||
raise "Mismatch (at #{pos.to_s(16)}) was:#{position} #{position.class} #{position.object} , should #{testing}#{testing.class}" if testing and testing.class != position.class
|
||||
self.positions[object] = position
|
||||
position.init(pos)
|
||||
position.init(pos , extra)
|
||||
@reverse_cache[position.at] = position unless object.is_a? Label
|
||||
log.debug "Set #{position} (#{pos.to_s(16)}) for #{position.class}"
|
||||
position
|
||||
|
@ -22,9 +22,9 @@ module Risc
|
||||
"0x#{@at.to_s(16)}"
|
||||
end
|
||||
# just a callback after creation AND insertion
|
||||
def init(pos)
|
||||
def init(pos , is_nil)
|
||||
end
|
||||
def reset_to(pos)
|
||||
def reset_to(pos , guaranteed_nil )
|
||||
return false if pos == at
|
||||
if((at - pos).abs > 1000)
|
||||
raise "position set too far off #{pos}!=#{at} for #{object}:#{object.class}"
|
||||
|
Reference in New Issue
Block a user