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
|
||||
|
||||
# arm intrucioons are pretty sensible, and always 4 bytes (thumb not supported)
|
||||
def mem_length
|
||||
def byte_length
|
||||
4
|
||||
end
|
||||
|
||||
|
@ -25,7 +25,7 @@ module Arm
|
||||
# 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
|
||||
# determined (in link) and so see below in assemble
|
||||
def mem_length
|
||||
def word_length
|
||||
@extra ? 8 : 4
|
||||
end
|
||||
|
||||
|
@ -89,7 +89,7 @@ module Parfait
|
||||
get_layout().index_of(name)
|
||||
end
|
||||
|
||||
def mem_length
|
||||
def word_length
|
||||
padded_words( get_layout().get_length() + 2 )
|
||||
end
|
||||
|
||||
|
@ -128,8 +128,8 @@ module Parfait
|
||||
raise "called"
|
||||
class_for(MoveInstruction).new(value , self , :opcode => :mov)
|
||||
end
|
||||
def mem_length
|
||||
padded(1 + string.length)
|
||||
def word_length
|
||||
(string.length+1) / 4
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -25,7 +25,7 @@ module Register
|
||||
# binary code (array) to right length
|
||||
@machine.objects.each do |objekt|
|
||||
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
|
||||
at = 0
|
||||
# then we make sure we really get the binary codes first
|
||||
@ -33,7 +33,7 @@ module Register
|
||||
next unless objekt.is_a? Parfait::BinaryCode
|
||||
objekt.set_position at
|
||||
# puts "CODE #{objekt.name} at #{objekt.position}"
|
||||
at += objekt.mem_length
|
||||
at += objekt.word_length
|
||||
end
|
||||
# and then everything else
|
||||
@machine.objects.each do | objekt|
|
||||
@ -44,7 +44,7 @@ module Register
|
||||
end
|
||||
next if objekt.is_a? Parfait::BinaryCode
|
||||
objekt.set_position at
|
||||
at += objekt.mem_length
|
||||
at += objekt.word_length
|
||||
end
|
||||
end
|
||||
|
||||
@ -55,7 +55,7 @@ module Register
|
||||
link
|
||||
all= @machine.objects.sort{|a,b| a.position <=> b.position}
|
||||
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
|
||||
end
|
||||
# first we need to create the binary code for the methods
|
||||
@ -107,8 +107,8 @@ module Register
|
||||
index = 1
|
||||
stream.rewind
|
||||
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 #{stream.length} != #{method.info.mem_length}" if method.info.mem_length - stream.length > 32
|
||||
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.byte_length}" if method.info.byte_length - stream.length > 32
|
||||
stream.each_byte do |b|
|
||||
method.code.set_char(index , b )
|
||||
index = index + 1
|
||||
@ -116,7 +116,7 @@ module Register
|
||||
end
|
||||
|
||||
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
|
||||
raise "Assemble #{obj.class} #{obj.object_id.to_s(16)} at #{@stream.length.to_s(16)} not #{obj.position.to_s(16)}"
|
||||
end
|
||||
@ -154,8 +154,8 @@ module Register
|
||||
puts "Nil for #{object.class}.#{var}" unless inst
|
||||
write_ref_for(inst)
|
||||
end
|
||||
puts "layout leng=#{layout.get_length.to_s(16)} mem_len=#{layout.mem_length.to_s(16)}"
|
||||
pad_after( layout.mem_length )
|
||||
puts "layout leng=#{layout.get_length.to_s(16)} mem_len=#{layout.word_length.to_s(16)}"
|
||||
pad_after( layout.word_length )
|
||||
object.position
|
||||
end
|
||||
|
||||
@ -192,7 +192,7 @@ module Register
|
||||
|
||||
def assemble_Method(method)
|
||||
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)
|
||||
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
|
||||
@ -224,7 +224,7 @@ module Register
|
||||
write_ref_for( string.get_layout ) #ref
|
||||
@stream.write str
|
||||
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
|
||||
|
||||
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
|
||||
def pad_after length
|
||||
pad = padding_for(lenght)
|
||||
pad = padding_for(length)
|
||||
pad.times do
|
||||
@stream.write_uint8(0)
|
||||
end
|
||||
|
@ -12,7 +12,7 @@ module Register
|
||||
block.mov( self , right ) #move the value
|
||||
elsif right.is_a? StringConstant
|
||||
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)
|
||||
block.add( self , right , nil) #move the address, by "adding" to pc, ie pc relative
|
||||
else
|
||||
|
@ -2,7 +2,7 @@ module StreamReader
|
||||
def read_binary(size, count, type)
|
||||
d = __sr_read(size*count)
|
||||
ret = d.unpack(type*count)
|
||||
return ret if ret.mem_length > 1
|
||||
return ret if ret.word_length > 1
|
||||
return ret[0]
|
||||
end
|
||||
def read_uint32(n=1)
|
||||
@ -74,7 +74,7 @@ module StreamWriter
|
||||
return __sr_write(str + 0.chr)
|
||||
end
|
||||
def write_cstr_prefixed(str)
|
||||
write_uint8(str.mem_length)
|
||||
write_uint8(str.word_length)
|
||||
return __sr_write(str)
|
||||
end
|
||||
def write_str(str)
|
||||
|
@ -62,13 +62,13 @@ module Virtual
|
||||
puts "BLOCK #{self.to_s[0..5000]}"
|
||||
raise e
|
||||
end
|
||||
raise code.inspect unless code.mem_length
|
||||
at += code.mem_length
|
||||
raise code.inspect unless code.byte_length
|
||||
at += code.byte_length
|
||||
end
|
||||
end
|
||||
|
||||
def mem_length
|
||||
@codes.inject(0){|count , instruction| count += instruction.mem_length }
|
||||
def byte_length
|
||||
@codes.inject(0){|count , instruction| count += instruction.byte_length }
|
||||
end
|
||||
|
||||
def to_s
|
||||
|
@ -135,9 +135,8 @@ module Virtual
|
||||
add_code ::Arm::ArmMachine.send(meth , *arg_names)
|
||||
end
|
||||
|
||||
def mem_length
|
||||
l = @blocks.inject(0) { |c , block| c += block.mem_length }
|
||||
padded(l)
|
||||
def byte_length
|
||||
@blocks.inject(0) { |c , block| c += block.byte_length }
|
||||
end
|
||||
|
||||
# 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
|
||||
@blocks.each do |block|
|
||||
block.set_position at
|
||||
at = at + block.mem_length
|
||||
at = at + block.byte_length
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -26,7 +26,7 @@ module FakeMem
|
||||
def position
|
||||
if @position.nil?
|
||||
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
|
||||
@position
|
||||
end
|
||||
@ -61,7 +61,7 @@ class Symbol
|
||||
def get_layout
|
||||
Virtual.machine.class_mappings[:Word].object_layout
|
||||
end
|
||||
def mem_length
|
||||
def word_length
|
||||
to_s.length
|
||||
end
|
||||
# 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
|
||||
class List
|
||||
def mem_length
|
||||
def word_length
|
||||
padded_words(get_length())
|
||||
end
|
||||
def to_sof_node(writer , level , ref )
|
||||
@ -174,7 +174,7 @@ module Parfait
|
||||
end
|
||||
|
||||
class Word
|
||||
def mem_length
|
||||
def word_length
|
||||
padded(1 + length())
|
||||
end
|
||||
|
||||
|
@ -41,9 +41,9 @@ module Virtual
|
||||
# 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.
|
||||
def mem_length
|
||||
len = @data.inject(super) {| sum , item | sum + item.mem_length}
|
||||
len + @branch_code.mem_length
|
||||
def byte_length
|
||||
len = @data.inject(super) {| sum , item | sum + item.word_length}
|
||||
len + @branch_code.word_length
|
||||
end
|
||||
|
||||
# again, super + branch plus data
|
||||
@ -52,7 +52,7 @@ module Virtual
|
||||
@branch_code.link_at pos , context
|
||||
@data.each do |code|
|
||||
code.link_at(pos , context)
|
||||
pos += code.mem_length
|
||||
pos += code.word_length
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -3,7 +3,7 @@ require_relative "type"
|
||||
module Positioned
|
||||
def position
|
||||
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
|
||||
@position
|
||||
end
|
||||
|
@ -24,15 +24,15 @@ end
|
||||
class TestPositioning < MiniTest::Test
|
||||
def test_list1
|
||||
list = Virtual.new_list([1])
|
||||
assert_equal 32 , list.mem_length
|
||||
assert_equal 32 , list.word_length
|
||||
end
|
||||
def test_list5
|
||||
list = Virtual.new_list([1,2,3,4,5])
|
||||
assert_equal 32 , list.mem_length
|
||||
assert_equal 32 , list.word_length
|
||||
end
|
||||
def test_layout
|
||||
layout = Parfait::Layout.new Object
|
||||
layout.push 5
|
||||
assert_equal 32 , layout.mem_length
|
||||
assert_equal 32 , layout.word_length
|
||||
end
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user