本文整理汇总了C#中Constant.TruncOrBitCast方法的典型用法代码示例。如果您正苦于以下问题:C# Constant.TruncOrBitCast方法的具体用法?C# Constant.TruncOrBitCast怎么用?C# Constant.TruncOrBitCast使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Constant
的用法示例。
在下文中一共展示了Constant.TruncOrBitCast方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GenerateHeader
/// <summary>
/// Generates the BrainF runtime environment.
/// </summary>
private void GenerateHeader()
{
this.module = new Module(this.context, "BrainF");
// === Function prototypes =========================================
Function memsetFunction = Intrinsic.GetDecleration(this.module, IntrinsicType.memset,
Type.GetInteger8PointerType(this.context), Type.GetInteger32Type(this.context));
// declare i32 @getchar()
this.getcharFunction = (Function)this.module.GetOrInsertFunction("getchar",
new FunctionType(Type.GetInteger32Type(this.context)));
// declare i32 @putchar(i32)
this.putcharFunction = (Function)this.module.GetOrInsertFunction("putchar",
new FunctionType(Type.GetInteger32Type(this.context), Type.GetInteger32Type(this.context)));
// === Function header =============================================
// define void @brainf()
this.brainfFunction = (Function)this.module.GetOrInsertFunction("brainf",
new FunctionType(Type.GetVoidType(this.context)));
this.builder = new IRBuilder(new BasicBlock(
this.context, this.brainfFunction, "brainf"));
// %arr = malloc i8, i32 %d
Constant valMemory = new Constant(this.context, 32, this.totalMemory);
BasicBlock bb = this.builder.GetInsertBlock();
Type intType = Type.GetInteger32Type(this.context);
Type byteType = Type.GetInteger8Type(this.context);
Constant allocsize = new Constant(byteType);
allocsize.TruncOrBitCast(intType);
Instruction pointerArray = CallInstruction.CreateMalloc(bb, intType, byteType, allocsize, valMemory, "arr");
bb.PushBack(pointerArray);
// call void @llvm.memset.
CallInstruction memsetCall = this.builder.CreateCall(
memsetFunction,
pointerArray,
new Constant(this.context, 8, 0),
valMemory,
new Constant(this.context, 32, 1),
new Constant(this.context, 1, 0));
memsetCall.TailCall = false;
//
this.currentHead = this.builder.CreateGEP(
pointerArray, new Constant(this.context, 32, this.totalMemory / 2), "head");
// Footer
this.endBlock = new BasicBlock(this.context, this.brainfFunction, "brainf");
this.endBlock.PushBack(CallInstruction.CreateFree(pointerArray, this.endBlock));
ReturnInstruction.Create(this.context, this.endBlock);
}