本文整理汇总了Golang中llvm/org/llvm/bindings/go/llvm.ConstNull函数的典型用法代码示例。如果您正苦于以下问题:Golang ConstNull函数的具体用法?Golang ConstNull怎么用?Golang ConstNull使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了ConstNull函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: memsetZero
func (fr *frame) memsetZero(ptr llvm.Value, size llvm.Value) {
memset := fr.runtime.memset
ptr = fr.builder.CreateBitCast(ptr, llvm.PointerType(llvm.Int8Type(), 0), "")
fill := llvm.ConstNull(llvm.Int8Type())
size = fr.createZExtOrTrunc(size, fr.target.IntPtrType(), "")
align := llvm.ConstInt(llvm.Int32Type(), 1, false)
isvolatile := llvm.ConstNull(llvm.Int1Type())
fr.builder.CreateCall(memset, []llvm.Value{ptr, fill, size, align, isvolatile}, "")
}
示例2: registerGcRoots
func (fr *frame) registerGcRoots() {
if len(fr.gcRoots) != 0 {
rootty := fr.gcRoots[0].Type()
roots := append(fr.gcRoots, llvm.ConstNull(rootty))
rootsarr := llvm.ConstArray(rootty, roots)
rootsstruct := llvm.ConstStruct([]llvm.Value{llvm.ConstNull(llvm.PointerType(llvm.Int8Type(), 0)), rootsarr}, false)
rootsglobal := llvm.AddGlobal(fr.module.Module, rootsstruct.Type(), "")
rootsglobal.SetInitializer(rootsstruct)
rootsglobal.SetLinkage(llvm.InternalLinkage)
fr.runtime.registerGcRoots.callOnly(fr, llvm.ConstBitCast(rootsglobal, llvm.PointerType(llvm.Int8Type(), 0)))
}
}
示例3: build
func (gi *globalInit) build(typ llvm.Type) llvm.Value {
if gi.val.C != nil {
return gi.val
}
if len(gi.elems) == 0 {
return llvm.ConstNull(typ)
}
switch typ.TypeKind() {
case llvm.StructTypeKind:
eltypes := typ.StructElementTypes()
elems := make([]llvm.Value, len(eltypes))
for i, eltyp := range eltypes {
elems[i] = gi.elems[i].build(eltyp)
}
return llvm.ConstStruct(elems, false)
case llvm.ArrayTypeKind:
eltyp := typ.ElementType()
elems := make([]llvm.Value, len(gi.elems))
for i := range gi.elems {
elems[i] = gi.elems[i].build(eltyp)
}
return llvm.ConstArray(eltyp, elems)
default:
panic("unexpected type")
}
}
示例4: compareStrings
func (fr *frame) compareStrings(lhs, rhs *govalue, op token.Token) *govalue {
if op == token.EQL {
if lhs.value.IsNull() {
return fr.compareStringEmpty(rhs.value)
}
if rhs.value.IsNull() {
return fr.compareStringEmpty(lhs.value)
}
}
result := fr.runtime.strcmp.call(fr, lhs.value, rhs.value)[0]
zero := llvm.ConstNull(fr.types.inttype)
var pred llvm.IntPredicate
switch op {
case token.EQL:
pred = llvm.IntEQ
case token.LSS:
pred = llvm.IntSLT
case token.GTR:
pred = llvm.IntSGT
case token.LEQ:
pred = llvm.IntSLE
case token.GEQ:
pred = llvm.IntSGE
case token.NEQ:
panic("NEQ is handled in govalue.BinaryOp")
default:
panic("unreachable")
}
result = fr.builder.CreateICmp(pred, result, zero, "")
result = fr.builder.CreateZExt(result, llvm.Int8Type(), "")
return newValue(result, types.Typ[types.Bool])
}
示例5: emitInitPrologue
// emitInitPrologue emits the init-specific function prologue (guard check and
// initialization of dependent packages under the llgo native ABI), and returns
// the basic block into which the GC registration call should be emitted.
func (fr *frame) emitInitPrologue() llvm.BasicBlock {
if fr.GccgoABI {
return fr.builder.GetInsertBlock()
}
initGuard := llvm.AddGlobal(fr.module.Module, llvm.Int1Type(), "init$guard")
initGuard.SetLinkage(llvm.InternalLinkage)
initGuard.SetInitializer(llvm.ConstNull(llvm.Int1Type()))
returnBlock := llvm.AddBasicBlock(fr.function, "")
initBlock := llvm.AddBasicBlock(fr.function, "")
initGuardVal := fr.builder.CreateLoad(initGuard, "")
fr.builder.CreateCondBr(initGuardVal, returnBlock, initBlock)
fr.builder.SetInsertPointAtEnd(returnBlock)
fr.builder.CreateRetVoid()
fr.builder.SetInsertPointAtEnd(initBlock)
fr.builder.CreateStore(llvm.ConstInt(llvm.Int1Type(), 1, false), initGuard)
int8ptr := llvm.PointerType(fr.types.ctx.Int8Type(), 0)
ftyp := llvm.FunctionType(llvm.VoidType(), []llvm.Type{int8ptr}, false)
for _, pkg := range fr.pkg.Object.Imports() {
initname := ManglePackagePath(pkg.Path()) + "..import"
initfn := fr.module.Module.NamedFunction(initname)
if initfn.IsNil() {
initfn = llvm.AddFunction(fr.module.Module, initname, ftyp)
}
args := []llvm.Value{llvm.Undef(int8ptr)}
fr.builder.CreateCall(initfn, args, "")
}
return initBlock
}
示例6: callRecover
func (fr *frame) callRecover(isDeferredRecover bool) *govalue {
startbb := fr.builder.GetInsertBlock()
recoverbb := llvm.AddBasicBlock(fr.function, "")
contbb := llvm.AddBasicBlock(fr.function, "")
canRecover := fr.builder.CreateTrunc(fr.canRecover, llvm.Int1Type(), "")
fr.builder.CreateCondBr(canRecover, recoverbb, contbb)
fr.builder.SetInsertPointAtEnd(recoverbb)
var recovered llvm.Value
if isDeferredRecover {
recovered = fr.runtime.deferredRecover.call(fr)[0]
} else {
recovered = fr.runtime.recover.call(fr)[0]
}
recoverbb = fr.builder.GetInsertBlock()
fr.builder.CreateBr(contbb)
fr.builder.SetInsertPointAtEnd(contbb)
eface := types.NewInterface(nil, nil)
llv := fr.builder.CreatePHI(fr.types.ToLLVM(eface), "")
llv.AddIncoming(
[]llvm.Value{llvm.ConstNull(llv.Type()), recovered},
[]llvm.BasicBlock{startbb, recoverbb},
)
return newValue(llv, eface)
}
示例7: 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, "")
}
示例8: chanSelect
func (fr *frame) chanSelect(sel *ssa.Select) (index, recvOk *govalue, recvElems []*govalue) {
n := uint64(len(sel.States))
if !sel.Blocking {
// non-blocking means there's a default case
n++
}
size := llvm.ConstInt(llvm.Int32Type(), n, false)
selectp := fr.runtime.newSelect.call(fr, size)[0]
// Allocate stack for the values to send and receive.
ptrs := make([]llvm.Value, len(sel.States))
for i, state := range sel.States {
chantyp := state.Chan.Type().Underlying().(*types.Chan)
elemtyp := fr.types.ToLLVM(chantyp.Elem())
if state.Dir == types.SendOnly {
ptrs[i] = fr.allocaBuilder.CreateAlloca(elemtyp, "")
fr.builder.CreateStore(fr.llvmvalue(state.Send), ptrs[i])
} else {
// Only allocate stack space if the received value is used.
used := chanSelectStateUsed(sel, len(recvElems))
if used {
ptrs[i] = fr.allocaBuilder.CreateAlloca(elemtyp, "")
} else {
ptrs[i] = llvm.ConstNull(llvm.PointerType(llvm.Int8Type(), 0))
}
recvElems = append(recvElems, newValue(ptrs[i], chantyp.Elem()))
}
}
// Create select{send,recv2} calls.
var receivedp llvm.Value
if len(recvElems) > 0 {
receivedp = fr.allocaBuilder.CreateAlloca(fr.types.ToLLVM(types.Typ[types.Bool]), "")
}
if !sel.Blocking {
// If the default case is chosen, the index must be -1.
fr.runtime.selectdefault.call(fr, selectp, llvm.ConstAllOnes(llvm.Int32Type()))
}
for i, state := range sel.States {
ch := fr.llvmvalue(state.Chan)
index := llvm.ConstInt(llvm.Int32Type(), uint64(i), false)
if state.Dir == types.SendOnly {
fr.runtime.selectsend.call(fr, selectp, ch, ptrs[i], index)
} else {
fr.runtime.selectrecv2.call(fr, selectp, ch, ptrs[i], receivedp, index)
}
}
// Fire off the select.
index = newValue(fr.runtime.selectgo.call(fr, selectp)[0], types.Typ[types.Int])
if len(recvElems) > 0 {
recvOk = newValue(fr.builder.CreateLoad(receivedp, ""), types.Typ[types.Bool])
for _, recvElem := range recvElems {
recvElem.value = fr.builder.CreateLoad(recvElem.value, "")
}
}
return index, recvOk, recvElems
}
示例9: memcpy
func (fr *frame) memcpy(dest llvm.Value, src llvm.Value, size llvm.Value) {
memcpy := fr.runtime.memcpy
dest = fr.builder.CreateBitCast(dest, llvm.PointerType(llvm.Int8Type(), 0), "")
src = fr.builder.CreateBitCast(src, llvm.PointerType(llvm.Int8Type(), 0), "")
size = fr.createZExtOrTrunc(size, fr.target.IntPtrType(), "")
align := llvm.ConstInt(llvm.Int32Type(), 1, false)
isvolatile := llvm.ConstNull(llvm.Int1Type())
fr.builder.CreateCall(memcpy, []llvm.Value{dest, src, size, align, isvolatile}, "")
}
示例10: createLandingPad
func (fr *frame) createLandingPad(cleanup bool) llvm.Value {
lp := fr.builder.CreateLandingPad(fr.runtime.gccgoExceptionType, fr.runtime.gccgoPersonality, 0, "")
if cleanup {
lp.SetCleanup(true)
} else {
lp.AddClause(llvm.ConstNull(llvm.PointerType(llvm.Int8Type(), 0)))
}
return lp
}
示例11: getInterfaceValueOrNull
// If cond is true, reads the value from the given interface type, otherwise
// returns a nil value.
func (fr *frame) getInterfaceValueOrNull(cond llvm.Value, v *govalue, ty types.Type) *govalue {
val := fr.builder.CreateExtractValue(v.value, 1, "")
if _, ok := ty.Underlying().(*types.Pointer); ok {
val = fr.builder.CreateSelect(cond, val, llvm.ConstNull(val.Type()), "")
} else {
val = fr.loadOrNull(cond, val, ty).value
}
return newValue(val, ty)
}
示例12: genSizeofExpr
func (v *Codegen) genSizeofExpr(n *parser.SizeofExpr) llvm.Value {
if n.Expr != nil {
gep := v.builder.CreateGEP(llvm.ConstNull(llvm.PointerType(v.typeToLLVMType(n.Expr.GetType()), 0)), []llvm.Value{llvm.ConstInt(llvm.Int32Type(), 1, false)}, "")
return v.builder.CreatePtrToInt(gep, v.typeToLLVMType(n.GetType()), "sizeof")
} else {
// we have a type
panic("can't do this yet")
}
}
示例13: mapIterInit
// mapIterInit creates a map iterator
func (fr *frame) mapIterInit(m *govalue) []*govalue {
// We represent an iterator as a tuple (map, *bool). The second element
// controls whether the code we generate for "next" (below) calls the
// runtime function for the first or the next element. We let the
// optimizer reorganize this into something more sensible.
isinit := fr.allocaBuilder.CreateAlloca(llvm.Int1Type(), "")
fr.builder.CreateStore(llvm.ConstNull(llvm.Int1Type()), isinit)
return []*govalue{m, newValue(isinit, types.NewPointer(types.Typ[types.Bool]))}
}
示例14: Gen
func (n *ForExpr) Gen(cg *CG) llvm.Value {
startVal := n.Start.Gen(cg)
if startVal.IsNil() {
return errv("Code generation failed for start expression")
}
fun := cg.GetInsertBlock().Parent()
alloca := createEntryBlockAlloca(fun, n.Var)
cg.CreateStore(startVal, alloca)
loopBB := llvm.AddBasicBlock(fun, "loop")
cg.CreateBr(loopBB)
cg.SetInsertPointAtEnd(loopBB)
oldVal := cg.NamedValues[n.Var]
cg.NamedValues[n.Var] = alloca
if n.Body.Gen(cg).IsNil() {
return llvm.Value{}
}
var stepVal llvm.Value
if n.Step != nil {
stepVal = n.Step.Gen(cg)
if stepVal.IsNil() {
return llvm.ConstNull(llvm.DoubleType())
}
} else {
stepVal = llvm.ConstFloat(llvm.DoubleType(), 1)
}
endVal := n.End.Gen(cg)
if endVal.IsNil() {
return llvm.Value{}
}
curVar := cg.CreateLoad(alloca, n.Var)
nextVar := cg.CreateFAdd(curVar, stepVal, "nextvar")
cg.CreateStore(nextVar, alloca)
endVal = cg.CreateFCmp(llvm.FloatONE, endVal, llvm.ConstFloat(llvm.DoubleType(), 0), "loopcond")
afterBB := cg.AddBasicBlock(fun, "afterloop")
cg.CreateCondBr(endVal, loopBB, afterBB)
cg.SetInsertPointAtEnd(afterBB)
if !oldVal.IsNil() {
cg.NamedValues[n.Var] = oldVal
} else {
delete(cg.NamedValues, n.Var)
}
return llvm.ConstFloat(llvm.DoubleType(), 0)
}
示例15: makeMap
// makeMap implements make(maptype[, initial space])
func (fr *frame) makeMap(typ types.Type, cap_ *govalue) *govalue {
// TODO(pcc): call __go_new_map_big here if needed
dyntyp := fr.types.getMapDescriptorPointer(typ)
dyntyp = fr.builder.CreateBitCast(dyntyp, llvm.PointerType(llvm.Int8Type(), 0), "")
var cap llvm.Value
if cap_ != nil {
cap = fr.convert(cap_, types.Typ[types.Uintptr]).value
} else {
cap = llvm.ConstNull(fr.types.inttype)
}
m := fr.runtime.newMap.call(fr, dyntyp, cap)
return newValue(m[0], typ)
}