Exemplo n.º 1
0
        /// <summary>
        /// Executes a list of IL instructions.
        /// </summary>
        /// <param name="methodILContext">Instructions to execute</param>
        /// <param name="callerContext">A reference to caller's context</param>
        public void ExecuteILMethod(MethodILInfo methodILContext, VCLRExecContext callerContext = null)
        {
            Console.WriteLine("\r\n--Executing Instructions--\r\n");
            foreach (var instruction in methodILContext.Instructions)
            {
                Console.WriteLine(instruction);
            }

            //TODO: Set locals boundaries
            var vCLRExecContext = new VCLRExecContext(methodILContext);

            if (callerContext != null && callerContext.Arguments != null)
            {
                vCLRExecContext.Arguments = callerContext.Arguments;
            }

            var position = new int();

            var offsetMappings = methodILContext.Instructions.ToDictionary(ilInstruction => ilInstruction.Offset, ilInstruction => methodILContext.Instructions.IndexOf(ilInstruction));

            //process the instructions
            while (position < methodILContext.Instructions.Count)
            {
                var instruction = methodILContext.Instructions[position++];

                object targetOffset = ExecuteInstruction(instruction, vCLRExecContext, callerContext);

                //branch if requested
                if (targetOffset != null)
                {
                    //get the position by the given offset
                    position = offsetMappings[(int)targetOffset];
                }
            }
        }
Exemplo n.º 2
0
 public VCLRExecContext(MethodILInfo methodILInfo, int localsSize = 1024)
 {
     this.MethodIL        = methodILInfo;
     this.EvaluationStack = new Stack <object>();
     this.MethodLocals    = new object[localsSize];
 }