本文整理汇总了Golang中llvm/org/llvm/bindings/go/llvm.Undef函数的典型用法代码示例。如果您正苦于以下问题:Golang Undef函数的具体用法?Golang Undef怎么用?Golang Undef使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Undef函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: encode
func (ri *directRetInfo) encode(ctx llvm.Context, allocaBuilder llvm.Builder, builder llvm.Builder, vals []llvm.Value) {
if len(ri.retTypes) == 0 {
builder.CreateRetVoid()
return
}
var val llvm.Value
switch ri.numResults {
case 1:
val = vals[0]
default:
val = llvm.Undef(ri.resultsType)
for i, v := range vals {
val = builder.CreateInsertValue(val, v, i, "")
}
}
args := make([]llvm.Value, len(ri.retTypes))
directEncode(ctx, allocaBuilder, builder, ri.retTypes, args, val)
var retval llvm.Value
switch len(ri.retTypes) {
case 1:
retval = args[0]
default:
retval = llvm.Undef(ctx.StructType(ri.retTypes, false))
for i, a := range args {
retval = builder.CreateInsertValue(retval, a, i, "")
}
}
builder.CreateRet(retval)
}
示例2: unaryOp
func (fr *frame) unaryOp(v *govalue, op token.Token) *govalue {
switch op {
case token.SUB:
var value llvm.Value
if isComplex(v.typ) {
realv := fr.builder.CreateExtractValue(v.value, 0, "")
imagv := fr.builder.CreateExtractValue(v.value, 1, "")
negzero := llvm.ConstFloatFromString(realv.Type(), "-0")
realv = fr.builder.CreateFSub(negzero, realv, "")
imagv = fr.builder.CreateFSub(negzero, imagv, "")
value = llvm.Undef(v.value.Type())
value = fr.builder.CreateInsertValue(value, realv, 0, "")
value = fr.builder.CreateInsertValue(value, imagv, 1, "")
} else if isFloat(v.typ) {
negzero := llvm.ConstFloatFromString(fr.types.ToLLVM(v.Type()), "-0")
value = fr.builder.CreateFSub(negzero, v.value, "")
} else {
value = fr.builder.CreateNeg(v.value, "")
}
return newValue(value, v.typ)
case token.ADD:
return v // No-op
case token.NOT:
value := fr.builder.CreateXor(v.value, boolLLVMValue(true), "")
return newValue(value, v.typ)
case token.XOR:
lhs := v.value
rhs := llvm.ConstAllOnes(lhs.Type())
value := fr.builder.CreateXor(lhs, rhs, "")
return newValue(value, v.typ)
default:
panic(fmt.Sprintf("Unhandled operator: %s", op))
}
}
示例3: generateVarDecl
func (c *Codegen) generateVarDecl(node *parser.VarDeclNode, global bool) {
t := c.getLLVMType(node.Type)
name := node.Name.Value
if c.scope.Declared(name) {
// Error name has already been declared
}
var alloc, val llvm.Value
if node.Value == nil {
if t.TypeKind() == llvm.PointerTypeKind {
val = c.convert(c.scope.GetValue("null"), t)
} else {
val = llvm.Undef(t)
}
} else {
val = c.convert(c.generateExpression(node.Value), t)
}
if !global {
alloc = c.builder.CreateAlloca(t, name)
c.builder.CreateStore(val, alloc)
} else {
alloc = llvm.AddGlobal(c.module, t, name)
alloc.SetInitializer(val)
}
c.scope.AddVariable(name, alloc)
}
示例4: genDefaultValue
func (v *Codegen) genDefaultValue(typ parser.Type) llvm.Value {
atyp := typ.ActualType()
// Generate default struct values
if structType, ok := atyp.(parser.StructType); ok {
lit := createStructInitializer(typ)
if lit != nil {
return v.genStructLiteral(lit)
} else {
return llvm.Undef(v.typeToLLVMType(structType))
}
}
if tupleType, ok := atyp.(parser.TupleType); ok {
values := make([]llvm.Value, len(tupleType.Members))
for idx, member := range tupleType.Members {
values[idx] = v.genDefaultValue(member)
}
return llvm.ConstStruct(values, false)
}
if atyp.IsIntegerType() || atyp == parser.PRIMITIVE_bool {
return llvm.ConstInt(v.typeToLLVMType(atyp), 0, false)
}
if atyp.IsFloatingType() {
return llvm.ConstFloat(v.typeToLLVMType(atyp), 0)
}
panic("type does not have default value: " + atyp.TypeName())
}
示例5: callBuiltin
func (fr *frame) callBuiltin(typ types.Type, builtin *ssa.Builtin, args []ssa.Value) []*govalue {
switch builtin.Name() {
case "print", "println":
llargs := make([]*govalue, len(args))
for i, arg := range args {
llargs[i] = fr.value(arg)
}
fr.printValues(builtin.Name() == "println", llargs...)
return nil
case "panic":
fr.callPanic(fr.value(args[0]))
return nil
case "recover":
return []*govalue{fr.callRecover(false)}
case "append":
return []*govalue{fr.callAppend(fr.value(args[0]), fr.value(args[1]))}
case "close":
fr.chanClose(fr.value(args[0]))
return nil
case "cap":
return []*govalue{fr.callCap(fr.value(args[0]))}
case "len":
return []*govalue{fr.callLen(fr.value(args[0]))}
case "copy":
return []*govalue{fr.callCopy(fr.value(args[0]), fr.value(args[1]))}
case "delete":
fr.mapDelete(fr.value(args[0]), fr.value(args[1]))
return nil
case "real":
return []*govalue{fr.extractRealValue(fr.value(args[0]))}
case "imag":
return []*govalue{fr.extractImagValue(fr.value(args[0]))}
case "complex":
r := fr.llvmvalue(args[0])
i := fr.llvmvalue(args[1])
cmplx := llvm.Undef(fr.llvmtypes.ToLLVM(typ))
cmplx = fr.builder.CreateInsertValue(cmplx, r, 0, "")
cmplx = fr.builder.CreateInsertValue(cmplx, i, 1, "")
return []*govalue{newValue(cmplx, typ)}
case "ssa:wrapnilchk":
ptr := fr.value(args[0])
fr.nilCheck(args[0], ptr.value)
return []*govalue{ptr}
default:
panic("unimplemented: " + builtin.Name())
}
}
示例6: createInitMainFunction
func (c *compiler) createInitMainFunction(mainPkg *ssa.Package) {
int8ptr := llvm.PointerType(c.types.ctx.Int8Type(), 0)
ftyp := llvm.FunctionType(llvm.VoidType(), []llvm.Type{int8ptr}, false)
initMain := llvm.AddFunction(c.module.Module, "__go_init_main", ftyp)
c.addCommonFunctionAttrs(initMain)
entry := llvm.AddBasicBlock(initMain, "entry")
builder := llvm.GlobalContext().NewBuilder()
defer builder.Dispose()
builder.SetInsertPointAtEnd(entry)
args := []llvm.Value{llvm.Undef(int8ptr)}
if !c.GccgoABI {
initfn := c.module.Module.NamedFunction("main..import")
if !initfn.IsNil() {
builder.CreateCall(initfn, args, "")
}
builder.CreateRetVoid()
return
}
initdata := c.buildPackageInitData(mainPkg)
for _, init := range initdata.Inits {
initfn := c.module.Module.NamedFunction(init.InitFunc)
if initfn.IsNil() {
initfn = llvm.AddFunction(c.module.Module, init.InitFunc, ftyp)
}
builder.CreateCall(initfn, args, "")
}
builder.CreateRetVoid()
}
示例7: 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
}
示例8: makeInterfaceFromPointer
func (fr *frame) makeInterfaceFromPointer(vptr llvm.Value, vty types.Type, iface types.Type) *govalue {
i8ptr := llvm.PointerType(llvm.Int8Type(), 0)
llv := fr.builder.CreateBitCast(vptr, i8ptr, "")
value := llvm.Undef(fr.types.ToLLVM(iface))
itab := fr.types.getItabPointer(vty, iface.Underlying().(*types.Interface))
value = fr.builder.CreateInsertValue(value, itab, 0, "")
value = fr.builder.CreateInsertValue(value, llv, 1, "")
return newValue(value, iface)
}
示例9: convertI2E
// convertI2E converts a non-empty interface value to an empty interface.
func (fr *frame) convertI2E(v *govalue) *govalue {
td := fr.getInterfaceTypeDescriptor(v)
val := fr.builder.CreateExtractValue(v.value, 1, "")
typ := types.NewInterface(nil, nil)
intf := llvm.Undef(fr.types.ToLLVM(typ))
intf = fr.builder.CreateInsertValue(intf, td, 0, "")
intf = fr.builder.CreateInsertValue(intf, val, 1, "")
return newValue(intf, typ)
}
示例10: genTupleLiteral
func (v *Codegen) genTupleLiteral(n *parser.TupleLiteral) llvm.Value {
tupleLLVMType := v.typeToLLVMType(n.Type)
tupleValue := llvm.Undef(tupleLLVMType)
for idx, mem := range n.Members {
memberValue := v.genExpr(mem)
if !v.inFunction() && !memberValue.IsConstant() {
v.err("Encountered non-constant value in global tuple literal")
}
tupleValue = v.builder().CreateInsertValue(tupleValue, memberValue, idx, "")
}
return tupleValue
}
示例11: changeInterface
func (fr *frame) changeInterface(v *govalue, ty types.Type, assert bool) *govalue {
td := fr.getInterfaceTypeDescriptor(v)
tytd := fr.types.ToRuntime(ty)
var itab llvm.Value
if assert {
itab = fr.runtime.assertInterface.call(fr, tytd, td)[0]
} else {
itab = fr.runtime.convertInterface.call(fr, tytd, td)[0]
}
val := fr.builder.CreateExtractValue(v.value, 1, "")
intf := llvm.Undef(fr.types.ToLLVM(ty))
intf = fr.builder.CreateInsertValue(intf, itab, 0, "")
intf = fr.builder.CreateInsertValue(intf, val, 1, "")
return newValue(intf, ty)
}
示例12: genEnumLiteral
func (v *Codegen) genEnumLiteral(n *parser.EnumLiteral) llvm.Value {
enumType := n.Type.ActualType().(parser.EnumType)
enumLLVMType := v.typeToLLVMType(n.Type)
memberIdx := enumType.MemberIndex(n.Member)
member := enumType.Members[memberIdx]
if enumType.Simple {
return llvm.ConstInt(enumLLVMType, uint64(member.Tag), false)
}
// TODO: Handle other integer size, maybe dynamic depending on max value?
tagValue := llvm.ConstInt(llvm.IntType(32), uint64(member.Tag), false)
enumValue := llvm.Undef(enumLLVMType)
enumValue = v.builder().CreateInsertValue(enumValue, tagValue, 0, "")
memberLLVMType := v.typeToLLVMType(member.Type)
var memberValue llvm.Value
if n.TupleLiteral != nil {
memberValue = v.genTupleLiteral(n.TupleLiteral)
} else if n.CompositeLiteral != nil {
memberValue = v.genCompositeLiteral(n.CompositeLiteral)
}
if v.inFunction() {
alloc := v.builder().CreateAlloca(enumLLVMType, "")
tagGep := v.builder().CreateStructGEP(alloc, 0, "")
v.builder().CreateStore(tagValue, tagGep)
if !memberValue.IsNil() {
dataGep := v.builder().CreateStructGEP(alloc, 1, "")
dataGep = v.builder().CreateBitCast(dataGep, llvm.PointerType(memberLLVMType, 0), "")
v.builder().CreateStore(memberValue, dataGep)
}
return v.builder().CreateLoad(alloc, "")
} else {
panic("unimplemented: global enum literal")
}
}
示例13: call
func (fi *functionTypeInfo) call(ctx llvm.Context, allocaBuilder llvm.Builder, builder llvm.Builder, callee llvm.Value, chain llvm.Value, args []llvm.Value) []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.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)
}
示例14: genArrayLiteral
// Allocates a literal array on the stack
func (v *Codegen) genArrayLiteral(n *parser.CompositeLiteral) llvm.Value {
arrayLLVMType := v.typeToLLVMType(n.Type)
memberLLVMType := v.typeToLLVMType(n.Type.ActualType().(parser.ArrayType).MemberType)
arrayValues := make([]llvm.Value, len(n.Values))
for idx, mem := range n.Values {
value := v.genExpr(mem)
if !v.inFunction() && !value.IsConstant() {
v.err("Encountered non-constant value in global array")
}
arrayValues[idx] = value
}
lengthValue := llvm.ConstInt(v.typeToLLVMType(parser.PRIMITIVE_uint), uint64(len(n.Values)), false)
var backingArrayPointer llvm.Value
if v.inFunction() {
// allocate backing array
backingArray := v.builder().CreateAlloca(llvm.ArrayType(memberLLVMType, len(n.Values)), "")
// copy the constant array to the backing array
for idx, value := range arrayValues {
gep := v.builder().CreateStructGEP(backingArray, idx, "")
v.builder().CreateStore(value, gep)
}
backingArrayPointer = v.builder().CreateBitCast(backingArray, llvm.PointerType(memberLLVMType, 0), "")
} else {
backName := fmt.Sprintf("_globarr_back_%d", v.arrayIndex)
v.arrayIndex++
backingArray := llvm.AddGlobal(v.curFile.LlvmModule, llvm.ArrayType(memberLLVMType, len(n.Values)), backName)
backingArray.SetLinkage(llvm.InternalLinkage)
backingArray.SetGlobalConstant(false)
backingArray.SetInitializer(llvm.ConstArray(memberLLVMType, arrayValues))
backingArrayPointer = llvm.ConstBitCast(backingArray, llvm.PointerType(memberLLVMType, 0))
}
structValue := llvm.Undef(arrayLLVMType)
structValue = v.builder().CreateInsertValue(structValue, lengthValue, 0, "")
structValue = v.builder().CreateInsertValue(structValue, backingArrayPointer, 1, "")
return structValue
}
示例15: genStructLiteral
func (v *Codegen) genStructLiteral(n *parser.StructLiteral) llvm.Value {
structType := n.Type.ActualType().(*parser.StructType)
structLLVMType := v.typeToLLVMType(structType)
structValue := llvm.Undef(structLLVMType)
for name, value := range n.Values {
vari := structType.GetVariableDecl(name).Variable
idx := structType.VariableIndex(vari)
memberValue := v.genExpr(value)
if !v.inFunction && !memberValue.IsConstant() {
v.err("Encountered non-constant value in global struct literal")
}
structValue = v.builder.CreateInsertValue(structValue, v.genExpr(value), idx, "")
}
return structValue
}