adding register_names to instruction protocol

This commit is contained in:
Torsten 2020-03-18 17:49:23 +02:00
parent 8df1b8126f
commit d0b734c57c
13 changed files with 69 additions and 0 deletions

View File

@ -11,6 +11,11 @@ module Risc
end
attr_reader :label
# return an array of names of registers that is used by the instruction
def register_names
[]
end
def to_s
case label
when Label

View File

@ -12,6 +12,11 @@ module Risc
end
attr_reader :register
# return an array of names of registers that is used by the instruction
def register_names
[register.symbol ]
end
def to_s
class_source( register.to_s)
end

View File

@ -10,6 +10,11 @@ module Risc
end
attr_reader :method
# return an array of names of registers that is used by the instruction
def register_names
[]
end
def to_s
class_source method.name
end

View File

@ -11,6 +11,11 @@ module Risc
end
attr_reader :register
# return an array of names of registers that is used by the instruction
def register_names
[register.symbol]
end
def to_s
class_source "#{register} "
end

View File

@ -29,6 +29,13 @@ module Risc
end
attr_accessor :array , :index , :register
# return an array of names of registers that is used by the instruction
def register_names
names = [array.symbol , register.symbol]
names << index.symbol if index.is_a?(RegisterValue)
names
end
def to_s
class_source "#{array}[#{index}] -> #{register}"
end

View File

@ -41,6 +41,11 @@ module Risc
def precheck
end
# return an array of names of registers that is used by the instruction
def register_names
raise "Not implemented in #{self.class}"
end
def to_cpu( translator )
translator.translate( self )
end

View File

@ -23,6 +23,11 @@ module Risc
end
attr_reader :name , :address
# return an array of names of registers that is used by the instruction
def register_names
[]
end
def to_cpu(translator)
@cpu_label ||= super
end

View File

@ -14,6 +14,11 @@ module Risc
end
attr_accessor :register , :constant
# return an array of names of registers that is used by the instruction
def register_names
[register.symbol]
end
def to_s
class_source "#{register} <- #{constant_str}"
end

View File

@ -17,6 +17,11 @@ module Risc
end
attr_accessor :register , :constant
# return an array of names of registers that is used by the instruction
def register_names
[register.symbol]
end
def to_s
class_source "#{register} <- #{constant}"
end

View File

@ -32,6 +32,11 @@ module Risc
end
attr_reader :operator, :left , :right , :result
# return an array of names of registers that is used by the instruction
def register_names
[left.symbol , right.symbol, result.symbol]
end
def to_s
class_source "#{left} #{operator} #{right}"
end

View File

@ -27,6 +27,13 @@ module Risc
end
attr_accessor :register , :array , :index
# return an array of names of registers that is used by the instruction
def register_names
names = [array.symbol , register.symbol]
names << index.symbol if index.is_a?(RegisterValue)
names
end
def to_s
class_source "#{register} -> #{array}[#{index}]"
end

View File

@ -16,6 +16,11 @@ module Risc
end
attr_reader :name
# return an array of names of registers that is used by the instruction
def register_names
[]
end
def to_s
class_source name
end

View File

@ -25,6 +25,11 @@ module Risc
end
attr_reader :from, :to
# return an array of names of registers that is used by the instruction
def register_names
[from.symbol , to.symbol]
end
def to_s
class_source "#{from} -> #{to}"
end