Ejemplo n.º 1
0
        internal static Creators MergeMethods(AnnotatedMethod method1, AnnotatedMethod method2)
        {
            Creators crtrs = new Creators();

            for (int i = 0; i < method1.ParamVals.Count; i++)
            {
                crtrs.AddCreators(BTValue.Merge(method1.ParamVals[i].Val as ReferenceBTValue, method2.ParamVals[i].Val as ReferenceBTValue));
            }
            crtrs.AddCreators(BTValue.Merge(method1.ReturnValue, method2.ReturnValue));

            return(crtrs);
        }
Ejemplo n.º 2
0
        internal AnnotatedMethod AnnotateMethod(AnnotatedMethod method)
        {
            int count = 0;

            foreach (AnnotatedMethod key in this.getMethods())
            {
                if (method.SourceMethod == key.SourceMethod)
                {
                    count++;
                    if (AnnotatedMethod.EqualMethods(method, key))
                    {
                        return(key);
                    }
                }
            }

            if (count > AnnotatedAssemblyHolder.NUMBER_FOR_MERGE)
            {
                AnnotatedMethod keyMethod         = null;
                int             keyMethodCreators = 0;

                foreach (AnnotatedMethod key in this.getMethods())
                {
                    if (method.SourceMethod == key.SourceMethod)
                    {
                        int keyCreators = AnnotatedMethod.PseudoMergeMethods(method, key).Count;
                        if (keyMethod == null || keyMethodCreators > keyCreators)
                        {
                            keyMethod         = key;
                            keyMethodCreators = keyCreators;
                        }
                    }
                }

                if (keyMethod != null && (keyMethodCreators == 0 || count > AnnotatedAssemblyHolder.NUMBER_FOR_LIFT))
                {
                    Creators crtrs = AnnotatedMethod.MergeMethods(method, keyMethod);
                    if (!crtrs.IsEmpty)
                    {
                        throw new AnnotatingVisitor.LiftException(crtrs);
                    }

                    return(keyMethod);
                }
            }

            MethodBodyBlock mbbUp = Annotation.AnnotateMethod(this, method);

            this.addMethodBody(method, mbbUp);
            return(method);
        }
Ejemplo n.º 3
0
        public AnnotatedMethod GetAnnotatedMethod(MethodBase sMethod)
        {
            AnnotatedMethod aMethod = this.aMethods[sMethod] as AnnotatedMethod;
            if (aMethod == null)
            {
                ParameterInfo[] parms = sMethod.GetParameters();
                EvaluationStack stack = new EvaluationStack();
                if (! sMethod.IsStatic)
                    stack.Push(new ReferenceBTValue(BTType.Dynamic));
                for (int i = 0; i < parms.Length; i++)
                    stack.Push(new ReferenceBTValue(BTType.Dynamic));
                ParameterValues paramVals = stack.Perform_CallMethod(sMethod, false);
                ReferenceBTValue ret = ReferenceBTValue.NewReferenceBTValue(Annotation.GetReturnType(sMethod), BTType.Dynamic);
                this.aMethods[sMethod] = aMethod = new AnnotatedMethod(paramVals, ret);
            }

            return aMethod;
        }
Ejemplo n.º 4
0
        internal AnnotatedMethod AnnotateMethod(AnnotatedMethod method)
        {
            int count = 0;
            foreach (AnnotatedMethod key in this.getMethods())
            {
                if (method.SourceMethod == key.SourceMethod)
                {
                    count++;
                    if (AnnotatedMethod.EqualMethods(method, key))
                        return key;
                }
            }

            if (count > AnnotatedAssemblyHolder.NUMBER_FOR_MERGE)
            {
                AnnotatedMethod keyMethod = null;
                int keyMethodCreators = 0;

                foreach (AnnotatedMethod key in this.getMethods())
                    if (method.SourceMethod == key.SourceMethod)
                    {
                        int keyCreators = AnnotatedMethod.PseudoMergeMethods(method, key).Count;
                        if (keyMethod == null || keyMethodCreators > keyCreators)
                        {
                            keyMethod = key;
                            keyMethodCreators = keyCreators;
                        }
                    }

                if (keyMethod != null && (keyMethodCreators == 0 || count > AnnotatedAssemblyHolder.NUMBER_FOR_LIFT))
                {
                    Creators crtrs = AnnotatedMethod.MergeMethods(method, keyMethod);
                    if (! crtrs.IsEmpty)
                        throw new AnnotatingVisitor.LiftException(crtrs);

                    return keyMethod;
                }
            }

            MethodBodyBlock mbbUp = Annotation.AnnotateMethod(this, method);
            this.addMethodBody(method, mbbUp);
            return method;
        }
