renamed reg ref to reg val
more appropriate alas, salaam-arm will break for a sec
This commit is contained in:
parent
dd3381e38b
commit
aa20f2ca77
@ -1,6 +1,6 @@
|
||||
GIT
|
||||
remote: git://github.com/salama/salama-arm.git
|
||||
revision: 4fd8d6fa93f5abcee5d960da9e2b2ec968ba3ea0
|
||||
revision: c278f7eec20e9d62a55394bb7691e976980cbbe9
|
||||
specs:
|
||||
salama-arm (0.3.0)
|
||||
|
||||
|
@ -58,15 +58,15 @@ module Interpreter
|
||||
end
|
||||
|
||||
def get_register( reg )
|
||||
reg = reg.symbol if reg.is_a? Register::RegisterReference
|
||||
raise "Not a register #{reg}" unless Register::RegisterReference.look_like_reg(reg)
|
||||
reg = reg.symbol if reg.is_a? Register::RegisterValue
|
||||
raise "Not a register #{reg}" unless Register::RegisterValue.look_like_reg(reg)
|
||||
@registers[reg]
|
||||
end
|
||||
|
||||
def set_register reg , val
|
||||
old = get_register( reg ) # also ensures format
|
||||
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
|
||||
trigger(:register_changed, reg , old , val)
|
||||
end
|
||||
|
@ -14,7 +14,7 @@ module Register
|
||||
end
|
||||
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
|
||||
# which in assembler is add r1 , r2 , r3
|
||||
# it would return [r2,r3]
|
||||
@ -22,7 +22,7 @@ module Register
|
||||
def uses
|
||||
raise "abstract called for #{self.class}"
|
||||
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
|
||||
# which in assembler is add r1 , r2 , r3
|
||||
# it would return [r1]
|
||||
@ -33,8 +33,8 @@ module Register
|
||||
|
||||
# wrap symbols into regsiter reference if needed
|
||||
def wrap_register reg , type
|
||||
return reg if reg.is_a? RegisterReference
|
||||
RegisterReference.new(reg , type)
|
||||
return reg if reg.is_a? RegisterValue
|
||||
RegisterValue.new(reg , type)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -24,8 +24,8 @@ module Register
|
||||
@index = index
|
||||
@register = register
|
||||
raise "not integer #{index}" unless index.is_a? Numeric
|
||||
raise "Not register #{register}" unless Register::RegisterReference.look_like_reg(register)
|
||||
raise "Not register #{array}" unless Register::RegisterReference.look_like_reg(array)
|
||||
raise "Not register #{register}" unless Register::RegisterValue.look_like_reg(register)
|
||||
raise "Not register #{array}" unless Register::RegisterValue.look_like_reg(array)
|
||||
end
|
||||
attr_accessor :array , :index , :register
|
||||
|
||||
|
@ -23,8 +23,8 @@ module Register
|
||||
@array = array
|
||||
@index = index
|
||||
raise "not integer #{index}" unless index.is_a? Numeric
|
||||
raise "Not register #{register}" unless Register::RegisterReference.look_like_reg(register)
|
||||
raise "Not register #{array}" unless Register::RegisterReference.look_like_reg(array)
|
||||
raise "Not register #{register}" unless Register::RegisterValue.look_like_reg(register)
|
||||
raise "Not register #{array}" unless Register::RegisterValue.look_like_reg(array)
|
||||
end
|
||||
attr_accessor :register , :array , :index
|
||||
def to_s
|
||||
|
@ -1,5 +1,5 @@
|
||||
require_relative "instruction"
|
||||
require_relative "register_reference"
|
||||
require_relative "register_value"
|
||||
require_relative "assembler"
|
||||
require_relative "passes/frame_implementation"
|
||||
require_relative "passes/set_implementation"
|
||||
|
@ -1,12 +1,8 @@
|
||||
module Register
|
||||
|
||||
# RegisterReference is not the name for a register, "only" for a certain use of it.
|
||||
# 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.
|
||||
# RegisterValue is like a variable name, a storage location. The location is a register off course.
|
||||
|
||||
class RegisterReference
|
||||
class RegisterValue
|
||||
|
||||
attr_accessor :symbol , :type
|
||||
|
||||
@ -29,7 +25,7 @@ module Register
|
||||
end
|
||||
|
||||
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
|
||||
if( [:lr , :pc].include? is_it )
|
||||
return true
|
||||
@ -43,7 +39,7 @@ module Register
|
||||
|
||||
def == other
|
||||
return false if other.nil?
|
||||
return false if other.class != RegisterReference
|
||||
return false if other.class != RegisterValue
|
||||
symbol == other.symbol
|
||||
end
|
||||
|
||||
@ -51,7 +47,7 @@ module Register
|
||||
def next_reg_use type
|
||||
int = @symbol[1,3].to_i
|
||||
sym = "r#{int + 1}".to_sym
|
||||
RegisterReference.new( sym , type)
|
||||
RegisterValue.new( sym , type)
|
||||
end
|
||||
|
||||
def sof_reference_name
|
||||
@ -65,30 +61,30 @@ module Register
|
||||
|
||||
# The register we use to store the current message object is :r0
|
||||
def self.message_reg
|
||||
RegisterReference.new :r0 , :ref
|
||||
RegisterValue.new :r0 , :ref
|
||||
end
|
||||
|
||||
# A register to hold the receiver of the current message, in oo terms the self. :r1
|
||||
def self.self_reg type = :ref
|
||||
RegisterReference.new :r1 , type
|
||||
RegisterValue.new :r1 , type
|
||||
end
|
||||
|
||||
# The register to hold a possible frame of the currently executing method. :r2
|
||||
# May be nil if the method has no local variables
|
||||
def self.frame_reg
|
||||
RegisterReference.new :r2 , :ref
|
||||
RegisterValue.new :r2 , :ref
|
||||
end
|
||||
|
||||
# The register we use to store the new message object is :r3
|
||||
# The new message is the one being built, to be sent
|
||||
def self.new_message_reg
|
||||
RegisterReference.new :r3 , :ref
|
||||
RegisterValue.new :r3 , :ref
|
||||
end
|
||||
|
||||
# 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
|
||||
def self.tmp_reg type
|
||||
RegisterReference.new :r4 , type
|
||||
RegisterValue.new :r4 , type
|
||||
end
|
||||
|
||||
# The first arg is a class name (possibly lowercase) and the second an instance variable name.
|
@ -82,7 +82,7 @@ module Virtual
|
||||
def locals_at l_block
|
||||
used =[]
|
||||
# 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|
|
||||
b.uses.each {|u|
|
||||
(used << u) unless assigned.include?(u)
|
||||
|
Loading…
Reference in New Issue
Block a user