コード例 #1
0
        public void Transform()
        {
            SetInitialValues();
            var wl = new WorkList <SsaIdentifier>();

            wl.AddRange(ssa.Identifiers);
            while (wl.TryGetWorkItem(out var sid) && !listener.IsCanceled())
            {
                var oldValue = ctx.GetValue(sid.Identifier);
                if (oldValue is InvalidConstant)
                {
                    continue;
                }

                var newValue = Evaluate(sid);
                if (!cmp.Equals(oldValue, newValue))
                {
                    ctx.SetValue(sid.Identifier, newValue);
                    foreach (var use in sid.Uses)
                    {
                        var uc   = new InstructionUseCollector();
                        var uses = uc.CollectUses(use);
                        wl.AddRange(uses.Keys.Select(id => ssa.Identifiers[id]));
                    }
                }
            }
        }
コード例 #2
0
        /// <summary>
        /// Compare uses stored in SsaState with actual ones
        /// </summary>
        public void ValidateUses(Action <string> error)
        {
            ValidateDeadUses(error);
            var uc = new InstructionUseCollector();

            foreach (var stm in Procedure.Statements)
            {
                var idMapStored = GetStatementIdentifiers(stm);
                var idMapActual = uc.CollectUses(stm);
                foreach (var id in idMapStored.Keys)
                {
                    if (!idMapActual.ContainsKey(id) || idMapActual[id] < idMapStored[id])
                    {
                        error(
                            string.Format(
                                "{0}: incorrect {1} id in {2} uses",
                                Procedure.Name,
                                id,
                                stm));
                    }
                }
                foreach (var id in idMapActual.Keys)
                {
                    if (!idMapStored.ContainsKey(id) || idMapStored[id] < idMapActual[id])
                    {
                        error(
                            string.Format(
                                "{0}: there is no {1} id in {2} uses",
                                Procedure.Name,
                                id,
                                stm));
                    }
                }
            }
        }