first go at translating DynamicCall to risc

This commit is contained in:
Torsten Ruger 2018-03-21 11:51:10 +05:30
parent d9ce295b89
commit d98e55907e
2 changed files with 26 additions and 2 deletions

View File

@ -18,8 +18,18 @@ module Mom
@cache_entry = Parfait::CacheEntry.new(type, method)
end
def to_risc(context)
Risc::Label.new(self,"DynamicCall")
# One could almost think that one can resolve this to a Risc::FunctionCall
# (which btw resolves to a simple jump), alas, the FunctionCall, like all other
# jumping, resolves the address at compile time.
#
# Instead we need a DynamicJump instruction that explicitly takes a register as
# a target (not a label)
def to_risc(compiler)
reg = compiler.use_reg( :int )
call = Risc.load_constant( self , @cache_entry , reg )
method_index = Risc.resolve_to_index(:cache_entry , :cached_method)
call << Risc::SlotToReg.new( self , reg ,method_index, reg)
call << Risc::DynamicJump.new(self, reg )
end
end

View File

@ -53,6 +53,20 @@ module Risc
end
# dynamic version of an Unconditional branch that jumps to the contents
# of a register instead of a hardcoded address
# As Branches jump to Labels, this is not derived from Branch
# PS: to conditionally jump to a dynamic adddress we do a normal branch
# over the dynamic one and then a dynamic one. Save us having all types of branches
# in two versions
class DynamicJump < Instruction
def initialize( source , register )
super(source)
@register = register
end
attr_reader :register
end
# branch if two registers contain same value
class IsSame < Branch
attr_reader :left , :right