Example #1
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);
 }
Example #2
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;
 }
Example #3
0
        protected override void VisitMethodBodyBlock(MethodBodyBlock node, object data)
        {
            foreach (Variable var in node.Variables)
                if (! state.Pool.ContainsVar(var))
                    state.Pool[var] = new Location(var.Type);

            AddTask(node.Next);
        }
Example #4
0
 private static void RemoveStackTypes(MethodBodyBlock method)
 {
     ForEachVisitor.ForEach(method, new ForEachCallback(RemoveStackTypesCallback) );
 }
Example #5
0
 public static void Emit(ILGenerator generator, MethodBodyBlock method)
 {
     GraphProcessor graphProcessor = new GraphProcessor();
     EmitterVisitor visitor = new EmitterVisitor(graphProcessor, generator, method);
     graphProcessor.Process();
 }
Example #6
0
        public AssemblyHolder(Assembly assembly)
        {
            this.assembly = assembly;

            Module[] modules = assembly.GetModules();
            foreach (Module module in modules)
            {
                ModuleEx moduleEx = new ModuleEx(module);
                foreach (MethodBase method in moduleEx)
                {
                    MethodEx methodEx = moduleEx.GetMethodEx(method);
                    MethodBodyBlock body = Converter.Convert(methodEx);
                    addMethodBody(method,body);
                }
            }

            entryPoint = null;
            MethodBase entryMethod = assembly.EntryPoint;
            if (entryMethod != null)
                entryPoint = this[entryMethod];
        }
Example #7
0
 public void AddSpecialCtor(MethodBodyBlock ctor)
 {
     specialCtors.Add(ctor);
 }
Example #8
0
 internal static void Map(MethodBodyBlock body, MetaDataMapper map)
 {
     NodeMapper mapper = new NodeMapper(map);
     ForEachVisitor.ForEach(body,new ForEachCallback(mapper.Callback));
 }
Example #9
0
 public MethodBase Map(MethodBodyBlock mbb)
 {
     return(methodByMBB[mbb] as MethodBase);
 }
Example #10
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();
 }
Example #11
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;
 }
Example #12
0
 protected override void VisitMethodBodyBlock(MethodBodyBlock upNode, object o)
 {
     State state = o as State;
     foreach (Variable var in upNode.Variables)
         if (! state.Pool.ContainsVar(var))
         {
             state.Pool[var] = new Location(var.Type);
             state.Pool[var].Val = (new ReferenceBTValue(var.Type, BTType.Static)).ToStack(var.Type);
         }
     Annotation.SetNodeBTType(upNode, BTType.eXclusive);
 }
Example #13
0
 protected override void VisitMethodBodyBlock(MethodBodyBlock upNode, object o)
 {
     throw new InternalException();
 }
Example #14
0
 protected internal override void VisitMethodBodyBlock(MethodBodyBlock node, object data)
 {
     currentBlock = node;
     AddTask(node.Next,null);
 }
Example #15
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;
        }
Example #16
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;
        }
Example #17
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);
        }
Example #18
0
 public static Type[] GetParamTypes(MethodBodyBlock mbb, bool doRemoveThis)
 {
     ArrayList paramTypesList = new ArrayList();
     int i0 = doRemoveThis ? 1 : 0;
     int I = mbb.Variables.ParameterMapper.Count;
     for(int i=i0; i<I; i++)
     {
         Variable var = mbb.Variables.ParameterMapper[i];
         paramTypesList.Add(var.Type);
     }
     Type[] paramTypes = new Type[paramTypesList.Count];
     paramTypesList.CopyTo(paramTypes);
     return(paramTypes);
 }
Example #19
0
 protected internal virtual void VisitMethodBodyBlock(MethodBodyBlock node, object data)
 {
     throw new NodeNotSupportedException(node);
 }
Example #20
0
 public void AddMethodBodyBlock(MethodBodyBlock mbb, MethodBase method)
 {
     methodByMBB[mbb] = method;
 }
Example #21
0
            protected internal override void VisitMethodBodyBlock(MethodBodyBlock node, object data)
            {
                StackTypes stack = data as StackTypes;
                if(stack.Count != 0)
                    throw new VerifierException();

                AddTask(node.Next,stack);
            }
Example #22
0
 public bool HasPseudoParameter(MethodBodyBlock ctor)
 {
     return(specialCtors.Contains(ctor));
 }
Example #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();
 }
Example #24
0
        protected void addMethodBody(object method, MethodBodyBlock body)
        {
            if (ContainsMethodBody(method))
                removeMethodBody(method);

            bodies.Add(method,body);
        }
Example #25
0
 public static Hashtable LabelNodes(MethodBodyBlock graph, ILGenerator generator)
 {
     Labeler labeler = new Labeler(generator);
     ForEachVisitor.ForEach(graph, new ForEachCallback(labeler.Label) );
     return(labeler.labels);
 }