Esempio n. 1
0
        public SymGraph <TFunc, TADomain> Join(SymGraph <TFunc, TADomain> that, out IMergeInfo mergeInfo, bool widen)
        {
            SymGraph <TFunc, TADomain> egraph = this;
            int updateSize;
            SymGraph <TFunc, TADomain> commonTail = ComputeCommonTail(egraph, that, out updateSize);
            bool hasCommonTail = commonTail != null;

            bool doingIncrementalJoin = hasCommonTail & commonTail != egraph.root_graph & !widen & DoIncrementalJoin;

            //debug

            if (DebugOptions.Debug)
            {
                Console.WriteLine("SymGraph {0}", widen ? "widen" : "join");
                if (commonTail != null)
                {
                    Console.WriteLine("Last common symbol: {0}", commonTail.LastSymbolId);
                }

                Console.WriteLine("  Doing {0}", doingIncrementalJoin ? "incremental join" : "full join");
            }

            SymGraph <TFunc, TADomain>  result;
            MergeInfo <TFunc, TADomain> mergeState;

            if (doingIncrementalJoin)
            {
                result     = new SymGraph <TFunc, TADomain> (commonTail);
                mergeState = new MergeInfo <TFunc, TADomain> (result, egraph, that, widen);
                mergeState.Replay(commonTail);
                mergeState.Commit();
            }
            else
            {
                result     = new SymGraph <TFunc, TADomain> (commonTail);
                mergeState = new MergeInfo <TFunc, TADomain> (result, egraph, that, widen);
                mergeState.ReplayEliminations(commonTail);
                mergeState.AddMapping(egraph.const_root, that.const_root, result.const_root);
                mergeState.JoinSymbolicValue(egraph.const_root, that.const_root, result.const_root);
                mergeState.Commit();
            }
            mergeInfo = mergeState;

            if (DebugOptions.Debug)
            {
                Console.WriteLine("  Result update size {0}", result.Updates.Length());
                Console.WriteLine("Done with Egraph join: changed = {0}", mergeInfo.Changed ? 1 : 0);
            }

            return(result);
        }
Esempio n. 2
0
        public override void Replay(MergeInfo <TFunc, TAbstractDomain> merge)
        {
            if (!merge.IsCommon(this.from))
            {
                return;
            }

            SymValue sv1 = merge.Graph1.LookupWithoutManifesting(this.from, this.function);
            SymValue sv2 = merge.Graph2.LookupWithoutManifesting(this.from, this.function);

            if (DebugOptions.Debug)
            {
                Console.WriteLine("Replay edge update: {0} -{1} -> [ {2}, {3} ]",
                                  this.from, this.function, sv1, sv2);
            }
            if (sv1 == null)
            {
                if (this.function.KeepAsBottomField && merge.Graph1.HasAllBottomFields(this.from))
                {
                    sv1 = merge.Graph1.BottomPlaceHolder;
                }
                else
                {
                    if (sv2 == null || merge.Widen || !this.function.ManifestField)
                    {
                        return;
                    }
                    if (DebugOptions.Debug)
                    {
                        Console.WriteLine("---SymGraph changed due to manifestation of a top edge in Graph1");
                    }
                    merge.Changed = true;
                }
            }
            if (sv2 == null)
            {
                if (this.function.KeepAsBottomField && merge.Graph2.HasAllBottomFields(this.from))
                {
                    sv2 = merge.Graph2.BottomPlaceHolder;
                }
                else
                {
                    if (merge.Widen || !this.function.ManifestField)
                    {
                        return;
                    }
                    if (DebugOptions.Debug)
                    {
                        Console.WriteLine("---SymGraph changed due to manifestation of due to missing target in Graph2");
                    }
                    merge.Changed = true;
                    return;
                }
            }

            SymValue r = merge.AddJointEdge(sv1, sv2, this.function, this.from);

            if (r == null || r.UniqueId <= merge.LastCommonVariable)
            {
                return;
            }

            merge.JoinSymbolicValue(sv1, sv2, r);
        }