public bool Resolve(MethodStateMachine methodSM)
        {
            //Pop away finished method
            _callStack.Pop();

            //Take its return value if needed
            if (methodSM.Context.ReturnsValue && _callStack.Count != 0)
            {
                _callStack.Peek().TakeMethodReturnValue(methodSM.Context.EvalStack);
            }

            if (methodSM.MethodDesc.IsEntryPoint && methodSM.MethodDesc.ReturnType != null)
            {
                EntryPointRet(methodSM.Context.EvalStack.Peek(), methodSM.MethodDesc.ReturnType);
            }

            //Find finally block. If exists, jump to its offset and continue execution. if not, break
            if (methodSM.FinalliesBeforeReturn())
            {
                methodSM.State.ExecutionInterruption = ExecutionInterruption.None;
                return(true);
            }
            else
            {
                return(false);
            }
        }
        public bool Resolve(MethodStateMachine methodSM)
        {
            //Create an execution model for calling method
            var cmExec = _methodStateMachineFactory.Create(methodSM.State.CallMethod);

            cmExec.Caller = methodSM;
            if (cmExec == null)
            {
                throw new Exception("Method not found");
            }

            //Fill calling method's arguments if any
            if (cmExec.MethodDesc.TakesArguments)
            {
                cmExec.SetMethodArguments(methodSM.Context.EvalStack);
            }

            //Add calling method to the call stack
            _callStack.Push(cmExec);

            //Reset the flow
            methodSM.State.ExecutionInterruption = ExecutionInterruption.None;
            methodSM.State.CallMethod            = null;

            return(false);
        }
Example #3
0
        public static MethodStateMachine CreateForMethod(MethodDesc methodDescription, IGCHeap gcHeap, ITypesHeap typesHeap, ITypeLoader typeLoader, IILOperationSet operationSet)
        {
            MethodStateMachine execModel = new MethodStateMachine()
            {
                _operationSet = operationSet,
                MethodDesc    = methodDescription,
                Context       = ILTool.Kernel.MethodContext.CreateForMethod(methodDescription, gcHeap, typesHeap, typeLoader),
                State         = new MethodState()
            };

            return(execModel);
        }
Example #4
0
 public void Start()
 {
     try
     {
         MethodDesc entryPoint = _compiledModel.Methods.Values.Where(d => d.IsEntryPoint).SingleOrDefault();
         if (entryPoint == null)
         {
             throw new InvalidOperationException("Entry point not found");
         }
         MethodStateMachine entryPointExecModel = _methodStateMachineFactory.Create(entryPoint);
         _callStack.Push(entryPointExecModel);
         ProcessCallStack();
     }
     catch (Exception ex)
     {
         throw;
     }
 }
Example #5
0
        private void ProcessCallStack()
        {
            while (_callStack.Count != 0)
            {
                MethodStateMachine methodSM = _callStack.Peek();
                while (true)
                {
                    methodSM.ExecInstructions();

                    if (_interruptionResolvers[methodSM.State.ExecutionInterruption].Resolve(methodSM))
                    {
                        continue;
                    }
                    else
                    {
                        break;
                    }
                }
            }
        }
        public bool Resolve(MethodStateMachine methodSM)
        {
            var         exInfo       = methodSM.State.ExeptionInfo;
            var         currMethod   = methodSM;
            EHTryEntity catchHandler = null;

            do
            {
                catchHandler = currMethod.ThrowLogicForMethod(exInfo);
                if (catchHandler != null)
                {
                    break;
                }

                //Continue to search an appropriate catch handler in the method one hierarchy upper
                currMethod = currMethod.Caller;
            }while (currMethod != null);

            methodSM.State.ExecutionInterruption = ExecutionInterruption.None;
            methodSM.State.ExeptionInfo          = null;
            return(true);
        }
Example #7
0
        public MethodStateMachine Create(MethodDesc methodDesc)
        {
            MethodStateMachine entryPointExecModel = MethodStateMachine.CreateForMethod(methodDesc, _gcHeap, _typesHeap, _typeLoader, _ilOperationSet);

            return(entryPointExecModel);
        }