renamed reg ref to reg val

more appropriate
alas, salaam-arm will break for a sec
This commit is contained in:
Torsten Ruger 2015-10-10 21:38:55 +03:00
parent dd3381e38b
commit aa20f2ca77
8 changed files with 24 additions and 28 deletions

View File

@ -1,6 +1,6 @@
GIT GIT
remote: git://github.com/salama/salama-arm.git remote: git://github.com/salama/salama-arm.git
revision: 4fd8d6fa93f5abcee5d960da9e2b2ec968ba3ea0 revision: c278f7eec20e9d62a55394bb7691e976980cbbe9
specs: specs:
salama-arm (0.3.0) salama-arm (0.3.0)

View File

@ -58,15 +58,15 @@ module Interpreter
end end
def get_register( reg ) def get_register( reg )
reg = reg.symbol if reg.is_a? Register::RegisterReference reg = reg.symbol if reg.is_a? Register::RegisterValue
raise "Not a register #{reg}" unless Register::RegisterReference.look_like_reg(reg) raise "Not a register #{reg}" unless Register::RegisterValue.look_like_reg(reg)
@registers[reg] @registers[reg]
end end
def set_register reg , val def set_register reg , val
old = get_register( reg ) # also ensures format old = get_register( reg ) # also ensures format
return if old === val return if old === val
reg = reg.symbol if reg.is_a? Register::RegisterReference reg = reg.symbol if reg.is_a? Register::RegisterValue
@registers[reg] = val @registers[reg] = val
trigger(:register_changed, reg , old , val) trigger(:register_changed, reg , old , val)
end end

View File

@ -14,7 +14,7 @@ module Register
end end
attr_reader :source attr_reader :source
# returns an array of registers (RegisterReferences) that this instruction uses. # returns an array of registers (RegisterValues) that this instruction uses.
# ie for r1 = r2 + r3 # ie for r1 = r2 + r3
# which in assembler is add r1 , r2 , r3 # which in assembler is add r1 , r2 , r3
# it would return [r2,r3] # it would return [r2,r3]
@ -22,7 +22,7 @@ module Register
def uses def uses
raise "abstract called for #{self.class}" raise "abstract called for #{self.class}"
end end
# returns an array of registers (RegisterReferences) that this instruction assigns to. # returns an array of registers (RegisterValues) that this instruction assigns to.
# ie for r1 = r2 + r3 # ie for r1 = r2 + r3
# which in assembler is add r1 , r2 , r3 # which in assembler is add r1 , r2 , r3
# it would return [r1] # it would return [r1]
@ -33,8 +33,8 @@ module Register
# wrap symbols into regsiter reference if needed # wrap symbols into regsiter reference if needed
def wrap_register reg , type def wrap_register reg , type
return reg if reg.is_a? RegisterReference return reg if reg.is_a? RegisterValue
RegisterReference.new(reg , type) RegisterValue.new(reg , type)
end end
end end

View File

@ -24,8 +24,8 @@ module Register
@index = index @index = index
@register = register @register = register
raise "not integer #{index}" unless index.is_a? Numeric raise "not integer #{index}" unless index.is_a? Numeric
raise "Not register #{register}" unless Register::RegisterReference.look_like_reg(register) raise "Not register #{register}" unless Register::RegisterValue.look_like_reg(register)
raise "Not register #{array}" unless Register::RegisterReference.look_like_reg(array) raise "Not register #{array}" unless Register::RegisterValue.look_like_reg(array)
end end
attr_accessor :array , :index , :register attr_accessor :array , :index , :register

View File

@ -23,8 +23,8 @@ module Register
@array = array @array = array
@index = index @index = index
raise "not integer #{index}" unless index.is_a? Numeric raise "not integer #{index}" unless index.is_a? Numeric
raise "Not register #{register}" unless Register::RegisterReference.look_like_reg(register) raise "Not register #{register}" unless Register::RegisterValue.look_like_reg(register)
raise "Not register #{array}" unless Register::RegisterReference.look_like_reg(array) raise "Not register #{array}" unless Register::RegisterValue.look_like_reg(array)
end end
attr_accessor :register , :array , :index attr_accessor :register , :array , :index
def to_s def to_s