Ejemplo n.º 5
0
        internal static bool EqualMethods(AnnotatedMethod method1, AnnotatedMethod method2)
        {
            if (!Equals(method1.ParamVals.Method, method2.ParamVals.Method))
            {
                return(false);
            }

            for (int i = 0; i < method1.ParamVals.Count; i++)
            {
                if (!BTValue.Equals(method1.ParamVals[i].Val as ReferenceBTValue, method2.ParamVals[i].Val as ReferenceBTValue))
                {
                    return(false);
                }
            }

            if (!BTValue.Equals(method1.ReturnValue, method2.ReturnValue))
            {
                return(false);
            }

            return(true);
        }
Ejemplo n.º 6
0
        public AnnotatedMethod GetAnnotatedMethod(MethodBase sMethod)
        {
            AnnotatedMethod aMethod = this.aMethods[sMethod] as AnnotatedMethod;

            if (aMethod == null)
            {
                ParameterInfo[] parms = sMethod.GetParameters();
                EvaluationStack stack = new EvaluationStack();
                if (!sMethod.IsStatic)
                {
                    stack.Push(new ReferenceBTValue(BTType.Dynamic));
                }
                for (int i = 0; i < parms.Length; i++)
                {
                    stack.Push(new ReferenceBTValue(BTType.Dynamic));
                }
                ParameterValues  paramVals = stack.Perform_CallMethod(sMethod, false);
                ReferenceBTValue ret       = ReferenceBTValue.NewReferenceBTValue(Annotation.GetReturnType(sMethod), BTType.Dynamic);
                this.aMethods[sMethod] = aMethod = new AnnotatedMethod(paramVals, ret);
            }

            return(aMethod);
        }
Ejemplo n.º 7
0
        internal static Creators PseudoMergeMethods(AnnotatedMethod method1, AnnotatedMethod method2)
        {
            Creators crtrs = new Creators();
            for (int i = 0; i < method1.ParamVals.Count; i++)
                crtrs.AddCreators(BTValue.PseudoMerge(method1.ParamVals[i].Val as ReferenceBTValue, method2.ParamVals[i].Val as ReferenceBTValue));
            crtrs.AddCreators(BTValue.PseudoMerge(method1.ReturnValue, method2.ReturnValue));

            return crtrs;
        }
Ejemplo n.º 8
0
        internal static bool EqualMethods(AnnotatedMethod method1, AnnotatedMethod method2)
        {
            if (! Equals(method1.ParamVals.Method, method2.ParamVals.Method))
                return false;

            for (int i = 0; i < method1.ParamVals.Count; i++)
                if (! BTValue.Equals(method1.ParamVals[i].Val as ReferenceBTValue, method2.ParamVals[i].Val as ReferenceBTValue))
                    return false;

            if (! BTValue.Equals(method1.ReturnValue, method2.ReturnValue))
                return false;

            return true;
        }
Ejemplo n.º 9
0
 internal void RemoveMethod(AnnotatedMethod method)
 {
     this.removeMethodBody(method);
 }
