当前位置: 首页>>代码示例>>C#>>正文


C# IType.GetTypeSize方法代码示例

本文整理汇总了C#中IType.GetTypeSize方法的典型用法代码示例。如果您正苦于以下问题:C# IType.GetTypeSize方法的具体用法?C# IType.GetTypeSize怎么用?C# IType.GetTypeSize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IType的用法示例。


在下文中一共展示了IType.GetTypeSize方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GetCalculationPartOfStringAllocationSizeMethodBody

        private static void GetCalculationPartOfStringAllocationSizeMethodBody(
            ITypeResolver typeResolver,
            IType stringType,
            IType charType,
            out object[] code,
            out IList<object> tokenResolutions,
            out IList<IType> locals,
            out IList<IParameter> parameters)
        {
            var codeList = new List<object>();

            // add element size
            var elementSize = charType.GetTypeSize(typeResolver, true);
            codeList.AppendLoadInt(elementSize);

            // load length
            codeList.AppendLoadArgument(0);
            codeList.Add(Code.Mul);

            var arrayTypeSizeWithoutArrayData = stringType.GetTypeSize(typeResolver);
            codeList.AppendLoadInt(arrayTypeSizeWithoutArrayData);
            codeList.Add(Code.Add);

            // calculate alignment
            codeList.Add(Code.Dup);

            var alignForType = Math.Max(LlvmWriter.PointerSize, !charType.IsStructureType() ? elementSize : LlvmWriter.PointerSize);
            codeList.AppendLoadInt(alignForType - 1);
            codeList.Add(Code.Add);

            codeList.AppendLoadInt(~(alignForType - 1));
            codeList.Add(Code.And);

            // locals
            locals = new List<IType>();

            // tokens
            tokenResolutions = new List<object>();

            // parameters
            parameters = GetParameters(typeResolver);

            code = codeList.ToArray();
        }
开发者ID:afrog33k,项目名称:csnative,代码行数:44,代码来源:StringGen.cs

示例2: WriteMemCopy

        /// <summary>
        /// </summary>
        /// <param name="llvmWriter">
        /// </param>
        /// <param name="type">
        /// </param>
        /// <param name="op1">
        /// </param>
        /// <param name="op2">
        /// </param>
        public static void WriteMemCopy(
            this LlvmWriter llvmWriter,
            IType type,
            FullyDefinedReference op1,
            FullyDefinedReference op2)
        {
            var writer = llvmWriter.Output;

            writer.WriteLine(
                "call void @llvm.memcpy.p0i8.p0i8.i32(i8* {0}, i8* {1}, i32 {2}, i32 {3}, i1 false)",
                op1,
                op2,
                type.GetTypeSize(llvmWriter),
                LlvmWriter.PointerSize

                /*Align*/);
        }
开发者ID:afrog33k,项目名称:csnative,代码行数:27,代码来源:LlvmHelpersGen.cs

示例3: WriteMemSet

        /// <summary>
        /// </summary>
        /// <param name="llvmWriter">
        /// </param>
        /// <param name="type">
        /// </param>
        /// <param name="op1">
        /// </param>
        public static void WriteMemSet(this LlvmWriter llvmWriter, IType type, FullyDefinedReference op1)
        {
            var writer = llvmWriter.Output;

            writer.Write(
                "call void @llvm.memset.p0i8.i32(i8* {0}, i8 0, i32 {1}, i32 {2}, i1 false)",
                op1,
                type.GetTypeSize(llvmWriter, type.IsPrimitiveType() && !type.UseAsClass),
                LlvmWriter.PointerSize

                /*Align*/);
        }
开发者ID:afrog33k,项目名称:csnative,代码行数:20,代码来源:LlvmHelpersGen.cs

示例4: DefineStructureType

        private void DefineStructureType(IType type, int line, int offset, int flags, CollectionMetadata structureType)
        {
            structureType.Add(
                    string.Format(
                        @"0x13\00{0}\00{1}\00{2}\00{3}\00{4}\00{5}\000", type.Name, line, type.GetTypeSize(true) * 8, LlvmWriter.PointerSize * 8, offset, flags),
                    this.file,
                    null,
                    null,
                // members
                    this.DefineMembers(type, structureType),
                    null,
                    null,
                    this.structuresByName ? type.FullName : null);

            if (structuresByName)
            {
                this.retainedTypes.Add(structureType);
            }
        }
开发者ID:SperoSophia,项目名称:il2bc,代码行数:19,代码来源:DebugInfoGenerator.cs

示例5: GetArrayValuesHeader

        /// <summary>
        /// </summary>
        /// <param name="llvmWriter">
        /// </param>
        /// <param name="elementType">
        /// </param>
        /// <param name="length">
        /// </param>
        /// <param name="storeLength">
        /// </param>
        /// <returns>
        /// </returns>
        public static string GetArrayValuesHeader(
            this LlvmWriter llvmWriter,
            IType elementType,
            int length,
            int storeLength)
        {
            var typeString = llvmWriter.WriteToString(
                () =>
                {
                    var writer = llvmWriter.Output;
                    elementType.WriteTypePrefix(llvmWriter);
                });

            return GetSingleDimArrayPrefixNullConstData(llvmWriter) + ", i16 0, i16 " + elementType.GetTypeCode() +
                   ", i32 " + elementType.GetTypeSize(llvmWriter, true) + ", i32 " + storeLength + ", [" +
                   length + " x " + typeString + "]";
        }
