add source to the to_s

This commit is contained in:
Torsten Ruger 2018-03-22 18:38:19 +02:00
parent 19afc376f4
commit 9932d0bf33
11 changed files with 21 additions and 12 deletions

View File

@ -26,7 +26,7 @@ module Risc
@source = source
@next = nekst
return unless source
raise "Source must be string or ast node, not #{source.class}" unless source.is_a?(String) or source.is_a?(Mom::Instruction)
raise "Source must be string or Instruction, not #{source.class}" unless source.is_a?(String) or source.is_a?(Mom::Instruction)
end
attr_reader :source
@ -72,6 +72,14 @@ module Risc
self.next.each_label(labels , &block) if self.next
end
def class_source( derived)
"#{self.class.name.split("::").last}: #{derived} #{source_mini}"
end
def source_mini
return "(no source)" unless source
return "(from: #{source[0..15]})" if source.is_a?(String)
"(from: #{source.class.name.split("::").last})"
end
end
end

View File

@ -11,7 +11,7 @@ module Risc
attr_reader :label
def to_s
"#{self.class.name.split("::").last}: #{label ? label.name : ''}"
class_source "#{label ? label.name : '(no label)'}"
end
alias :inspect :to_s

View File

@ -12,7 +12,7 @@ module Risc
attr_reader :method , :register
def to_s
"FunctionCall: #{method.name}"
class_source method.name
end
end

View File

@ -11,7 +11,7 @@ module Risc
attr_reader :register
def to_s
"FunctionReturn: #{register} "
class_source "#{register} "
end
end

View File

@ -30,7 +30,7 @@ module Risc
attr_accessor :array , :index , :register
def to_s
"#{self.class.name.split("::").last}: #{array}[#{index}] -> #{register}"
class_source "#{array}[#{index}] -> #{register}"
end
end

View File

@ -15,7 +15,7 @@ module Risc
attr_reader :name
def to_s
"Label: #{@name} (#{self.next.class.name.split("::").last})"
class_source "#{@name} (next: #{self.next.class.name.split("::").last})"
end
def sof_reference_name

View File

@ -14,7 +14,7 @@ module Risc
attr_accessor :register , :constant
def to_s
"LoadConstant: #{register} <- #{constant_str}"
class_source "#{register} <- #{constant_str}"
end
private

View File

@ -10,7 +10,7 @@ module Risc
attr_reader :operator, :left , :right
def to_s
"OperatorInstruction: #{left} #{operator} #{right}"
class_source "#{left} #{operator} #{right}"
end
end

View File

@ -15,7 +15,7 @@ module Risc
# If you had a c array and index offset
# the instruction would do array[index] = register
# The arguments are in the order that makes sense for the Instruction name
# So RegToSlot means the register (first argument) moves to the slot (array and index)
# So RegToSlot means the register (first argument) moves to the slot (array and index)
def initialize( source , register , array , index )
super(source)
@register = register
@ -29,7 +29,7 @@ module Risc
attr_accessor :register , :array , :index
def to_s
"#{self.class.name.split("::").last}: #{register} -> #{array}[#{index}]"
class_source "#{register} -> #{array}[#{index}]"
end
end

View File

@ -12,11 +12,12 @@ module Risc
def initialize source ,name
super(source)
@name = name
raise "must have name" unless name
end
attr_reader :name
def to_s
"Syscall: #{name}"
class_source name
end
end

View File

@ -26,7 +26,7 @@ module Risc
attr_reader :from, :to
def to_s
"Transfer: #{from} -> #{to}"
class_source "#{from} -> #{to}"
end
end
def self.transfer( source , from , to)