From 1e18db00c9b14d7b10b8c8de987335697107831f Mon Sep 17 00:00:00 2001 From: Torsten Ruger Date: Mon, 29 Jun 2015 20:57:16 +0300 Subject: [PATCH] add set_slot and save_return as functions to generate instructions --- lib/register/register_reference.rb | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/lib/register/register_reference.rb b/lib/register/register_reference.rb index 6748cb32..3e9f701d 100644 --- a/lib/register/register_reference.rb +++ b/lib/register/register_reference.rb @@ -24,6 +24,7 @@ module Register end def self.look_like_reg is_it + return true if is_it.is_a? RegisterReference return false unless is_it.is_a? Symbol if( [:lr , :pc].include? is_it ) return true @@ -84,13 +85,26 @@ module Register GetSlot.new( from , index , to) end + def self.set_slot from , to , index + index = resolve_index( to , index) + from = resolve_to_register from + to = resolve_to_register to + SetSlot.new( from , to , index) + end + + def self.save_return from , index + index = resolve_index( from , index) + from = resolve_to_register from + SaveReturn.new( from , index ) + end + def self.resolve_index( clazz_name , instance_name ) return instance_name unless instance_name.is_a? Symbol - real_name = "#{clazz_name}".capitalize.to_sym + real_name = clazz_name.to_s.split('_').last.capitalize.to_sym clazz = Parfait::Space.object_space.get_class_by_name(real_name) raise "Class name not given #{real_name}" unless clazz index = clazz.object_layout.index_of( instance_name ) - raise "Instance name=#{instance_name} not found on #{real_name}" unless index + raise "Instance name=#{instance_name} not found on #{real_name}" unless index.is_a?(Numeric) return index end @@ -100,6 +114,8 @@ module Register case reference when :message register = message_reg + when :new_message + register = new_message_reg when :self register = self_reg when :frame