Ejemplo n.º 1
0
        public static void ForEach(MethodBodyBlock method, ForEachCallback handler)
        {
            GraphProcessor graphProcessor = new GraphProcessor();
            Visitor        visitor        = new ForEachVisitor(graphProcessor, handler);

            visitor.AddTask(method, null);
            graphProcessor.Process();
        }
Ejemplo n.º 2
0
        private void ReConstruct()         //Andrew
        {
            mbb.RemoveOption(BasicBlock.BASIC_BLOCK_OPTION);
            GraphProcessor     processor = new GraphProcessor();
            BasicBlocksBuilder builder   = new BasicBlocksBuilder(processor);

            entry = builder.createBasicBlock();
            builder.AddTask(mbb, entry);
            processor.Process();
            blockList = builder.BlockList;
        }
Ejemplo n.º 3
0
        protected Visitor(GraphProcessor graphProcessor, int priority, VisitorTaskCollection tasks)
        {
            this.graphProcessor = graphProcessor;
            this.priority       = priority;
            this.tasks          = tasks;

            if (graphProcessor != null)
            {
                graphProcessor.addVisitor(this);
            }
        }
Ejemplo n.º 4
0
        public BasicBlocksGraph(MethodBodyBlock methodBodyBlock)
        {
            mbb = methodBodyBlock;
            mbb.RemoveOption(BasicBlock.BASIC_BLOCK_OPTION);
            GraphProcessor     processor = new GraphProcessor();
            BasicBlocksBuilder builder   = new BasicBlocksBuilder(processor);

            entry = builder.createBasicBlock();
            builder.AddTask(methodBodyBlock, entry);
            processor.Process();
            blockList = builder.BlockList;
        }
Ejemplo n.º 5
0
        public AnnotatedAssemblyHolder(AssemblyHolder sourceHolder, WhiteList whiteList)
            : base(sourceHolder)
        {
            this.aMethods = new Hashtable();
            this.GraphProcessor = new GraphProcessor();
            this.WhiteList = whiteList;

            foreach (MethodBase method in this.SourceHolder.getMethods())
                if (method.IsDefined(typeof(SpecializeAttribute), false))
                    ControllingVisitor.AddAnnotatedMethodUser(this.AnnotateMethod(this.GetAnnotatedMethod(method)));

            this.GraphProcessor.Process();
        }
Ejemplo n.º 6
0
 public static bool Check(MethodBodyBlock method)
 {
     //TODO: Will check parents consistency, if give up to do it automatically
     RemoveStackTypes(method);
     GraphProcessor graphProcessor = new GraphProcessor();
     VerifierVisitor verifierVisitor = new VerifierVisitor(graphProcessor);
     verifierVisitor.AddTask(method,new StackTypes());
     try
     {
         graphProcessor.Process();
     }
     catch(VerifierException)
     {
         RemoveStackTypes(method);
         return(false);
     }
     return(true);
 }
Ejemplo n.º 7
0
        public static bool Check(MethodBodyBlock method)
        {
            //TODO: Will check parents consistency, if give up to do it automatically
            RemoveStackTypes(method);
            GraphProcessor  graphProcessor  = new GraphProcessor();
            VerifierVisitor verifierVisitor = new VerifierVisitor(graphProcessor);

            verifierVisitor.AddTask(method, new StackTypes());
            try
            {
                graphProcessor.Process();
            }
            catch (VerifierException)
            {
                RemoveStackTypes(method);
                return(false);
            }
            return(true);
        }
Ejemplo n.º 8
0
 public EmitterVisitor(GraphProcessor processor, ILGenerator generator, MethodBodyBlock method)
     : base(processor, new Tasks())
 {
     this.tasks = base.tasks as Tasks;
     tasks.SetVisitor(this);
     paramMapper = method.Variables.ParameterMapper;
     this.labels = Labeler.LabelNodes(method,generator);
     this.generator = generator;
     alreadyVisited = new Hashtable();
     locals = new Hashtable();
     AddTask(method,null);
     foreach(Variable var in method.Variables)
     {
         if(var.Kind == VariableKind.Local)
             locals[var] = generator.DeclareLocal(var.Type);
     }
     extraVars = new Hashtable();
     boolVar = null;
     wasDumped = new Hashtable();;
     wasDumpedFlag = false;
     prevHasNext = true;
 }
Ejemplo n.º 9
0
 protected QueueVisitor(GraphProcessor graphProcessor, int priority)
     : base(graphProcessor, priority, new VisitorTaskQueue())
 {
 }
Ejemplo n.º 10
0
 protected QueueVisitor(GraphProcessor graphProcessor, int priority) : base(graphProcessor, priority, new VisitorTaskQueue())
 {
 }
Ejemplo n.º 11
0
 protected QueueVisitor(GraphProcessor graphProcessor) : base(graphProcessor, new VisitorTaskQueue())
 {
 }
