rubyx/lib/risc/instructions/branch.rb

52 lines
1.0 KiB
Ruby
Raw Normal View History

module Risc
# A branch must branch to a label.
# Different Branches (derived classes) use different registers, the base
# just stores the Label
class Branch < Instruction
def initialize( source , label )
2015-07-18 10:21:49 +02:00
super(source)
raise "not label #{label}:#{label.class}" unless label.is_a?(Label) or label.is_a?(Parfait::BinaryCode)
@label = label
end
attr_reader :label
2015-07-18 10:21:49 +02:00
# return an array of names of registers that is used by the instruction
def register_names
[]
end
2015-07-18 10:21:49 +02:00
def to_s
case label
when Label
str = label.name
when Parfait::BinaryCode
str = "Code"
str += ":#{Position.get(label)}" if Position.set?(label)
else
str = "(no label)"
end
class_source( str )
2015-07-18 10:21:49 +02:00
end
alias :inspect :to_s
# if branch_to is implemented it must return the label it branches to
def branch_to
label
end
end
class IsZero < Branch
end
class IsNotZero < Branch
end
class IsMinus < Branch
end
2015-07-18 10:21:49 +02:00
class IsPlus < Branch
end
2015-07-18 10:21:49 +02:00
end