mem_length to word/byte length
be more specific, and don’t include padding
This commit is contained in:
parent
30d9aaf61b
commit
1c29fcfd43
@ -119,7 +119,7 @@ module Arm
|
|||||||
end
|
end
|
||||||
|
|
||||||
# arm intrucioons are pretty sensible, and always 4 bytes (thumb not supported)
|
# arm intrucioons are pretty sensible, and always 4 bytes (thumb not supported)
|
||||||
def mem_length
|
def byte_length
|
||||||
4
|
4
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -25,7 +25,7 @@ module Arm
|
|||||||
# alas, full transparency is not achieved as we only know when to use 2 instruction once we
|
# alas, full transparency is not achieved as we only know when to use 2 instruction once we
|
||||||
# know where the other object is, and that position is only set after code positions have been
|
# know where the other object is, and that position is only set after code positions have been
|
||||||
# determined (in link) and so see below in assemble
|
# determined (in link) and so see below in assemble
|
||||||
def mem_length
|
def word_length
|
||||||
@extra ? 8 : 4
|
@extra ? 8 : 4
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -89,7 +89,7 @@ module Parfait
|
|||||||
get_layout().index_of(name)
|
get_layout().index_of(name)
|
||||||
end
|
end
|
||||||
|
|
||||||
def mem_length
|
def word_length
|
||||||
padded_words( get_layout().get_length() + 2 )
|
padded_words( get_layout().get_length() + 2 )
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -128,8 +128,8 @@ module Parfait
|
|||||||
raise "called"
|
raise "called"
|
||||||
class_for(MoveInstruction).new(value , self , :opcode => :mov)
|
class_for(MoveInstruction).new(value , self , :opcode => :mov)
|
||||||
end
|
end
|
||||||
def mem_length
|
def word_length
|
||||||
padded(1 + string.length)
|
(string.length+1) / 4
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -25,7 +25,7 @@ module Register
|
|||||||
# binary code (array) to right length
|
# binary code (array) to right length
|
||||||
@machine.objects.each do |objekt|
|
@machine.objects.each do |objekt|
|
||||||
next unless objekt.is_a? Parfait::Method
|
next unless objekt.is_a? Parfait::Method
|
||||||
objekt.code.set_length(objekt.info.mem_length , 0)
|
objekt.code.set_length(objekt.info.byte_length , 0)
|
||||||
end
|
end
|
||||||
at = 0
|
at = 0
|
||||||
# then we make sure we really get the binary codes first
|
# then we make sure we really get the binary codes first
|
||||||
@ -33,7 +33,7 @@ module Register
|
|||||||
next unless objekt.is_a? Parfait::BinaryCode
|
next unless objekt.is_a? Parfait::BinaryCode
|
||||||
objekt.set_position at
|
objekt.set_position at
|
||||||
# puts "CODE #{objekt.name} at #{objekt.position}"
|
# puts "CODE #{objekt.name} at #{objekt.position}"
|
||||||
at += objekt.mem_length
|
at += objekt.word_length
|
||||||
end
|
end
|
||||||
# and then everything else
|
# and then everything else
|
||||||
@machine.objects.each do | objekt|
|
@machine.objects.each do | objekt|
|
||||||
@ -44,7 +44,7 @@ module Register
|
|||||||
end
|
end
|
||||||
next if objekt.is_a? Parfait::BinaryCode
|
next if objekt.is_a? Parfait::BinaryCode
|
||||||
objekt.set_position at
|
objekt.set_position at
|
||||||
at += objekt.mem_length
|
at += objekt.word_length
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -55,7 +55,7 @@ module Register
|
|||||||
link
|
link
|
||||||
all= @machine.objects.sort{|a,b| a.position <=> b.position}
|
all= @machine.objects.sort{|a,b| a.position <=> b.position}
|
||||||
all.each do |objekt|
|
all.each do |objekt|
|
||||||
puts "Linked #{objekt.class}(#{objekt.object_id.to_s(16)}) at #{objekt.position.to_s(16)} / #{objekt.mem_length.to_s(16)}"
|
puts "Linked #{objekt.class}(#{objekt.object_id.to_s(16)}) at #{objekt.position.to_s(16)} / #{objekt.word_length.to_s(16)}"
|
||||||
objekt.position
|
objekt.position
|
||||||
end
|
end
|
||||||
# first we need to create the binary code for the methods
|
# first we need to create the binary code for the methods
|
||||||
@ -107,8 +107,8 @@ module Register
|
|||||||
index = 1
|
index = 1
|
||||||
stream.rewind
|
stream.rewind
|
||||||
puts "Assembled #{method.name} with length #{stream.length}"
|
puts "Assembled #{method.name} with length #{stream.length}"
|
||||||
raise "length error #{method.code.length} != #{method.info.mem_length}" if method.code.length != method.info.mem_length
|
raise "length error #{method.code.length} != #{method.info.byte_length}" if method.code.length != method.info.byte_length
|
||||||
raise "length error #{stream.length} != #{method.info.mem_length}" if method.info.mem_length - stream.length > 32
|
raise "length error #{stream.length} != #{method.info.byte_length}" if method.info.byte_length - stream.length > 32
|
||||||
stream.each_byte do |b|
|
stream.each_byte do |b|
|
||||||
method.code.set_char(index , b )
|
method.code.set_char(index , b )
|
||||||
index = index + 1
|
index = index + 1
|
||||||
@ -116,7 +116,7 @@ module Register
|
|||||||
end
|
end
|
||||||
|
|
||||||
def assemble_any obj
|
def assemble_any obj
|
||||||
puts "Assemble #{obj.class}(#{obj.object_id.to_s(16)}) at stream #{(@stream.length).to_s(16)} pos:#{obj.position.to_s(16)} , len:#{obj.mem_length}"
|
puts "Assemble #{obj.class}(#{obj.object_id.to_s(16)}) at stream #{(@stream.length).to_s(16)} pos:#{obj.position.to_s(16)} , len:#{obj.word_length}"
|
||||||
if @stream.length != obj.position
|
if @stream.length != obj.position
|
||||||
raise "Assemble #{obj.class} #{obj.object_id.to_s(16)} at #{@stream.length.to_s(16)} not #{obj.position.to_s(16)}"
|
raise "Assemble #{obj.class} #{obj.object_id.to_s(16)} at #{@stream.length.to_s(16)} not #{obj.position.to_s(16)}"
|
||||||
end
|
end
|
||||||
@ -154,8 +154,8 @@ module Register
|
|||||||
puts "Nil for #{object.class}.#{var}" unless inst
|
puts "Nil for #{object.class}.#{var}" unless inst
|
||||||
write_ref_for(inst)
|
write_ref_for(inst)
|
||||||
end
|
end
|
||||||
puts "layout leng=#{layout.get_length.to_s(16)} mem_len=#{layout.mem_length.to_s(16)}"
|
puts "layout leng=#{layout.get_length.to_s(16)} mem_len=#{layout.word_length.to_s(16)}"
|
||||||
pad_after( layout.mem_length )
|
pad_after( layout.word_length )
|
||||||
object.position
|
object.position
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -192,7 +192,7 @@ module Register
|
|||||||
|
|
||||||
def assemble_Method(method)
|
def assemble_Method(method)
|
||||||
raise "no"
|
raise "no"
|
||||||
count = method.info.blocks.inject(0) { |c , block| c += block.mem_length }
|
count = method.info.blocks.inject(0) { |c , block| c += block.word_length }
|
||||||
word = (count+7) / 32 # all object are multiple of 8 words (7 for header)
|
word = (count+7) / 32 # all object are multiple of 8 words (7 for header)
|
||||||
raise "Method too long, splitting not implemented #{method.name}/#{count}" if word > 15
|
raise "Method too long, splitting not implemented #{method.name}/#{count}" if word > 15
|
||||||
# first line is integers, convention is that following lines are the same
|
# first line is integers, convention is that following lines are the same
|
||||||
@ -224,7 +224,7 @@ module Register
|
|||||||
write_ref_for( string.get_layout ) #ref
|
write_ref_for( string.get_layout ) #ref
|
||||||
@stream.write str
|
@stream.write str
|
||||||
pad_after(str.length)
|
pad_after(str.length)
|
||||||
#puts "String (#{slot.mem_length}) stream #{@stream.mem_length.to_s(16)}"
|
#puts "String (#{slot.word_length}) stream #{@stream.word_length.to_s(16)}"
|
||||||
end
|
end
|
||||||
|
|
||||||
def assemble_Symbol(sym)
|
def assemble_Symbol(sym)
|
||||||
@ -245,7 +245,7 @@ module Register
|
|||||||
|
|
||||||
# pad_after is always in bytes and pads (writes 0's) up to the next 8 word boundary
|
# pad_after is always in bytes and pads (writes 0's) up to the next 8 word boundary
|
||||||
def pad_after length
|
def pad_after length
|
||||||
pad = padding_for(lenght)
|
pad = padding_for(length)
|
||||||
pad.times do
|
pad.times do
|
||||||
@stream.write_uint8(0)
|
@stream.write_uint8(0)
|
||||||
end
|
end
|
||||||
|
@ -12,7 +12,7 @@ module Register
|
|||||||
block.mov( self , right ) #move the value
|
block.mov( self , right ) #move the value
|
||||||
elsif right.is_a? StringConstant
|
elsif right.is_a? StringConstant
|
||||||
block.add( self , right , nil) #move the address, by "adding" to pc, ie pc relative
|
block.add( self , right , nil) #move the address, by "adding" to pc, ie pc relative
|
||||||
block.mov( Integer.new(self.register.next_reg_use) , right.mem_length ) #and the length HACK TODO
|
block.mov( Integer.new(self.register.next_reg_use) , right.word_length ) #and the length HACK TODO
|
||||||
elsif right.is_a?(Boot::BootClass) or right.is_a?(Boot::MetaClass)
|
elsif right.is_a?(Boot::BootClass) or right.is_a?(Boot::MetaClass)
|
||||||
block.add( self , right , nil) #move the address, by "adding" to pc, ie pc relative
|
block.add( self , right , nil) #move the address, by "adding" to pc, ie pc relative
|
||||||
else
|
else
|
||||||
|
@ -2,7 +2,7 @@ module StreamReader
|
|||||||
def read_binary(size, count, type)
|
def read_binary(size, count, type)
|
||||||
d = __sr_read(size*count)
|
d = __sr_read(size*count)
|
||||||
ret = d.unpack(type*count)
|
ret = d.unpack(type*count)
|
||||||
return ret if ret.mem_length > 1
|
return ret if ret.word_length > 1
|
||||||
return ret[0]
|
return ret[0]
|
||||||
end
|
end
|
||||||
def read_uint32(n=1)
|
def read_uint32(n=1)
|
||||||
@ -74,7 +74,7 @@ module StreamWriter
|
|||||||
return __sr_write(str + 0.chr)
|
return __sr_write(str + 0.chr)
|
||||||
end
|
end
|
||||||
def write_cstr_prefixed(str)
|
def write_cstr_prefixed(str)
|
||||||
write_uint8(str.mem_length)
|
write_uint8(str.word_length)
|
||||||
return __sr_write(str)
|
return __sr_write(str)
|
||||||
end
|
end
|
||||||
def write_str(str)
|
def write_str(str)
|
||||||
|
@ -62,13 +62,13 @@ module Virtual
|
|||||||
puts "BLOCK #{self.to_s[0..5000]}"
|
puts "BLOCK #{self.to_s[0..5000]}"
|
||||||
raise e
|
raise e
|
||||||
end
|
end
|
||||||
raise code.inspect unless code.mem_length
|
raise code.inspect unless code.byte_length
|
||||||
at += code.mem_length
|
at += code.byte_length
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def mem_length
|
def byte_length
|
||||||
@codes.inject(0){|count , instruction| count += instruction.mem_length }
|
@codes.inject(0){|count , instruction| count += instruction.byte_length }
|
||||||
end
|
end
|
||||||
|
|
||||||
def to_s
|
def to_s
|
||||||
|
@ -135,9 +135,8 @@ module Virtual
|
|||||||
add_code ::Arm::ArmMachine.send(meth , *arg_names)
|
add_code ::Arm::ArmMachine.send(meth , *arg_names)
|
||||||
end
|
end
|
||||||
|
|
||||||
def mem_length
|
def byte_length
|
||||||
l = @blocks.inject(0) { |c , block| c += block.mem_length }
|
@blocks.inject(0) { |c , block| c += block.byte_length }
|
||||||
padded(l)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# position of the function is the position of the entry block, is where we call
|
# position of the function is the position of the entry block, is where we call
|
||||||
@ -145,7 +144,7 @@ module Virtual
|
|||||||
at += 8 #for the 2 header words
|
at += 8 #for the 2 header words
|
||||||
@blocks.each do |block|
|
@blocks.each do |block|
|
||||||
block.set_position at
|
block.set_position at
|
||||||
at = at + block.mem_length
|
at = at + block.byte_length
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -26,7 +26,7 @@ module FakeMem
|
|||||||
def position
|
def position
|
||||||
if @position.nil?
|
if @position.nil?
|
||||||
str = "IN machine #{Virtual.machine.objects.include?(self)}\n"
|
str = "IN machine #{Virtual.machine.objects.include?(self)}\n"
|
||||||
raise str + "position not set for #{self.class} at #{mem_length} for #{self.inspect[0...100]}"
|
raise str + "position not set for #{self.class} at #{word_length} for #{self.inspect[0...100]}"
|
||||||
end
|
end
|
||||||
@position
|
@position
|
||||||
end
|
end
|
||||||
@ -61,7 +61,7 @@ class Symbol
|
|||||||
def get_layout
|
def get_layout
|
||||||
Virtual.machine.class_mappings[:Word].object_layout
|
Virtual.machine.class_mappings[:Word].object_layout
|
||||||
end
|
end
|
||||||
def mem_length
|
def word_length
|
||||||
to_s.length
|
to_s.length
|
||||||
end
|
end
|
||||||
# not the prettiest addition to the game, but it wasn't me who decided symbols are frozen in 2.x
|
# not the prettiest addition to the game, but it wasn't me who decided symbols are frozen in 2.x
|
||||||
@ -147,7 +147,7 @@ module Parfait
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
class List
|
class List
|
||||||
def mem_length
|
def word_length
|
||||||
padded_words(get_length())
|
padded_words(get_length())
|
||||||
end
|
end
|
||||||
def to_sof_node(writer , level , ref )
|
def to_sof_node(writer , level , ref )
|
||||||
@ -174,7 +174,7 @@ module Parfait
|
|||||||
end
|
end
|
||||||
|
|
||||||
class Word
|
class Word
|
||||||
def mem_length
|
def word_length
|
||||||
padded(1 + length())
|
padded(1 + length())
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -41,9 +41,9 @@ module Virtual
|
|||||||
# Code interface follows. Note position is inheitted as is from Code
|
# Code interface follows. Note position is inheitted as is from Code
|
||||||
|
|
||||||
# length of the Plock is the length of the block, plus the branch, plus data.
|
# length of the Plock is the length of the block, plus the branch, plus data.
|
||||||
def mem_length
|
def byte_length
|
||||||
len = @data.inject(super) {| sum , item | sum + item.mem_length}
|
len = @data.inject(super) {| sum , item | sum + item.word_length}
|
||||||
len + @branch_code.mem_length
|
len + @branch_code.word_length
|
||||||
end
|
end
|
||||||
|
|
||||||
# again, super + branch plus data
|
# again, super + branch plus data
|
||||||
@ -52,7 +52,7 @@ module Virtual
|
|||||||
@branch_code.link_at pos , context
|
@branch_code.link_at pos , context
|
||||||
@data.each do |code|
|
@data.each do |code|
|
||||||
code.link_at(pos , context)
|
code.link_at(pos , context)
|
||||||
pos += code.mem_length
|
pos += code.word_length
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -3,7 +3,7 @@ require_relative "type"
|
|||||||
module Positioned
|
module Positioned
|
||||||
def position
|
def position
|
||||||
if @position == nil
|
if @position == nil
|
||||||
raise "position accessed but not set at #{mem_length} for #{self.inspect[0...500]}"
|
raise "position accessed but not set at #{word_length} for #{self.inspect[0...500]}"
|
||||||
end
|
end
|
||||||
@position
|
@position
|
||||||
end
|
end
|
||||||
|
@ -24,15 +24,15 @@ end
|
|||||||
class TestPositioning < MiniTest::Test
|
class TestPositioning < MiniTest::Test
|
||||||
def test_list1
|
def test_list1
|
||||||
list = Virtual.new_list([1])
|
list = Virtual.new_list([1])
|
||||||
assert_equal 32 , list.mem_length
|
assert_equal 32 , list.word_length
|
||||||
end
|
end
|
||||||
def test_list5
|
def test_list5
|
||||||
list = Virtual.new_list([1,2,3,4,5])
|
list = Virtual.new_list([1,2,3,4,5])
|
||||||
assert_equal 32 , list.mem_length
|
assert_equal 32 , list.word_length
|
||||||
end
|
end
|
||||||
def test_layout
|
def test_layout
|
||||||
layout = Parfait::Layout.new Object
|
layout = Parfait::Layout.new Object
|
||||||
layout.push 5
|
layout.push 5
|
||||||
assert_equal 32 , layout.mem_length
|
assert_equal 32 , layout.word_length
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user