开发者ID:afrog33k,项目名称:csnative,代码行数:29,代码来源:ArraySingleDimensionGen.cs

示例6: DefinePrimitiveType

 private CollectionMetadata DefinePrimitiveType(IType type, int line, int offset, int flags)
 {
     return
         new CollectionMetadata(this.indexedMetadata).Add(
             string.Format(
                 @"0x24\00{0}\00{1}\00{2}\00{3}\00{4}\00{5}\005",
                 type.FullName,
                 line,
                 type.GetTypeSize(true) * 8,
                 LlvmWriter.PointerSize * 8,
                 offset,
                 flags),
             null,
             null);
 }
开发者ID:SperoSophia,项目名称:il2bc,代码行数:15,代码来源:DebugInfoGenerator.cs

示例7: GetCalculationPartOfMultiDimArrayAllocationSizeMethodBody

        private static void GetCalculationPartOfMultiDimArrayAllocationSizeMethodBody(
            ITypeResolver typeResolver,
            IType arrayType,
            out object[] code,
            out IList<object> tokenResolutions,
            out IList<IType> locals,
            out IList<IParameter> parameters)
        {
            var codeList = new List<object>();

            // add element size
            var elementType = arrayType.GetElementType();
            var elementSize = elementType.GetTypeSize(typeResolver, true);
            codeList.AppendLoadInt(elementSize);

            // init each item in lowerBounds
            foreach (var i in Enumerable.Range(0, arrayType.ArrayRank))
            {
                codeList.AppendLoadArgument(i);
                codeList.Add(Code.Mul);
            }

            // add element size
            var multiArrayTypeSizeWithoutArrayData = arrayType.GetTypeSize(typeResolver);
            codeList.AppendLoadInt(multiArrayTypeSizeWithoutArrayData);
            codeList.Add(Code.Add);

            // calculate alignment
            codeList.Add(Code.Dup);

            var alignForType = Math.Max(LlvmWriter.PointerSize, !elementType.IsStructureType() ? elementSize : LlvmWriter.PointerSize);
            codeList.AppendLoadInt(alignForType - 1);
            codeList.Add(Code.Add);

            codeList.AppendLoadInt(~(alignForType - 1));
            codeList.Add(Code.And);

            // locals
            locals = new List<IType>();

            // tokens
            tokenResolutions = new List<object>();

            // parameters
            parameters = GetParameters(arrayType, typeResolver);

            code = codeList.ToArray();
        }
开发者ID:afrog33k,项目名称:csnative,代码行数:48,代码来源:ArrayMultiDimensionGen.cs

示例8: WriteAllocateMemoryForObject

        public static void WriteAllocateMemoryForObject(this LlvmWriter llvmWriter, OpCodePart opCodePart, IType declaringClassType, bool doNotTestNullValue)
        {
            var writer = llvmWriter.Output;

            var size = declaringClassType.GetTypeSize();

            var mallocResult = llvmWriter.WriteSetResultNumber(opCodePart, llvmWriter.ResolveType("System.Byte").ToPointerType());
            writer.WriteLine("call i8* @{1}(i32 {0})", size, llvmWriter.GetAllocator());

            if (!doNotTestNullValue)
            {
                llvmWriter.WriteTestNullValueAndThrowException(writer, opCodePart, mallocResult, "System.OutOfMemoryException", "new_obj");
            }

            if (!llvmWriter.Gc)
            {
                llvmWriter.WriteMemSet(declaringClassType, mallocResult);
                writer.WriteLine(string.Empty);
            }

            llvmWriter.WriteBitcast(opCodePart, mallocResult, declaringClassType);
            writer.WriteLine(string.Empty);
        }
开发者ID:SperoSophia,项目名称:il2bc,代码行数:23,代码来源:ObjectInfrastructure.cs

