rename risc_value to register_value

almost to register, but it still carries that value
This commit is contained in:
Torsten Ruger 2018-06-29 11:39:07 +03:00
parent 606c7bf906
commit d50893bb0f
21 changed files with 67 additions and 67 deletions

View File

@ -60,7 +60,7 @@ module Arm
end
def reg_code r_name
raise "double r #{r_name}" if( :rr1 == r_name)
if r_name.is_a? ::Risc::RiscValue
if r_name.is_a? ::Risc::RegisterValue
r_name = r_name.symbol
end
if r_name.is_a? Fixnum
@ -93,7 +93,7 @@ module Arm
end
end
Risc::RiscValue.class_eval do
Risc::RegisterValue.class_eval do
def reg_no
@symbol.to_s[1 .. -1].to_i
end

View File

@ -18,19 +18,19 @@ module Arm
rn , operand , immediate= @rn , @operand , 1
arg = @right
operand = Risc::RiscValue.new( arg , :Integer) if( arg.is_a? Symbol )
operand = Risc::RegisterValue.new( arg , :Integer) if( arg.is_a? Symbol )
case operand
when Numeric
operand = arg
raise "numeric literal operand to large #{arg.inspect}" unless (arg.fits_u8?)
when Symbol , ::Risc::RiscValue
when Symbol , ::Risc::RegisterValue
immediate = 0
when Arm::Shift
handle_shift
else
raise "invalid operand argument #{arg.inspect} , #{inspect}"
end
val = (operand.is_a?(Symbol) or operand.is_a?(::Risc::RiscValue)) ? reg_code(operand) : operand
val = (operand.is_a?(Symbol) or operand.is_a?(::Risc::RegisterValue)) ? reg_code(operand) : operand
val = 0 if val == nil
val = shift(val , 0)
raise inspect unless reg_code(@rd)

View File

@ -24,7 +24,7 @@ module Arm
if (right.is_a?(Numeric))
operand = handle_numeric(right)
elsif (right.is_a?(Symbol) or right.is_a?(::Risc::RiscValue))
elsif (right.is_a?(Symbol) or right.is_a?(::Risc::RegisterValue))
operand = reg_code(right) #integer means the register the integer is in (otherwise constant)
immediate = 0 # ie not immediate is register
else
@ -89,7 +89,7 @@ module Arm
# this also loads constants, which are issued as pc relative adds
def determine_operands
if( @left.is_a?(Parfait::Object) or @left.is_a?(Risc::Label) or
(@left.is_a?(Symbol) and !Risc::RiscValue.look_like_reg(@left)))
(@left.is_a?(Symbol) and !Risc::RegisterValue.look_like_reg(@left)))
left = @left
left = left.address if left.is_a?(Risc::Label)
# do pc relative addressing with the difference to the instuction

View File

@ -24,8 +24,8 @@ module Arm
#TODO better test, this operand integer (register) does not work.
def assemble(io)
arg = @left
arg = arg.symbol if( arg.is_a? ::Risc::RiscValue )
is_reg = arg.is_a?(::Risc::RiscValue)
arg = arg.symbol if( arg.is_a? ::Risc::RegisterValue )
is_reg = arg.is_a?(::Risc::RegisterValue)
is_reg = (arg.to_s[0] == "r") if( arg.is_a?(Symbol) and not is_reg)
raise "invalid operand argument #{arg.inspect} #{inspect}" unless (is_reg )
@ -34,7 +34,7 @@ module Arm
#not sure about these 2 constants. They produce the correct output for str r0 , r1
# but i can't help thinking that that is because they are not used in that instruction and
# so it doesn't matter. Will see
if (operand.is_a?(Symbol) or operand.is_a?(::Risc::RiscValue))
if (operand.is_a?(Symbol) or operand.is_a?(::Risc::RegisterValue))
val = reg_code(operand)
i = 1 # not quite sure about this, but it gives the output of as. read read read.
else
@ -66,7 +66,7 @@ module Arm
def get_operand
return @operand unless @right
operand = @right
operand = operand.symbol if operand.is_a? ::Risc::RiscValue
operand = operand.symbol if operand.is_a? ::Risc::RegisterValue
unless( operand.is_a? Symbol)
# TODO test/check/understand: has no effect in current tests
# add_offset = (operand < 0) ? 0 : 1

