From 30d4f752f47217bcdc4dd05428010acf270189d0 Mon Sep 17 00:00:00 2001
From: Ficture Seven <FICTURE7@gmail.com>
Date: Mon, 13 Jul 2020 14:20:07 +0400
Subject: [PATCH] Fix Node Uses/Assignments (#1376)

* Fix Node Uses/Assignments

* Bump PPTC Version Number

Co-authored-by: jduncanator <1518948+jduncanator@users.noreply.github.com>
---
 .../IntermediateRepresentation/Node.cs        | 57 +++++++++----------
 ARMeilleure/Translation/PTC/Ptc.cs            |  2 +-
 2 files changed, 28 insertions(+), 31 deletions(-)

diff --git a/ARMeilleure/IntermediateRepresentation/Node.cs b/ARMeilleure/IntermediateRepresentation/Node.cs
index 9ce78c095..3f41d814c 100644
--- a/ARMeilleure/IntermediateRepresentation/Node.cs
+++ b/ARMeilleure/IntermediateRepresentation/Node.cs
@@ -10,25 +10,12 @@ namespace ARMeilleure.IntermediateRepresentation
 
         public Operand Destination
         {
-            get
-            {
-                return _destinations.Count != 0 ? GetDestination(0) : null;
-            }
-            set
-            {
-                if (value != null)
-                {
-                    SetDestination(value);
-                }
-                else
-                {
-                    _destinations.Clear();
-                }
-            }
+            get => _destinations.Count != 0 ? GetDestination(0) : null;
+            set => SetDestination(value);
         }
 
-        private List<Operand> _destinations;
-        private List<Operand> _sources;
+        private readonly List<Operand> _destinations;
+        private readonly List<Operand> _sources;
         private bool _clearedDest;
 
         public int DestinationsCount => _destinations.Count;
@@ -123,13 +110,14 @@ namespace ARMeilleure.IntermediateRepresentation
 
         private void RemoveOldDestinations()
         {
-            if (_destinations != null && !_clearedDest)
+            if (!_clearedDest)
             {
                 for (int index = 0; index < _destinations.Count; index++)
                 {
                     RemoveAssignment(_destinations[index]);
                 }
             }
+
             _clearedDest = false;
         }
 
@@ -137,13 +125,18 @@ namespace ARMeilleure.IntermediateRepresentation
         {
             RemoveOldDestinations();
 
-            Resize(_destinations, 1);
-
-            _destinations[0] = destination;
-
-            if (destination.Kind == OperandKind.LocalVariable)
+            if (destination == null)
             {
-                destination.Assignments.Add(this);
+                _destinations.Clear();
+                _clearedDest = true;
+            }
+            else
+            {
+                Resize(_destinations, 1);
+
+                _destinations[0] = destination;
+
+                AddAssignment(destination);
             }
         }
 
@@ -175,13 +168,17 @@ namespace ARMeilleure.IntermediateRepresentation
         {
             RemoveOldSources();
 
-            Resize(_sources, 1);
-
-            _sources[0] = source;
-
-            if (source.Kind == OperandKind.LocalVariable)
+            if (source == null)
             {
-                source.Uses.Add(this);
+                _sources.Clear();
+            }
+            else
+            {
+                Resize(_sources, 1);
+
+                _sources[0] = source;
+
+                AddUse(source);
             }
         }
 
diff --git a/ARMeilleure/Translation/PTC/Ptc.cs b/ARMeilleure/Translation/PTC/Ptc.cs
index b538e9480..0051d25ad 100644
--- a/ARMeilleure/Translation/PTC/Ptc.cs
+++ b/ARMeilleure/Translation/PTC/Ptc.cs
@@ -20,7 +20,7 @@ namespace ARMeilleure.Translation.PTC
     {
         private const string HeaderMagic = "PTChd";
 
-        private const int InternalVersion = 7; //! To be incremented manually for each change to the ARMeilleure project.
+        private const int InternalVersion = 8; //! To be incremented manually for each change to the ARMeilleure project.
 
         private const string BaseDir = "Ryujinx";