コード例 #1
0
        public override bool Optimize(OptimizationContext context)
        {
            var changed    = false;
            var offsetInfo = new VariableOffset[context.Count];

            for (var i = 0; i < offsetInfo.Length; i++)
            {
                offsetInfo[i] = new VariableOffset();
            }

            BuildOffsetInfo(context, offsetInfo);

            for (var i = context.Count - 1; i >= 0; i--)
            {
                var instruction = context[i];
                switch (instruction.Type)
                {
                case InstructionType.RestorePosition:
                    var offset = offsetInfo[i].Get(instruction.Data1);
                    if (offset == 0)
                    {
                        changed = true;
                        context.RemoveAt(i);
                    }
                    else if (offset > 0)
                    {
                        changed    = true;
                        context[i] = Instruction.Advance((short)-offset);
                    }
                    break;
                }
            }

            return(changed);
        }
コード例 #2
0
            public bool Equals(VariableOffset other)
            {
                foreach (var kvp in other.offsets)
                {
                    if (offsets.TryGetValue(kvp.Key, out var value))
                    {
                        if (value != kvp.Value)
                        {
                            return(false);
                        }
                    }
                    else
                    {
                        return(false);
                    }
                }

                return(true);
            }
コード例 #3
0
 public void UnionWith(VariableOffset other, int offset = 0)
 {
     foreach (var kvp in other.offsets)
     {
         if (kvp.Value == -1)
         {
             offsets[kvp.Key] = -1;
         }
         else if (offsets.TryGetValue(kvp.Key, out var value))
         {
             if (value == -1 || value != kvp.Value + offset)
             {
                 offsets[kvp.Key] = -1;
             }
         }
         else
         {
             offsets[kvp.Key] = kvp.Value + offset;
         }
     }
 }