From efcc33f8a1283114ae90aadd5b50d07bab268823 Mon Sep 17 00:00:00 2001 From: Torsten Ruger Date: Thu, 29 Mar 2018 20:37:25 +0300 Subject: [PATCH] get an elf written --- lib/elf/object_writer.rb | 10 +++++----- lib/vool/vool_compiler.rb | 5 +++++ test/elf/test_hello.rb | 13 ++++--------- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/lib/elf/object_writer.rb b/lib/elf/object_writer.rb index d586f8a4..88df42fa 100644 --- a/lib/elf/object_writer.rb +++ b/lib/elf/object_writer.rb @@ -7,9 +7,8 @@ require_relative 'string_table_section' module Elf class ObjectWriter - def initialize( machine , objects ) + def initialize( machine ) @machine = machine - @objects = objects target = Elf::Constants::TARGET_ARM @object = Elf::ObjectFile.new(target) sym_strtab = Elf::StringTableSection.new(".strtab") @@ -20,19 +19,20 @@ module Elf @text = Elf::TextSection.new(".text") @object.add_section @text - assembler = Risc::TextWriter.new(@machine , @objects) + assembler = Risc::TextWriter.new(@machine) set_text assembler.write_as_string # for debug add labels for labels Parfait.object_space.each_type do |type| type.methods.each do |f| - f.risc_instructions.each_label do |label| + f.cpu_instructions.each do |label| + next unless label.is_a?(Risc::Label) add_symbol "#{type.name}::#{f.name}:#{label.name}" , Positioned.position(label) end end end - @objects.each do |id,slot| + @machine.objects.each do |id,slot| next if slot.is_a?(Parfait::BinaryCode) if( slot.respond_to? :sof_reference_name ) label = "#{slot.sof_reference_name}" diff --git a/lib/vool/vool_compiler.rb b/lib/vool/vool_compiler.rb index 1c00f536..71af3b6e 100644 --- a/lib/vool/vool_compiler.rb +++ b/lib/vool/vool_compiler.rb @@ -13,5 +13,10 @@ module Vool statements = self.ruby_to_vool(source) statements.to_mom(nil) end + def self.ruby_to_binary(source) + machine = Risc.machine.boot + self.ruby_to_vool(source) + machine.position_all + end end end diff --git a/test/elf/test_hello.rb b/test/elf/test_hello.rb index 789038f6..adb0d28e 100644 --- a/test/elf/test_hello.rb +++ b/test/elf/test_hello.rb @@ -1,20 +1,15 @@ require_relative "../helper" class HelloTest < MiniTest::Test - include AST::Sexp def check - machine = Risc.machine.boot - Vm.compile_ast( @input ) - objects = Risc::Collector.collect_space - machine.translate_arm - writer = Elf::ObjectWriter.new(machine , objects ) + Vool::VoolCompiler.ruby_to_binary( "class Space;def main(arg);#{@input};end;end" ) + writer = Elf::ObjectWriter.new(Risc.machine) writer.save "test/hello.o" end - def pest_string_put - @input = s(:statements, s(:return, s(:call, :putstring, s(:arguments), - s(:receiver, s(:string, "Hello again\\n"))))) + def test_string_put + @input = "'Hello'.putstring" check end end