public CacheEntry(MethodBody body, MethodEntry methodEntry, IList <SourceCodePosition> sourceCodePositions, string classSourceFile)
 {
     Body                = body;
     MethodEntry         = methodEntry;
     ClassSourceFile     = classSourceFile;
     SourceCodePositions = sourceCodePositions != null ? new ReadOnlyCollection <SourceCodePosition>(sourceCodePositions) : null;
 }
 public CacheEntry(MethodBody body, MethodEntry methodEntry, IList<SourceCodePosition> sourceCodePositions, string classSourceFile)
 {
     Body = body;
     MethodEntry = methodEntry;
     ClassSourceFile = classSourceFile;
     SourceCodePositions = sourceCodePositions != null ? new ReadOnlyCollection<SourceCodePosition>(sourceCodePositions) : null;
 }
        /// <summary>
        /// Operands refering to types, methods or fields need to be fixed, as they might have
        /// gotten another name in the target package. he same applies for catch references.
        /// </summary>
        private void FixReferences(MethodBody body, AssemblyCompiler compiler, DexTargetPackage targetPackage)
        {
            // fix operands
            foreach (var ins in body.Instructions)
            {
                var fieldRef  = ins.Operand as FieldReference;
                var methodRef = ins.Operand as MethodReference;
                var classRef  = ins.Operand as ClassReference;

                if (classRef != null)
                {
                    ins.Operand = ConvertClassReference(classRef, compiler, targetPackage);
                }
                else if (fieldRef != null)
                {
                    ins.Operand = ConvertFieldReference(fieldRef, compiler, targetPackage);
                }
                else if (methodRef != null)
                {
                    ins.Operand = ConvertMethodReference(methodRef, compiler, targetPackage);
                }
            }

            // fix catch clauses
            foreach (var @catch in body.Exceptions.SelectMany(e => e.Catches))
            {
                if (@catch.Type != null)
                {
                    @catch.Type = ConvertTypeReference(@catch.Type, compiler, targetPackage);
                }
            }
        }
예제 #4
0
        /// <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);
                }
            }
        }
예제 #5
0
        /// <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);
                }
            }
        }
        /// <summary>
        /// Operands refering to types, methods or fields need to be fixed, as they might have
        /// gotten another name in the target package. he same applies for catch references.
        /// </summary>
        private void FixReferences(MethodBody body, AssemblyCompiler compiler,  DexTargetPackage targetPackage)
        {
            // fix operands
            foreach (var ins in body.Instructions)
            {
                var fieldRef = ins.Operand as FieldReference;
                var methodRef = ins.Operand as MethodReference;
                var classRef = ins.Operand as ClassReference;

                if (classRef != null)
                {
                    ins.Operand = ConvertClassReference(classRef, compiler, targetPackage);
                }
                else if (fieldRef != null)
                {
                    ins.Operand = ConvertFieldReference(fieldRef, compiler, targetPackage);
                }
                else if (methodRef != null)
                {
                    ins.Operand = ConvertMethodReference(methodRef, compiler, targetPackage);
                }
            }

            // fix catch clauses
            foreach (var @catch in body.Exceptions.SelectMany(e => e.Catches))
            {
                if (@catch.Type != null)
                    @catch.Type = ConvertTypeReference(@catch.Type, compiler, targetPackage);
            }

        }
예제 #7
0
        /// <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);
            }
        }
예제 #8
0
        /// <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);
            }
        }