get an elf written
This commit is contained in:
parent
3844a738cd
commit
efcc33f8a1
@ -7,9 +7,8 @@ require_relative 'string_table_section'
|
|||||||
module Elf
|
module Elf
|
||||||
|
|
||||||
class ObjectWriter
|
class ObjectWriter
|
||||||
def initialize( machine , objects )
|
def initialize( machine )
|
||||||
@machine = machine
|
@machine = machine
|
||||||
@objects = objects
|
|
||||||
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")
|
||||||
@ -20,19 +19,20 @@ 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 , @objects)
|
assembler = Risc::TextWriter.new(@machine)
|
||||||
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|
|
Parfait.object_space.each_type do |type|
|
||||||
type.methods.each do |f|
|
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)
|
add_symbol "#{type.name}::#{f.name}:#{label.name}" , Positioned.position(label)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@objects.each do |id,slot|
|
@machine.objects.each do |id,slot|
|
||||||
next if slot.is_a?(Parfait::BinaryCode)
|
next if slot.is_a?(Parfait::BinaryCode)
|
||||||
if( slot.respond_to? :sof_reference_name )
|
if( slot.respond_to? :sof_reference_name )
|
||||||
label = "#{slot.sof_reference_name}"
|
label = "#{slot.sof_reference_name}"
|
||||||
|
@ -13,5 +13,10 @@ module Vool
|
|||||||
statements = self.ruby_to_vool(source)
|
statements = self.ruby_to_vool(source)
|
||||||
statements.to_mom(nil)
|
statements.to_mom(nil)
|
||||||
end
|
end
|
||||||
|
def self.ruby_to_binary(source)
|
||||||
|
machine = Risc.machine.boot
|
||||||
|
self.ruby_to_vool(source)
|
||||||
|
machine.position_all
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -1,20 +1,15 @@
|
|||||||
require_relative "../helper"
|
require_relative "../helper"
|
||||||
|
|
||||||
class HelloTest < MiniTest::Test
|
class HelloTest < MiniTest::Test
|
||||||
include AST::Sexp
|
|
||||||
|
|
||||||
def check
|
def check
|
||||||
machine = Risc.machine.boot
|
Vool::VoolCompiler.ruby_to_binary( "class Space;def main(arg);#{@input};end;end" )
|
||||||
Vm.compile_ast( @input )
|
writer = Elf::ObjectWriter.new(Risc.machine)
|
||||||
objects = Risc::Collector.collect_space
|
|
||||||
machine.translate_arm
|
|
||||||
writer = Elf::ObjectWriter.new(machine , objects )
|
|
||||||
writer.save "test/hello.o"
|
writer.save "test/hello.o"
|
||||||
end
|
end
|
||||||
|
|
||||||
def pest_string_put
|
def test_string_put
|
||||||
@input = s(:statements, s(:return, s(:call, :putstring, s(:arguments),
|
@input = "'Hello'.putstring"
|
||||||
s(:receiver, s(:string, "Hello again\\n")))))
|
|
||||||
check
|
check
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user