Ejemplo n.º 10
0
        private void callMethod(Node downNode, AnnotatedMethod method, PointerToNode ptrUpNode, Node upNode, Value[] args)
        {
            if (method.SourceMethod.IsDefined(typeof(InlineAttribute), false) && ! (upNode is NewObject))
            {
                MethodBodyBlock mbbDown = this.holder.AnnotatedHolder[method];
                SpecState state = new SpecState(mbbDown.Variables.Count);

                int varCount = 0;
                int argCount = 0;
                foreach (Variable varDown in mbbDown.Variables.ParameterMapper)
                {
                    state.Pool[varDown] = new Location(varDown.Type);
                    Variable varUp = this.mbbUp.Variables.CreateVar(varDown.Type, VariableKind.Local);
                    this.varsHash[new PointerToLocationValue(state.Pool[varDown])] = varUp;

                    if (Annotation.GetValueBTType(method.ParamVals[varCount++].Val) == BTType.Static)
                    {
                        state.Pool[varDown].Val = args[argCount];
                        state.Stack.Push(args[argCount++]);
                    }
                    else
                    {
                        Node upNext = new StoreVar(varUp);
                        Node upPrevNext = ptrUpNode.Node;
                        ptrUpNode.Node = upNext;
                        upNext.Next = upPrevNext;
                    }
                }
                while (ptrUpNode.Node != null)
                    ptrUpNode = new PointerToNode(ptrUpNode.Node);
                foreach (Variable varDown in mbbDown.Variables)
                    if (! state.Pool.ContainsVar(varDown))
                    {
                        state.Pool[varDown] = new Location(varDown.Type);
                        Variable varUp = this.mbbUp.Variables.CreateVar(varDown.Type, VariableKind.Local);
                        this.varsHash[new PointerToLocationValue(state.Pool[varDown])] = varUp;
                        ptrUpNode = SpecializingVisitor.initVariable(varUp, ptrUpNode);
                    }

                int depth = state.Stack.Count + 1;

                GraphProcessor graphProc = new GraphProcessor();
                SpecializingVisitor visitor = new SpecializingVisitor(graphProc, this.holder, this.mbbUp, state, this.varsHash);
                visitor.AddTask(mbbDown.Next, ptrUpNode);
                graphProc.Process();

                foreach (Data newData in visitor.exitData)
                {
                    state.Recall(newData.MemoSpecState, newData.ObjectHashtable);
                    if (state.Stack.Count == depth)
                        this.state.Stack.Push(state.Stack.Pop());
                    this.AddTask(downNode.Next, newData.PointerToNode);
                }
            }
            else
            {
                ObjectHashtable objHash = new ObjectHashtable();
                MemoState memoArgs = new MemoState(args, objHash);
                PointerValue[] ptrs = this.varsHash.GetPointers(objHash);

                for (int i = 0; i < ptrs.Length; i++)
                    ptrUpNode = new PointerToNode(ptrUpNode.Node = new LoadVarAddr(this.varsHash[ptrs[i]]));
                ptrUpNode = new PointerToNode(ptrUpNode.Node = upNode);

                ResidualMethod callMethod = new ResidualMethod(method, memoArgs, args, ptrs);
                Specialization.SetResidualMethod(upNode, callMethod);
                this.holder.SpecializeMethod(callMethod);

                this.AddTask(downNode.Next, ptrUpNode);
            }
        }
Ejemplo n.º 11
0
        private void callMethod(Node upNode, ParameterValues paramVals, ReferenceBTValue ret, bool isVirtCall)
        {
            bool flag;
            if (isVirtCall)
            {
                ReferenceBTValue thisObj = paramVals[0].Val as ReferenceBTValue;
                flag = thisObj.BTType == BTType.Dynamic;

                for (int i = 0; (! flag) && i < thisObj.Types.Length; i++)
                    if (paramVals.Method.DeclaringType.IsAssignableFrom(thisObj.Types[i]) && thisObj.Types[i] != PrimitiveBTValue.PrimitiveType())
                    {

                        ParameterValues exactParamVals = paramVals.Clone();
                        exactParamVals.ChooseVirtualMethod(thisObj.Types[i]);
                        flag = ! this.holder.SourceHolder.ContainsMethodBody(exactParamVals.Method);
                    }
            }
            else
                flag = ! this.holder.SourceHolder.ContainsMethodBody(paramVals.Method);

            if (flag)
                Annotation.SetNodeBTType(upNode, this.checkAnnotatedMethodForInvoke(new AnnotatedMethod(paramVals, ret)));
            else
            {
                if (isVirtCall)
                {
                    foreach (Type type in (paramVals[0].Val as ReferenceBTValue).Types)
                        if (paramVals.Method.DeclaringType.IsAssignableFrom(type) && type != PrimitiveBTValue.PrimitiveType())
                        {
                            ParameterValues exactParamVals = paramVals.Clone();
                            exactParamVals.ChooseVirtualMethod(type);
                            AnnotatedMethod method = new AnnotatedMethod(exactParamVals, ret);
                            Annotation.SetAnnotatedMethod(upNode, type, this.checkAnnotatedMethodForCall(method));
                        }
                }
                else
                    Annotation.SetAnnotatedMethod(upNode, this.checkAnnotatedMethodForCall(new AnnotatedMethod(paramVals, ret)));
                Annotation.SetNodeBTType(upNode, BTType.eXclusive);
            }
        }
Ejemplo n.º 12
0
 internal AnnotatingVisitor(AnnotatedAssemblyHolder holder, AnnotatedMethod method, ControllingVisitor cVisitor, UpAndDownNodes upDownNodes)
     : base(holder.GraphProcessor, 0)
 {
     this.holder = holder;
     this.cVisitor = cVisitor;
     this.upDownNodes = upDownNodes;
     this.ret = method.ReturnValue;
 }
Ejemplo n.º 13
0
        private AnnotatedMethod checkAnnotatedMethodForCall(AnnotatedMethod method)
        {
            if (! method.SourceMethod.IsDefined(typeof(InlineAttribute), false) || (method.SourceMethod.IsConstructor && (method.ParamVals[0].Val as ReferenceBTValue).BTType == BTType.Dynamic))
            {
                Creators crtrs = new Creators();
                for (int i = 0; i < method.ParamVals.Count; i++)
                {
                    ReferenceBTValue val = method.ParamVals[i].Val as ReferenceBTValue;
                    if (val.BTType == BTType.Static)
                        crtrs.AddCreators(val.LiftAllFields());
                }
                ReferenceBTValue ret = method.ReturnValue;
                if (ret != null)
                    crtrs.AddCreators(ret.Lift());

                if (! crtrs.IsEmpty)
                    throw new LiftException(crtrs);
            }

            return this.holder.AnnotateMethod(method);
        }
