Browse Source

Fixed repeated type tests in cooperative cases

git-svn-id: https://svn.inf.ethz.ch/svn/lecturers/a2/trunk@8369 8c9fc860-2736-0410-a75d-ab315db34111
negelef 6 years ago
parent
commit
1d672e64a8
1 changed files with 9 additions and 1 deletions
  1. 9 1
      source/FoxIntermediateBackend.Mod

+ 9 - 1
source/FoxIntermediateBackend.Mod

@@ -10501,9 +10501,17 @@ TYPE
 		END VisitIfStatement;
 
 		PROCEDURE BrWithPart(CONST tag: IntermediateCode.Operand; x: SyntaxTree.WithPart; VAR trueL: Label);
+		VAR reg: IntermediateCode.Operand;
 		BEGIN
 			trueL := NewLabel();
-			TypeTest(tag, x.type, trueL, NIL,TRUE);
+			IF backend.cooperative THEN
+				IntermediateCode.InitRegister(reg,tag.type,tag.registerClass, AcquireRegister(tag.type, tag.registerClass));
+				Emit(Mov(position,reg,tag));
+				TypeTest(reg, x.type, trueL, NIL,TRUE);
+				ReleaseIntermediateOperand(reg);
+			ELSE
+				TypeTest(tag, x.type, trueL, NIL,TRUE);
+			END;
 		END BrWithPart;
 		
 		PROCEDURE EmitWithPart(x: SyntaxTree.WithPart);