示例#1
0
        public bool ExtraUsedMethod(QualifiedMemberName name)
        {
            var assemblyDef = default(AssemblyDef);
            var typeDef     = default(TypeDef);
            var memberDef   = default(MemberDef);

            if (name.PrimTryResolve(Global, out assemblyDef, out typeDef, out memberDef))
            {
                return(memberDef.MarkAsUsed(this, assemblyDef, typeDef));
            }
            return(false);
        }
示例#2
0
        private int MethodBodySize(CST.QualifiedMemberName name)
        {
            var s = default(int);

            if (bodySizeCache.TryGetValue(name, out s))
            {
                // Already determined
                return(s);
            }

            var assemblyDef = default(CST.AssemblyDef);
            var typeDef     = default(CST.TypeDef);
            var memberDef   = default(CST.MemberDef);

            if (name.PrimTryResolve(env.Global, out assemblyDef, out typeDef, out memberDef))
            {
                var methodDef = (CST.MethodDef)memberDef;

                if (PrimIsInlinable(assemblyDef, typeDef, methodDef))
                {
                    // Local method size, ignoring inlining
                    var instructions = methodDef.Instructions(env.Global);
                    s = instructions.Size;

                    // Collect calls
                    foreach (var call in methodDef.UsedMembers.Where(n => n.Signature.Flavor == CST.MemberDefFlavor.Method))
                    {
                        var t = MethodBodySize(call);
                        if (t >= 0)
                        {
                            // Inlinable method, replace call with body
                            s += t - 1;
                        }
                    }
                }
                else
                {
                    // Obviously non-inlinable method
                    s = -1;
                }
            }
            else
            {
                s = -1;
            }

            bodySizeCache.Add(name, s);
            return(s);
        }