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-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-03-22 17:38:19 +01:00
|
|
|
class_source "#{label ? label.name : '(no label)'}"
|
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
|
|
|
|
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
|
|
|
|
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
|