예제 #1
0
        public IWeight GetInitial(Implementation impl)
        {
            var domainG = program.TopLevelDeclarations
                          .OfType <GlobalVariable>()
                          .Where(g => g.TypedIdent.Type.IsInt);
            var domainL = impl.LocVars.OfType <Variable>()
                          .Concat(impl.OutParams.OfType <Variable>())
                          .Where(v => v.TypedIdent.Type.IsInt);

            var ret = new ConstantProp();

            domainG.Iter(g => ret.val.Add(g.Name, Value.GetSingleton(g)));
            domainL.Iter(l => ret.val.Add(l.Name, Value.GetTop()));
            ret.impl   = impl;
            ret.isZero = false;

            return(ret);
        }
예제 #2
0
        private ConstantProp ApplyCall(CallCmd cmd, ConstantProp summary)
        {
            Debug.Assert(summary.impl != null && impl != null);

            var domainG = program.TopLevelDeclarations
                          .OfType <GlobalVariable>()
                          .Where(g => g.TypedIdent.Type.IsInt)
                          .Where(g => val.ContainsKey(g.Name));

            var domainL = impl.LocVars.OfType <Variable>()
                          .Concat(impl.OutParams.OfType <Variable>())
                          .Where(v => v.TypedIdent.Type.IsInt)
                          .Where(v => val.ContainsKey(v.Name));

            var ret   = new Dictionary <string, Value>();
            var subst = new Dictionary <string, Value>();

            domainG.Iter(g => subst.Add(g.Name, val[g.Name]));
            for (int i = 0; i < summary.impl.InParams.Count; i++)
            {
                var formal = summary.impl.InParams[i];
                var actual = Value.GetTop();
                if (cmd.Ins[i] != null)
                {
                    actual = Evaluate(cmd.Ins[i]);
                }
                subst.Add(formal.Name, actual);
            }

            foreach (var g in domainG)
            {
                Debug.Assert(summary.val.ContainsKey(g.Name));
                var value = summary.val[g.Name];
                ret.Add(g.Name, value.Subst(subst));
            }

            var assigned = new HashSet <string>();

            for (int i = 0; i < cmd.Outs.Count; i++)
            {
                var l = cmd.Outs[i];
                if (l == null)
                {
                    continue;
                }
                if (!val.ContainsKey(l.Name))
                {
                    continue;
                }

                assigned.Add(l.Name);
                var formal = summary.impl.OutParams[i];
                var value  = summary.val[formal.Name].Subst(subst);

                if (ret.ContainsKey(l.Name))
                {
                    ret[l.Name] = value;
                }
                else
                {
                    ret.Add(l.Name, value);
                }
            }

            foreach (var l in domainL)
            {
                if (assigned.Contains(l.Name))
                {
                    continue;
                }
                ret.Add(l.Name, new Value(val[l.Name]));
            }

            return(new ConstantProp(ret, impl));
        }