Ejemplo n.º 14
0
 internal static void AddAnnotatedMethodUser(AnnotatedMethod method)
 {
     method.ControllingVisitor.users++;
 }
Ejemplo n.º 15
0
        internal static MethodBodyBlock AnnotateMethod(AnnotatedAssemblyHolder holder, AnnotatedMethod method)
        {
            MethodBodyBlock mbbDown = holder.SourceHolder[method.SourceMethod];
            MethodBodyBlock mbbUp = mbbDown.Clone() as MethodBodyBlock;

            UpAndDownNodes upDownNodes = new UpAndDownNodes();
            State state = new State(mbbUp.Variables.Count);
            for(int i = 0; i < mbbUp.Variables.ParameterMapper.Count; i++)
            {
                Variable var = mbbUp.Variables.ParameterMapper[i];
                state.Pool[var] = new Location(var.Type);
                state.Pool[var].Val = (method.ParamVals[i].Val as ReferenceBTValue).ToStack(var.Type);
            }
            upDownNodes.SetUpAndDownNode(mbbDown, state, mbbUp);

            AnnotatingVisitor aVisitor;
            LiftingVisitor lVisitor;
            ControllingVisitor cVisitor = new ControllingVisitor(holder, method, upDownNodes, mbbUp, out aVisitor, out lVisitor);
            aVisitor.AddTask(mbbUp, state);

            return mbbUp;
        }
Ejemplo n.º 16
0
 internal ControllingVisitor(AnnotatedAssemblyHolder holder, AnnotatedMethod method, UpAndDownNodes upDownNodes, MethodBodyBlock mbbUp, out AnnotatingVisitor aVisitor, out LiftingVisitor lVisitor)
     : base(holder.GraphProcessor, 2)
 {
     this.holder = holder;
     this.method = method;
     this.method.ControllingVisitor = this;
     this.aVisitor = aVisitor = new AnnotatingVisitor(holder, method, this, upDownNodes);
     this.lVisitor = lVisitor = new LiftingVisitor(holder, this, aVisitor, upDownNodes);
     this.upDownNodes = upDownNodes;
     this.mbbUp = mbbUp;
     this.users = 0;
 }
Ejemplo n.º 17
0
        private BTType checkAnnotatedMethodForInvoke(AnnotatedMethod aMethod)
        {
            MethodBase sMethod = aMethod.SourceMethod;
            if (sMethod.DeclaringType.ToString() == "System.Object" &&
                sMethod.Name == ".ctor" &&
                sMethod.GetParameters().Length == 0)
            {
                BTValue obj = aMethod.ParamVals[0].Val as BTValue;
                return obj.BTType;
            }
            else if (this.holder.WhiteList.Contains(sMethod))
            {
                ObjectHashtable hash = new ObjectHashtable();
                for (int i = 0; i < aMethod.ParamVals.Count; i++)
                    getAllFieldBTValue(aMethod.ParamVals[i].Val as ReferenceBTValue, 5, hash);
                if (aMethod.ReturnValue != null)
                    getAllFieldBTValue(aMethod.ReturnValue, 5, hash);

                foreach (ReferenceBTValue val in hash.Keys)
                    if (val.BTType == BTType.Dynamic)
                        goto P;

                return BTType.Static;
            }

              P:

            Creators crtrs = new Creators();
            for (int i = 0; i < aMethod.ParamVals.Count; i++)
                crtrs.AddCreators((aMethod.ParamVals[i].Val as ReferenceBTValue).Lift());
            ReferenceBTValue ret = aMethod.ReturnValue;
            if (ret != null)
                crtrs.AddCreators(ret.Lift());

            if (! crtrs.IsEmpty)
                throw new LiftException(crtrs);

            return BTType.Dynamic;
        }
Ejemplo n.º 18
0
 internal void RemoveMethod(AnnotatedMethod method)
 {
     this.removeMethodBody(method);
 }
Ejemplo n.º 19
0
 internal static void SetAnnotatedMethod(Node upNode, Type type, AnnotatedMethod method)
 {
     Annotation.GetAnnotatedMethodHashtable(upNode)[type] = method;
     upNode.Options[Annotation.MethodBTTypeOption] = method;
     ControllingVisitor.AddAnnotatedMethodUser(method);
 }