示例9: WriteNewArray

        /// <summary>
        /// </summary>
        /// <param name="llvmWriter">
        /// </param>
        /// <param name="opCode">
        /// </param>
        /// <param name="declaringType">
        /// </param>
        /// <param name="length">
        /// </param>
        public static void WriteNewArray(this LlvmWriter llvmWriter, OpCodePart opCode, IType declaringType, OpCodePart length)
        {
            var writer = llvmWriter.Output;

            writer.WriteLine("; New array");

            var arraySystemType = llvmWriter.ResolveType("System.Array");
            var intType = llvmWriter.ResolveType("System.Int32");

            var sizeOfElement = declaringType.GetTypeSize(true);
            llvmWriter.UnaryOper(writer, opCode, "mul", intType, options: LlvmWriter.OperandOptions.AdjustIntTypes);
            writer.WriteLine(", {0}", sizeOfElement);

            var resMul = opCode.Result;

            llvmWriter.WriteSetResultNumber(opCode, intType);
            writer.Write("add i32 {1}, {0}", resMul, arraySystemType.GetTypeSize() + 2 * intType.GetTypeSize(true)); // add header size
            writer.WriteLine(string.Empty);

            var resAdd = opCode.Result;

            var resAlloc = llvmWriter.WriteSetResultNumber(opCode, llvmWriter.ResolveType("System.Byte").ToPointerType());
            writer.Write("call i8* @{1}(i32 {0})", resAdd, llvmWriter.GetAllocator());

            writer.WriteLine(string.Empty);
            llvmWriter.WriteTestNullValueAndThrowException(writer, opCode, resAlloc, "System.OutOfMemoryException", "new_arr");

            writer.WriteLine(string.Empty);

            if (!llvmWriter.Gc)
            {
                writer.WriteLine(
                    "call void @llvm.memset.p0i8.i32(i8* {0}, i8 0, i32 {1}, i32 {2}, i1 false)", resAlloc, resAdd, LlvmWriter.PointerSize /*Align*/);
            }

            var opCodeTemp = OpCodePart.CreateNop;
            opCodeTemp.OpCodeOperands = opCode.OpCodeOperands;

            // init System.Array
            llvmWriter.WriteBitcast(opCode, resAlloc, arraySystemType);
            arraySystemType.WriteCallInitObjectMethod(llvmWriter, opCode);
            writer.WriteLine(string.Empty);

            var arrayType = declaringType.ToArrayType(1);
            llvmWriter.WriteBitcast(opCode, resAlloc, arrayType);
            writer.WriteLine(string.Empty);

            var arrayInstanceResult = opCode.Result;

            // save element size
            llvmWriter.WriteSetResultNumber(opCode, intType);
            writer.Write("getelementptr inbounds ");
            arrayInstanceResult.Type.WriteTypePrefix(writer);
            writer.Write(" ");
            llvmWriter.WriteResult(arrayInstanceResult);
            writer.Write(", i32 0, i32 3");
            writer.WriteLine(string.Empty);

            writer.Write("store ");
            opCode.Result.Type.WriteTypePrefix(writer);
            writer.Write(" {0}, ", sizeOfElement);
            opCode.Result.Type.WriteTypePrefix(writer, true);
            writer.Write(" ");
            llvmWriter.WriteResult(opCode.Result);
            writer.WriteLine(string.Empty);

            // save array size
            llvmWriter.WriteSetResultNumber(opCode, intType);
            writer.Write("getelementptr inbounds ");
            arrayInstanceResult.Type.WriteTypePrefix(writer);
            writer.Write(" ");
            llvmWriter.WriteResult(arrayInstanceResult);
            writer.Write(", i32 0, i32 4");
            writer.WriteLine(string.Empty);

            writer.Write("store ");
            length.Result.Type.WriteTypePrefix(writer);
            writer.Write(" ");
            llvmWriter.WriteResult(length.Result);
            writer.Write(", ");
            opCode.Result.Type.WriteTypePrefix(writer, true);
            writer.Write(" ");
            llvmWriter.WriteResult(opCode.Result);
            writer.WriteLine(string.Empty);

            writer.WriteLine("; end of new array");

            opCode.Result = arrayInstanceResult;
        }
开发者ID:SperoSophia,项目名称:il2bc,代码行数:99,代码来源:ArraySingleDimensionGen.cs

示例10: GetArrayValuesHeader

        /// <summary>
        /// </summary>
        /// <param name="llvmWriter">
        /// </param>
        /// <param name="elementType">
        /// </param>
        /// <param name="length">
        /// </param>
        /// <param name="storeLength">
        /// </param>
        /// <returns>
        /// </returns>
        public static string GetArrayValuesHeader(this LlvmWriter llvmWriter, IType elementType, int length, int storeLength)
        {
            var typeString = llvmWriter.WriteToString(
                () =>
                    {
                        var writer = llvmWriter.Output;
                        elementType.WriteTypePrefix(writer);
                    });

            ////var arrayType = llvmWriter.ResolveType("System.Array");
            ////var cloneableType = llvmWriter.ResolveType("System.ICloneable");
            ////var listType = llvmWriter.ResolveType("System.Collections.IList");
            ////return "i8** " + arrayType.GetVirtualTableReference(llvmWriter) + ", i8** " + arrayType.GetVirtualTableReference(cloneableType) + ", i8** "
            ////       + arrayType.GetVirtualTableReference(listType) + ", i32 " + elementType.GetTypeSize(true) + ", i32 " + storeLength + ", [" + length + " x "
            ////       + typeString + "]";
            return "i8* null, i8* null, i8* null, i32 " + elementType.GetTypeSize(true) + ", i32 " + storeLength + ", [" + length + " x " + typeString + "]";
        }
开发者ID:SperoSophia,项目名称:il2bc,代码行数:29,代码来源:ArraySingleDimensionGen.cs


注:本文中的IType.GetTypeSize方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。