misc fixes and (finally, sigh) green again

deeeep dive, almost 40 commits
This commit is contained in:
Torsten Ruger 2018-07-04 09:18:55 +03:00
parent d8b58d8da6
commit 2485f7e9eb
9 changed files with 30 additions and 52 deletions

View File

@ -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 )

View File

@ -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)}

View File

@ -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)

View File

@ -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))

View File

@ -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")

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -39,6 +39,7 @@ module MomCompile
end
def compile_mom(input)
Risc.boot!
RubyX::RubyXCompiler.new(input).ruby_to_mom
end