private static bool SimplifyScans(AbstractSyntaxTree root)
        {
            if (root.Count > 1)
            {
                bool RetVal = false;
                foreach (AbstractSyntaxTree ast in root.ChildNodes)
                {
                    RetVal |= SimplifyScans(ast);
                }

                return(RetVal);
            }

            if (root.Count == 1)
            {
                if (root[0].Op == OpCode.AddPtr)
                {
                    root.RemoveAt(0);
                    root.Op = OpCode.ScanRight;
                    return(true);
                }
                if (root[0].Op == OpCode.SubPtr)
                {
                    root.RemoveAt(0);
                    root.Op = OpCode.ScanLeft;
                    return(true);
                }
            }

            return(false);
        }
        private static bool EliminateUnreachableLoops(AbstractSyntaxTree root, bool trueRoot)
        {
            bool RetVal = false;

            for (int i = 1; i < root.Count; i++)
            {
                RetVal |= EliminateUnreachableLoops(root[i], false);
                if (root[i].Op == OpCode.Loop && (root[i - 1].Op == OpCode.Loop || root[i - 1].Op == OpCode.AssignZero))
                {
                    root.RemoveAt(i);
                    RetVal = true;
                    i--;
                }
            }

            if (trueRoot)
            {
                if (root.Count > 0 && root[0].Op == OpCode.Loop)
                {
                    root.RemoveAt(0);
                    return(true);
                }

                if (root.Count == 0 && root.Op == OpCode.Loop)
                {
                    root.Op = OpCode.Nop;
                    return(true);
                }
            }

            return(RetVal);
        }
        private static bool EliminateDeadStores(AbstractSyntaxTree root, bool trueRoot)
        {
            bool RetVal = false;

            for (int i = root.Count - 2; i >= 0; i--)
            {
                RetVal |= EliminateDeadStores(root[i], false);
                if (root[i + 1].Op == OpCode.AssignZero || root[i + 1].Op == OpCode.AssignVal)
                {
                    AbstractSyntaxTree ast = root[i];
                    if (ast.Op.AssignsValue() || ast.Op == OpCode.AssignZero || ast.Op.ModifiesValue())
                    {
                        root.Remove(ast);
                    }
                }
            }

            if (root.Count > 0 && root[0].Op == OpCode.AssignZero && trueRoot)
            {
                root.RemoveAt(0);
                return(true);
            }

            return(RetVal);
        }
        internal static bool EliminateConflictingInstructions(AbstractSyntaxTree ast)
        {
            bool RetVal = false;

            if (ast.Count > 0)
            {
                RetVal |= EliminateConflictingInstructions(ast[0]);
            }

            for (int i = 1; i < ast.Count; i++)
            {
                RetVal |= EliminateConflictingInstructions(ast[i]);
                if (ast[i - 1].Op.IsReversable() && ast[i - 1].Op.GetReversedOpCode() == ast[i].Op)
                {
                    ast.RemoveAt(i);
                    ast.RemoveAt(i - 1);
                    i     += 2;
                    RetVal = true;
                }
            }

            return(RetVal);
        }