to_s for reg instructions

This commit is contained in:
Torsten Ruger 2015-07-24 13:23:56 +03:00
parent fa552bf751
commit 139b0174d8
10 changed files with 47 additions and 5 deletions

View File

@ -8,10 +8,10 @@ module Register
raise "No block" unless to
@block = to
end
attr_reader :block
attr_reader :block
def to_s
"Branch(to: #{block.name})"
"Branch(block: #{block.name})"
end
end

View File

@ -8,5 +8,10 @@ module Register
@method = method
end
attr_reader :method
def to_s
"FunctionCall(#{method.name})"
end
end
end
end

View File

@ -9,5 +9,10 @@ module Register
@index = index
end
attr_reader :register , :index
def to_s
"FunctionReturn(#{register}: #{index})"
end
end
end
end

View File

@ -27,6 +27,11 @@ module Register
raise "Not register #{array}" unless Register::RegisterReference.look_like_reg(array)
end
attr_accessor :register , :array , :index
def to_s
"GetSlot(#{register}: #{array}[#{index}])"
end
end
# Produce a GetSlot instruction.

View File

@ -10,5 +10,10 @@ module Register
@constant = constant
end
attr_accessor :register , :constant
def to_s
"LoadConstant(#{register}: #{constant})"
end
end
end

View File

@ -15,11 +15,16 @@ module Register
# First argument from
# second arguemnt to
#
# Note: this may be reversed from some assembler notations (also arm)
# Note: this may be reversed from some assembler notations (also arm)
def initialize from , to
@from = wrap_register(from)
@to = wrap_register(to)
end
attr_reader :from, :to
def to_s
"RegisterTransfer(#{from} -> #{to})"
end
end
end

View File

@ -12,6 +12,11 @@ module Register
@index = index
end
attr_reader :register , :index
def to_s
"SaveReturn(#{register}[#{index}])"
end
end
# Produce a SaveReturn instruction.

View File

@ -26,6 +26,10 @@ module Register
raise "Not register #{array}" unless Register::RegisterReference.look_like_reg(array)
end
attr_accessor :register , :array , :index
def to_s
"SetSlot(#{register}: #{array}[#{index}])"
end
end
# Produce a SetSlot instruction.

View File

@ -13,5 +13,10 @@ module Register
@name = name
end
attr_reader :name
def to_s
"Syscall(#{name})"
end
end
end

View File

@ -17,6 +17,9 @@ module Register
@symbol = r
end
def to_s
symbol.to_s
end
def self.convert something
return something unless something.is_a? Symbol
return something unless look_like_reg(something)