Example #1
0
        protected override void VisitNewObject(NewObject downNode, object o)
        {
            PointerToNode   ptrUpNode = (o as Data).PointerToNode;
            AnnotatedMethod method    = Annotation.GetAnnotatedMethod(downNode);

            Node      upNode;
            ArrayList list = new ArrayList();

            for (int i = method.ParamVals.Count - 1; i > 0; i--)
            {
                if (Annotation.GetValueBTType(method.ParamVals[i].Val) == BTType.Static)
                {
                    list.Add(this.state.Stack.Pop());
                }
            }
            if (Annotation.GetValueBTType(method.ParamVals[0].Val) == BTType.Static)
            {
                Type objtype                  = downNode.Constructor.DeclaringType;
                ObjectReferenceValue obj      = new ObjectReferenceValue(FormatterServices.GetUninitializedObject(objtype));
                FieldInfo[]          fldInfos = ReflectionUtils.GetAllFields(objtype);
                BTType[]             btTypes  = Annotation.GetObjectFieldBTTypes(downNode);
                for (int i = 0; i < fldInfos.Length; i++)
                {
                    if (btTypes[i] == BTType.Dynamic)
                    {
                        Variable varUp = this.mbbUp.Variables.CreateVar(fldInfos[i].FieldType, VariableKind.Local);
                        this.varsHash[new PointerToObjectFieldValue(obj.Obj, fldInfos[i])] = varUp;
                        ptrUpNode = SpecializingVisitor.initVariable(varUp, ptrUpNode);
                    }
                }
                list.Add(obj);
                this.state.Stack.Push(obj);
                upNode = new CallMethod(downNode.Constructor, false, false);
            }
            else
            {
                upNode = new NewObject(downNode.Constructor);
            }
            list.Reverse();
            Value[] args = list.ToArray(typeof(Value)) as Value[];

            this.callMethod(downNode, method, ptrUpNode, upNode, args);
        }
Example #2
0
        protected override void VisitNewArray(NewArray downNode, object o)
        {
            PointerToNode        ptrUpNode = (o as Data).PointerToNode;
            StructValue          idx       = this.state.Stack.Pop() as StructValue;
            Array                arr       = Array.CreateInstance(downNode.Type, SpecializingVisitor.toInt(idx));
            ObjectReferenceValue obj       = new ObjectReferenceValue(arr);

            if (Annotation.GetArrayElementsBTType(downNode) == BTType.Dynamic)
            {
                for (int i = 0; i < SpecializingVisitor.toInt(idx); i++)
                {
                    Variable varUp = this.mbbUp.Variables.CreateVar(downNode.Type, VariableKind.Local);
                    this.varsHash[new PointerToElementValue(arr, i)] = varUp;
                    ptrUpNode = SpecializingVisitor.initVariable(varUp, ptrUpNode);
                }
            }

            this.state.Stack.Push(obj);
            this.AddTask(downNode.Next, ptrUpNode);
        }
Example #3
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);
            }
        }