Esempio n. 1
0
        public ReadWriteDomain Lub(ReadWriteDomain other, BoolRef changed)
        {
            switch (Value)
            {
            case ReadWriteEnum.None:
                if (other.Value != ReadWriteEnum.None)
                {
                    changed.Set();
                    return(other);
                }
                else
                {
                    return(this);
                }

            case ReadWriteEnum.Read:
                if (other.Value == ReadWriteEnum.ReadWrite)
                {
                    changed.Set();
                    return(other);
                }
                else
                {
                    return(this);
                }

            case ReadWriteEnum.ReadWrite:
                return(this);

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
Esempio n. 2
0
        public IntSet Union(IntSet other, BoolRef changed)
        {
            var res = new IntSet(Math.Max(n, other.n));

            for (var i = 0; i < Math.Min(v.Length, other.v.Length); i++)
            {
                var origv = v[i];
                res.v[i] = v[i] | other.v[i];
                if (res.v[i] != origv)
                {
                    changed.Set();
                }
            }
            if (v.Length < other.v.Length)
            {
                for (var i = v.Length; i < other.v.Length; i++)
                {
                    res.v[i] = other.v[i];
                    if (other.v[i] != 0u)
                    {
                        changed.Set();
                    }
                }
            }
            else
            {
                for (var i = other.v.Length; i < v.Length; i++)
                {
                    res.v[i] = v[i];
                }
            }
            return(res);
        }
Esempio n. 3
0
 public EvalTimes Lub(EvalTimes other, BoolRef changed)
 {
     if (Value == other.Value || Value == EvalTimesEnum.Any || other.Value == EvalTimesEnum.Once)
     {
         return(this);
     }
     else if (other.Value == EvalTimesEnum.Any || Value == EvalTimesEnum.Once)
     {
         changed.Set();
         return(other);
     }
     else
     {
         changed.Set();
         return(Top);
     }
 }
Esempio n. 4
0
        public DiscreteDomain <T> Lub(DiscreteDomain <T> other, BoolRef changed)
        {
            switch (Flag)
            {
            case DiscreteEnum.None:
                if (other.Flag == DiscreteEnum.None)
                {
                    return(this);
                }
                else
                {
                    changed.Set();
                    return(other);
                }

            case DiscreteEnum.Specific:
                if (other.Flag == DiscreteEnum.None)
                {
                    return(this);
                }
                else if (other.Flag == DiscreteEnum.Specific)
                {
                    if (Value.Equals(other.Value))
                    {
                        return(this);
                    }
                    else
                    {
                        return(null);
                    }
                }
                else
                {
                    changed.Set();
                    return(other);
                }

            case DiscreteEnum.Any:
                return(this);

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
Esempio n. 5
0
 public BooleanDomain Lub(BooleanDomain other, BoolRef changed)
 {
     if (!Value && other.Value)
     {
         changed.Set();
         return(Top);
     }
     else
     {
         return(this);
     }
 }
Esempio n. 6
0
 public ControlFlow Lub(ControlFlow other, BoolRef changed)
 {
     if (Value == other.Value || Value == ControlFlowEnum.Any)
     {
         return(this);
     }
     else
     {
         changed.Set();
         return(Top);
     }
 }
Esempio n. 7
0
 public void UnionInPlace(IntSet other, BoolRef changed)
 {
     k = -1;
     n = Math.Max(n, other.n);
     if (v.Length < other.v.Length)
     {
         var newv = new uint[other.v.Length];
         other.v.CopyTo(newv, 0);
         for (var i = 0; i < v.Length; i++)
         {
             var origv = newv[i];
             newv[i] |= v[i];
             if (newv[i] != origv)
             {
                 changed.Set();
             }
         }
         for (var i = v.Length; i < other.v.Length; i++)
         {
             if (newv[i] != 0u)
             {
                 changed.Set();
             }
         }
         v = newv;
     }
     else
     {
         for (var i = 0; i < other.v.Length; i++)
         {
             var origv = v[i];
             v[i] |= other.v[i];
             if (v[i] != origv)
             {
                 changed.Set();
             }
         }
     }
 }
Esempio n. 8
0
        public IntPowersetDomain Lub(IntPowersetDomain other, BoolRef changed)
        {
            var thisChanged = new BoolRef();
            var members     = Members.Union(other.Members, thisChanged);

            if (thisChanged.Value)
            {
                changed.Set();
                return(new IntPowersetDomain(members));
            }
            else
            {
                return(this);
            }
        }
Esempio n. 9
0
        public ReadWriteVectorDomain Lub(ReadWriteVectorDomain other, BoolRef changed)
        {
            var thisChanged = new BoolRef();
            var isRead      = IsRead.Union(other.IsRead, thisChanged);
            var isWrite     = IsWrite.Union(other.IsWrite, thisChanged);

            if (thisChanged.Value)
            {
                changed.Set();
                return(new ReadWriteVectorDomain(isRead, isWrite));
            }
            else
            {
                return(this);
            }
        }
Esempio n. 10
0
 public DroppedDomain <T> Lub(DroppedDomain <T> other, BoolRef changed)
 {
     if (IsTop)
     {
         return(Top);
     }
     else if (other.IsTop)
     {
         changed.Set();
         return(Top);
     }
     else
     {
         var value = Value.Lub(other.Value, changed);
         return(value == null ? null : new DroppedDomain <T>(value));
     }
 }
Esempio n. 11
0
        public VectorDomain <T> Lub(VectorDomain <T> other, BoolRef changed)
        {
            if (Elements.Count != other.Elements.Count)
            {
                return(null);
            }
            var res = default(Seq <T>);

            for (var i = 0; i < Elements.Count; i++)
            {
                var thisChanged = new BoolRef();
                var elem        = Elements[i].Lub(other.Elements[i], thisChanged);
                if (elem == null)
                {
                    return(null);
                }
                if (thisChanged.Value && res == null)
                {
                    changed.Set();
                    res = new Seq <T>(Elements.Count);
                    for (var j = 0; j < i; j++)
                    {
                        res.Add(Elements[i]);
                    }
                }
                if (res != null)
                {
                    res[i] = elem;
                }
            }
            if (res == null)
            {
                return(this);
            }
            else
            {
                return(new VectorDomain <T>(res));
            }
        }
Esempio n. 12
0
        public void Unify(RootEnvironment rootEnv, StackEntryState other, BoolRef changed)
        {
            var type = Type.Lub(rootEnv, other.Type, changed);

            var upperBound = default(TypeRef);
            if (UpperBound != null && other.UpperBound != null)
                upperBound = UpperBound.Glb(rootEnv, other.UpperBound, changed);
            else if (other.UpperBound != null)
            {
                upperBound = other.UpperBound;
                changed.Set();
            }
            else
                upperBound = UpperBound;

            if (upperBound != null && !type.IsAssignableTo(rootEnv, upperBound))
                throw new InvalidOperationException("stack entries are not unifiable");

            var pointsTo = PointsTo.Lub(other.PointsTo, changed);

            UpperBound = upperBound;
            Type = type;
            PointsTo = pointsTo;
        }
Esempio n. 13
0
 private void UnifyAfterState(MachineState state, int offset, BoolRef changed)
 {
     var existing = default(MachineState);
     if (offsetToAfterState.TryGetValue(offset, out existing))
         existing.Unify(state, changed);
     else
     {
         offsetToAfterState.Add(offset, state);
         changed.Set();
     }
 }
Esempio n. 14
0
 public void Unify(ArgsLocalsState other, BoolRef changed)
 {
     foreach (var kv in other.argLocalToPointsTo)
     {
         var pt = default(PointsTo);
         if (!kv.Value.IsBottom)
         {
             if (argLocalToPointsTo.TryGetValue(kv.Key, out pt))
                 argLocalToPointsTo[kv.Key] = pt.Lub(kv.Value, changed);
             else
             {
                 changed.Set();
                 argLocalToPointsTo.Add(kv.Key, kv.Value);
             }
         }
     }
     argsAlive.UnionInPlace(other.argsAlive, changed);
     localsAlive.UnionInPlace(other.localsAlive, changed);
 }
Esempio n. 15
0
 public void SourceToTargetTransition(ArgsLocalsState other, BoolRef changed)
 {
     // Any pointers in source are pointers in target
     foreach (var kv in argLocalToPointsTo)
     {
         var pt = default(PointsTo);
         if (!kv.Value.IsBottom)
         {
             if (other.argLocalToPointsTo.TryGetValue(kv.Key, out pt))
                 other.argLocalToPointsTo[kv.Key] = pt.Lub(kv.Value, changed);
             else
             {
                 changed.Set();
                 other.argLocalToPointsTo.Add(kv.Key, kv.Value);
             }
         }
     }
     // Anything alive in target is alive in source
     argsAlive.UnionInPlace(other.argsAlive, changed);
     localsAlive.UnionInPlace(other.localsAlive, changed);
 }
Esempio n. 16
0
 public void SetUpperBound(RootEnvironment rootEnv, TypeRef type, BoolRef changed)
 {
     var s = type.Style(rootEnv);
     if (s is ValueTypeStyle || s is PointerTypeStyle || s is CodePointerTypeStyle)
     {
         // These types are only assignable to themselves, so no need to remember
         // the upper bound, just check it
         if (!Type.IsAssignableTo(rootEnv, type))
         {
             if (s is UnmanagedPointerTypeStyle)
                 throw new InvalidOperationException("unmanaged pointer");
             else
                 throw new InvalidOperationException("stack entry cannot be generalized");
         }
     }
     else
     {
         var upperBound = UpperBound == null ? type : UpperBound.Glb(rootEnv, type, changed);
         if (!Type.IsAssignableTo(rootEnv, upperBound))
             throw new InvalidOperationException("stack entry cannot be generalized");
         if (!upperBound.IsEquivalentTo(rootEnv, rootEnv.Global.ObjectRef))
         {
             if (UpperBound == null)
                 changed.Set();
             UpperBound = upperBound;
         }
     }
 }
Esempio n. 17
0
 private MachineState ForwardBlock(InstructionContext context, MachineState initState, BoolRef changed)
 {
     if (context.HasBody)
     {
         var state = initState;
         for (var i = 0; i < context.Block.Body.Count; i++)
         {
             var offset = context.Block.Body[i].Offset;
             if (state == null)
             {
                 // Has an earlier instruction transferred control to here?
                 if (!offsetToBeforeState.TryGetValue(offset, out state))
                 {
                     // CLR spec requires that an instruction only reached by back jumps, and the entry of
                     // a try block, has an empty entry stack. We initially assume no pointers are
                     // stored in arguments or locals.
                     state = new MachineState(methEnv, method.ValueParameters.Count, method.Locals.Count);
                     offsetToBeforeState.Add(offset, state);
                     changed.Set();
                 }
             }
             else
                 // Current instruction cannot be a try
                 UnifyBeforeState(state, offset, changed);
             context.Block.Body[i].BeforeState = state; // not necessarialy final
             state = ForwardInstruction(context, i, state, changed);
             if (!context.Block.Body[i].IsStructural)
                 UnifyAfterState(state, offset, changed);
             context.Block.Body[i].AfterState = state; // not necessarialy final
             if (context.Block.Body[i].NeverReturns)
                 state = null;
         }
         if (state != null)
             throw new InvalidOperationException("fell off of end of instructions");
         return context.Block.Body[context.Block.Body.Count - 1].AfterState;
     }
     else
         return initState;
 }