Example #1
0
 public Java.Attributes.Code End(Java.ConstantPool pool)
 {
     Java.Attributes.Code result = new Java.Attributes.Code();
     result.CodeBytes = Link(pool);
     StackSimulator.SimulateStack(pool, result);
     return(result);
 }
Example #2
0
        public void Compile()
        {
            MethodDefinition methodDef = thisMethod.Body.Method;

            Messages.Verbose("      Generating IL graph...");

            ILAstBuilder builder = new ILAstBuilder();

            ilBody = new ILBlock();

            DecompilerContext context = new DecompilerContext(methodDef.Module)
            {
                CurrentType = methodDef.DeclaringType, CurrentMethod = methodDef
            };

            Utils.SetDecompillerSettings(context.Settings);

            ilBody.Body = builder.Build(methodDef, true, context);
            new ILAstOptimizer().Optimize(context, ilBody);

            FillVars(builder.Parameters);

            Messages.Verbose("      Preprocess IL graph...");
            RunPreprocessor();

            Messages.Verbose("      Compiling IL graph to java bytecode...");
            CompileNode(ilBody, ExpectType.None);

            //Checking for deleted last ret
            if (ilBody.Body.Count > 0)
            {
                ILNode lastNode = ilBody.Body.Last();
                if ((lastNode is ILExpression) && (((ILExpression)lastNode).Code != ILCode.Ret) &&
                    (((ILExpression)lastNode).Code != ILCode.Throw))
                {
                    CompileRet(null, ExpectType.None);
                }
                else if (thisMethod.ReturnParameter.Type.PrimitiveType == PrimitiveType.Void)
                {
                    CompileRet(null, ExpectType.None);
                }
            }
            else
            {
                CompileRet(null, ExpectType.None);
            }

            oldCodeGenerator = codeGenerator;
            byte[] prolog = GenerateMethodProlog();
            codeGenerator = oldCodeGenerator;

            Messages.Verbose("      Linking java bytecode...");
            codeGenerator.StartOffset = prolog.Length;
            byte[] codeBytes = codeGenerator.Link(constsPool);
            GenerateJavaExceptionTable();

            resultCode           = new Java.Attributes.Code();
            resultCode.CodeBytes = prolog.Concat(codeBytes).ToArray();

            WriteJavaExceptionTable(prolog.Length);

            Messages.Verbose("      Simulating stack to calculate MaxStack and MaxLocals...");
            StackSimulator.SimulateStack(constsPool, resultCode);
            resultCode.MaxLocals = (ushort)nextVarIndex;

            if (Program.Debug)
            {
                GenerateDebugInfo(prolog.Length);
            }
        }