View File

@ -4,8 +4,8 @@ module Arm
def initialize( to , from , options = {})
super(nil)
@attributes = options
if( from.is_a?(Symbol) and Risc::RiscValue.look_like_reg(from) )
from = Risc::RiscValue.new(from , :Integer)
if( from.is_a?(Symbol) and Risc::RegisterValue.look_like_reg(from) )
from = Risc::RegisterValue.new(from , :Integer)
end
@from = from
@to = to
@ -28,7 +28,7 @@ module Arm
case right
when Numeric
operand = numeric_operand(right)
when Risc::RiscValue
when Risc::RegisterValue
operand = reg_code(right)
immediate = 0 # ie not immediate is register
else

View File

@ -35,7 +35,7 @@ end
require_relative "risc/instruction"
require_relative "risc/risc_value"
require_relative "risc/register_value"
require_relative "risc/text_writer"
require_relative "risc/builtin"
require_relative "risc/builder"

View File

@ -162,7 +162,7 @@ module Risc
# by the slots. All data (at any time) is in one of the instance variables of these two
# objects. Risc defines module methods with the same names (and _reg)
def self.resolve_to_register( reference )
return reference if reference.is_a?(RiscValue)
return reference if reference.is_a?(RegisterValue)
case reference
when :message
return message_reg
@ -175,7 +175,7 @@ module Risc
# The first arg is a class name (possibly lowercase) and the second an instance variable name.
def self.resolve_type( object , compiler )
object = object.type if object.is_a?(RiscValue)
object = object.type if object.is_a?(RegisterValue)
case object
when :name
type = Parfait.object_space.get_class_by_name( :Word ).instance_type
@ -206,7 +206,7 @@ module Risc
# The class can be mapped to a register, and so we get a memory address (reg+index)
# Third arg, compiler, is only needed to resolve receiver/arguments/frame
def self.resolve_to_index(object , variable_name ,compiler = nil)
return variable_name if variable_name.is_a?(Integer) or variable_name.is_a?(RiscValue)
return variable_name if variable_name.is_a?(Integer) or variable_name.is_a?(RegisterValue)
type = resolve_type(object , compiler)
index = type.variable_index(variable_name)
raise "Index not found for #{variable_name} in #{object} of type #{type}" unless index

View File

@ -104,12 +104,12 @@ module Risc
# This relies on linux to save and restore all registers
#
def save_message(builder)
r8 = RiscValue.new( :r8 , :Message)
r8 = RegisterValue.new( :r8 , :Message)
builder.add_code Risc.transfer("save_message", Risc.message_reg , r8 )
end
def restore_message(builder)
r8 = RiscValue.new( :r8 , :Message)
r8 = RegisterValue.new( :r8 , :Message)
return_tmp = builder.compiler.use_reg :fixnum
source = "_restore_message"
# get the sys return out of the way

View File

@ -9,7 +9,7 @@ module Risc
builder = compiler.builder(true, compiler.method)
builder.add_slot_to_reg( "putstring" , :message , :receiver , :new_message )
index = Parfait::Word.get_length_index
reg = RiscValue.new(:r2 , :Integer)
reg = RegisterValue.new(:r2 , :Integer)
builder.add_slot_to_reg( "putstring" , :new_message , index , reg )
Risc::Builtin::Object.emit_syscall( builder , :putstring )
compiler.add_mom( Mom::ReturnSequence.new)

View File

@ -7,7 +7,7 @@ module Risc
def initialize( source , register )
super(source)
@register = register
raise "Not register #{register}" unless RiscValue.look_like_reg(register)
raise "Not register #{register}" unless RegisterValue.look_like_reg(register)
end
attr_reader :register

View File

