adds first version of the expanded as assembler from mikko

This commit is contained in:
Torsten Ruger
2014-04-14 18:09:56 +03:00
parent 52e9542d73
commit 408b290b8a
32 changed files with 1943 additions and 1 deletions

43
lib/asm/assembler.rb Normal file
View File

@@ -0,0 +1,43 @@
module Asm
ERRSTR_NUMERIC_TOO_LARGE = 'cannot fit numeric literal argument in operand'
ERRSTR_INVALID_ARG = 'invalid operand argument'
class Assembler
def initialize
@objects = []
@label_objects = []
@label_callbacks = []
@relocations = []
end
attr_reader :relocations, :objects
def add_object(obj)
@objects << obj
end
def add_relocation(*args)
@relocations << Asm::Relocation.new(*args)
end
def register_label_callback(label, io_pos, &block)
@label_callbacks << [label, io_pos, block]
end
def assemble(io)
@objects.each do |obj|
obj.assemble io, self
end
@relocations.delete_if do |reloc|
io.seek reloc.position
if (reloc.label.extern?)
reloc.handler.call(io, io.tell, reloc.type)
else
reloc.handler.call(io, reloc.label.address, reloc.type)
end
not reloc.label.extern?
end
end
end
end