fix and use object writer in test
This commit is contained in:
parent
b5c39b2749
commit
18f33770b5
@ -6,9 +6,9 @@ require 'elf/string_table_section'
|
|||||||
module Elf
|
module Elf
|
||||||
|
|
||||||
class ObjectWriter
|
class ObjectWriter
|
||||||
def initialize(program , target)
|
def initialize(space , target = Elf::Constants::TARGET_ARM )
|
||||||
@object = Elf::ObjectFile.new(target)
|
@object = Elf::ObjectFile.new(target)
|
||||||
@object_space = program
|
@object_space = space
|
||||||
sym_strtab = Elf::StringTableSection.new(".strtab")
|
sym_strtab = Elf::StringTableSection.new(".strtab")
|
||||||
@object.add_section sym_strtab
|
@object.add_section sym_strtab
|
||||||
@symbol_table = Elf::SymbolTableSection.new(".symtab", sym_strtab)
|
@symbol_table = Elf::SymbolTableSection.new(".symtab", sym_strtab)
|
||||||
@ -17,23 +17,20 @@ module Elf
|
|||||||
@text = Elf::TextSection.new(".text")
|
@text = Elf::TextSection.new(".text")
|
||||||
@object.add_section @text
|
@object.add_section @text
|
||||||
|
|
||||||
program.link_at( 0 , program.context )
|
@object_space.run_passes
|
||||||
program.run_passes
|
assembler = Register::Assembler.new(@object_space)
|
||||||
binary = program.assemble(StringIO.new )
|
set_text assembler.assemble
|
||||||
|
|
||||||
|
# for debug add labels to the block positions
|
||||||
blocks = []
|
blocks = []
|
||||||
program.classes.values.each do |clazz|
|
space.classes.values.each do |clazz|
|
||||||
clazz.functions.each do |f|
|
clazz.instance_methods.each do |f|
|
||||||
f.blocks.each do |b|
|
f.blocks.each do |b|
|
||||||
add_symbol "#{clazz.name}::#{f.name}@#{b.name}" , b.position
|
add_symbol "#{clazz.name}::#{f.name}@#{b.name}" , b.position
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
blocks += [program.entry , program.exit , program.main]
|
|
||||||
blocks.flatten.each do |b|
|
|
||||||
add_symbol b.name.to_s , b.position
|
|
||||||
end
|
|
||||||
set_text binary.string
|
|
||||||
end
|
end
|
||||||
attr_reader :text
|
attr_reader :text
|
||||||
def set_text(text)
|
def set_text(text)
|
||||||
|
@ -6,11 +6,10 @@ class HelloTest < MiniTest::Test
|
|||||||
def check
|
def check
|
||||||
machine = Virtual::Machine.boot
|
machine = Virtual::Machine.boot
|
||||||
expressions = machine.compile_main @string_input
|
expressions = machine.compile_main @string_input
|
||||||
puts ""
|
|
||||||
Virtual::BootSpace.space.run_passes
|
writer = Elf::ObjectWriter.new(Virtual::BootSpace.space)
|
||||||
ass = Register::Assembler.new(Virtual::BootSpace.space)
|
writer.save "hello.o"
|
||||||
ass.assemble
|
# puts Sof::Writer.write(expressions)
|
||||||
puts Sof::Writer.write(expressions)
|
|
||||||
# puts Sof::Writer.write(Virtual::BootSpace.space)
|
# puts Sof::Writer.write(Virtual::BootSpace.space)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user