コード例 #1
0
ファイル: CompiledMethod.cs プロジェクト: rfcclub/dot42
        /// <summary>
        /// Compile RL into the Dex method body.
        /// </summary>
        private void CompileToDex(DexTargetPackage targetPackage, bool generateDebugInfo, MapFile mapFile)
        {
            var dmethod = DexMethod;
            if (dmethod == null)
                throw new ArgumentException("No DexMethod set");
            if ((dmethod.IsAbstract) || (dmethod.IsNative))
                return;
            var rlBody = RLBody;
            if (rlBody == null)
                throw new ArgumentException("No RL body set");

            // Ensure RL is optimized
            OptimizeRL(targetPackage.DexFile);

            // Compile to Dex
            var dbody = new Dot42.DexLib.Instructions.MethodBody(dmethod, 0);
            var dexCompiler = new DexCompiler(rlBody, dbody, InvocationFrame);
            regMapper = dexCompiler.Compile();

            // Optimize code
            //dbody.UpdateInstructionOffsets();
            DexOptimizer.DexOptimizer.Optimize(dbody);

            // Ensure correct offsets
            dbody.UpdateInstructionOffsets();
            dmethod.Body = dbody;

            if (generateDebugInfo || (mapFile != null))
            {
                // Add debug info
                var debugInfoBuilder = new DebugInfoBuilder(this);
                if (generateDebugInfo)
                    debugInfoBuilder.CreateDebugInfo(dbody, regMapper, targetPackage);
                if (mapFile != null)
                    debugInfoBuilder.AddDocumentMapping(mapFile);
            }
        }
コード例 #2
0
ファイル: CompiledMethod.cs プロジェクト: Xtremrules/dot42
        /// <summary>
        /// Compile RL into the Dex method body.
        /// </summary>
        private void CompileToDex(DexTargetPackage targetPackage, bool generateDebugInfo, MapFile mapFile)
        {
            var dmethod = DexMethod;
            if (dmethod == null)
                throw new ArgumentException("No DexMethod set");
            if ((dmethod.IsAbstract) || (dmethod.IsNative))
                return;

            var rlBody = RLBody;

            if (rlBody == null && dmethod.Body != null) // already satisfied from the cache?
                return;

            if (rlBody == null)
                throw new ArgumentException(string.Format("internal compiler error: No RL body set on method '{2}'.'{3}' => '{0}'.'{1}'", dmethod.Owner.Name, dmethod.Name, method == null ? null : method.DeclaringType.FullName, method == null ? null : method.Name));

            // Ensure RL is optimized
            OptimizeRL(targetPackage.DexFile);

            // Compile to Dex
            var dbody = new Dot42.DexLib.Instructions.MethodBody(dmethod, 0);
            var dexCompiler = new DexCompiler(rlBody, dbody, InvocationFrame);
            regMapper = dexCompiler.Compile();

            // Optimize code
            //dbody.UpdateInstructionOffsets();
            DexOptimizer.DexOptimizer.Optimize(dbody);

            // Ensure correct offsets
            dbody.UpdateInstructionOffsets();
            dmethod.Body = dbody;

            if (generateDebugInfo || (mapFile != null))
            {
                // Add debug info
                var debugInfoBuilder = new DebugInfoBuilder(this);
                if (generateDebugInfo)
                    debugInfoBuilder.CreateDebugInfo(dbody, regMapper, targetPackage);
                if (mapFile != null && dmethod.MapFileId != 0)
                    debugInfoBuilder.AddDocumentMapping(mapFile);
            }
        }