View File

@ -1,5 +1,5 @@
require_relative "instruction" require_relative "instruction"
require_relative "register_reference" require_relative "register_value"
require_relative "assembler" require_relative "assembler"
require_relative "passes/frame_implementation" require_relative "passes/frame_implementation"
require_relative "passes/set_implementation" require_relative "passes/set_implementation"

View File

@ -1,12 +1,8 @@
module Register module Register
# RegisterReference is not the name for a register, "only" for a certain use of it. # RegisterValue is like a variable name, a storage location. The location is a register off course.
# In a way it is like a variable name, a storage location. The location is a register off course,
# but which register can be changed, and _all_ instructions sharing the RegisterReference then
# use that register
# In other words a simple level of indirection, or change from value to reference sematics.
class RegisterReference class RegisterValue
attr_accessor :symbol , :type attr_accessor :symbol , :type
@ -29,7 +25,7 @@ module Register
end end
def self.look_like_reg is_it def self.look_like_reg is_it
return true if is_it.is_a? RegisterReference return true if is_it.is_a? RegisterValue
return false unless is_it.is_a? Symbol return false unless is_it.is_a? Symbol
if( [:lr , :pc].include? is_it ) if( [:lr , :pc].include? is_it )
return true return true
@ -43,7 +39,7 @@ module Register
def == other def == other
return false if other.nil? return false if other.nil?
return false if other.class != RegisterReference return false if other.class != RegisterValue
symbol == other.symbol symbol == other.symbol
end end
@ -51,7 +47,7 @@ module Register
def next_reg_use type def next_reg_use type
int = @symbol[1,3].to_i int = @symbol[1,3].to_i
sym = "r#{int + 1}".to_sym sym = "r#{int + 1}".to_sym
RegisterReference.new( sym , type) RegisterValue.new( sym , type)
end end
def sof_reference_name def sof_reference_name
@ -65,30 +61,30 @@ module Register
# The register we use to store the current message object is :r0 # The register we use to store the current message object is :r0
def self.message_reg def self.message_reg
RegisterReference.new :r0 , :ref RegisterValue.new :r0 , :ref
end end
# A register to hold the receiver of the current message, in oo terms the self. :r1 # A register to hold the receiver of the current message, in oo terms the self. :r1
def self.self_reg type = :ref def self.self_reg type = :ref
RegisterReference.new :r1 , type RegisterValue.new :r1 , type
end end
# The register to hold a possible frame of the currently executing method. :r2 # The register to hold a possible frame of the currently executing method. :r2
# May be nil if the method has no local variables # May be nil if the method has no local variables
def self.frame_reg def self.frame_reg
RegisterReference.new :r2 , :ref RegisterValue.new :r2 , :ref
end end
# The register we use to store the new message object is :r3 # The register we use to store the new message object is :r3
# The new message is the one being built, to be sent # The new message is the one being built, to be sent
def self.new_message_reg def self.new_message_reg
RegisterReference.new :r3 , :ref RegisterValue.new :r3 , :ref
end end
# The first scratch register. There is a next_reg_use to get a next and next. # The first scratch register. There is a next_reg_use to get a next and next.
# Current thinking is that scratch is schatch between instructions # Current thinking is that scratch is schatch between instructions
def self.tmp_reg type def self.tmp_reg type
RegisterReference.new :r4 , type RegisterValue.new :r4 , type
end end
# The first arg is a class name (possibly lowercase) and the second an instance variable name. # The first arg is a class name (possibly lowercase) and the second an instance variable name.

View File

@ -82,7 +82,7 @@ module Virtual
def locals_at l_block def locals_at l_block
used =[] used =[]
# call assigns the return register, but as it is in l_block, it is not asked. # call assigns the return register, but as it is in l_block, it is not asked.
assigned = [ Register::RegisterReference.new(Virtual::RegisterMachine.instance.return_register) ] assigned = [ Register::RegisterValue.new(Virtual::RegisterMachine.instance.return_register) ]
l_block.reachable.each do |b| l_block.reachable.each do |b|
b.uses.each {|u| b.uses.each {|u|
(used << u) unless assigned.include?(u) (used << u) unless assigned.include?(u)