This commit is contained in:
Torsten Ruger 2014-05-05 15:59:29 +03:00
parent de66238a9e
commit 69b04d930f
6 changed files with 34 additions and 12 deletions

View File

@ -11,12 +11,14 @@ module Support
name = name.to_s name = name.to_s
if args.length == 1 #must be assignemnt for ir attr= val if args.length == 1 #must be assignemnt for ir attr= val
if name.include? "=" if name.include? "="
return @attributes[name.chop] = args[0] #puts "setting :#{name.chop}:#{args[0]}"
return @attributes[name.chop.to_sym] = args[0]
else else
super super
end end
else else
return @attributes[name] #puts "getting :#{name}:#{@attributes[name.to_sym]}"
return @attributes[name.to_sym]
end end
end end
end end

View File

@ -39,7 +39,7 @@ module Vm
# so currently the interface passes the io (usually string_io) in for the code to assemble itself. # so currently the interface passes the io (usually string_io) in for the code to assemble itself.
# this may change as the writing is still done externally (or that will change) # this may change as the writing is still done externally (or that will change)
def assemble(io) def assemble(io)
throw "Not implemented #{self}" raise "Not implemented #{self.inspect}"
end end
end end
end end

View File

@ -10,7 +10,7 @@ module Vm
def initialize program def initialize program
@attributes = {} @attributes = {}
@attributes["program"] = program @attributes[:program] = program
end end
end end

View File

@ -26,7 +26,7 @@ module Vm
include Support::HashAttributes include Support::HashAttributes
def initialize options def initialize options
@options = options @attributes = options
end end
end end

View File

@ -54,12 +54,16 @@ module Vm
fun fun
end end
# linking entry , main , exit
# functions , objects
def link_at( start , context) def link_at( start , context)
@position = start @position = start
@entry.link_at( start , context ) @entry.link_at( start , context )
start += @entry.length start += @entry.length
@main.link_at( start , context ) @main.link_at( start , context )
start += @main.length start += @main.length
@exit.link_at( start , context)
start += @exit.length
@functions.each do |function| @functions.each do |function|
function.link_at(start , context) function.link_at(start , context)
start += function.length start += function.length
@ -68,17 +72,26 @@ module Vm
o.link_at(start , context) o.link_at(start , context)
start += o.length start += o.length
end end
@exit.link_at( start , context) end
start += @exit.length
# assemble in the same order as linked
def assemble( io )
link_at( @position , {}) #second link in case of forward declarations
@entry.assemble( io )
@main.assemble( io )
@exit.assemble( io )
@functions.each do |function|
function.assemble(io)
end
@objects.each do |o|
o.assemble(io)
end
io
end end
def main= code def main= code
@main = code @main = code
end end
private
# the main function
def create_main
end
end end
end end

View File

@ -29,6 +29,13 @@ class TestRunner < MiniTest::Test
binary = program.assemble(StringIO.new ) binary = program.assemble(StringIO.new )
writer = Elf::ObjectWriter.new(Elf::Constants::TARGET_ARM)
assembly = program.assemble(StringIO.new)
writer.set_text assembly
writer.save("#{file}_test.o")
puts program.to_yaml puts program.to_yaml
end end