start BranchListener
but on hold, since it needs positions before we have them Must create them during collection phase
This commit is contained in:
@ -23,6 +23,10 @@ module Risc
|
||||
end
|
||||
alias :inspect :to_s
|
||||
|
||||
# if branch is implemented it must return the label it branches to
|
||||
def branch
|
||||
label
|
||||
end
|
||||
end
|
||||
|
||||
# dynamic version of an Branch branch that jumps to the contents
|
||||
|
22
lib/risc/position/branch_listener.rb
Normal file
22
lib/risc/position/branch_listener.rb
Normal file
@ -0,0 +1,22 @@
|
||||
module Risc
|
||||
|
||||
class BranchListener
|
||||
|
||||
# initialize with the instruction listener
|
||||
def initialize(listener)
|
||||
@listener = listener
|
||||
end
|
||||
|
||||
|
||||
def position_changed(position)
|
||||
end
|
||||
|
||||
# don't react to insertion, as the CodeListener will take care
|
||||
def position_inserted(position)
|
||||
end
|
||||
|
||||
# dont react, as we do the work in position_changed
|
||||
def position_changing(position , to)
|
||||
end
|
||||
end
|
||||
end
|
@ -13,7 +13,7 @@ module Risc
|
||||
# the same BinaryCode, or else move it and the code along
|
||||
#
|
||||
class InstructionListener
|
||||
attr_reader :binary
|
||||
attr_reader :binary , :index
|
||||
|
||||
def initialize(binary)
|
||||
@binary = binary
|
||||
@ -91,7 +91,12 @@ module Risc
|
||||
while(instruction)
|
||||
position = Position.new(instruction , -1)
|
||||
first = position unless first
|
||||
position.position_listener(InstructionListener.new( code ))
|
||||
il = InstructionListener.new( code )
|
||||
position.position_listener(il)
|
||||
if instruction.respond_to?(:branch)
|
||||
# label_pos = Position.get(instruction.branch)
|
||||
# label_pos.position_listener( BranchListener.new(il))
|
||||
end
|
||||
instruction = instruction.next
|
||||
end
|
||||
first
|
||||
|
Reference in New Issue
Block a user