diff --git a/lib/elf/object_writer.rb b/lib/elf/object_writer.rb index 9684c2ce..596616b5 100644 --- a/lib/elf/object_writer.rb +++ b/lib/elf/object_writer.rb @@ -7,8 +7,8 @@ require_relative 'string_table_section' module Elf class ObjectWriter - def initialize( machine ) - @machine = machine + def initialize( linker ) + @linker = linker target = Elf::Constants::TARGET_ARM @object = Elf::ObjectFile.new(target) sym_strtab = Elf::StringTableSection.new(".strtab") @@ -19,24 +19,23 @@ module Elf @text = Elf::TextSection.new(".text") @object.add_section @text - assembler = Risc::TextWriter.new(@machine) + assembler = Risc::TextWriter.new(@linker) set_text assembler.write_as_string # for debug add labels for labels - Parfait.object_space.each_type do |type| - type.each_method do |meth| - meth.cpu_instructions.each do |label| - next unless label.is_a?(Risc::Label) - add_symbol "#{type.name}@#{meth.name}:Label=#{label.name}" , Risc::Position.get(label).at - end - meth.binary.each_block do |code| - label = "BinaryCode@#{meth.name}" - add_symbol label , Risc::Position.get(code).at - end + @linker.assemblers.each do |asm| + meth = asm.method + asm.instructions.each do |label| + next unless label.is_a?(Risc::Label) + add_symbol "#{meth.for_type.name}@#{meth.name}:Label=#{label.name}" , Risc::Position.get(label).at + end + meth.binary.each_block do |code| + label = "BinaryCode@#{meth.name}" + add_symbol label , Risc::Position.get(code).at end end - @machine.object_positions.each do |slot , position| + @linker.object_positions.each do |slot , position| next if slot.is_a?(Parfait::BinaryCode) next if slot.class.name.include?("Arm") if( slot.respond_to? :rxf_reference_name ) diff --git a/test/mom/instruction/test_slot_definition.rb b/test/mom/instruction/test_slot_definition.rb index 1b3aab63..7a94dfa3 100644 --- a/test/mom/instruction/test_slot_definition.rb +++ b/test/mom/instruction/test_slot_definition.rb @@ -14,7 +14,7 @@ module Mom assert_equal :caller , slot.slots.first end def test_to_s - assert_equal "[message,caller]" , slot.to_s + assert_equal "[message, caller]" , slot.to_s end def test_create_fail_none assert_raises {slot(nil)} diff --git a/test/risc/interpreter/calling/test_minus.rb b/test/risc/interpreter/calling/test_minus.rb index d8596f9b..1b3a58c5 100644 --- a/test/risc/interpreter/calling/test_minus.rb +++ b/test/risc/interpreter/calling/test_minus.rb @@ -45,7 +45,7 @@ module Risc ret = main_ticks(63) assert_equal FunctionReturn , ret.class assert_equal :r1 , ret.register.symbol - assert_equal 20996 , @interpreter.get_register(ret.register) + assert_equal 21924 , @interpreter.get_register(ret.register) end def test_sys sys = main_ticks(68) diff --git a/test/risc/position/test_branch_listener.rb b/test/risc/position/test_branch_listener.rb index 776aba93..c49a7175 100644 --- a/test/risc/position/test_branch_listener.rb +++ b/test/risc/position/test_branch_listener.rb @@ -5,6 +5,7 @@ module Risc class TestBranchListenerBooted < MiniTest::Test def setup Parfait.boot! + Risc.boot! @binary = Parfait::BinaryCode.new(1) @bin_pos = CodeListener.init(@binary,:interpreter).set(0) @label = Label.new("HI","ho" , FakeAddress.new(2)) diff --git a/test/risc/position/test_code_position.rb b/test/risc/position/test_code_position.rb index 6df0daf2..98e1a364 100644 --- a/test/risc/position/test_code_position.rb +++ b/test/risc/position/test_code_position.rb @@ -4,6 +4,7 @@ module Risc class TestPositionTranslated < MiniTest::Test def setup Parfait.boot! + Risc.boot! @binary = Parfait::BinaryCode.new(1) @method = Parfait.object_space.types.values.first.methods @label = Risc.label("hi","ho") diff --git a/test/risc/test_linker.rb b/test/risc/test_linker.rb index 1b4befa3..5c2b0c98 100644 --- a/test/risc/test_linker.rb +++ b/test/risc/test_linker.rb @@ -19,17 +19,13 @@ module Risc end class TestLinkerInit < MiniTest::Test def setup - Parfait.boot! - Risc.boot! - @linker = Mom::MomCompiler.new.translate(:arm) - @linker.position_all - @linker.create_binary + @linker = RubyX::RubyXCompiler.new("class Space;def main;return 1;end;end").ruby_to_binary(:arm) end def test_pos_cpu assert_equal 0 , Position.get(@linker.cpu_init).at end def test_cpu_at - assert_equal "0x624c" , Position.get(@linker.cpu_init.first).to_s + assert_equal "0x626c" , Position.get(@linker.cpu_init.first).to_s end def test_cpu_label assert_equal Position , Position.get(@linker.cpu_init.first).class @@ -44,7 +40,7 @@ module Risc end def test_positions_set @linker.object_positions.each do |obj,position| - assert position.valid? , "#{position} , #{obj.object_id.to_s(16)}" + assert position.valid? , "#{position} #{position.object.class}, #{obj.object_id.to_s(16)}" end end end diff --git a/test/risc/test_method_compiler.rb b/test/risc/test_method_compiler.rb index dfbaa887..388bb945 100644 --- a/test/risc/test_method_compiler.rb +++ b/test/risc/test_method_compiler.rb @@ -78,7 +78,7 @@ module Risc input = in_Test("def meth; return 'Hi';end") mom = RubyX::RubyXCompiler.new(input).ruby_to_mom assert_equal Mom::MomCompiler , mom.class - compiler = mom.method_compilers.last + compiler = mom.method_compilers.first assert_equal MethodCompiler , compiler.class assert compiler.constants.include?("Hi") end diff --git a/test/risc/test_translator.rb b/test/risc/test_translator.rb index 04b57bf6..d3feb2e2 100644 --- a/test/risc/test_translator.rb +++ b/test/risc/test_translator.rb @@ -5,38 +5,18 @@ module Risc def setup Parfait.boot! - @machine = Risc.machine.boot @translator = Arm::Translator.new end + def test_has_translate + assert @translator.respond_to?(:translate) + end + def test_no_translate_junk + assert_raises {@translator.translate( "Hi there")} + end def test_translate_label - label = Parfait.object_space.get_main.risc_instructions - assert_equal "Space_Type.main" ,label.to_cpu(@translator).name , label - end - - def test_translate_space - assert @machine.translate(:arm) - end - - def test_no_loops_in_chain - @machine.translate(:arm) - @machine.position_all - init = Parfait.object_space.get_init - all = [] - init.cpu_instructions.each do |ins| - assert !all.include?(ins) - all << ins - end - end - def test_no_risc #by assembling, risc doesnt have assemble method - @machine.translate(:arm) - @machine.position_all - @machine.object_positions.keys.each do |method| - next unless method.is_a? Parfait::TypedMethod - method.cpu_instructions.each do |ins| - ins.assemble(Util::DevNull.new) - end - end + label = Risc::Label.new("HI","ho" , FakeAddress.new(0)) + assert_equal "ho" ,label.to_cpu(@translator).name , label end end diff --git a/test/support/compiling.rb b/test/support/compiling.rb index adadb173..09dcbe5e 100644 --- a/test/support/compiling.rb +++ b/test/support/compiling.rb @@ -39,6 +39,7 @@ module MomCompile end def compile_mom(input) + Risc.boot! RubyX::RubyXCompiler.new(input).ruby_to_mom end