register reference creation got more complicated

This commit is contained in:
Torsten Ruger 2015-06-01 08:34:17 +03:00
parent 66f5dcf152
commit 336e6c18de
3 changed files with 30 additions and 9 deletions

View File

@ -77,7 +77,7 @@ module Arm
options = {} if options == nil
options.merge defaults
options[:opcode] = inst
first = Register::RegisterReference.new(first) if first.is_a? Symbol
first = Register::RegisterReference.convert(first)
clazz.new(first , options)
end
end
@ -88,8 +88,8 @@ module Arm
create_method(inst) do |left ,right , options = nil|
options = {} if options == nil
options.merge defaults
left = Register::RegisterReference.new(left) if left.is_a? Symbol
right = Register::RegisterReference.new(right) if right.is_a? Symbol
left = Register::RegisterReference.convert(left)
right = Register::RegisterReference.convert(right)
options[:opcode] = inst
clazz.new(left , right ,options)
end
@ -102,9 +102,9 @@ module Arm
options = {} if options == nil
options.merge defaults
options[:opcode] = inst
result = Register::RegisterReference.new(result) if result.is_a? Symbol
left = Register::RegisterReference.new(left) if left.is_a? Symbol
right = Register::RegisterReference.new(right) if right.is_a? Symbol
result = Register::RegisterReference.convert(result)
left = Register::RegisterReference.convert(left)
right = Register::RegisterReference.convert(right)
clazz.new(result, left , right ,options)
end
end

View File

@ -26,7 +26,11 @@ module Arm
arg = @left
arg = arg.symbol if( arg.is_a? ::Register::RegisterReference )
#str / ldr are _serious instructions. With BIG possibilities not half are implemented
if (arg.is_a?(Symbol) or arg.is_a?(::Register::RegisterReference)) #symbol is register
is_reg = arg.is_a?(::Register::RegisterReference)
if( arg.is_a?(Symbol) and not is_reg)
is_reg = (arg.to_s[0] == "r")
end
if (is_reg ) #symbol is register
rn = arg
if @right
operand = @right
@ -46,7 +50,7 @@ module Arm
end
end
end
elsif (arg.is_a?(Parfait::Object) ) #use pc relative
elsif (arg.is_a?(Parfait::Object) or arg.is_a? Symbol ) #use pc relative
rn = :pc
operand = arg.position - self.position - 8 #stringtable is after code
add_offset = 1

View File

@ -12,10 +12,27 @@ module Register
def initialize r
raise "wrong type for register init #{r}" unless r.is_a? Symbol
raise "double r #{r}" if r == :rr1
raise "double r #{r}" if r.to_s[0,1] == "rr"
raise "not reg #{r}" unless self.class.look_like_reg r
@symbol = r
end
def self.convert something
return something unless something.is_a? Symbol
return something unless look_like_reg(something)
return new(something)
end
def self.look_like_reg is_it
if( [:lr , :pc].include? is_it )
return true
end
if( (is_it.to_s.length < 3) and (is_it.to_s[0] == "r"))
return true
end
return false
end
def == other
return false if other.nil?
return false if other.class != RegisterReference