From fa797f722d70e6280f8fd62f7220a68065fd0fbc Mon Sep 17 00:00:00 2001 From: Torsten Ruger Date: Wed, 21 Mar 2018 12:38:28 +0530 Subject: [PATCH] to_risc for NotSameCheck which is only used in call cache checking some fixing, needed to add a abel for the cache check jump --- lib/mom/instruction/not_same_check.rb | 12 +++++++++--- lib/risc/instructions/branch.rb | 8 ++++++++ lib/vool/statements/send_statement.rb | 8 +++++--- test/vool/to_mom/send/test_send_cached_simple.rb | 3 ++- test/vool/to_mom/test_if_condition.rb | 12 ++++++------ 5 files changed, 30 insertions(+), 13 deletions(-) diff --git a/lib/mom/instruction/not_same_check.rb b/lib/mom/instruction/not_same_check.rb index 8b0ce28a..4c758f93 100644 --- a/lib/mom/instruction/not_same_check.rb +++ b/lib/mom/instruction/not_same_check.rb @@ -9,12 +9,18 @@ module Mom class NotSameCheck < Check attr_reader :left , :right - def initialize(left, right) + def initialize(left, right , label) + super(label) @left , @right = left , right end - def to_risc(context) - Risc::Label.new(self,"NotSameCheck") + # basically move both left and right values into register and issue a + # risc comparison + def to_risc(compiler) + l_val = left.to_register(compiler, self) + r_val = right.to_register(compiler, self) + check = Risc::NotSame.new(self, l_val.register, r_val.register, false_jump.to_risc(compiler)) + l_val << r_val << check end end end diff --git a/lib/risc/instructions/branch.rb b/lib/risc/instructions/branch.rb index 3067ae3e..40ad0fcd 100644 --- a/lib/risc/instructions/branch.rb +++ b/lib/risc/instructions/branch.rb @@ -75,6 +75,14 @@ module Risc end end + # branch if two registers contain different values + class NotSame < Branch + attr_reader :left , :right + def initialize(source , left , right , label) + super(source , label) + end + end + class Unconditional < Branch end diff --git a/lib/vool/statements/send_statement.rb b/lib/vool/statements/send_statement.rb index c209cd86..79e113c2 100644 --- a/lib/vool/statements/send_statement.rb +++ b/lib/vool/statements/send_statement.rb @@ -95,9 +95,11 @@ module Vool # if cached_type != current_type # cached_type = current_type # cached_method = current_type.resolve_method(method.name) - check = build_condition + ok = Mom::Label.new("cache_ok") + check = build_condition(ok) check << build_type_cache_update check << build_method_cache_update(in_method) + check << ok end # this may look like a simple_call, but the difference is that we don't know @@ -107,10 +109,10 @@ module Vool end private - def build_condition + def build_condition(ok_label) cached_type = Mom::SlotDefinition.new(dynamic_call.cache_entry , [:cached_type]) current_type = Mom::SlotDefinition.new(:message , [:receiver , :type]) - Mom::NotSameCheck.new(cached_type , current_type) + Mom::NotSameCheck.new(cached_type , current_type, ok_label) end def build_type_cache_update Mom::SlotLoad.new([dynamic_call.cache_entry, :cached_type] , [:message , :receiver , :type]) diff --git a/test/vool/to_mom/send/test_send_cached_simple.rb b/test/vool/to_mom/send/test_send_cached_simple.rb index f841b7e2..a9c0a2a5 100644 --- a/test/vool/to_mom/send/test_send_cached_simple.rb +++ b/test/vool/to_mom/send/test_send_cached_simple.rb @@ -26,7 +26,8 @@ module Vool end def test_array - check_array [SlotLoad,NotSameCheck,SlotLoad,MessageSetup,ArgumentTransfer,SimpleCall,SlotLoad,MessageSetup,ArgumentTransfer,DynamicCall] , @ins + check_array [SlotLoad, NotSameCheck, SlotLoad, MessageSetup, ArgumentTransfer, SimpleCall , + SlotLoad, Label, MessageSetup, ArgumentTransfer, DynamicCall] , @ins end end diff --git a/test/vool/to_mom/test_if_condition.rb b/test/vool/to_mom/test_if_condition.rb index 47fb6dca..37202075 100644 --- a/test/vool/to_mom/test_if_condition.rb +++ b/test/vool/to_mom/test_if_condition.rb @@ -12,19 +12,19 @@ module Vool end def test_condition - assert_equal TruthCheck , @ins.next(10).class + assert_equal TruthCheck , @ins.next(11).class end def test_condition_is_slot - assert_equal SlotDefinition , @ins.next(10).condition.class , @ins + assert_equal SlotDefinition , @ins.next(11).condition.class , @ins end def test_hoisted_dynamic_call - assert_equal DynamicCall , @ins.next(8).class + assert_equal DynamicCall , @ins.next(9).class end def test_array check_array [NotSameCheck, SlotLoad, MessageSetup, ArgumentTransfer, SimpleCall, SlotLoad , - MessageSetup, ArgumentTransfer, DynamicCall, SlotLoad, TruthCheck, Label , - MessageSetup, ArgumentTransfer, SimpleCall, Jump, Label, MessageSetup , - ArgumentTransfer, SimpleCall, Label] , @ins + Label, MessageSetup, ArgumentTransfer, DynamicCall, SlotLoad, TruthCheck , + Label, MessageSetup, ArgumentTransfer, SimpleCall, Jump, Label , + MessageSetup, ArgumentTransfer, SimpleCall, Label] , @ins end end