2017-01-19 08:02:29 +01:00
|
|
|
module Risc
|
2015-07-17 12:21:57 +02:00
|
|
|
|
2018-03-19 16:50:11 +01:00
|
|
|
# A branch must branch to a label.
|
|
|
|
# Different Branches (derived classes) use different registers, the base
|
|
|
|
# just stores the Label
|
2015-07-17 12:21:57 +02:00
|
|
|
class Branch < Instruction
|
2018-03-19 16:50:11 +01:00
|
|
|
def initialize( source , label )
|
2015-07-18 10:21:49 +02:00
|
|
|
super(source)
|
2018-11-21 10:12:39 +01:00
|
|
|
raise "not label #{label}:#{label.class}" unless label.is_a?(Label) or label.is_a?(Parfait::BinaryCode)
|
2018-03-19 16:50:11 +01:00
|
|
|
@label = label
|
2015-07-17 12:21:57 +02:00
|
|
|
end
|
2015-10-23 20:27:36 +02:00
|
|
|
attr_reader :label
|
2015-07-18 10:21:49 +02:00
|
|
|
|
2020-03-18 16:49:23 +01: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
|
2018-05-25 18:04:48 +02:00
|
|
|
case label
|
|
|
|
when Label
|
|
|
|
str = label.name
|
|
|
|
when Parfait::BinaryCode
|
|
|
|
str = "Code"
|
2018-07-03 18:15:36 +02:00
|
|
|
str += ":#{Position.get(label)}" if Position.set?(label)
|
2018-05-25 18:04:48 +02:00
|
|
|
else
|
|
|
|
str = "(no label)"
|
|
|
|
end
|
|
|
|
class_source( str )
|
2015-07-18 10:21:49 +02:00
|
|
|
end
|
2015-10-19 13:46:12 +02:00
|
|
|
alias :inspect :to_s
|
2015-10-23 20:27:36 +02:00
|
|
|
|
2018-06-17 21:25:38 +02:00
|
|
|
# if branch_to is implemented it must return the label it branches to
|
|
|
|
def branch_to
|
2018-06-14 20:29:34 +02:00
|
|
|
label
|
|
|
|
end
|
2015-10-07 09:02:51 +02:00
|
|
|
end
|
|
|
|
|
2015-10-19 15:08:00 +02:00
|
|
|
class IsZero < Branch
|
2015-10-07 09:02:51 +02:00
|
|
|
end
|
|
|
|
|
2018-03-24 16:54:15 +01:00
|
|
|
class IsNotZero < Branch
|
2015-10-07 09:02:51 +02:00
|
|
|
end
|
|
|
|
|
2015-10-19 15:08:00 +02:00
|
|
|
class IsMinus < Branch
|
2015-10-07 09:02:51 +02:00
|
|
|
end
|
2015-07-18 10:21:49 +02:00
|
|
|
|
2015-10-19 15:08:00 +02:00
|
|
|
class IsPlus < Branch
|
2015-07-17 12:21:57 +02:00
|
|
|
end
|
2015-07-18 10:21:49 +02:00
|
|
|
|
2015-07-17 12:21:57 +02:00
|
|
|
end
|