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
|
|
|
|
|
|
|
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
|
|
|
|
|
2018-04-02 18:30:34 +02:00
|
|
|
# dynamic version of an Branch branch that jumps to the contents
|
2018-03-21 07:21:10 +01:00
|
|
|
# of a register instead of a hardcoded address
|
|
|
|
# As Branches jump to Labels, this is not derived from Branch
|
|
|
|
# PS: to conditionally jump to a dynamic adddress we do a normal branch
|
|
|
|
# over the dynamic one and then a dynamic one. Save us having all types of branches
|
|
|
|
# in two versions
|
|
|
|
class DynamicJump < Instruction
|
|
|
|
def initialize( source , register )
|
|
|
|
super(source)
|
|
|
|
@register = register
|
|
|
|
end
|
|
|
|
attr_reader :register
|
2019-09-10 11:33:57 +02:00
|
|
|
|
|
|
|
def to_s
|
|
|
|
class_source( register.to_s)
|
|
|
|
end
|
2018-03-21 07:21:10 +01:00
|
|
|
end
|
|
|
|
|
2018-07-24 10:35:49 +02:00
|
|
|
# A Dynamic yield is very much like a DynamicJump, especially in it's idea
|
|
|
|
#
|
|
|
|
# The implentation differes slightly, as we use a chache entry in the DynamicJump
|
|
|
|
# but a block in the DynamicYield.
|
|
|
|
# Using means that we assume the register to be ready loaded with a Block
|
|
|
|
class DynamicYield < DynamicJump
|
|
|
|
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
|