update to use parfait not virtual
more ripples reverting to integers (not virtual::integer)
This commit is contained in:
parent
c28430698c
commit
a46b2d5c56
@ -8,6 +8,8 @@ module Arm
|
||||
# - Move
|
||||
# - Call class Instruction
|
||||
class Instruction
|
||||
include Positioned
|
||||
|
||||
def initialize options
|
||||
@attributes = options
|
||||
end
|
||||
@ -15,17 +17,7 @@ module Arm
|
||||
def opcode
|
||||
@attributes[:opcode]
|
||||
end
|
||||
def position
|
||||
raise "position accessed but not set at #{length} for #{self.inspect}" if @position == nil
|
||||
@position
|
||||
end
|
||||
def set_position pos
|
||||
# resetting of position used to be error, but since relink and dynamic instruction size it is ok. in measures
|
||||
if @position != nil and ((@position - pos).abs > 32)
|
||||
raise "position set again #{pos}!=#{@position} for #{self}"
|
||||
end
|
||||
@position = pos
|
||||
end
|
||||
|
||||
|
||||
# this is giving read access to the attributes hash via .attibute syntax
|
||||
# so for an instruction pop you can write pop.opcode to get the :opcode attribute
|
||||
|
@ -33,33 +33,27 @@ module Arm
|
||||
when :b, :call
|
||||
arg = @first
|
||||
#puts "BLAB #{arg.inspect}"
|
||||
if( arg.is_a? Fixnum ) #HACK to not have to change the code just now
|
||||
arg = Virtual::IntegerConstant.new( arg )
|
||||
end
|
||||
if arg.is_a?(Virtual::Block) or arg.is_a?(Virtual::CompiledMethodInfo)
|
||||
if arg.is_a?(Virtual::Block) or arg.is_a?(Parfait::Method)
|
||||
#relative addressing for jumps/calls
|
||||
diff = arg.position - self.position
|
||||
# but because of the arm "theoretical" 3- stage pipeline, we have to subtract 2 words (fetch/decode)
|
||||
# But, for methods, this happens to be the size of the object header, so there it balances out, but not blocks
|
||||
diff -= 8 if arg.is_a?(Virtual::Block)
|
||||
arg = Virtual::IntegerConstant.new(diff)
|
||||
arg = diff
|
||||
end
|
||||
if (arg.is_a?(Virtual::IntegerConstant))
|
||||
jmp_val = arg.integer >> 2
|
||||
if (arg.is_a?(Numeric))
|
||||
jmp_val = arg >> 2
|
||||
packed = [jmp_val].pack('l')
|
||||
# signed 32-bit, condense to 24-bit
|
||||
# TODO add check that the value fits into 24 bits
|
||||
io << packed[0,3]
|
||||
else
|
||||
raise "else not coded arg =#{arg}: #{inspect}"
|
||||
raise "else not coded arg =\n#{arg.to_s[0..1000]}: #{inspect[0..1000]}"
|
||||
end
|
||||
io.write_uint8 op_bit_code | (COND_CODES[@attributes[:condition_code]] << 4)
|
||||
when :swi
|
||||
arg = @first
|
||||
if( arg.is_a? Fixnum ) #HACK to not have to change the code just now
|
||||
arg = Virtual::IntegerConstant.new( arg )
|
||||
end
|
||||
if (arg.is_a?(Virtual::IntegerConstant))
|
||||
if (arg.is_a?(Numeric))
|
||||
packed = [arg.integer].pack('L')[0,3]
|
||||
io << packed
|
||||
io.write_uint8 0b1111 | (COND_CODES[@attributes[:condition_code]] << 4)
|
||||
|
@ -21,16 +21,16 @@ module Arm
|
||||
immediate = @immediate
|
||||
|
||||
arg = @right
|
||||
if arg.is_a?(Virtual::ObjectConstant)
|
||||
if arg.is_a?(Parfait::Object)
|
||||
# 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 = Virtual::IntegerConstant.new( arg.position - self.position - 8 )
|
||||
arg = arg.position - self.position - 8
|
||||
rn = :pc
|
||||
end
|
||||
if( arg.is_a? Fixnum ) #HACK to not have to change the code just now
|
||||
if( arg.is_a? Symbol )
|
||||
arg = Register::RegisterReference.new( arg )
|
||||
end
|
||||
if (arg.is_a?(Virtual::IntegerConstant))
|
||||
if (arg.is_a?(Numeric))
|
||||
if (arg.fits_u8?)
|
||||
# no shifting needed
|
||||
operand = arg.integer
|
||||
|
@ -10,7 +10,7 @@ module Arm
|
||||
super(attributes)
|
||||
@result = result
|
||||
@left = left
|
||||
@right = right.is_a?(Fixnum) ? Virtual::IntegerConstant.new(right) : right
|
||||
@right = right
|
||||
@attributes[:update_status] = 0 if @attributes[:update_status] == nil
|
||||
@attributes[:condition_code] = :al if @attributes[:condition_code] == nil
|
||||
@operand = 0
|
||||
@ -27,17 +27,13 @@ module Arm
|
||||
immediate = @immediate
|
||||
|
||||
right = @right
|
||||
if @left.is_a?(Virtual::ObjectConstant)
|
||||
if @left.is_a?(Parfait::Object)
|
||||
# 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 = @left.position - self.position - 8
|
||||
left = :pc
|
||||
end
|
||||
# automatic wrapping, for machine internal code and testing
|
||||
if( right.is_a? Fixnum )
|
||||
right = Virtual::IntegerConstant.new( right )
|
||||
end
|
||||
if (right.is_a?(Virtual::IntegerConstant))
|
||||
if (right.is_a?(Numeric))
|
||||
if (right.fits_u8?)
|
||||
# no shifting needed
|
||||
operand = right.integer
|
||||
|
@ -46,14 +46,14 @@ module Arm
|
||||
end
|
||||
end
|
||||
end
|
||||
elsif (arg.is_a?(Virtual::ObjectConstant) ) #use pc relative
|
||||
elsif (arg.is_a?(Parfait::Object) ) #use pc relative
|
||||
rn = :pc
|
||||
operand = arg.position - self.position - 8 #stringtable is after code
|
||||
add_offset = 1
|
||||
if (operand.abs > 4095)
|
||||
raise "reference offset too large/small (max 4095) #{arg} #{inspect}"
|
||||
end
|
||||
elsif( arg.is_a?(Virtual::IntegerConstant) )
|
||||
elsif( arg.is_a?(Numeric) )
|
||||
#TODO untested brach, probably not working
|
||||
raise "is this working ?? #{arg} #{inspect}"
|
||||
@pre_post_index = 1
|
||||
|
@ -36,7 +36,7 @@ module Arm
|
||||
operand = @operand
|
||||
immediate = @immediate
|
||||
right = @from
|
||||
if right.is_a?(Virtual::ObjectConstant)
|
||||
if right.is_a?(Parfait::Object)
|
||||
r_pos = right.position
|
||||
# do pc relative addressing with the difference to the instuction
|
||||
# 8 is for the funny pipeline adjustment (ie pc pointing to fetch and not execute)
|
||||
@ -44,7 +44,7 @@ module Arm
|
||||
puts "Position #{r_pos} from #{self.position} = #{right}"
|
||||
rn = :pc
|
||||
end
|
||||
if (right.is_a?(Virtual::IntegerConstant))
|
||||
if (right.is_a?(Numeric))
|
||||
if (right.fits_u8?)
|
||||
# no shifting needed
|
||||
operand = right.integer
|
||||
|
@ -1,4 +1,5 @@
|
||||
require "parfait/value"
|
||||
require "parfait/integer"
|
||||
require "parfait/object"
|
||||
require "parfait/module"
|
||||
require "parfait/class"
|
||||
|
Loading…
Reference in New Issue
Block a user