Exemplo n.º 1
0
            private void UpdateState(ConstantPropagationDomain state, IVariable v, Constant c)
            {
                var cpd = ConstantSetDomain.Bottom;

                cpd.Add(c);
                state.Set(v, cpd);
            }
Exemplo n.º 2
0
            private void UpdateStateCopy(ConstantPropagationDomain state, IFieldAccess dest, IVariable src)
            {
                /*
                 * When we set a field of an object O to a constant, we also need to set the same field
                 * to objects that are must aliased to O. We know that all field accesses corresponding
                 * to closure fields must alias each other since they are compiler generated. That is,
                 * a user cannot instantiate such class nor does the compiler instantiate it inside the class itself.
                 */

                var faccess           = GetAccessRef(dest);
                IFieldDefinition fdef = faccess.Item2.Resolve(parent.Host);

                // We know that closure field accesses must alias each other.
                if (IsClosureField(fdef))
                {
                    foreach (var pair in parent.Fields)
                    {
                        var fresolved = pair.Item2.Resolve(parent.Host);

                        if (fresolved == fdef || fresolved.Equals(fdef))
                        {
                            state.Set(GetAccess(pair.Item1), state.Constants(src).Clone());
                        }
                    }
                }
                else
                {
                    // TODO: refine this by type of the field.
                    state.SetFieldNonConstant();
                }
            }
Exemplo n.º 3
0
        public ConstantPropagationDomain Clone()
        {
            var clone = new ConstantPropagationDomain();

            foreach (var v in varMapping.Keys)
            {
                clone.Set(v, varMapping[v].Clone());
            }
            foreach (var f in fieldMapping.Keys)
            {
                clone.Set(f, fieldMapping[f].Clone());
            }

            return(clone);
        }
Exemplo n.º 4
0
        public static ConstantPropagationDomain Top(IEnumerable <IVariable> vars, IEnumerable <IFieldAccess> fields)
        {
            var cpd = new ConstantPropagationDomain();

            foreach (var v in vars)
            {
                cpd.Set(v, ConstantSetDomain.Top);
            }

            foreach (var f in fields)
            {
                cpd.Set(f, ConstantSetDomain.Top);
            }

            return(cpd);
        }
Exemplo n.º 5
0
        public void Join(ConstantPropagationDomain other)
        {
            if (VarCount != other.VarCount)
            {
                throw new IncompatibleConstantPropagationDomains("Not the same variable set!");
            }

            for (int i = 0; i < varMapping.Keys.Count; i++)
            {
                var v = varMapping.Keys.ElementAt(i);
                if (!other.Contains(v))
                {
                    throw new IncompatibleConstantPropagationDomains("Not the same variable set! " + v.ToString());
                }
                var ncsd = Constants(v).Clone();
                ncsd.Join(other.Constants(v));
                Set(v, ncsd);
            }

            if (FieldCount != other.FieldCount)
            {
                throw new IncompatibleConstantPropagationDomains("Not the same field set!");
            }

            for (int i = 0; i < fieldMapping.Keys.Count; i++)
            {
                var f = fieldMapping.Keys.ElementAt(i);
                if (!other.Contains(f))
                {
                    throw new IncompatibleConstantPropagationDomains("Not the same field set! " + f.ToString());
                }
                var ncsd = Constants(f).Clone();
                ncsd.Join(other.Constants(f));
                Set(f, ncsd);
            }
        }
Exemplo n.º 6
0
            /// <summary>
            /// Method that conservatively checks if the current method is string concatenation
            /// and parameters are known string constants.
            /// </summary>
            /// <param name="instruction"></param>
            /// <param name="state"></param>
            /// <returns></returns>
            private bool IsStringConcatenationPossible(MethodCallInstruction instruction, ConstantPropagationDomain state)
            {
                if (!instruction.HasResult)
                {
                    return(false);
                }

                if (instruction.Arguments.Count != 2)
                {
                    return(false);
                }

                if (instruction.Method.ContainingType.FullName() != "System.String")
                {
                    return(false);
                }

                if (instruction.Method.Name.Value != "Concat")
                {
                    return(false);
                }

                var arg0 = instruction.Arguments.ElementAt(0);
                var arg1 = instruction.Arguments.ElementAt(1);

                if (arg0.Type.FullName() != "System.String" || arg1.Type.FullName() != "System.String")
                {
                    return(false);
                }

                var cons1 = state.Constants(arg0);
                var cons2 = state.Constants(arg1);

                if (cons1.IsBottom || cons2.IsBottom || cons1.IsTop || cons2.IsTop)
                {
                    return(false);
                }

                return(true);
            }
Exemplo n.º 7
0
 public ConstantPropagationTransferVisitor(ConstantPropagationDomain start, ConstantPropagationSetAnalysis dad)
 {
     parent = dad;
     SetCurrent(start);
 }
Exemplo n.º 8
0
            private void UpdateStateCopy(ConstantPropagationDomain state, IVariable dest, IFieldAccess src)
            {
                var cl = state.Constants(GetAccess(src)).Clone();

                state.Set(dest, cl);
            }
Exemplo n.º 9
0
 private void UpdateStateNotConstant(ConstantPropagationDomain state)
 {
     state.SetNonConstant();
 }
Exemplo n.º 10
0
 private void UpdateStateNotConstant(ConstantPropagationDomain state, IFieldAccess f)
 {
     state.SetNonConstant(GetAccess(f));
 }
Exemplo n.º 11
0
 private void UpdateStateNotConstant(ConstantPropagationDomain state, IVariable v)
 {
     state.SetNonConstant(v);
 }
Exemplo n.º 12
0
 private void SavePostState(Instruction instruction, ConstantPropagationDomain cpd)
 {
     postState[instruction] = cpd;
 }
Exemplo n.º 13
0
 private void SetCurrent(ConstantPropagationDomain curr)
 {
     current = curr;
 }