Exemplo n.º 1
0
 public DebugFunctionType CreateFunctionType(DebugInfoBuilder diBuilder
                                             , IDebugType <ITypeRef, DIType> retType
                                             , IEnumerable <IDebugType <ITypeRef, DIType> > argTypes
                                             )
 {
     return(CreateFunctionType(diBuilder, false, retType, argTypes));
 }
Exemplo n.º 2
0
 public DebugFunctionType CreateFunctionType(DebugInfoBuilder diBuilder
                                             , IDebugType <ITypeRef, DIType> retType
                                             , params IDebugType <ITypeRef, DIType>[] argTypes
                                             )
 {
     return(CreateFunctionType(diBuilder, false, retType, argTypes));
 }
Exemplo n.º 3
0
 public DebugFunctionType CreateFunctionType(DebugInfoBuilder diBuilder
                                             , bool isVarArg
                                             , IDebugType <ITypeRef, DIType> retType
                                             , params IDebugType <ITypeRef, DIType>[] argTypes
                                             )
 {
     return(CreateFunctionType(diBuilder, isVarArg, retType, (IEnumerable <IDebugType <ITypeRef, DIType> >)argTypes));
 }
Exemplo n.º 4
0
        /// <summary>Creates a FunctionType with Debug information</summary>
        /// <param name="diBuilder"><see cref="DebugInfoBuilder"/>to use to create the debug information</param>
        /// <param name="isVarArg">Flag to indicate if this function is variadic</param>
        /// <param name="retType">Return type of the function</param>
        /// <param name="argTypes">Argument types of the function</param>
        /// <returns>Function signature</returns>
        public DebugFunctionType CreateFunctionType(DebugInfoBuilder diBuilder
                                                    , bool isVarArg
                                                    , IDebugType <ITypeRef, DIType> retType
                                                    , IEnumerable <IDebugType <ITypeRef, DIType> > argTypes
                                                    )
        {
            if (diBuilder == null)
            {
                throw new ArgumentNullException(nameof(diBuilder));
            }

            if (!retType.HasDebugInfo( ))
            {
                throw new ArgumentNullException(nameof(retType), "Return type does not have debug information");
            }

            var  nativeArgTypes = new List <ITypeRef>( );
            var  debugArgTypes  = new List <DIType>( );
            var  msg            = new StringBuilder("One or more parameter types ar not valid:\n");
            bool hasParamErrors = false;

            foreach (var indexedPair in argTypes.Select((t, i) => new { Type = t, Index = i }))
            {
                if (indexedPair.Type == null)
                {
                    msg.AppendFormat("\tArgument {0} is null", indexedPair.Index);
                    hasParamErrors = true;
                }
                else
                {
                    nativeArgTypes.Add(indexedPair.Type.NativeType);
                    debugArgTypes.Add(indexedPair.Type.DIType);
                    if (indexedPair.Type.HasDebugInfo( ))
                    {
                        continue;
                    }

                    msg.AppendFormat("\tArgument {0} does not contain debug type information", indexedPair.Index);
                    hasParamErrors = true;
                }
            }

            // if any parameters don't have errors, then provide a hopefully helpful message indicating which one(s)
            if (hasParamErrors)
            {
                throw new ArgumentException(msg.ToString( ), nameof(argTypes));
            }

            var llvmType = GetFunctionType(retType.NativeType, nativeArgTypes, isVarArg);

            var diType = diBuilder.CreateSubroutineType(0, retType.DIType, debugArgTypes);

            Debug.Assert(diType != null && !diType.IsTemporary);

            return(new DebugFunctionType(llvmType, diType));
        }
Exemplo n.º 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 && 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);
                }
            }
        }
Exemplo n.º 6
0
        /// <summary>Creates a FunctionType with Debug information</summary>
        /// <param name="diBuilder"><see cref="DebugInfoBuilder"/>to use to create the debug information</param>
        /// <param name="isVarArg">Flag to indicate if this function is variadic</param>
        /// <param name="retType">Return type of the function</param>
        /// <param name="argTypes">Argument types of the function</param>
        /// <returns>Function signature</returns>
        public DebugFunctionType CreateFunctionType(DebugInfoBuilder diBuilder
                                                    , bool isVarArg
                                                    , [ValidatedNotNull] IDebugType <ITypeRef, DIType> retType
                                                    , [ValidatedNotNull] IEnumerable <IDebugType <ITypeRef, DIType> > argTypes
                                                    )
        {
            diBuilder.ValidateNotNull(nameof(diBuilder));
            retType.ValidateNotNull(nameof(retType));
            argTypes.ValidateNotNull(nameof(retType));

            if (!retType.HasDebugInfo( ))
            {
                throw new ArgumentNullException(nameof(retType), Resources.Return_type_does_not_have_debug_information);
            }

            var  nativeArgTypes = new List <ITypeRef>( );
            var  debugArgTypes  = new List <DIType>( );
            var  msg            = new StringBuilder(Resources.One_or_more_parameter_types_are_not_valid);
            bool hasParamErrors = false;

            foreach (var indexedPair in argTypes.Select((t, i) => new { Type = t, Index = i }))
            {
                if (indexedPair.Type == null)
                {
                    msg.AppendFormat(CultureInfo.CurrentCulture, Resources.Argument_0_is_null, indexedPair.Index);
                    hasParamErrors = true;
                }
                else
                {
                    nativeArgTypes.Add(indexedPair.Type.NativeType);
                    debugArgTypes.Add(indexedPair.Type.DIType);
                    if (indexedPair.Type.HasDebugInfo( ))
                    {
                        continue;
                    }

                    msg.AppendFormat(CultureInfo.CurrentCulture, Resources.Argument_0_does_not_contain_debug_type_information, indexedPair.Index);
                    hasParamErrors = true;
                }
            }

            // if any parameters have errors, then provide a hopefully helpful message indicating which one(s)
            if (hasParamErrors)
            {
                throw new ArgumentException(msg.ToString( ), nameof(argTypes));
            }

            var llvmType = GetFunctionType(retType.NativeType, nativeArgTypes, isVarArg);

            var diType = diBuilder.CreateSubroutineType(0, retType.DIType, debugArgTypes);

            Debug.Assert(diType != null && !diType.IsTemporary, Resources.Assert_Should_have_a_valid_non_temp_type_by_now);

            return(new DebugFunctionType(llvmType, diType));
        }
Exemplo n.º 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);
                }
            }
        }
Exemplo n.º 8
0
        /// <summary>Resolves a temporary metadata node for the array if full size information wasn't available at creation time</summary>
        /// <param name="layout">Type layout information</param>
        /// <param name="diBuilder">Debug information builder for creating the new debug information</param>
        public void ResolveTemporary(DataLayout layout, DebugInfoBuilder diBuilder)
        {
            if (layout == null)
            {
                throw new ArgumentNullException(nameof(layout));
            }

            if (diBuilder == null)
            {
                throw new ArgumentNullException(nameof(diBuilder));
            }

            if (DIType.IsTemporary && !DIType.IsResolved)
            {
                DIType = diBuilder.CreateArrayType(layout.BitSizeOf(NativeType)
                                                   , layout.AbiBitAlignmentOf(NativeType)
                                                   , DebugElementType.DIType
                                                   , diBuilder.CreateSubRange(LowerBound, NativeType.Length)
                                                   );
            }
        }