diff --git a/lib/arm/arm_machine.rb b/lib/arm/arm_machine.rb index 5e381f5c..55dc5a53 100644 --- a/lib/arm/arm_machine.rb +++ b/lib/arm/arm_machine.rb @@ -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 diff --git a/lib/arm/instructions/memory_instruction.rb b/lib/arm/instructions/memory_instruction.rb index 11507c95..d54cdd52 100644 --- a/lib/arm/instructions/memory_instruction.rb +++ b/lib/arm/instructions/memory_instruction.rb @@ -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 diff --git a/lib/register/register_reference.rb b/lib/register/register_reference.rb index 5e73c7df..977557b0 100644 --- a/lib/register/register_reference.rb +++ b/lib/register/register_reference.rb @@ -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