本文整理匯總了Golang中llvm/org/llvm/bindings/go/llvm.Builder.CreateBitCast方法的典型用法代碼示例。如果您正苦於以下問題:Golang Builder.CreateBitCast方法的具體用法?Golang Builder.CreateBitCast怎麽用?Golang Builder.CreateBitCast使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類llvm/org/llvm/bindings/go/llvm.Builder
的用法示例。
在下文中一共展示了Builder.CreateBitCast方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: directEncode
func directEncode(ctx llvm.Context, allocaBuilder llvm.Builder, builder llvm.Builder, argTypes []llvm.Type, args []llvm.Value, val llvm.Value) {
valType := val.Type()
switch len(argTypes) {
case 0:
// do nothing
case 1:
if argTypes[0].C == valType.C {
args[0] = val
return
}
alloca := allocaBuilder.CreateAlloca(valType, "")
bitcast := builder.CreateBitCast(alloca, llvm.PointerType(argTypes[0], 0), "")
builder.CreateStore(val, alloca)
args[0] = builder.CreateLoad(bitcast, "")
case 2:
encodeType := llvm.StructType(argTypes, false)
alloca := allocaBuilder.CreateAlloca(valType, "")
bitcast := builder.CreateBitCast(alloca, llvm.PointerType(encodeType, 0), "")
builder.CreateStore(val, alloca)
args[0] = builder.CreateLoad(builder.CreateStructGEP(bitcast, 0, ""), "")
args[1] = builder.CreateLoad(builder.CreateStructGEP(bitcast, 1, ""), "")
default:
panic("unexpected argTypes size")
}
}
示例2: directDecode
func directDecode(ctx llvm.Context, allocaBuilder llvm.Builder, builder llvm.Builder, valType llvm.Type, args []llvm.Value) llvm.Value {
var alloca llvm.Value
switch len(args) {
case 0:
return llvm.ConstNull(ctx.StructType(nil, false))
case 1:
if args[0].Type().C == valType.C {
return args[0]
}
alloca = allocaBuilder.CreateAlloca(valType, "")
bitcast := builder.CreateBitCast(alloca, llvm.PointerType(args[0].Type(), 0), "")
builder.CreateStore(args[0], bitcast)
case 2:
alloca = allocaBuilder.CreateAlloca(valType, "")
var argTypes []llvm.Type
for _, a := range args {
argTypes = append(argTypes, a.Type())
}
encodeType := ctx.StructType(argTypes, false)
bitcast := builder.CreateBitCast(alloca, llvm.PointerType(encodeType, 0), "")
builder.CreateStore(args[0], builder.CreateStructGEP(bitcast, 0, ""))
builder.CreateStore(args[1], builder.CreateStructGEP(bitcast, 1, ""))
default:
panic("unexpected argTypes size")
}
return builder.CreateLoad(alloca, "")
}
示例3: call
func (fi *functionTypeInfo) call(ctx llvm.Context, allocaBuilder llvm.Builder, builder llvm.Builder, callee llvm.Value, args []llvm.Value) []llvm.Value {
callArgs := make([]llvm.Value, len(fi.argAttrs))
for i, a := range args {
fi.argInfos[i].encode(ctx, allocaBuilder, builder, callArgs, a)
}
fi.retInf.prepare(ctx, allocaBuilder, callArgs)
typedCallee := builder.CreateBitCast(callee, llvm.PointerType(fi.functionType, 0), "")
call := builder.CreateCall(typedCallee, callArgs, "")
call.AddInstrAttribute(0, fi.retAttr)
for i, a := range fi.argAttrs {
call.AddInstrAttribute(i+1, a)
}
return fi.retInf.decode(ctx, allocaBuilder, builder, call)
}
示例4: invoke
func (fi *functionTypeInfo) invoke(ctx llvm.Context, allocaBuilder llvm.Builder, builder llvm.Builder, callee llvm.Value, chain llvm.Value, args []llvm.Value, cont, lpad llvm.BasicBlock) []llvm.Value {
callArgs := make([]llvm.Value, len(fi.argAttrs))
if chain.C == nil {
chain = llvm.Undef(llvm.PointerType(ctx.Int8Type(), 0))
}
callArgs[fi.chainIndex] = chain
for i, a := range args {
fi.argInfos[i].encode(ctx, allocaBuilder, builder, callArgs, a)
}
fi.retInf.prepare(ctx, allocaBuilder, callArgs)
typedCallee := builder.CreateBitCast(callee, llvm.PointerType(fi.functionType, 0), "")
call := builder.CreateInvoke(typedCallee, callArgs, cont, lpad, "")
call.AddInstrAttribute(0, fi.retAttr)
for i, a := range fi.argAttrs {
call.AddInstrAttribute(i+1, a)
}
builder.SetInsertPointAtEnd(cont)
return fi.retInf.decode(ctx, allocaBuilder, builder, call)
}