Beispiel #1
0
        /// <summary>
        /// Translates given <see cref="IMethodBody"/> using given  <see cref="ICodeProvider"/>.
        /// </summary>
        /// <param name="method">The method to translate.</param>
        /// <param name="body">body to translate.</param>
        /// <param name="provider">code provider to use.</param>
        /// <returns>translated code.</returns>
        public IInstruction[] Translate(IMethod method, IMethodBody body, ICodeProvider provider)
        {
            var clrBody = body as IClrMethodBody;

            if (clrBody == null)
            {
                throw new NotSupportedException("Unsupported body format");
            }

            _context = new TranslationContext(new Code(method, clrBody, provider), null);

#if PERF
            ++CallCount;
#endif

            _result = TranslateCore(_context);

            return(_result.Output.ToArray());
        }
Beispiel #2
0
        public static void Dump(IClrMethodBody body, TranslatorResult result, string format, string filename)
        {
            if (!(DebugHooks.EvalFilter(body.Method) || DebugHooks.DumpILMap))
            {
                return;
            }

            DebugHooks.LogInfo("DumpILMap started. Format = {0}. FileName = {1}.", format, filename);

            string dir = body.GetTestDirectory();

            Directory.CreateDirectory(dir);
            using (var writer = new StreamWriter(Path.Combine(dir, filename)))
            {
                DumpService.DumpLocalVariables(writer, body);
                writer.WriteLine(Separator);

                if (result.Begin != null && result.Begin.Length > 0)
                {
                    writer.WriteLine("#BEGIN CODE");
                    writer.WriteLine(Separator);
                    for (int i = 0; i < result.Begin.Length; ++i)
                    {
                        writer.WriteLine(result.Output[i].ToString(format, null));
                    }
                    writer.WriteLine(Separator);
                }

                foreach (var bb in body.ControlFlowGraph.Blocks)
                {
                    writer.WriteLine("#BASIC BLOCK {0}", bb.Index);
                    DumpStackState(writer, bb);
                    writer.WriteLine(Separator);

                    writer.WriteLine("#ORIGINAL CODE");
                    foreach (var instruction in bb.Code)
                    {
                        writer.WriteLine(instruction.ToString(format, null));
                    }
                    writer.WriteLine();

                    var code = bb.TranslatedCode;
                    writer.WriteLine("#TRANSLATED CODE");
                    foreach (var instruction in code)
                    {
                        writer.WriteLine(instruction.ToString(format, null));
                    }
                    writer.WriteLine(Separator);
                }

                if (result.End != null && result.End.Length > 0)
                {
                    writer.WriteLine("#END CODE");
                    writer.WriteLine(Separator);
                    foreach (var instruction in result.End)
                    {
                        writer.WriteLine(instruction.ToString(format, null));
                    }
                }
            }

            DebugHooks.LogInfo("DumpILMap succeded");
        }