rename data_object to string_node and move the padding there
This commit is contained in:
@ -6,7 +6,7 @@ require 'asm/arm/generator_label'
|
||||
require 'asm/nodes'
|
||||
require 'stream_reader'
|
||||
require 'stringio'
|
||||
require "asm/data_object"
|
||||
require "asm/string_node"
|
||||
|
||||
module Asm
|
||||
module Arm
|
||||
|
@ -46,7 +46,7 @@ module Asm
|
||||
def build_operand(arg , position = 0)
|
||||
#position only needed for calculating relative addresses to data objects
|
||||
#there is a design stink here which makes my head ache. But shanti shanti
|
||||
if arg.is_a?(Asm::DataObject)
|
||||
if arg.is_a?(Asm::StringNode)
|
||||
# do pc relative addressing with the difference to the instuction
|
||||
# 8 is for the funny pipeline adjustment (ie oc pointing to fetch and not execute)
|
||||
arg = Asm::NumLiteralNode.new( arg.position - position - 8 )
|
||||
|
@ -16,7 +16,7 @@ module Asm
|
||||
def add_string str
|
||||
value = @string_table[str]
|
||||
return value if value
|
||||
data = Asm::DataObject.new(str)
|
||||
data = Asm::StringNode.new(str)
|
||||
@string_table[str] = data
|
||||
end
|
||||
|
||||
@ -27,8 +27,6 @@ module Asm
|
||||
def add_value(val)
|
||||
val.at(@position)
|
||||
length = val.length
|
||||
#rounding up to the next 4
|
||||
length = (((length - 1 ) / 4 ) + 1 ) * 4
|
||||
@position += length
|
||||
@values << val
|
||||
end
|
||||
|
@ -1,21 +0,0 @@
|
||||
module Asm
|
||||
class DataObject
|
||||
def initialize(data)
|
||||
@data = data
|
||||
end
|
||||
|
||||
def position
|
||||
throw "Not set" unless @address
|
||||
@address
|
||||
end
|
||||
def at address
|
||||
@address = address
|
||||
end
|
||||
def length
|
||||
@data.length
|
||||
end
|
||||
def assemble(io, as)
|
||||
io << @data
|
||||
end
|
||||
end
|
||||
end
|
26
lib/asm/string_node.rb
Normal file
26
lib/asm/string_node.rb
Normal file
@ -0,0 +1,26 @@
|
||||
module Asm
|
||||
class StringNode
|
||||
def initialize(str)
|
||||
#align
|
||||
length = str.length
|
||||
# rounding up to the next 4 (always adding one for zero pad)
|
||||
pad = ((length / 4 ) + 1 ) * 4 - length
|
||||
raise "#{pad} #{self}" unless pad >= 1
|
||||
@string = str + "\x00" * pad
|
||||
end
|
||||
|
||||
def position
|
||||
throw "Not set" unless @address
|
||||
@address
|
||||
end
|
||||
def at address
|
||||
@address = address
|
||||
end
|
||||
def length
|
||||
@string.length
|
||||
end
|
||||
def assemble(io, as)
|
||||
io << @string
|
||||
end
|
||||
end
|
||||
end
|
Reference in New Issue
Block a user