2014-04-28 10:19:28 +02:00
|
|
|
require_relative 'helper'
|
2014-05-03 14:13:44 +02:00
|
|
|
require "yaml"
|
2014-04-28 10:19:28 +02:00
|
|
|
class TestRunner < MiniTest::Test
|
|
|
|
|
|
|
|
# this creates test methods dynamically , one for each file in runners directory
|
|
|
|
def self.runnable_methods
|
|
|
|
methods = []
|
2014-04-28 15:47:12 +02:00
|
|
|
Dir[File.join(File.dirname(__FILE__) , "runners" , "*.rb")].each do |file|
|
2014-04-28 10:19:28 +02:00
|
|
|
meth = File.basename(file).split(".").first
|
|
|
|
name = "test_#{meth}"
|
|
|
|
methods << name
|
|
|
|
self.send(:define_method, name ) {
|
|
|
|
execute file
|
|
|
|
}
|
|
|
|
end
|
|
|
|
methods
|
|
|
|
end
|
|
|
|
|
|
|
|
def execute file
|
|
|
|
string = File.read(file)
|
|
|
|
syntax = Parser::Composed.new.parse(string)
|
2014-05-05 10:03:43 +02:00
|
|
|
main = Parser::Transform.new.apply(syntax)
|
2014-05-03 17:51:47 +02:00
|
|
|
|
|
|
|
program = Vm::Program.new "Arm"
|
2014-05-05 10:03:43 +02:00
|
|
|
|
|
|
|
program.main = main.compile( program.context )
|
|
|
|
|
|
|
|
program.link_at( 0 , program.context )
|
|
|
|
|
|
|
|
binary = program.assemble(StringIO.new )
|
|
|
|
|
2014-05-05 14:59:29 +02:00
|
|
|
writer = Elf::ObjectWriter.new(Elf::Constants::TARGET_ARM)
|
|
|
|
|
|
|
|
assembly = program.assemble(StringIO.new)
|
|
|
|
|
2014-05-05 21:21:11 +02:00
|
|
|
writer.set_text assembly.string
|
|
|
|
writer.save(file.gsub(".rb" , ".o"))
|
2014-05-05 14:59:29 +02:00
|
|
|
|
2014-05-05 08:35:40 +02:00
|
|
|
puts program.to_yaml
|
2014-04-28 10:19:28 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|