Esempio n. 1
0
        /// <summary>
        /// Generate method code
        /// </summary>
        public virtual void GenerateCode(ClassDefinition declaringClass, DexTargetPackage targetPackage)
        {
            if (dmethod == null)
            {
                return;
            }

            // Create body (if any)
            if (!method.HasBody)
            {
                return;
            }

            cachedBody = compiler.MethodBodyCompilerCache.GetFromCache(dmethod, xMethod, compiler, targetPackage);

            if (cachedBody != null)
            {
                dmethod.Body = cachedBody.Body;
                // important to fix the owners source file as early as possible,
                // so it can't be changed later. Else we would have to recreate
                // all cached method bodies debug infos.
                dmethod.Owner.SetSourceFile(cachedBody.ClassSourceFile);
                return;
            }

            var source = new MethodSource(xMethod, method);

            ExpandSequencePoints(method.Body);

            bool generateSetNextInstructionCode = compiler.GenerateSetNextInstructionCode &&
                                                  method.DeclaringType.IsInDebugBuildAssembly();

            DexMethodBodyCompiler.TranslateToRL(compiler, targetPackage, source, dmethod, generateSetNextInstructionCode, out compiledMethod);
        }
Esempio n. 2
0
        public override void DecompileMethod(ilspy::Mono.Cecil.MethodDefinition method, ITextOutput output, DecompilationOptions options)
        {
            var xMethod  = GetXMethodDefinition(method);
            var ilMethod = xMethod as XBuilder.ILMethodDefinition;

            CompiledMethod cmethod;

            if (ilMethod == null || !ilMethod.OriginalMethod.HasBody)
            {
                output.Write("");
                output.WriteLine("// not an il method or method without body.");
                return;
            }

            var methodSource = new MethodSource(xMethod, ilMethod.OriginalMethod);
            var target       = (DexTargetPackage)AssemblyCompiler.TargetPackage;
            var dMethod      = (MethodDefinition)xMethod.GetReference(target);

            DexMethodBodyCompiler.TranslateToRL(AssemblyCompiler, target, methodSource, dMethod, GenerateSetNextInstructionCode, out cmethod);

            var rlBody = cmethod.RLBody;

            // Optimize RL code
            string lastApplied = RLTransformations.Transform(target.DexFile, rlBody, StopOptimizationAfter == -1?int.MaxValue:StopOptimizationAfter);

            if (lastApplied != null)
            {
                output.WriteLine("// Stop after " + lastApplied);
            }

            PrintMethod(cmethod, output, options);
        }
Esempio n. 3
0
        /// <summary>
        /// Generate method code
        /// </summary>
        public virtual void GenerateCode(ClassDefinition declaringClass, DexTargetPackage targetPackage)
        {
            if (dmethod == null)
            {
                return;
            }

            // Create body (if any)
            if (method.HasBody)
            {
                ExpandSequencePoints(method.Body);
                var source = new MethodSource(xMethod, method);
                DexMethodBodyCompiler.TranslateToRL(compiler, targetPackage, source, dmethod, out compiledMethod);
            }
        }
        /// <summary>
        /// Compile this method to dex code.
        /// </summary>
        public void Compile(AssemblyCompiler compiler, DexTargetPackage targetPackage)
        {
            if (Body == null)
            {
                throw new ArgumentException("Body expected");
            }
            if (dexMethod == null)
            {
                throw new ArgumentException("dexMethod expected");
            }
            CompiledMethod compiledMethod;
            var            source = new MethodSource(this, Body);

            DexMethodBodyCompiler.TranslateToRL(compiler, targetPackage, source, dexMethod, false, out compiledMethod);
            compiledMethod.DexMethod = dexMethod;
        }
Esempio n. 5
0
        /// <summary>
        /// Generate method code
        /// </summary>
        public void GenerateCode(ClassDefinition declaringClass, DexTargetPackage targetPackage)
        {
            if (dmethod == null)
            {
                return;
            }

            // Create body (if any)
            if (!method.HasCode)
            {
                return;
            }

            if (compiler.DxClassfileMethodBodyCompiler != null)
            {
                var dxBody = compiler.DxClassfileMethodBodyCompiler.GetMethodBody(dmethod, xMethod);
                if (dxBody == null)
                {
                    throw new Exception("unable to get method body through 'dx': " + dmethod);
                }

                dmethod.Body = dxBody;
                dmethod.Owner.SetSourceFile(dxBody.Owner.Owner.SourceFile);
                return;
            }

            var cachedBody = compiler.MethodBodyCompilerCache.GetFromCache(dmethod, xMethod, compiler, targetPackage);

            if (cachedBody != null)
            {
                dmethod.Body = cachedBody.Body;
                // important to fix the owners source file as early as possible,
                // so it can't be changed later. Else we would have to recreate
                // all cached method bodies debug infos.
                dmethod.Owner.SetSourceFile(cachedBody.ClassSourceFile);
                return;
            }

            //ExpandSequencePoints(method.Body);
            var source = new MethodSource(xMethod, method);

            DexMethodBodyCompiler.TranslateToRL(compiler, targetPackage, source, dmethod, false, out compiledMethod);
        }