Ejemplo n.º 12
0
        public IReadonlyNodeArray CollectGarbage()
        {
            foreach (Node n in ChildArray)
                n.needed = false;

            GraphProcessor graphProcessor = new GraphProcessor();
            GCVisitor gcVisitor = new GCVisitor(graphProcessor);
            foreach (Node n in NextArray)
                gcVisitor.AddTask(n, null);
            graphProcessor.Process();

            NodeArray arr = new NodeArray();
            foreach (Node n in ChildArray)
                if (! n.needed)
                    arr.Add(n);
            return arr;
        }
Ejemplo n.º 13
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.º 14
0
        public static Value InterpretMethod(MethodBodyHolder holder, 
            MethodBodyBlock body, ParameterValues paramVals, out Exception exc, 
            string indent)
        {
            exc = null;

            GraphProcessor graphProcessor = new GraphProcessor();
            IntVisitor visitor = new IntVisitor(graphProcessor,holder,indent);
            visitor.state = new State(body.Variables.Count);

            int paramCount = 0;
            foreach (Variable var in body.Variables.ParameterMapper)
                visitor.state.Pool[var] = paramVals[paramCount++];

            visitor.AddTask(body);
            graphProcessor.Process();

            Value result = null;
            if (visitor.unhandledException != null)
                exc = visitor.unhandledException;
            else if (body.ReturnType != typeof(void))
                result = visitor.state.Stack.Pop().FromStack(body.ReturnType);

            return result;
        }
Ejemplo n.º 15
0
 public VerifierVisitor(GraphProcessor graphProcessor)
     : base(graphProcessor,new VisitorTaskQueue())
 {
 }
Ejemplo n.º 16
0
 public ForEachVisitor(GraphProcessor processor, ForEachCallback handler)
     : base(processor)
 {
     alreadyVisited = new Hashtable();
     this.handler = handler;
 }
Ejemplo n.º 17
0
 protected QueueVisitor(GraphProcessor graphProcessor)
     : base(graphProcessor, new VisitorTaskQueue())
 {
 }
Ejemplo n.º 18
0
        protected Visitor(GraphProcessor graphProcessor, int priority, VisitorTaskCollection tasks)
        {
            this.graphProcessor = graphProcessor;
            this.priority = priority;
            this.tasks = tasks;

            if (graphProcessor != null)
                graphProcessor.addVisitor(this);
        }
Ejemplo n.º 19
0
 protected VisitorEX(GraphProcessor graphProcessor, int priority, VisitorTaskCollection tasks)
     : base(graphProcessor, priority, tasks)
 {
 }
Ejemplo n.º 20
0
 public ForEachVisitor(GraphProcessor processor, ForEachCallback handler) : base(processor)
 {
     alreadyVisited = new Hashtable();
     this.handler   = handler;
 }
Ejemplo n.º 21
0
 public VerifierVisitor(GraphProcessor graphProcessor) : base(graphProcessor, new VisitorTaskQueue())
 {
 }
Ejemplo n.º 22
0
        internal static void SpecializeMethod(ResidualAssemblyHolder holder, ResidualMethod method)
        {
            Value[] args = method.Arguments;
            PointerValue[] ptrs = method.Pointers;
            MethodBodyBlock mbbDown = holder.AnnotatedHolder[method.AnnotatedMethod];
            MethodBodyBlock mbbUp = new MethodBodyBlock(mbbDown.ReturnType);
            holder.AddMethod(method, mbbUp);

            SpecState state = new SpecState(mbbDown.Variables.Count);
            VariablesHashtable varsHash = new VariablesHashtable();

            int varCount = 0;
            int argCount = 0;
            foreach (Variable varDown in mbbDown.Variables.ParameterMapper)
            {
                state.Pool[varDown] = new Location(varDown.Type);
                Variable varUp;
                if (Annotation.GetValueBTType(method.AnnotatedMethod.ParamVals[varCount++].Val) == BTType.Static)
                {
                    state.Pool[varDown].Val = args[argCount++];
                    varUp = mbbUp.Variables.CreateVar(varDown.Type, VariableKind.Local);
                }
                else
                    varUp = mbbUp.Variables.CreateVar(varDown.Type, VariableKind.Parameter);
                varsHash[new PointerToLocationValue(state.Pool[varDown])] = varUp;
            }
            foreach (Variable varDown in mbbDown.Variables)
                if (! state.Pool.ContainsVar(varDown))
                {
                    state.Pool[varDown] = new Location(varDown.Type);
                    Variable varUp = mbbUp.Variables.CreateVar(varDown.Type, VariableKind.Local);
                    varsHash[new PointerToLocationValue(state.Pool[varDown])] = varUp;
                }

            PointerToNode ptrUpNode = new PointerToNode(mbbUp);
            Node dummyUp = new DummyNode(mbbUp);
            Node upNode = dummyUp;
            for (int i = 0; i < ptrs.Length; i++)
            {
                Type ptrType = ptrs[i].Type;
                Type type = ptrType.GetElementType();
                Variable newVar1 = mbbUp.Variables.CreateVar(ptrType, VariableKind.Parameter);
                Variable newVar2 = mbbUp.Variables.CreateVar(type, VariableKind.Local);
                varsHash[ptrs[i]] = newVar2;

                ptrUpNode = new PointerToNode(ptrUpNode.Node = new LoadVar(newVar1));
                ptrUpNode = new PointerToNode(ptrUpNode.Node = new LoadIndirect(type));
                ptrUpNode = new PointerToNode(ptrUpNode.Node = new StoreVar(newVar2));

                upNode = upNode.Next = new LoadVar(newVar1);
                upNode = upNode.Next = new LoadVar(newVar2);
                upNode = upNode.Next = new StoreIndirect(type);
            }
            upNode.Next = new Leave();
            upNode = dummyUp.Next;
            dummyUp.RemoveFromGraph();

            GraphProcessor graphProc = new GraphProcessor();
            SpecializingVisitor visitor = new SpecializingVisitor(graphProc, holder, mbbUp, state, varsHash);
            visitor.AddTask(mbbDown.Next, ptrUpNode);
            graphProc.Process();
            visitor.SetLastNode(upNode);
        }