@ -23,9 +23,9 @@ module Risc
@index = index
@register = register
raise "index #{index}" if index.is_a?(Numeric) and index < 0
raise "Not integer or reg #{index}" unless index.is_a?(Numeric) or RiscValue.look_like_reg(index)
raise "Not register #{register}" unless RiscValue.look_like_reg(register)
raise "Not register #{array}" unless RiscValue.look_like_reg(array)
raise "Not integer or reg #{index}" unless index.is_a?(Numeric) or RegisterValue.look_like_reg(index)
raise "Not register #{register}" unless RegisterValue.look_like_reg(register)
raise "Not register #{array}" unless RegisterValue.look_like_reg(array)
end
attr_accessor :array , :index , :register

View File

@ -10,7 +10,7 @@ module Risc
@register = register
@constant = constant
raise "Not Constant #{constant}" if constant.is_a?(Mom::SlotDefinition)
raise "Not register #{register}" unless RiscValue.look_like_reg(register)
raise "Not register #{register}" unless RegisterValue.look_like_reg(register)
end
attr_accessor :register , :constant

View File

@ -13,7 +13,7 @@ module Risc
@register = register
@constant = constant
raise "Not Integer #{constant}" unless constant.is_a?(Integer)
raise "Not register #{register}" unless RiscValue.look_like_reg(register)
raise "Not register #{register}" unless RegisterValue.look_like_reg(register)
end
attr_accessor :register , :constant

View File

@ -17,8 +17,8 @@ module Risc
raise "unsuported operator :#{operator}:" unless Risc.operators.include?(operator)
@left = left
@right = right
raise "Not register #{left}" unless RiscValue.look_like_reg(left)
raise "Not register #{right}" unless RiscValue.look_like_reg(right)
raise "Not register #{left}" unless RegisterValue.look_like_reg(left)
raise "Not register #{right}" unless RegisterValue.look_like_reg(right)
end
attr_reader :operator, :left , :right

View File

@ -22,9 +22,9 @@ module Risc
@array = array
@index = index
# raise "index 0 " if index < 0
raise "Not integer or reg #{index}" unless index.is_a?(Numeric) or RiscValue.look_like_reg(index)
raise "Not register #{register}" unless RiscValue.look_like_reg(register)
raise "Not register #{array}" unless RiscValue.look_like_reg(array)
raise "Not integer or reg #{index}" unless index.is_a?(Numeric) or RegisterValue.look_like_reg(index)
raise "Not register #{register}" unless RegisterValue.look_like_reg(register)
raise "Not register #{array}" unless RegisterValue.look_like_reg(array)
end
attr_accessor :register , :array , :index

View File

@ -20,8 +20,8 @@ module Risc
super(source)
@from = from
@to = to
raise "Fix me #{from}" unless from.is_a? RiscValue
raise "Fix me #{to}" unless to.is_a? RiscValue
raise "Fix me #{from}" unless from.is_a? RegisterValue
raise "Fix me #{to}" unless to.is_a? RegisterValue
end
attr_reader :from, :to

View File

@ -70,8 +70,8 @@ module Risc
end
def get_register( reg )
reg = reg.symbol if reg.is_a? Risc::RiscValue
raise "Not a register #{reg}" unless Risc::RiscValue.look_like_reg(reg)
reg = reg.symbol if reg.is_a? Risc::RegisterValue
raise "Not a register #{reg}" unless Risc::RegisterValue.look_like_reg(reg)
@registers[reg]
end
@ -87,7 +87,7 @@ module Risc
@flags[:minus] = false
end
return if old === val
reg = reg.symbol if reg.is_a? Risc::RiscValue
reg = reg.symbol if reg.is_a? Risc::RegisterValue
val = Parfait.object_space.nil_object if val.nil? #because that's what real code has
@registers[reg] = val
trigger(:register_changed, reg , old , val)

View File

