get an elf written

This commit is contained in:
Torsten Ruger 2018-03-29 20:37:25 +03:00
parent 3844a738cd
commit efcc33f8a1
3 changed files with 14 additions and 14 deletions

View File

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

View File

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

View File

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