Ejemplo n.º 23
0
 public static void ForEach(MethodBodyBlock method, ForEachCallback handler)
 {
     GraphProcessor graphProcessor = new GraphProcessor();
     Visitor visitor = new ForEachVisitor(graphProcessor,handler);
     visitor.AddTask(method,null);
     graphProcessor.Process();
 }
Ejemplo n.º 24
0
 protected VisitorEX(GraphProcessor graphProcessor, VisitorTaskCollection tasks)
     : base(graphProcessor, tasks)
 {
 }
Ejemplo n.º 25
0
 internal IntVisitor(GraphProcessor graphProcessor, MethodBodyHolder holder, string indent)
     : base(graphProcessor)
 {
     this.holder = holder;
     this.indent = indent;
 }
Ejemplo n.º 26
0
        public BasicBlocksGraph(MethodBodyBlock methodBodyBlock)
        {
            mbb = methodBodyBlock;
            mbb.RemoveOption(BasicBlock.BASIC_BLOCK_OPTION);
            GraphProcessor processor = new GraphProcessor();
            BasicBlocksBuilder builder = new BasicBlocksBuilder(processor);

            entry = builder.createBasicBlock();
            builder.AddTask(methodBodyBlock,entry);
            processor.Process();
            blockList = builder.BlockList;
        }
Ejemplo n.º 27
0
 protected StackVisitor(GraphProcessor graphProcessor)
     : base(graphProcessor, new VisitorTaskStack())
 {
 }
Ejemplo n.º 28
0
 internal SpecializingVisitor(GraphProcessor graphProcessor, ResidualAssemblyHolder holder, MethodBodyBlock mbbUp, SpecState state, VariablesHashtable varsHash)
     : base(graphProcessor)
 {
     this.holder = holder;
     this.mbbUp = mbbUp;
     this.state = state;
     this.varsHash = varsHash;
     this.upDownNodes = new Hashtable();
     this.exitData = new ArrayList();
 }
Ejemplo n.º 29
0
 public BasicBlocksBuilder(GraphProcessor graphProcessor) :
     base(graphProcessor)
 {
     blockList = new BasicBlockArray();
 }
Ejemplo n.º 30
0
 protected StackVisitor(GraphProcessor graphProcessor, int priority)
     : base(graphProcessor, priority, new VisitorTaskStack())
 {
 }
Ejemplo n.º 31
0
 public BasicBlocksBuilder(GraphProcessor graphProcessor)
     : base(graphProcessor)
 {
     blockList = new BasicBlockArray();
 }
Ejemplo n.º 32
0
 protected StackVisitor(GraphProcessor graphProcessor) : base(graphProcessor, new VisitorTaskStack())
 {
 }
Ejemplo n.º 33
0
        //Andrew
        private void ReConstruct()
        {
            mbb.RemoveOption(BasicBlock.BASIC_BLOCK_OPTION);
            GraphProcessor processor = new GraphProcessor();
            BasicBlocksBuilder builder = new BasicBlocksBuilder(processor);

            entry = builder.createBasicBlock();
            builder.AddTask(mbb,entry);
            processor.Process();
            blockList = builder.BlockList;
        }
Ejemplo n.º 34
0
 protected StackVisitor(GraphProcessor graphProcessor, int priority) : base(graphProcessor, priority, new VisitorTaskStack())
 {
 }
Ejemplo n.º 35
0
 public GCVisitor(GraphProcessor graphProcessor)
     : base(graphProcessor)
 {
 }
Ejemplo n.º 36
0
 public static void Emit(ILGenerator generator, MethodBodyBlock method)
 {
     GraphProcessor graphProcessor = new GraphProcessor();
     EmitterVisitor visitor = new EmitterVisitor(graphProcessor, generator, method);
     graphProcessor.Process();
 }