add to_asm debug output functions

This commit is contained in:
Torsten Ruger 2014-06-12 21:40:25 +03:00
parent dcd691fe00
commit 017d93d929
4 changed files with 13 additions and 7 deletions

View File

@ -22,6 +22,9 @@ module Vm
def value def value
@integer @integer
end end
def to_asm
@integer.to_s
end
end end
# The name really says it all. # The name really says it all.

View File

@ -90,7 +90,7 @@ module Vm
@first @first
end end
def to_s def to_s
"#{opcode} #{@first} #{super}" "#{opcode} [#{@first.collect {|f| f.to_asm}.join(',') }] #{super}"
end end
end end
class MemoryInstruction < Instruction class MemoryInstruction < Instruction
@ -131,8 +131,8 @@ module Vm
def assigns def assigns
[@result.used_register] [@result.used_register]
end end
def to_s def to_asm
"#{opcode} #{result.register_symbol} , #{left.register_symbol} , #{right.register_symbol} #{super}" "#{opcode} #{result.to_asm} , #{left.to_asm} , #{right.to_asm} #{super}"
end end
end end
class CompareInstruction < Instruction class CompareInstruction < Instruction
@ -165,7 +165,7 @@ module Vm
[@to.used_register] [@to.used_register]
end end
def to_s def to_s
"#{opcode} #{@to.register_symbol} , #{@from.is_a?(Constant) ? @from.value : @from.register_symbol} #{super}" "#{opcode} #{@to.to_asm} , #{@from.to_asm} #{super}"
end end
end end
class CallInstruction < Instruction class CallInstruction < Instruction

View File

@ -103,6 +103,10 @@ module Vm
def length def length
4 4
end end
# aka to string
def to_asm
"#{register_symbol}"
end
end end
class Unsigned < Word class Unsigned < Word
@ -169,7 +173,6 @@ module Vm
block.mov( self , right ) block.mov( self , right )
self self
end end
end end
end end
require_relative "constants" require_relative "constants"

View File

@ -28,9 +28,9 @@ end
t_seven() t_seven()
HERE HERE
@should = [0x0,0x40,0x2d,0xe9,0x2,0x30,0x41,0xe0,0x3,0x70,0xa0,0xe1,0x0,0x80,0xbd,0xe8,0x0,0x40,0x2d,0xe9,0x2,0x30,0x41,0xe0,0x3,0x70,0xa0,0xe1,0x0,0x80,0xbd,0xe8] @should = [0x0,0x40,0x2d,0xe9,0x0,0x0,0x54,0xe3,0x10,0x0,0x0,0xa,0x8,0x0,0x2d,0xe9,0x4,0x30,0xa0,0xe1,0x1,0x40,0xa0,0xe3,0xf2,0xff,0xff,0xeb,0x8,0x0,0xbd,0xe8,0x0,0x50,0xa0,0xe1,0x8,0x0,0x2d,0xe9,0x5,0x40,0xa0,0xe1,0xf3,0xff,0xff,0xeb,0x8,0x0,0xbd,0xe8,0x0,0x60,0xa0,0xe1,0x10,0x0,0x2d,0xe9,0x6,0x40,0xa0,0xe1,0xeb,0xff,0xff,0xeb,0x10,0x0,0xbd,0xe8,0x0,0x30,0xa0,0xe1,0x0,0x0,0x0,0xea,0x0,0x30,0xa0,0xe3,0x3,0x0,0xa0,0xe1,0x0,0x80,0xbd,0xe8]
@output = " 42 " @output = " 42 "
@target = [:Object , :minus] @target = [:Object , :times]
parse parse
write "functions" write "functions"
end end