rename Position get/set
This commit is contained in:
parent
e89c4d1ce1
commit
68fb9b1bdc
@ -47,12 +47,12 @@ module Arm
|
||||
# relative addressing for jumps/calls
|
||||
# but because of the arm "theoretical" 3- stage pipeline,
|
||||
# we have to subtract 2 words (fetch/decode)
|
||||
arg = Risc::Position.position(@first) - Risc::Position.position(self) - 8
|
||||
arg = Risc::Position.get(@first) - Risc::Position.get(self) - 8
|
||||
when Parfait::BinaryCode
|
||||
# But, for methods, this happens to be the size of the object header,
|
||||
# so there it balances out, but not blocks
|
||||
# have to use the code, not the method object for methods
|
||||
arg = Risc::Position.position(@first) - Risc::Position.position(self) + 4
|
||||
arg = Risc::Position.get(@first) - Risc::Position.get(self) + 4
|
||||
else
|
||||
arg = @first
|
||||
end
|
||||
|
@ -23,12 +23,12 @@ module Arm
|
||||
|
||||
def insert(instruction)
|
||||
super
|
||||
my_pos = Risc::Position.position(self)
|
||||
my_pos = Risc::Position.get(self)
|
||||
@next.set_position( my_pos + self.byte_length , 0 , my_pos.binary)
|
||||
end
|
||||
|
||||
def set_position( position , count , extra = nil)
|
||||
Risc::Position.set_position(self,position , extra)
|
||||
Risc::Position.set(self,position , extra)
|
||||
position += byte_length
|
||||
if self.next
|
||||
count += 1 #assumes 4 byte instructions, as does the whole setup
|
||||
|
@ -69,7 +69,7 @@ module Arm
|
||||
else
|
||||
unless @extra
|
||||
@extra = 1
|
||||
# puts "RELINK L at #{Risc::Position.position(self)}"
|
||||
# puts "RELINK L at #{Risc::Position.get(self)}"
|
||||
# use sub for sub and add for add, ie same as opcode
|
||||
insert ArmMachine.send( opcode , result , result , 0 ) #noop
|
||||
end
|
||||
@ -92,7 +92,7 @@ module Arm
|
||||
(@left.is_a?(Symbol) and !Risc::RiscValue.look_like_reg(@left)))
|
||||
# do pc relative addressing with the difference to the instuction
|
||||
# 8 is for the funny pipeline adjustment (ie pointing to fetch and not execute)
|
||||
right = Risc::Position.position(@left) - Risc::Position.position(self) - 8
|
||||
right = Risc::Position.get(@left) - Risc::Position.get(self) - 8
|
||||
if( (right < 0) && ((opcode == :add) || (opcode == :sub)) )
|
||||
right *= -1 # this works as we never issue sub only add
|
||||
set_opcode :sub # so (as we can't change the sign permanently) we can change the opcode
|
||||
|
@ -67,7 +67,7 @@ module Arm
|
||||
end
|
||||
raise "Negatives not implemented #{right} " if right < 0
|
||||
unless @extra
|
||||
puts "RELINK M at #{Risc::Position.position(self)}"
|
||||
puts "RELINK M at #{Risc::Position.get(self)}"
|
||||
@extra = 1
|
||||
insert ArmMachine.add( to , to , 0 ) #noop that we change below
|
||||
end
|
||||
|
@ -27,7 +27,7 @@ module Elf
|
||||
type.each_method do |f|
|
||||
f.cpu_instructions.each do |label|
|
||||
next unless label.is_a?(Risc::Label)
|
||||
add_symbol "#{type.name}::#{f.name}:#{label.name}" , Risc::Position.position(label).at
|
||||
add_symbol "#{type.name}::#{f.name}:#{label.name}" , Risc::Position.get(label).at
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -37,12 +37,12 @@ module Elf
|
||||
if( slot.respond_to? :sof_reference_name )
|
||||
label = "#{slot.sof_reference_name}"
|
||||
else
|
||||
label = "#{slot.class.name}::#{Risc::Position.position(slot)}"
|
||||
label = "#{slot.class.name}::#{Risc::Position.get(slot)}"
|
||||
end
|
||||
label += "=#{slot}" if slot.is_a?(Symbol) or slot.is_a?(String)
|
||||
add_symbol label , Risc::Position.position(slot).at
|
||||
add_symbol label , Risc::Position.get(slot).at
|
||||
if slot.is_a?(Parfait::TypedMethod)
|
||||
add_symbol slot.name.to_s , Risc::Position.position(slot.binary).at
|
||||
add_symbol slot.name.to_s , Risc::Position.get(slot.binary).at
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -46,7 +46,7 @@ module Risc
|
||||
|
||||
# labels have the same position as their next
|
||||
def set_position( position , count = 0 , extra = nil)
|
||||
Position.set_position(self,position , extra)
|
||||
Position.set(self,position , extra)
|
||||
self.next.set_position(position,count,extra) if self.next
|
||||
end
|
||||
|
||||
|
@ -77,7 +77,7 @@ module Risc
|
||||
def position_all
|
||||
translate_arm unless @translated
|
||||
#need the initial jump at 0 and then functions
|
||||
Position.set_position(binary_init,0)
|
||||
Position.set(binary_init,0)
|
||||
cpu_init.set_position( 12 ,0 , binary_init)
|
||||
@code_start = position_objects( binary_init.padded_length )
|
||||
# and then everything code
|
||||
@ -91,7 +91,7 @@ module Risc
|
||||
# want to have the objects first in the executable
|
||||
objects.each do | id , objekt|
|
||||
next if objekt.is_a?( Parfait::BinaryCode) or objekt.is_a?( Risc::Label )
|
||||
Position.set_position(objekt,at)
|
||||
Position.set(objekt,at)
|
||||
before = at
|
||||
at += objekt.padded_length
|
||||
log.debug "Object #{objekt.class}:#{before.to_s(16)} len: #{(at - before).to_s(16)}"
|
||||
@ -114,7 +114,7 @@ module Risc
|
||||
before = at
|
||||
nekst = method.binary
|
||||
while(nekst)
|
||||
Position.set_position(nekst , at , method)
|
||||
Position.set(nekst , at , method)
|
||||
at += nekst.padded_length
|
||||
nekst = nekst.next
|
||||
end
|
||||
|
@ -48,7 +48,11 @@ module Risc
|
||||
@positions
|
||||
end
|
||||
|
||||
def self.position(object)
|
||||
def self.set?(object)
|
||||
self.positions.has_key?(object)
|
||||
end
|
||||
|
||||
def self.get(object)
|
||||
pos = self.positions[object]
|
||||
if pos == nil
|
||||
str = "position accessed but not set, "
|
||||
@ -59,7 +63,7 @@ module Risc
|
||||
pos
|
||||
end
|
||||
|
||||
def self.set_position( object , pos , extra = nil)
|
||||
def self.set( object , pos , extra = nil)
|
||||
# resetting of position used to be error, but since relink and dynamic instruction size it is ok.
|
||||
# in measures (of 32)
|
||||
#puts "Setting #{pos} for #{self.class}"
|
||||
|
@ -41,7 +41,7 @@ module Risc
|
||||
def write_debug
|
||||
@machine.objects.each do |id , objekt|
|
||||
next if objekt.is_a?(Risc::Label)
|
||||
log.debug "Linked #{objekt.class}:0x#{objekt.object_id.to_s(16)} at #{Position.position(objekt)} / 0x#{objekt.padded_length.to_s(16)}"
|
||||
log.debug "Linked #{objekt.class}:0x#{objekt.object_id.to_s(16)} at #{Position.get(objekt)} / 0x#{objekt.padded_length.to_s(16)}"
|
||||
end
|
||||
end
|
||||
|
||||
@ -71,16 +71,16 @@ module Risc
|
||||
# Write any object just logs a bit and passes to write_any_out
|
||||
def write_any( obj )
|
||||
write_any_log( obj , "Write")
|
||||
if @stream.length != Position.position(obj).at
|
||||
raise "Write #{obj.class}:0x#{obj.object_id.to_s(16)} at 0x#{stream_position.to_s(16)} not #{Position.position(obj)}"
|
||||
if @stream.length != Position.get(obj).at
|
||||
raise "Write #{obj.class}:0x#{obj.object_id.to_s(16)} at 0x#{stream_position.to_s(16)} not #{Position.get(obj)}"
|
||||
end
|
||||
write_any_out(obj)
|
||||
write_any_log( obj , "Wrote")
|
||||
Position.position(obj)
|
||||
Position.get(obj)
|
||||
end
|
||||
|
||||
def write_any_log( obj , at)
|
||||
log.debug "#{at} #{obj.class}:0x#{obj.object_id.to_s(16)} at stream #{stream_position} pos:#{Position.position(obj)} , len:0x#{obj.padded_length.to_s(16)}"
|
||||
log.debug "#{at} #{obj.class}:0x#{obj.object_id.to_s(16)} at stream #{stream_position} pos:#{Position.get(obj)} , len:0x#{obj.padded_length.to_s(16)}"
|
||||
end
|
||||
|
||||
# Most objects are the same and get passed to write_object
|
||||
@ -108,14 +108,14 @@ module Risc
|
||||
log.debug "type #{obj_written} , total #{obj_written + indexed_written} (array #{indexed_written})"
|
||||
log.debug "Len = 0x#{object.get_length.to_s(16)} , inst =0x#{object.get_type.instance_length.to_s(16)}" if object.is_a? Parfait::Type
|
||||
pad_after( obj_written + indexed_written )
|
||||
Position.position(object)
|
||||
Position.get(object)
|
||||
end
|
||||
|
||||
def write_object_check(object)
|
||||
log.debug "Write object #{object.class} #{object.inspect[0..100]}"
|
||||
#Only initially created codes are collected. Binary_init and method "tails" not
|
||||
if !@machine.objects.has_key?(object.object_id) and !object.is_a?(Parfait::BinaryCode)
|
||||
log.debug "Object at 0x#{Position.position(object).to_s(16)}:#{object.get_type()}"
|
||||
log.debug "Object at 0x#{Position.get(object).to_s(16)}:#{object.get_type()}"
|
||||
raise "Object(0x#{object.object_id.to_s(16)}) not linked #{object.inspect}"
|
||||
end
|
||||
end
|
||||
@ -178,7 +178,7 @@ module Risc
|
||||
raise "length mismatch #{str.length} != #{string.char_length}" if str.length != string.char_length
|
||||
end
|
||||
str = string.to_s if string.is_a? Symbol
|
||||
log.debug "#{string.class} is #{string} at 0x#{Position.position(string)} length 0x#{string.length.to_s(16)}"
|
||||
log.debug "#{string.class} is #{string} at 0x#{Position.get(string)} length 0x#{string.length.to_s(16)}"
|
||||
write_checked_string(string , str)
|
||||
end
|
||||
|
||||
@ -206,7 +206,7 @@ module Risc
|
||||
when Fixnum
|
||||
@stream.write_signed_int_32(object)
|
||||
else
|
||||
@stream.write_signed_int_32(Position.position(object) + @load_at)
|
||||
@stream.write_signed_int_32(Position.get(object) + @load_at)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -18,9 +18,9 @@ module Arm
|
||||
def test_method_call
|
||||
Risc.machine.boot
|
||||
bin = Parfait::BinaryCode.new(1)
|
||||
Risc::Position.set_position(bin , 0x20)
|
||||
Risc::Position.set(bin , 0x20)
|
||||
code = @machine.call( bin ,{} )#this jumps to the next instruction
|
||||
Risc::Position.set_position(code , 0)
|
||||
Risc::Position.set(code , 0)
|
||||
assert_code code , :call, [0x09,0x0,0x0,0xeb]
|
||||
end
|
||||
def test_swi
|
||||
|
@ -25,7 +25,7 @@ module Risc
|
||||
end
|
||||
def test_has_positions
|
||||
@machine.objects.each do |id,obj|
|
||||
assert Position.position(obj)
|
||||
assert Position.get(obj)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -22,27 +22,27 @@ module Risc
|
||||
assert_equal 4 , res
|
||||
end
|
||||
def test_set
|
||||
pos = Position.set_position(self , 5)
|
||||
pos = Position.set(self , 5)
|
||||
assert_equal 5 , pos.at
|
||||
end
|
||||
def test_set_instr
|
||||
pos = Position.set_position( Risc::Label.new("hi","ho") , 0)
|
||||
pos = Position.set( Risc::Label.new("hi","ho") , 0)
|
||||
assert_equal IPosition , pos.class
|
||||
end
|
||||
def tet_tos
|
||||
assert_equal "0x10" , Position.set_position(self).to_s
|
||||
assert_equal "0x10" , Position.set(self).to_s
|
||||
end
|
||||
def test_reset_ok
|
||||
pos = Position.set_position(self , 5)
|
||||
pos = Position.set_position(self , 10)
|
||||
pos = Position.set(self , 5)
|
||||
pos = Position.set(self , 10)
|
||||
assert_equal 10 , pos.at
|
||||
end
|
||||
def test_reset_fail
|
||||
Position.set_position(self , 5)
|
||||
assert_raises{Position.set_position(self , 10000)}
|
||||
Position.set(self , 5)
|
||||
assert_raises{Position.set(self , 10000)}
|
||||
end
|
||||
def test_raises_set_nil
|
||||
assert_raises { Position.set_position(self,nil)}
|
||||
assert_raises { Position.set(self,nil)}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user