/// <summary> /// Calculates the remaining space. /// </summary> /// <param name="ctx">The context.</param> /// <param name="operandStack">The operand stack.</param> /// <param name="space">The space.</param> private void CalculateRemainingSpace(Context ctx, Stack <Operand> operandStack, ref int space) { while (operandStack.Count != 0) { Operand operand = operandStack.Pop(); int size, alignment; _architecture.GetTypeRequirements(operand.Type, out size, out alignment); space -= size; Push(ctx, operand, space); } }
/// <summary> /// Performs a sequential layout of the type. /// </summary> /// <param name="type">The type.</param> private void CreateSequentialLayout(RuntimeType type) { Debug.Assert(type != null, "No type given."); // Receives the size/alignment int packingSize = type.Pack; // Instance size int typeSize = 0; RuntimeType baseType = type.BaseType; if (null != baseType) { typeSize = baseType.Size; } foreach (RuntimeField field in type.Fields) { if ((field.Attributes & FieldAttributes.Static) == FieldAttributes.Static) { // Assign a memory slot to the static & initialize it, if there's initial data set CreateStaticField(field); } else { int size; int alignment; _architecture.GetTypeRequirements(field.Type, out size, out alignment); // Pad the field in the type if (0 != packingSize) { int padding = (typeSize % packingSize); typeSize += padding; } // Set the field address field.Address = new IntPtr(typeSize); typeSize += size; } } type.Size = typeSize; }
/// <summary> /// Calculates the remaining space. /// </summary> /// <param name="ctx">The context.</param> /// <param name="operandStack">The operand stack.</param> /// <param name="space">The space.</param> private void PushOperands(Context ctx, Stack <Operand> operandStack, int space) { while (operandStack.Count != 0) { Operand operand = operandStack.Pop(); int size, alignment; architecture.GetTypeRequirements(operand.Type, out size, out alignment); if (operand.Type.Type == CilElementType.ValueType) { // FIXME throw new System.NotImplementedException(); //size = typeLayout.GetTypeSize(typeSystem.GetType(context, (operand.Type as ValueTypeSigType).Token)); //size = ObjectModelUtility.ComputeTypeSize((operand.Type as ValueTypeSigType).Token, moduleTypeSystem, architecture); } space -= size; Push(ctx, operand, space, size); } }
/// <summary> /// Fields the size. /// </summary> /// <param name="field">The field.</param> /// <param name="metadataProvider">The metadata provider.</param> /// <param name="architecture">The architecture.</param> /// <returns></returns> public static int FieldSize(ISignatureContext context, TokenTypes field, IMetadataProvider metadataProvider, IArchitecture architecture) { Metadata.Tables.FieldRow fieldRow; metadataProvider.Read(field, out fieldRow); FieldSignature signature = Signature.FromMemberRefSignatureToken(context, metadataProvider, fieldRow.SignatureBlobIdx) as FieldSignature; // If the field is another struct, we have to dig down and compute its size too. if (signature.Type.Type == CilElementType.ValueType) { TokenTypes valueTypeSig = ValueTokenTypeFromSignature(metadataProvider, fieldRow.SignatureBlobIdx); return ComputeTypeSize(context, valueTypeSig, metadataProvider, architecture); } int size, alignment; architecture.GetTypeRequirements(signature.Type, out size, out alignment); return size; }
/// <summary> /// Setups the specified compiler. /// </summary> /// <param name="compiler">The compiler.</param> public void Setup(IMethodCompiler compiler) { if (compiler == null) { throw new ArgumentNullException(@"compiler"); } methodCompiler = compiler; InstructionSet = compiler.InstructionSet; basicBlocks = compiler.BasicBlocks; architecture = compiler.Architecture; typeModule = compiler.Method.Module; typeSystem = compiler.TypeSystem; typeLayout = compiler.TypeLayout; callingConvention = architecture.GetCallingConvention(); architecture.GetTypeRequirements(BuiltInSigType.IntPtr, out nativePointerSize, out nativePointerAlignment); }
/// <summary> /// Setups the specified compiler. /// </summary> /// <param name="compiler">The compiler.</param> public void Setup(IMethodCompiler compiler) { if (compiler == null) throw new ArgumentNullException(@"compiler"); methodCompiler = compiler; instructionSet = compiler.InstructionSet; basicBlocks = compiler.BasicBlocks; architecture = compiler.Architecture; typeModule = compiler.Method.Module; typeSystem = compiler.TypeSystem; typeLayout = compiler.TypeLayout; callingConvention = architecture.GetCallingConvention(); architecture.GetTypeRequirements(BuiltInSigType.IntPtr, out nativePointerSize, out nativePointerAlignment); }