adds hand coded fibo, works

This commit is contained in:
Torsten Ruger
2014-05-19 17:32:41 +03:00
parent 285988f173
commit fe1414f383
8 changed files with 76 additions and 15 deletions

View File

@ -4,3 +4,4 @@ require_relative "test_logic"
require_relative "test_move"
require_relative "test_memory"
require_relative "test_compare"
require_relative "test_small_program"

26
test/arm/test_fibo.rb Normal file
View File

@ -0,0 +1,26 @@
require_relative 'helper'
class TestFibo < MiniTest::Test
def setup
@program = Vm::Program.new "Arm"
end
# a hand coded version of the fibonachi numbers
# not my hand off course, found in the net from a basic introduction
def test_fibo
int = Vm::Integer.new(1) # the one is funny, but the fibo is _really_ tight code and reuses registers
fibo = utoa = @program.get_or_create_function(:fibo)
@program.main.mov( int , 10 )
@program.main.call( fibo )
#could put ...
write 20 , "fibo"
end
#helper to write the file
def write len ,name
writer = Elf::ObjectWriter.new(@program , Elf::Constants::TARGET_ARM)
writer.save("#{name}_test.o")
end
end

View File

@ -1,4 +1,3 @@
require_relative "arm/test_all"
require_relative "test_small_program"
#require_relative "test_runner"
require_relative "parser/test_all"

View File

@ -35,18 +35,8 @@ class TestRunner < MiniTest::Test
end
end
program.link_at( 0 , program.context )
binary = program.assemble(StringIO.new )
assert binary
writer = Elf::ObjectWriter.new(Elf::Constants::TARGET_ARM)
blocks = program.functions.collect{ |f| [f.entry , f.exit , f.body] }
blocks += [program.entry , program.exit , program.main]
blocks.flatten.each do |b|
writer.add_symbol b.name.to_s , b.position
end
writer = Elf::ObjectWriter.new(program , Elf::Constants::TARGET_ARM)
writer.set_text binary.string
writer.save(file.gsub(".rb" , ".o"))
# puts program.to_yaml