better testing for small assembly (for coming changes)
This commit is contained in:
parent
0fa47d204e
commit
fcf76eed34
@ -14,6 +14,12 @@ module Elf
|
||||
Elf::Constants::SHF_WRITE | Elf::Constants::SHF_ALLOC | Elf::Constants::SHF_EXECINSTR
|
||||
end
|
||||
|
||||
def length
|
||||
@text.length
|
||||
end
|
||||
def to_s
|
||||
"[" + @text.bytes.join(",") + "]"
|
||||
end
|
||||
def alignment
|
||||
4
|
||||
end
|
||||
|
@ -63,6 +63,9 @@ module Vm
|
||||
end
|
||||
end
|
||||
|
||||
def at where
|
||||
@current = where
|
||||
end
|
||||
# set the next executed block after self.
|
||||
# why is this useful? if it's unconditional, why not merge them:
|
||||
# So the second block can be used as a jump target. You standard loop needs a block to setup
|
||||
@ -74,7 +77,10 @@ module Vm
|
||||
# sugar to create instructions easily. Any method with one arg is sent to the machine and the result
|
||||
# (hopefully an instruction) added as code
|
||||
def method_missing(meth, *args, &block)
|
||||
raise "hallo" if( meth.to_s[-1] == "=")
|
||||
if( meth.to_s[-1] == "=")
|
||||
val = @current.eval meth.to_s[0 ... -1]
|
||||
raise "hallo #{val}"
|
||||
end
|
||||
add_code CMachine.instance.send(meth , *args)
|
||||
end
|
||||
|
||||
|
@ -13,8 +13,8 @@ class TestFibo < MiniTest::Test
|
||||
fibo = @program.get_or_create_function(:fibo)
|
||||
@program.main.mov( int , 10 )
|
||||
@program.main.call( fibo )
|
||||
putint = @program.get_or_create_function(:putint)
|
||||
@program.main.call( putint )
|
||||
# putint = @program.get_or_create_function(:putint)
|
||||
# @program.main.call( putint )
|
||||
write 20 , "fibo"
|
||||
end
|
||||
|
||||
|
@ -22,6 +22,7 @@ class TestSmallProg < MiniTest::Test
|
||||
bne start ,{} #3
|
||||
end
|
||||
end
|
||||
@should = [0,176,160,227,5,0,160,227,1,0,80,226,253,255,255,26,1,112,160,227,0,0,0,239]
|
||||
write( 6 , "loop" )
|
||||
end
|
||||
|
||||
@ -35,17 +36,18 @@ class TestSmallProg < MiniTest::Test
|
||||
mov :r2 , hello.length
|
||||
swi 0 #software interupt, ie kernel syscall
|
||||
end
|
||||
@should = [0,176,160,227,4,112,160,227,1,0,160,227,12,16,143,226,16,32,160,227,0,0,0,239,1,112,160,227,0,0,0,239,72,101,108,108,111,32,82,97,105,115,97,10,0,0,0,0]
|
||||
write(7 + hello.length/4 + 1 , 'hello')
|
||||
end
|
||||
|
||||
#helper to write the file
|
||||
def write len ,name
|
||||
writer = Elf::ObjectWriter.new(Elf::Constants::TARGET_ARM)
|
||||
io = @program.assemble(StringIO.new)
|
||||
assembly = io.string
|
||||
assert_equal len * 4 , assembly.length
|
||||
writer.set_text assembly
|
||||
writer.save("#{name}_test.o")
|
||||
writer = Elf::ObjectWriter.new(@program , Elf::Constants::TARGET_ARM)
|
||||
assembly = writer.text
|
||||
assembly.text.bytes.each_with_index do |byte , index|
|
||||
assert_equal byte , @should[index] , "byte #{index}"
|
||||
end
|
||||
# writer.save("#{name}_test.o")
|
||||
end
|
||||
end
|
||||
# _start copied from dietc
|
||||
|
Loading…
Reference in New Issue
Block a user