misc fixes and (finally, sigh) green again
deeeep dive, almost 40 commits
This commit is contained in:
parent
d8b58d8da6
commit
2485f7e9eb
@ -7,8 +7,8 @@ require_relative 'string_table_section'
|
|||||||
module Elf
|
module Elf
|
||||||
|
|
||||||
class ObjectWriter
|
class ObjectWriter
|
||||||
def initialize( machine )
|
def initialize( linker )
|
||||||
@machine = machine
|
@linker = linker
|
||||||
target = Elf::Constants::TARGET_ARM
|
target = Elf::Constants::TARGET_ARM
|
||||||
@object = Elf::ObjectFile.new(target)
|
@object = Elf::ObjectFile.new(target)
|
||||||
sym_strtab = Elf::StringTableSection.new(".strtab")
|
sym_strtab = Elf::StringTableSection.new(".strtab")
|
||||||
@ -19,24 +19,23 @@ module Elf
|
|||||||
@text = Elf::TextSection.new(".text")
|
@text = Elf::TextSection.new(".text")
|
||||||
@object.add_section @text
|
@object.add_section @text
|
||||||
|
|
||||||
assembler = Risc::TextWriter.new(@machine)
|
assembler = Risc::TextWriter.new(@linker)
|
||||||
set_text assembler.write_as_string
|
set_text assembler.write_as_string
|
||||||
|
|
||||||
# for debug add labels for labels
|
# for debug add labels for labels
|
||||||
Parfait.object_space.each_type do |type|
|
@linker.assemblers.each do |asm|
|
||||||
type.each_method do |meth|
|
meth = asm.method
|
||||||
meth.cpu_instructions.each do |label|
|
asm.instructions.each do |label|
|
||||||
next unless label.is_a?(Risc::Label)
|
next unless label.is_a?(Risc::Label)
|
||||||
add_symbol "#{type.name}@#{meth.name}:Label=#{label.name}" , Risc::Position.get(label).at
|
add_symbol "#{meth.for_type.name}@#{meth.name}:Label=#{label.name}" , Risc::Position.get(label).at
|
||||||
end
|
end
|
||||||
meth.binary.each_block do |code|
|
meth.binary.each_block do |code|
|
||||||
label = "BinaryCode@#{meth.name}"
|
label = "BinaryCode@#{meth.name}"
|
||||||
add_symbol label , Risc::Position.get(code).at
|
add_symbol label , Risc::Position.get(code).at
|
||||||
end
|
end
|
||||||
end
|
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.is_a?(Parfait::BinaryCode)
|
||||||
next if slot.class.name.include?("Arm")
|
next if slot.class.name.include?("Arm")
|
||||||
if( slot.respond_to? :rxf_reference_name )
|
if( slot.respond_to? :rxf_reference_name )
|
||||||
|
@ -45,7 +45,7 @@ module Risc
|
|||||||
ret = main_ticks(63)
|
ret = main_ticks(63)
|
||||||
assert_equal FunctionReturn , ret.class
|
assert_equal FunctionReturn , ret.class
|
||||||
assert_equal :r1 , ret.register.symbol
|
assert_equal :r1 , ret.register.symbol
|
||||||
assert_equal 20996 , @interpreter.get_register(ret.register)
|
assert_equal 21924 , @interpreter.get_register(ret.register)
|
||||||
end
|
end
|
||||||
def test_sys
|
def test_sys
|
||||||
sys = main_ticks(68)
|
sys = main_ticks(68)
|
||||||
|
@ -5,6 +5,7 @@ module Risc
|
|||||||
class TestBranchListenerBooted < MiniTest::Test
|
class TestBranchListenerBooted < MiniTest::Test
|
||||||
def setup
|
def setup
|
||||||
Parfait.boot!
|
Parfait.boot!
|
||||||
|
Risc.boot!
|
||||||
@binary = Parfait::BinaryCode.new(1)
|
@binary = Parfait::BinaryCode.new(1)
|
||||||
@bin_pos = CodeListener.init(@binary,:interpreter).set(0)
|
@bin_pos = CodeListener.init(@binary,:interpreter).set(0)
|
||||||
@label = Label.new("HI","ho" , FakeAddress.new(2))
|
@label = Label.new("HI","ho" , FakeAddress.new(2))
|
||||||
|
@ -4,6 +4,7 @@ module Risc
|
|||||||
class TestPositionTranslated < MiniTest::Test
|
class TestPositionTranslated < MiniTest::Test
|
||||||
def setup
|
def setup
|
||||||
Parfait.boot!
|
Parfait.boot!
|
||||||
|
Risc.boot!
|
||||||
@binary = Parfait::BinaryCode.new(1)
|
@binary = Parfait::BinaryCode.new(1)
|
||||||
@method = Parfait.object_space.types.values.first.methods
|
@method = Parfait.object_space.types.values.first.methods
|
||||||
@label = Risc.label("hi","ho")
|
@label = Risc.label("hi","ho")
|
||||||
|
@ -19,17 +19,13 @@ module Risc
|
|||||||
end
|
end
|
||||||
class TestLinkerInit < MiniTest::Test
|
class TestLinkerInit < MiniTest::Test
|
||||||
def setup
|
def setup
|
||||||
Parfait.boot!
|
@linker = RubyX::RubyXCompiler.new("class Space;def main;return 1;end;end").ruby_to_binary(:arm)
|
||||||
Risc.boot!
|
|
||||||
@linker = Mom::MomCompiler.new.translate(:arm)
|
|
||||||
@linker.position_all
|
|
||||||
@linker.create_binary
|
|
||||||
end
|
end
|
||||||
def test_pos_cpu
|
def test_pos_cpu
|
||||||
assert_equal 0 , Position.get(@linker.cpu_init).at
|
assert_equal 0 , Position.get(@linker.cpu_init).at
|
||||||
end
|
end
|
||||||
def test_cpu_at
|
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
|
end
|
||||||
def test_cpu_label
|
def test_cpu_label
|
||||||
assert_equal Position , Position.get(@linker.cpu_init.first).class
|
assert_equal Position , Position.get(@linker.cpu_init.first).class
|
||||||
@ -44,7 +40,7 @@ module Risc
|
|||||||
end
|
end
|
||||||
def test_positions_set
|
def test_positions_set
|
||||||
@linker.object_positions.each do |obj,position|
|
@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
|
end
|
||||||
end
|
end
|
||||||
|
@ -78,7 +78,7 @@ module Risc
|
|||||||
input = in_Test("def meth; return 'Hi';end")
|
input = in_Test("def meth; return 'Hi';end")
|
||||||
mom = RubyX::RubyXCompiler.new(input).ruby_to_mom
|
mom = RubyX::RubyXCompiler.new(input).ruby_to_mom
|
||||||
assert_equal Mom::MomCompiler , mom.class
|
assert_equal Mom::MomCompiler , mom.class
|
||||||
compiler = mom.method_compilers.last
|
compiler = mom.method_compilers.first
|
||||||
assert_equal MethodCompiler , compiler.class
|
assert_equal MethodCompiler , compiler.class
|
||||||
assert compiler.constants.include?("Hi")
|
assert compiler.constants.include?("Hi")
|
||||||
end
|
end
|
||||||
|
@ -5,38 +5,18 @@ module Risc
|
|||||||
|
|
||||||
def setup
|
def setup
|
||||||
Parfait.boot!
|
Parfait.boot!
|
||||||
@machine = Risc.machine.boot
|
|
||||||
@translator = Arm::Translator.new
|
@translator = Arm::Translator.new
|
||||||
end
|
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
|
def test_translate_label
|
||||||
label = Parfait.object_space.get_main.risc_instructions
|
label = Risc::Label.new("HI","ho" , FakeAddress.new(0))
|
||||||
assert_equal "Space_Type.main" ,label.to_cpu(@translator).name , label
|
assert_equal "ho" ,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
|
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
@ -39,6 +39,7 @@ module MomCompile
|
|||||||
end
|
end
|
||||||
|
|
||||||
def compile_mom(input)
|
def compile_mom(input)
|
||||||
|
Risc.boot!
|
||||||
RubyX::RubyXCompiler.new(input).ruby_to_mom
|
RubyX::RubyXCompiler.new(input).ruby_to_mom
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user