2014-04-28 10:19:28 +02:00
|
|
|
require_relative 'helper'
|
2014-05-03 14:13:44 +02:00
|
|
|
require "yaml"
|
2014-05-08 18:31:36 +02:00
|
|
|
require "parslet/convenience"
|
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)
|
2014-07-29 17:33:11 +02:00
|
|
|
parser = Parser::Salama.new
|
2014-08-22 17:00:23 +02:00
|
|
|
object_space = Register::Program.new "Arm"
|
2014-05-10 10:23:45 +02:00
|
|
|
syntax = parser.parse_with_debug(string)
|
2014-05-19 10:29:18 +02:00
|
|
|
assert syntax
|
2014-05-10 10:23:45 +02:00
|
|
|
parts = Parser::Transform.new.apply(syntax)
|
2015-10-09 16:51:14 +02:00
|
|
|
# file is a list of statements, all but the last must be a function
|
2014-05-10 10:23:45 +02:00
|
|
|
# and the last is wrapped as a main
|
2014-05-10 09:59:36 +02:00
|
|
|
parts.each_with_index do |part,index|
|
2014-05-14 11:02:54 +02:00
|
|
|
if index == (parts.length - 1)
|
2014-06-10 22:57:56 +02:00
|
|
|
expr = part.compile( program.context )
|
2014-05-14 11:02:54 +02:00
|
|
|
else
|
2014-06-10 22:57:56 +02:00
|
|
|
expr = part.compile( program.context )
|
2014-08-22 17:00:23 +02:00
|
|
|
raise "should be function definition for now" unless expr.is_a? Register::Function
|
2014-05-10 09:59:36 +02:00
|
|
|
end
|
|
|
|
end
|
2014-05-05 10:03:43 +02:00
|
|
|
|
2015-05-16 11:53:10 +02:00
|
|
|
#object writer takes machine
|
2014-05-19 16:32:41 +02:00
|
|
|
writer = Elf::ObjectWriter.new(program , Elf::Constants::TARGET_ARM)
|
2014-05-05 14:59:29 +02:00
|
|
|
|
2014-05-05 21:21:11 +02:00
|
|
|
writer.save(file.gsub(".rb" , ".o"))
|
2014-05-05 14:59:29 +02:00
|
|
|
|
2014-05-10 09:59:36 +02:00
|
|
|
# puts program.to_yaml
|
2014-04-28 10:19:28 +02:00
|
|
|
end
|
|
|
|
|
2015-05-16 11:53:10 +02:00
|
|
|
end
|