本文整理汇总了C#中IType.ToArrayType方法的典型用法代码示例。如果您正苦于以下问题:C# IType.ToArrayType方法的具体用法?C# IType.ToArrayType怎么用?C# IType.ToArrayType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IType
的用法示例。
在下文中一共展示了IType.ToArrayType方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetArrayTypeReference
/// <summary>
/// </summary>
/// <param name="llvmWriter">
/// </param>
/// <param name="name">
/// </param>
/// <param name="elementType">
/// </param>
/// <param name="length">
/// </param>
/// <returns>
/// </returns>
public static string GetArrayTypeReference(this LlvmWriter llvmWriter, string name, IType elementType, int length)
{
var convertString = llvmWriter.WriteToString(
() =>
{
var writer = llvmWriter.Output;
var array = elementType.ToArrayType(1);
writer.Write("bitcast (");
writer.Write("{1}* {0} to ", name, llvmWriter.GetArrayTypeHeader(elementType, length));
array.WriteTypePrefix(writer);
writer.Write(")");
});
return convertString;
}
示例2: 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;
}