Ejemplo n.º 1
0
 public Variable(JST.Identifier id, ArgLocal argLocal, bool isInit, bool isReadOnly, CST.TypeRef type)
 {
     Id         = id;
     ArgLocal   = argLocal;
     IsInit     = isInit;
     IsReadOnly = isReadOnly;
     Type       = type;
 }
Ejemplo n.º 2
0
        public TypeRef ArgLocalType(ArgLocal argLocal, int index)
        {
            switch (argLocal)
            {
            case ArgLocal.Arg:
                return(ValueParameters[index].Type);

            case ArgLocal.Local:
                return(Locals[index].Type);

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
Ejemplo n.º 3
0
        public MachineState PopAddArgLocalPointsTo(int n, ArgLocal argLocal, int index, PointsTo pointsTo)
        {
            if (n > Depth)
            {
                throw new InvalidOperationException("stack is too shallow");
            }
            var stack = new Seq <StackEntryState>(Depth - n);

            for (var i = n; i < Depth; i++)
            {
                stack.Add(innerState.Value.Stack[i]);
            }
            return(CloneWithArgLocalPointsTo(stack, argLocal, index, pointsTo));
        }
Ejemplo n.º 4
0
        private IntSet ArgLocalToLiveness(ArgLocal argLocal)
        {
            switch (argLocal)
            {
            case ArgLocal.Arg:
                return(argsAlive);

            case ArgLocal.Local:
                return(localsAlive);

            default:
                throw new ArgumentOutOfRangeException("argLocal");
            }
        }
Ejemplo n.º 5
0
        public PointsTo ArgLocalPointsTo(ArgLocal argLocal, int index)
        {
            var key = ArgLocalInstruction.Key(argLocal, index);
            var pt  = default(PointsTo);

            if (argLocalToPointsTo.TryGetValue(key, out pt))
            {
                return(pt);
            }
            else
            {
                return(PointsTo.MakeBottom(argsAlive.Capacity, localsAlive.Capacity));
            }
        }
Ejemplo n.º 6
0
        public ArgsLocalsState CloneWithArgLocalPointsTo(ArgLocal argLocal, int index, PointsTo pointsTo)
        {
            var key = ArgLocalInstruction.Key(argLocal, index);
            var res = new ArgsLocalsState(argsAlive.Capacity, localsAlive.Capacity);

            foreach (var kv in argLocalToPointsTo)
            {
                if (kv.Key != key)
                {
                    res.argLocalToPointsTo.Add(kv.Key, kv.Value);
                }
            }
            if (!pointsTo.IsBottom)
            {
                res.argLocalToPointsTo.Add(key, pointsTo);
            }
            return(res);
        }
Ejemplo n.º 7
0
        public static PointsTo MakeArgLocal(int nArgs, int nLocals, ArgLocal argLocal, int index)
        {
            switch (argLocal)
            {
            case ArgLocal.Arg:
                return(new PointsTo
                           (IntPowersetDomain.Singleton(nArgs, index),
                           IntPowersetDomain.Bottom(nLocals),
                           BooleanDomain.Bottom));

            case ArgLocal.Local:
                return(new PointsTo
                           (IntPowersetDomain.Bottom(nArgs),
                           IntPowersetDomain.Singleton(nLocals, index),
                           BooleanDomain.Bottom));

            default:
                throw new ArgumentOutOfRangeException("argLocal");
            }
        }
Ejemplo n.º 8
0
        public static MessageContext ArgOrLocal(MessageContext parent, ArgLocal argLocal, int index)
        {
            return(new MessageContext
                       (parent,
                       null,
                       sb =>
            {
                switch (argLocal)
                {
                case ArgLocal.Arg:
                    sb.Append("Argument ");
                    break;

                case ArgLocal.Local:
                    sb.Append("Local ");
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }
                sb.Append(index.ToString());
            }));
        }
Ejemplo n.º 9
0
        public void PropogateBackwards(ArgsLocalsState other, ArgLocal argLocal, int index, bool isAlive, BoolRef changed)
        {
            var newArgsAlive   = other.argsAlive.Clone();
            var newLocalsAlive = other.localsAlive.Clone();

            if (index >= 0)
            {
                switch (argLocal)
                {
                case ArgLocal.Arg:
                    newArgsAlive[index] = isAlive;
                    break;

                case ArgLocal.Local:
                    newLocalsAlive[index] = isAlive;
                    break;

                default:
                    throw new ArgumentOutOfRangeException("argLocal");
                }
            }
            argsAlive.UnionInPlace(newArgsAlive, changed);
            localsAlive.UnionInPlace(newLocalsAlive, changed);
        }
Ejemplo n.º 10
0
        public static Effects MakeArgLocal(int nArgs, int nLocals, ArgLocal argLocal, int index, bool isWrite, bool couldThrow)
        {
            switch (argLocal)
            {
            case ArgLocal.Arg:
                return(new Effects
                           (ReadWriteVectorDomain.FromSameElementExcept
                               (ReadWriteDomain.Bottom, nArgs, new ReadWriteDomain(true, isWrite), index),
                           ReadWriteVectorDomain.FromSameElement(ReadWriteDomain.Bottom, nLocals),
                           ReadWriteDomain.Bottom,
                           new BooleanDomain(couldThrow)));

            case ArgLocal.Local:
                return(new Effects
                           (ReadWriteVectorDomain.FromSameElement(ReadWriteDomain.Bottom, nArgs),
                           ReadWriteVectorDomain.FromSameElementExcept
                               (ReadWriteDomain.Bottom, nLocals, new ReadWriteDomain(true, isWrite), index),
                           ReadWriteDomain.Bottom,
                           new BooleanDomain(couldThrow)));

            default:
                throw new ArgumentOutOfRangeException("argLocal");
            }
        }
Ejemplo n.º 11
0
 public bool ArgLocalIsAlive(ArgLocal argLocal, int index)
 {
     return ArgLocalToLiveness(argLocal)[index];
 }
Ejemplo n.º 12
0
 public bool ArgLocalIsAlive(ArgLocal argLocal, int index)
 {
     return(innerState.Value.ArgsLocalsState.ArgLocalIsAlive(argLocal, index));
 }
Ejemplo n.º 13
0
 public void ReadArgLocal(MachineState nextState, ArgLocal argLocal, int index, BoolRef changed)
 {
     innerState.Value.ArgsLocalsState.PropogateBackwards(nextState.innerState.Value.ArgsLocalsState, argLocal, index, true, changed);
 }
Ejemplo n.º 14
0
 public void PropogateBackwards(ArgsLocalsState other, ArgLocal argLocal, int index, bool isAlive, BoolRef changed)
 {
     var newArgsAlive = other.argsAlive.Clone();
     var newLocalsAlive = other.localsAlive.Clone();
     if (index >= 0)
     {
         switch (argLocal)
         {
             case ArgLocal.Arg:
                 newArgsAlive[index] = isAlive;
                 break;
             case ArgLocal.Local:
                 newLocalsAlive[index] = isAlive;
                 break;
             default:
                 throw new ArgumentOutOfRangeException("argLocal");
         }
     }
     argsAlive.UnionInPlace(newArgsAlive, changed);
     localsAlive.UnionInPlace(newLocalsAlive, changed);
 }
Ejemplo n.º 15
0
 public PointsTo ArgLocalPointsTo(ArgLocal argLocal, int index)
 {
     return(innerState.Value.ArgsLocalsState.ArgLocalPointsTo(argLocal, index));
 }
Ejemplo n.º 16
0
 public PointsTo ArgLocalPointsTo(ArgLocal argLocal, int index)
 {
     return innerState.Value.ArgsLocalsState.ArgLocalPointsTo(argLocal, index);
 }
Ejemplo n.º 17
0
 public bool ArgLocalIsAlive(ArgLocal argLocal, int index)
 {
     return(ArgLocalToLiveness(argLocal)[index]);
 }
Ejemplo n.º 18
0
 public InnerMachineState CloneWithArgLocalPointsTo(IImSeq<StackEntryState> stack, ArgLocal argLocal, int index, PointsTo pointsTo)
 {
     return new InnerMachineState(stack, ArgsLocalsState.CloneWithArgLocalPointsTo(argLocal, index, pointsTo));
 }
Ejemplo n.º 19
0
 private IntSet ArgLocalToLiveness(ArgLocal argLocal)
 {
     switch (argLocal)
     {
         case ArgLocal.Arg:
             return argsAlive;
         case ArgLocal.Local:
             return localsAlive;
         default:
             throw new ArgumentOutOfRangeException("argLocal");
     }
 }
Ejemplo n.º 20
0
 public InnerMachineState CloneWithArgLocalPointsTo(IImSeq <StackEntryState> stack, ArgLocal argLocal, int index, PointsTo pointsTo)
 {
     return(new InnerMachineState(stack, ArgsLocalsState.CloneWithArgLocalPointsTo(argLocal, index, pointsTo)));
 }
Ejemplo n.º 21
0
 public bool ArgLocalIsAlive(ArgLocal argLocal, int index)
 {
     return innerState.Value.ArgsLocalsState.ArgLocalIsAlive(argLocal, index);
 }
Ejemplo n.º 22
0
 public void ReadArgLocal(MachineState nextState, ArgLocal argLocal, int index, BoolRef changed)
 {
     innerState.Value.ArgsLocalsState.PropogateBackwards(nextState.innerState.Value.ArgsLocalsState, argLocal, index, true, changed);
 }
Ejemplo n.º 23
0
 public MachineState PopAddArgLocalPointsTo(int n, ArgLocal argLocal, int index, PointsTo pointsTo)
 {
     if (n > Depth)
         throw new InvalidOperationException("stack is too shallow");
     var stack = new Seq<StackEntryState>(Depth - n);
     for (var i = n; i < Depth; i++)
         stack.Add(innerState.Value.Stack[i]);
     return CloneWithArgLocalPointsTo(stack, argLocal, index, pointsTo);
 }
Ejemplo n.º 24
0
 public PointsTo ArgLocalPointsTo(ArgLocal argLocal, int index)
 {
     var key = ArgLocalInstruction.Key(argLocal, index);
     var pt = default(PointsTo);
     if (argLocalToPointsTo.TryGetValue(key, out pt))
         return pt;
     else
         return PointsTo.MakeBottom(argsAlive.Capacity, localsAlive.Capacity);
 }
Ejemplo n.º 25
0
 public ArgsLocalsState CloneWithArgLocalPointsTo(ArgLocal argLocal, int index, PointsTo pointsTo)
 {
     var key = ArgLocalInstruction.Key(argLocal, index);
     var res = new ArgsLocalsState(argsAlive.Capacity, localsAlive.Capacity);
     foreach (var kv in argLocalToPointsTo)
     {
         if (kv.Key != key)
             res.argLocalToPointsTo.Add(kv.Key, kv.Value);
     }
     if (!pointsTo.IsBottom)
         res.argLocalToPointsTo.Add(key, pointsTo);
     return res;
 }
Ejemplo n.º 26
0
 public TypeRef ArgLocalType(ArgLocal argLocal, int index)
 {
     switch (argLocal)
     {
     case ArgLocal.Arg:
         return ValueParameters[index].Type;
     case ArgLocal.Local:
         return Locals[index].Type;
     default:
         throw new ArgumentOutOfRangeException();
     }
 }
Ejemplo n.º 27
0
 public static MessageContext ArgOrLocal(ArgLocal argLocal, int index)
 {
     return(ArgOrLocal(null, argLocal, index));
 }
Ejemplo n.º 28
0
 public MachineState CloneWithArgLocalPointsTo(IImSeq<StackEntryState> stack, ArgLocal argLocal, int index, PointsTo pointsTo)
 {
     return new MachineState(RootEnv, nArgs, nLocals, innerState.Value.CloneWithArgLocalPointsTo(stack, argLocal, index, pointsTo));
 }
Ejemplo n.º 29
0
 public MachineState CloneWithArgLocalPointsTo(IImSeq <StackEntryState> stack, ArgLocal argLocal, int index, PointsTo pointsTo)
 {
     return(new MachineState(RootEnv, nArgs, nLocals, innerState.Value.CloneWithArgLocalPointsTo(stack, argLocal, index, pointsTo)));
 }
Ejemplo n.º 30
0
 private PointsTo ArgLocalPT(ArgLocal argLocal, int index)
 {
     var key = ArgLocalInstruction.Key(argLocal, index);
     if (stackLocPTCache == null)
         stackLocPTCache = new Map<string, PointsTo>();
     var pt = default(PointsTo);
     if (!stackLocPTCache.TryGetValue(key, out pt))
     {
         pt = PointsTo.MakeArgLocal(method.ValueParameters.Count, method.Locals.Count, argLocal, index);
         stackLocPTCache.Add(key, pt);
     }
     return pt;
 }