@ -1,8 +1,8 @@
module Risc
# RiscValue is like a variable name, a storage location. The location is a register off course.
# RegisterValue is like a variable name, a storage location. The location is a register off course.
class RiscValue
class RegisterValue
attr_reader :symbol , :type , :value
@ -26,7 +26,7 @@ module Risc
end
def self.look_like_reg is_it
return true if is_it.is_a? RiscValue
return true if is_it.is_a? RegisterValue
return false unless is_it.is_a? Symbol
if( [:lr , :pc].include? is_it )
return true
@ -40,7 +40,7 @@ module Risc
def == other
return false if other.nil?
return false if other.class != RiscValue
return false if other.class != RegisterValue
symbol == other.symbol
end
@ -49,7 +49,7 @@ module Risc
int = @symbol[1,3].to_i
raise "No more registers #{self}" if int > 11
sym = "r#{int + 1}".to_sym
RiscValue.new( sym , type, value)
RegisterValue.new( sym , type, value)
end
def rxf_reference_name
@ -57,16 +57,16 @@ module Risc
end
# can't overload "=" , so use shift for it.
# move the right side to the left. Left (this) is a RiscValue
# move the right side to the left. Left (this) is a RegisterValue
# right value may be
# - constant (Parfait object) , resulting in a LoadConstant
# - another RiscValue, resulting in a Transfer instruction
# - another RegisterValue, resulting in a Transfer instruction
# - an RValue, resulting in an SlotToReg
def <<( right )
case right
when Parfait::Object , Symbol
ins = Risc.load_constant("#{right.class} to #{self.type}" , right , self)
when RiscValue
when RegisterValue
ins = Risc.transfer("#{right.type} to #{self.type}" , right , self)
when RValue
ins = Risc.slot_to_reg("#{right.register.type}[#{right.index}] -> #{self.type}" , right.register , right.index , self)
@ -78,7 +78,7 @@ module Risc
end
def -( right )
raise "operators only on registers, not #{right.class}" unless right.is_a? RiscValue
raise "operators only on registers, not #{right.class}" unless right.is_a? RegisterValue
op = Risc.op("#{self.type} - #{right.type}", :- , self , right )
builder.add_code(op) if builder
op
@ -92,7 +92,7 @@ module Risc
end
end
# Just a struct, see comment for [] of RiscValue
# Just a struct, see comment for [] of RegisterValue
#
class RValue
attr_reader :register , :index , :builder
@ -103,7 +103,7 @@ module Risc
# fullfil the objects purpose by creating a RegToSlot instruction from
# itself (the slot) and the register given
def <<( reg )
raise "not reg #{reg}" unless reg.is_a?(RiscValue)
raise "not reg #{reg}" unless reg.is_a?(RegisterValue)
reg_to_slot = Risc.reg_to_slot("#{reg.type} -> #{register.type}[#{index}]" , reg , register, index)
builder.add_code(reg_to_slot) if builder
reg_to_slot
@ -113,19 +113,19 @@ module Risc
# The register we use to store the current message object is :r0
def self.message_reg
RiscValue.new :r0 , :Message
RegisterValue.new :r0 , :Message
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
RiscValue.new :r1 , :Message
RegisterValue.new :r1 , :Message
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 , value = nil)
RiscValue.new :r1 , type , value
RegisterValue.new :r1 , type , value
end
end

View File

