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