rubyx/lib/asm/assembler.rb

53 lines
976 B
Ruby
Raw Normal View History

module Asm
ERRSTR_NUMERIC_TOO_LARGE = 'cannot fit numeric literal argument in operand'
ERRSTR_INVALID_ARG = 'invalid operand argument'
class Assembler
def initialize
2014-04-22 21:24:22 +02:00
@values = []
@position = 0 # marks not set
2014-04-22 21:24:22 +02:00
@labels = []
@string_table = {}
#@relocations = []
end
2014-04-22 21:24:22 +02:00
attr_reader :relocations, :values , :position
2014-04-22 21:24:22 +02:00
def add_string str
value = @string_table[str]
return value if value
data = Asm::StringNode.new(str)
2014-04-22 21:24:22 +02:00
@string_table[str] = data
end
2014-04-21 20:21:45 +02:00
2014-04-22 21:24:22 +02:00
def strings
@string_table.values
end
def add_value(val)
val.at(@position)
length = val.length
@position += length
2014-04-22 21:24:22 +02:00
@values << val
end
def label
label = Asm::Arm::GeneratorLabel.new(self)
@labels << label
label
end
def label!
label.set!
end
def assemble(io)
2014-04-22 21:24:22 +02:00
@values.each do |obj|
obj.assemble io, self
end
end
end
2014-04-21 20:38:39 +02:00
end