@ -37,28 +37,28 @@ module Arm
end
def test_shiftr1
code = @machine.mov :r1, :r2 , :shift_asr => Risc::RiscValue.new(:r3 , :Integer)
code = @machine.mov :r1, :r2 , :shift_asr => Risc::RegisterValue.new(:r3 , :Integer)
assert_code code , :mov , [0x52,0x13,0xb0,0xe1] #e1 b0 13 52
end
def test_shiftr2
code = @machine.mov :r2, :r3 , :shift_asr => Risc::RiscValue.new(:r4 , :Integer)
code = @machine.mov :r2, :r3 , :shift_asr => Risc::RegisterValue.new(:r4 , :Integer)
assert_code code , :mov , [0x53,0x24,0xb0,0xe1] #e1 b0 24 53
end
def test_shiftr3
code = @machine.mov :r3, :r4 , :shift_asr => Risc::RiscValue.new(:r5 , :Integer)
code = @machine.mov :r3, :r4 , :shift_asr => Risc::RegisterValue.new(:r5 , :Integer)
assert_code code , :mov , [0x54,0x35,0xb0,0xe1] #e1 b0 35 54
end
def test_shiftl1
code = @machine.mov :r1, :r2 , :shift_lsr => Risc::RiscValue.new(:r3 , :Integer)
code = @machine.mov :r1, :r2 , :shift_lsr => Risc::RegisterValue.new(:r3 , :Integer)
assert_code code , :mov , [0x32,0x13,0xb0,0xe1] #e1 b0 13 32
end
def test_shiftl2
code = @machine.mov :r2, :r3 , :shift_lsr => Risc::RiscValue.new(:r4 , :Integer)
code = @machine.mov :r2, :r3 , :shift_lsr => Risc::RegisterValue.new(:r4 , :Integer)
assert_code code , :mov , [0x33,0x24,0xb0,0xe1] #e1 b0 24 33
end
def test_shiftl3
code = @machine.mov :r3, :r4 , :shift_lsr => Risc::RiscValue.new(:r5 , :Integer)
code = @machine.mov :r3, :r4 , :shift_lsr => Risc::RegisterValue.new(:r5 , :Integer)
assert_code code , :mov , [0x34,0x35,0xb0,0xe1] #e1 b0 35 34
end

View File

@ -17,7 +17,7 @@ module Risc
end
def test_alloc_space
reg = @builder.space
assert_equal RiscValue , reg.class
assert_equal RegisterValue , reg.class
assert_equal :Space , reg.type
end
def test_next_message
@ -31,36 +31,36 @@ module Risc
assert_equal :Message , reg.type
end
def test_returns_built
r1 = RiscValue.new(:r1 , :Space)
r1 = RegisterValue.new(:r1 , :Space)
built = @builder.build{ space << r1 }
assert_equal Transfer , built.class
end
def test_returns_two
r1 = RiscValue.new(:r1 , :Space)
r1 = RegisterValue.new(:r1 , :Space)
built = @builder.build{ space << r1 ; space << r1}
assert_equal Transfer , built.next.class
end
def test_returns_slot
r2 = RiscValue.new(:r2 , :Message)
r2 = RegisterValue.new(:r2 , :Message)
r2.builder = @builder
built = @builder.build{ r2 << space[:first_message] }
assert_equal SlotToReg , built.class
assert_equal :r1 , built.array.symbol
end
def test_returns_slot_reverse
r2 = RiscValue.new(:r2 , :Message)
r2 = RegisterValue.new(:r2 , :Message)
r2.builder = @builder
built = @builder.build{ r2 << space[:first_message] }
assert_equal SlotToReg , built.class
assert_equal :r1 , built.array.symbol
end
def test_reuses_names
r1 = RiscValue.new(:r1 , :Space)
r1 = RegisterValue.new(:r1 , :Space)
built = @builder.build{ space << r1 ; space << r1}
assert_equal built.to.symbol , built.next.to.symbol
end
def test_uses_message_as_message
r1 = RiscValue.new(:r1 , :Space)
r1 = RegisterValue.new(:r1 , :Space)
built = @builder.build{ message[:receiver] << r1}
assert_equal RegToSlot , built.class
assert_equal :r0 , built.array.symbol
@ -105,7 +105,7 @@ module Risc
@builder = Risc::MethodCompiler.new( @init ).builder(true, @init)
end
def test_inserts_built
r1 = RiscValue.new(:r1 , :Space)
r1 = RegisterValue.new(:r1 , :Space)
@builder.build{ space << r1 }
assert_equal Transfer , @init.risc_instructions.next.class , @init.risc_instructions.next
end

View File

@ -11,8 +11,8 @@ module Risc
def setup
Risc.machine.boot
@r0 = RiscValue.new(:r0 , :Message)
@r1 = RiscValue.new(:r1 , :Space)
@r0 = RegisterValue.new(:r0 , :Message)
@r1 = RegisterValue.new(:r1 , :Space)
end
def test_r0
assert_equal :r0 , @r0.symbol