improve output

This commit is contained in:
Torsten Ruger 2014-06-12 21:04:15 +03:00
parent ea0572c836
commit 200da192b4
2 changed files with 20 additions and 4 deletions

View File

@ -28,7 +28,14 @@ module Vm
def opcode
@attributes[:opcode]
end
#abstract, only should be called from derived
def to_s
atts = @attributes.dup
atts.delete(:opcode)
atts.delete(:update_status)
atts.delete(:condition_code) if atts[:condition_code] == :al
atts.empty? ? "" : ", #{atts}"
end
# returns an array of registers (RegisterUses) that this instruction uses.
# ie for r1 = r2 + r3
# which in assembler is add r1 , r2 , r3
@ -82,6 +89,9 @@ module Vm
def regs
@first
end
def to_s
"#{opcode} #{@first} #{super}"
end
end
class MemoryInstruction < Instruction
def initialize result , left , right = nil , options = {}
@ -121,6 +131,9 @@ module Vm
def assigns
[@result.used_register]
end
def to_s
"#{opcode} #{result.register_symbol} , #{left.register_symbol} , #{right.register_symbol} #{super}"
end
end
class CompareInstruction < Instruction
def initialize left , right , options = {}
@ -151,6 +164,9 @@ module Vm
def assigns
[@to.used_register]
end
def to_s
"#{opcode} #{@to.register_symbol} , #{@from.is_a?(Constant) ? @from.value : @from.register_symbol} #{super}"
end
end
class CallInstruction < Instruction
def initialize first , options = {}

View File

@ -34,8 +34,7 @@ module Vm
# small todo. This does not catch condition_code that are not :al
next if (n.attributes.length > 3) or (kode.attributes.length > 3)
if kode.result == n.from
puts "KODE #{kode.inspect} , #{kode.attributes.length}"
puts "N #{n.inspect} , #{n.attributes.length}"
puts "Logic #{kode} goes #{n}"
kode.result = n.to
block.codes.delete(n)
end
@ -57,6 +56,7 @@ module Vm
# small todo. This does not catch condition_code that are not :al
next if (n.attributes.length > 3) or (kode.attributes.length > 3)
if kode.to == n.from
puts "Move #{kode} goes #{n} "
kode.to = n.to
block.codes.delete(n)
end
@ -74,7 +74,7 @@ module Vm
next if (kode.attributes.length > 3)
if kode.to == kode.from
block.codes.delete(kode)
puts "deleted noop move in #{block.name} #{kode.inspect}"
puts "deleted noop move in #{block.name} #{kode}"
end
end
end