add branch listener functionaliy
have to store the branches and loop again as labels dont neccessarily have positions yet
This commit is contained in:
@ -3,12 +3,13 @@ module Risc
|
||||
class BranchListener
|
||||
|
||||
# initialize with the instruction listener
|
||||
def initialize(listener)
|
||||
@listener = listener
|
||||
def initialize(branch)
|
||||
@branch = branch
|
||||
end
|
||||
|
||||
|
||||
# incoming position is the labels
|
||||
def position_changed(position)
|
||||
@branch.precheck
|
||||
end
|
||||
|
||||
# don't react to insertion, as the CodeListener will take care
|
||||
|
@ -88,16 +88,18 @@ module Risc
|
||||
raise "Not Binary Code #{code.class}" unless code.is_a?(Parfait::BinaryCode)
|
||||
raise "Must init with instruction, not nil" unless instruction
|
||||
first = nil
|
||||
branches = []
|
||||
while(instruction)
|
||||
position = Position.get_or_create(instruction)
|
||||
first = position unless first
|
||||
position.position_listener( InstructionListener.new( code ) )
|
||||
if instruction.respond_to?(:branch)
|
||||
# label_pos = Position.get(instruction.branch)
|
||||
# label_pos.position_listener( BranchListener.new(il))
|
||||
end
|
||||
branches << instruction if instruction.respond_to?(:branch_to)
|
||||
instruction = instruction.next
|
||||
end
|
||||
branches.each do |branch|
|
||||
label_pos = Position.get(branch.branch_to)
|
||||
label_pos.position_listener( BranchListener.new(branch) )
|
||||
end
|
||||
first
|
||||
end
|
||||
end
|
||||
|
@ -220,5 +220,6 @@ module Risc
|
||||
end
|
||||
require_relative "position_listener"
|
||||
require_relative "instruction_listener"
|
||||
require_relative "branch_listener"
|
||||
require_relative "code_listener"
|
||||
require_relative "label_listener"
|
||||
|
Reference in New Issue
Block a user