Beispiel #1
0
        /// <summary>
        /// Gets the size of the field.
        /// </summary>
        /// <param name="field">The field.</param>
        /// <returns></returns>
        int ITypeLayout.GetFieldSize(RuntimeField field)
        {
            int size = 0;

            if (fieldSizes.TryGetValue(field, out size))
            {
                return(size);
            }
            else
            {
                ResolveType(field.DeclaringType);
            }

            // If the field is another struct, we have to dig down and compute its size too.
            if (field.SignatureType.Type == CilElementType.ValueType)
            {
                size = ((ITypeLayout)this).GetTypeSize(field.DeclaringType);
            }
            else
            {
                size = GetMemorySize(field.SignatureType);
            }

            fieldSizes.Add(field, size);

            return(size);
        }
        /// <summary>
        /// Initializes a new instance of <see cref="MemberOperand"/>.
        /// </summary>
        /// <param name="field">The runtime field to reference.</param>
        /// <exception cref="System.ArgumentNullException"><paramref name="field"/> is null.</exception>
        public MemberOperand(RuntimeField field)
            : base(field.SignatureType, null, IntPtr.Zero)
        {
            if (field == null)
                throw new ArgumentNullException(@"field");

            this.member = field;
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="CilGenericField"/> class.
        /// </summary>
        /// <param name="module">The module.</param>
        /// <param name="genericField">The generic field.</param>
        /// <param name="signature">The signature.</param>
        /// <param name="declaringType">Type of the declaring.</param>
        public CilGenericField(ITypeModule module, RuntimeField genericField, FieldSignature signature, CilGenericType declaringType)
            : base(module, declaringType)
        {
            this.Signature = signature;
            this.Attributes = genericField.Attributes;
            //TODO
            //this.SetAttributes(genericField.CustomAttributes);

            base.Name = genericField.Name;
        }
Beispiel #4
0
        /// <summary>
        /// Gets the size of the field.
        /// </summary>
        /// <param name="field">The field.</param>
        /// <returns></returns>
        int ITypeLayout.GetFieldOffset(RuntimeField field)
        {
            ResolveType(field.DeclaringType);

            int size = 0;

            fieldOffets.TryGetValue(field, out size);

            return(size);
        }
Beispiel #5
0
        /// <summary>
        /// Gets the size of the field.
        /// </summary>
        /// <param name="field">The field.</param>
        /// <returns></returns>
        int ITypeLayout.GetFieldSize(RuntimeField field)
        {
            int size = 0;

            if (fieldSizes.TryGetValue(field, out size))
            {
                return size;
            }
            else
            {
                ResolveType(field.DeclaringType);
            }

            // If the field is another struct, we have to dig down and compute its size too.
            if (field.SignatureType.Type == CilElementType.ValueType)
            {
                size = ((ITypeLayout)this).GetTypeSize(field.DeclaringType);
            }
            else
            {
                size = GetMemorySize(field.SignatureType);
            }

            fieldSizes.Add(field, size);

            return size;
        }
Beispiel #6
0
        /// <summary>
        /// Gets the size of the field.
        /// </summary>
        /// <param name="field">The field.</param>
        /// <returns></returns>
        int ITypeLayout.GetFieldOffset(RuntimeField field)
        {
            ResolveType(field.DeclaringType);

            int size = 0;

            fieldOffets.TryGetValue(field, out size);

            return size;
        }
 /// <summary>
 /// Creates a new SymbolOperand for the given runtime field.
 /// </summary>
 /// <param name="runtimeField">The field to create a symbol operand for.</param>
 /// <returns>The created symbol operand.</returns>
 public static SymbolOperand FromField(RuntimeField runtimeField)
 {
     return new SymbolOperand(runtimeField.SignatureType, runtimeField.ToString());
 }
 /* field.Address */
 /// <summary>
 /// Initializes a new instance of the <see cref="StaticFieldOperand"/> class.
 /// </summary>
 /// <param name="field">The field.</param>
 public StaticFieldOperand(RuntimeField field, IntPtr offset)
     : base(field.SignatureType, null, offset)
 {
 }
 private void InitializeStaticValueFromRVA(Stream stream, int size, RuntimeField field)
 {
     using (Stream source = field.Module.MetadataModule.GetDataSection((long)field.RVA))
     {
         byte[] data = new byte[size];
         source.Read(data, 0, size);
         stream.Write(data, 0, size);
     }
 }
        /// <summary>
        /// Allocates memory for the static field and initializes it.
        /// </summary>
        /// <param name="field">The field.</param>
        private void CreateStaticField(RuntimeField field)
        {
            Debug.Assert(field != null, @"No field given.");

            // Determine the size of the type & alignment requirements
            int size, alignment;
            architecture.GetTypeRequirements(field.SignatureType, out size, out alignment);

            size = (int)typeLayout.GetFieldSize(field);

            // The linker section to move this field into
            SectionKind section;
            // Does this field have an RVA?
            if (field.RVA != 0)
            {
                // FIXME: Move a static field into ROData, if it is read-only and can be initialized
                // using static analysis
                section = SectionKind.Data;
            }
            else
            {
                section = SectionKind.BSS;
            }

            this.AllocateSpace(field, section, size, alignment);
        }
 private void AllocateSpace(RuntimeField field, SectionKind section, int size, int alignment)
 {
     using (Stream stream = linker.Allocate(field.ToString(), section, size, alignment))
     {
         if (field.RVA != 0)
         {
             InitializeStaticValueFromRVA(stream, size, field);
         }
         else
         {
             WriteDummyBytes(stream, size);
         }
     }
 }
 /* field.Address */
 /// <summary>
 /// Initializes a new instance of the <see cref="ObjectFieldOperand"/> class.
 /// </summary>
 /// <param name="objectInstance">The operand, representing the object instance.</param>
 /// <param name="field">The referenced field.</param>
 public ObjectFieldOperand(Operand objectInstance, RuntimeField field, IntPtr offset)
     : base(field.SignatureType, null, offset)
 {
 }