pass extra info into register init, not just value

extra info may be hash, maybe just type info
This commit is contained in:
Torsten Ruger 2018-07-16 11:23:09 +03:00
parent b410538d07
commit e3673e579c
5 changed files with 22 additions and 17 deletions

View File

@ -11,7 +11,7 @@ module Risc
builder = compiler.compiler_builder(compiler.source)
me = builder.add_known( :receiver )
builder.reduce_int( source , me )
two = compiler.use_reg :fixnum , 2
two = compiler.use_reg :fixnum , value: 2
builder.add_load_data( source , 2 , two )
builder.add_code Risc.op( source , :>> , me , two)
builder.add_new_int(source,me , two)
@ -84,7 +84,7 @@ module Risc
builder.reduce_int( s , me )
builder.reduce_int( s , tmp )
builder.reduce_int( s , q )
const = compiler.use_reg :fixnum , 1
const = compiler.use_reg :fixnum , value: 1
builder.add_load_data( s , 1 , const )
# int tmp = self >> 1
builder.add_code Risc.op( s , :>> , tmp , const)

View File

@ -53,12 +53,13 @@ module Risc
end
# require a (temporary) register. code must give this back with release_reg
def use_reg( type , value = nil )
# Second extra parameter may give extra info about the value, see RegisterValue
def use_reg( type , extra = {} )
raise "Not type #{type.inspect}" unless type.is_a?(Symbol) or type.is_a?(Parfait::Type)
if @regs.empty?
reg = Risc.tmp_reg(type , value)
reg = Risc.tmp_reg(type , extra)
else
reg = @regs.last.next_reg_use(type , value)
reg = @regs.last.next_reg_use(type , extra)
end
@regs << reg
return reg

View File

@ -122,12 +122,12 @@ module Risc
end
# require a (temporary) register. code must give this back with release_reg
def use_reg( type , value = nil )
def use_reg( type , extra = {} )
raise "Not type #{type.inspect}" unless type.is_a?(Symbol) or type.is_a?(Parfait::Type)
if @regs.empty?
reg = Risc.tmp_reg(type , value)
reg = Risc.tmp_reg(type , extra)
else
reg = @regs.last.next_reg_use(type , value)
reg = @regs.last.next_reg_use(type , extra)
end
@regs << reg
return reg

View File

@ -3,6 +3,7 @@ module Risc
# RegisterValue is like a variable name, a storage location.
# The location is a register off course.
# The type is always known, and sometimes the value too
# Or something about the value, like some instances types
#
# When participating in the builder dsl, a builder may be set to get the
# results of dsl operations (like <<) back to the builder
@ -15,12 +16,16 @@ module Risc
# The first arg is a symbol :r0 - :r12
# Second arg is the type, which may be given as the symbol of the class name
# (internally we store the actual type instance, resolving any symbols)
def initialize( reg , type , value = nil)
# A third value may give extra information. This is a hash, where keys may
# be :value, or :value_XX or :type_XX to indicate value or type information
# for an XX instance
def initialize( reg , type , extra = {})
raise "Not Hash #{extra}" unless extra.is_a?(Hash)
raise "not reg #{reg}" unless self.class.look_like_reg( reg )
type = Parfait.object_space.get_type_by_class_name(type) if type.is_a?(Symbol)
@type = type
@symbol = reg
@value = value
@value = extra
end
# using the registers type, resolve the slot to an index
@ -57,20 +62,19 @@ module Risc
new_left
end
# resolve the type of the slot, by inferring from it's name
# Currently this is implemented in Risc.resolve_type , but code shoudl be moved here
# resolve the type of the slot, by inferring from it's name, using the type
# scope related slots are resolved by the compiler
def resolve_new_type(slot, compiler)
case slot
when :frame , :arguments , :receiver
type = compiler.resolve_type(slot)
when :name
type = Parfait.object_space.get_type_by_class_name( :Word )
when Symbol
type = @type.type_for(slot)
raise "Not found object #{slot}: in #{@type}" unless type
else
raise "Not implemented object #{slot}:#{slot.class}"
end
#puts "RESOLVE in #{@type.class_name} #{slot}->#{type}"
return type
end
@ -183,8 +187,8 @@ module Risc
# 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)
RegisterValue.new :r1 , type , value
def self.tmp_reg( type , extra = {})
RegisterValue.new :r1 , type , extra
end
end

View File

@ -8,7 +8,7 @@ module Mom
return nil
end
def use_reg( type )
Risc.tmp_reg(type , nil)
Risc.tmp_reg(type )
end
def reset_regs