From 18f33770b57d02740841f08966b86dd2d2e88df2 Mon Sep 17 00:00:00 2001 From: Torsten Ruger Date: Sat, 30 Aug 2014 14:17:00 +0300 Subject: [PATCH] fix and use object writer in test --- lib/elf/object_writer.rb | 23 ++++++++++------------- test/virtual/hello.rb | 9 ++++----- 2 files changed, 14 insertions(+), 18 deletions(-) diff --git a/lib/elf/object_writer.rb b/lib/elf/object_writer.rb index 43fa7fab..97bebdfe 100644 --- a/lib/elf/object_writer.rb +++ b/lib/elf/object_writer.rb @@ -6,9 +6,9 @@ require 'elf/string_table_section' module Elf class ObjectWriter - def initialize(program , target) + def initialize(space , target = Elf::Constants::TARGET_ARM ) @object = Elf::ObjectFile.new(target) - @object_space = program + @object_space = space sym_strtab = Elf::StringTableSection.new(".strtab") @object.add_section sym_strtab @symbol_table = Elf::SymbolTableSection.new(".symtab", sym_strtab) @@ -17,23 +17,20 @@ module Elf @text = Elf::TextSection.new(".text") @object.add_section @text - program.link_at( 0 , program.context ) - program.run_passes - binary = program.assemble(StringIO.new ) - + @object_space.run_passes + assembler = Register::Assembler.new(@object_space) + set_text assembler.assemble + + # for debug add labels to the block positions blocks = [] - program.classes.values.each do |clazz| - clazz.functions.each do |f| + space.classes.values.each do |clazz| + clazz.instance_methods.each do |f| f.blocks.each do |b| add_symbol "#{clazz.name}::#{f.name}@#{b.name}" , b.position end end end - blocks += [program.entry , program.exit , program.main] - blocks.flatten.each do |b| - add_symbol b.name.to_s , b.position - end - set_text binary.string + end attr_reader :text def set_text(text) diff --git a/test/virtual/hello.rb b/test/virtual/hello.rb index 67ae8a16..ededa05c 100644 --- a/test/virtual/hello.rb +++ b/test/virtual/hello.rb @@ -6,11 +6,10 @@ class HelloTest < MiniTest::Test def check machine = Virtual::Machine.boot expressions = machine.compile_main @string_input - puts "" - Virtual::BootSpace.space.run_passes - ass = Register::Assembler.new(Virtual::BootSpace.space) - ass.assemble - puts Sof::Writer.write(expressions) + + writer = Elf::ObjectWriter.new(Virtual::BootSpace.space) + writer.save "hello.o" +# puts Sof::Writer.write(expressions) # puts Sof::Writer.write(Virtual::BootSpace.space) end