rubyx/lib/asm/arm/addr_table_object.rb

48 lines
1.3 KiB
Ruby
Raw Normal View History

2014-04-21 16:27:05 +02:00
module Asm
module Arm
2014-04-21 19:59:48 +02:00
# TODO actually find the closest somehow (DROPPED for now)
def self.closest_addrtable(as)
2014-04-22 21:24:22 +02:00
as.values.find do |obj|
2014-04-21 19:59:48 +02:00
obj.is_a?(Asm::Arm::AddrTableObject)
end || (raise Asm::AssemblyError.new('could not find addrtable to use', nil))
end
#this has been DROPPED for now (didn't work) and we can do without it
2014-04-21 16:27:05 +02:00
class AddrTableObject
def initialize
@table = []
@const = []
end
2014-04-21 16:27:05 +02:00
# TODO don't create new entry if there's already an entry for the same label/const
def add_label(label)
d = [label, Asm::LabelObject.new]
@table << d
d[1]
end
2014-04-21 16:27:05 +02:00
def add_const(const)
d = [const, Asm::LabelObject.new]
@const << d
d[1]
end
2014-04-21 16:27:05 +02:00
def assemble(io, as)
@table.each do |pair|
target_label, here_label = *pair
here_label.assemble io, as
as.add_relocation io.tell, target_label, Asm::Arm::R_ARM_ABS32,
Asm::Arm::Instruction::RelocHandler
io.write_uint32 0
end
@const.each do |pair|
const, here_label = *pair
here_label.assemble io, as
io.write_uint32 const
end
end
end
end
2014-04-21 16:27:05 +02:00
end