improve output
This commit is contained in:
parent
ea0572c836
commit
200da192b4
@ -28,7 +28,14 @@ module Vm
|
|||||||
def opcode
|
def opcode
|
||||||
@attributes[:opcode]
|
@attributes[:opcode]
|
||||||
end
|
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.
|
# returns an array of registers (RegisterUses) that this instruction uses.
|
||||||
# ie for r1 = r2 + r3
|
# ie for r1 = r2 + r3
|
||||||
# which in assembler is add r1 , r2 , r3
|
# which in assembler is add r1 , r2 , r3
|
||||||
@ -82,6 +89,9 @@ module Vm
|
|||||||
def regs
|
def regs
|
||||||
@first
|
@first
|
||||||
end
|
end
|
||||||
|
def to_s
|
||||||
|
"#{opcode} #{@first} #{super}"
|
||||||
|
end
|
||||||
end
|
end
|
||||||
class MemoryInstruction < Instruction
|
class MemoryInstruction < Instruction
|
||||||
def initialize result , left , right = nil , options = {}
|
def initialize result , left , right = nil , options = {}
|
||||||
@ -121,6 +131,9 @@ module Vm
|
|||||||
def assigns
|
def assigns
|
||||||
[@result.used_register]
|
[@result.used_register]
|
||||||
end
|
end
|
||||||
|
def to_s
|
||||||
|
"#{opcode} #{result.register_symbol} , #{left.register_symbol} , #{right.register_symbol} #{super}"
|
||||||
|
end
|
||||||
end
|
end
|
||||||
class CompareInstruction < Instruction
|
class CompareInstruction < Instruction
|
||||||
def initialize left , right , options = {}
|
def initialize left , right , options = {}
|
||||||
@ -151,6 +164,9 @@ module Vm
|
|||||||
def assigns
|
def assigns
|
||||||
[@to.used_register]
|
[@to.used_register]
|
||||||
end
|
end
|
||||||
|
def to_s
|
||||||
|
"#{opcode} #{@to.register_symbol} , #{@from.is_a?(Constant) ? @from.value : @from.register_symbol} #{super}"
|
||||||
|
end
|
||||||
end
|
end
|
||||||
class CallInstruction < Instruction
|
class CallInstruction < Instruction
|
||||||
def initialize first , options = {}
|
def initialize first , options = {}
|
||||||
|
@ -34,8 +34,7 @@ module Vm
|
|||||||
# small todo. This does not catch condition_code that are not :al
|
# small todo. This does not catch condition_code that are not :al
|
||||||
next if (n.attributes.length > 3) or (kode.attributes.length > 3)
|
next if (n.attributes.length > 3) or (kode.attributes.length > 3)
|
||||||
if kode.result == n.from
|
if kode.result == n.from
|
||||||
puts "KODE #{kode.inspect} , #{kode.attributes.length}"
|
puts "Logic #{kode} goes #{n}"
|
||||||
puts "N #{n.inspect} , #{n.attributes.length}"
|
|
||||||
kode.result = n.to
|
kode.result = n.to
|
||||||
block.codes.delete(n)
|
block.codes.delete(n)
|
||||||
end
|
end
|
||||||
@ -57,6 +56,7 @@ module Vm
|
|||||||
# small todo. This does not catch condition_code that are not :al
|
# small todo. This does not catch condition_code that are not :al
|
||||||
next if (n.attributes.length > 3) or (kode.attributes.length > 3)
|
next if (n.attributes.length > 3) or (kode.attributes.length > 3)
|
||||||
if kode.to == n.from
|
if kode.to == n.from
|
||||||
|
puts "Move #{kode} goes #{n} "
|
||||||
kode.to = n.to
|
kode.to = n.to
|
||||||
block.codes.delete(n)
|
block.codes.delete(n)
|
||||||
end
|
end
|
||||||
@ -74,7 +74,7 @@ module Vm
|
|||||||
next if (kode.attributes.length > 3)
|
next if (kode.attributes.length > 3)
|
||||||
if kode.to == kode.from
|
if kode.to == kode.from
|
||||||
block.codes.delete(kode)
|
block.codes.delete(kode)
|
||||||
puts "deleted noop move in #{block.name} #{kode.inspect}"
|
puts "deleted noop move in #{block.name} #{kode}"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user